Skip to content

Commit dfb8543

Browse files
Properly handle Escape key in native Window event handling function if event WM_EXITSIZEMOVE occurs
1 parent 277e066 commit dfb8543

File tree

2 files changed

+11
-41
lines changed

2 files changed

+11
-41
lines changed

src/FloatingDockContainer.cpp

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
namespace ads
5858
{
5959
#ifdef Q_OS_WIN
60+
#if 0 // set to 1 if you need this function for debugging
6061
/**
6162
* Just for debuging to convert windows message identifiers to strings
6263
*/
@@ -350,6 +351,7 @@ static const char* windowsMessageString(int MessageId)
350351
return "unknown WM_ message";
351352
}
352353
#endif
354+
#endif
353355

354356

355357
static unsigned int zOrderCounter = 0;
@@ -713,7 +715,6 @@ bool CFloatingDockContainer::nativeEvent(const QByteArray &eventType, void *mess
713715
if (d->isState(DraggingMousePressed))
714716
{
715717
ADS_PRINT("CFloatingDockContainer::nativeEvent WM_ENTERSIZEMOVE" << e->type());
716-
qApp->installEventFilter(this);
717718
d->setState(DraggingFloatingWidget);
718719
d->updateDropOverlays(QCursor::pos());
719720
}
@@ -722,8 +723,15 @@ bool CFloatingDockContainer::nativeEvent(const QByteArray &eventType, void *mess
722723
case WM_EXITSIZEMOVE:
723724
if (d->isState(DraggingFloatingWidget))
724725
{
725-
ADS_PRINT("CFloatingDockContainer::nativeEvent WM_EXITSIZEMOVE" << e->type());;
726-
d->titleMouseReleaseEvent();
726+
ADS_PRINT("CFloatingDockContainer::nativeEvent WM_EXITSIZEMOVE" << e->type());
727+
if (GetAsyncKeyState(VK_ESCAPE) & 0x8000)
728+
{
729+
d->handleEscapeKey();
730+
}
731+
else
732+
{
733+
d->titleMouseReleaseEvent();
734+
}
727735
}
728736
break;
729737
}
@@ -796,43 +804,6 @@ void CFloatingDockContainer::showEvent(QShowEvent *event)
796804
}
797805

798806

799-
//============================================================================
800-
bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *e)
801-
{
802-
Q_UNUSED(watched);
803-
// I have not found a way to detect non client area key press events to
804-
// handle escape key presses. On Windows, if the escape key is pressed while
805-
// dragging around a widget, the widget position is reset to its start position
806-
// which in turn generates a QEvent::NonClientAreaMouseButtonRelease event
807-
// if the mouse is outside of the widget after the move to its initial position
808-
// or a QEvent::MouseButtonRelease event, if the mouse is inside of teh widget
809-
// after the position has been reset.
810-
// So we can install an event filter on the application to get these events
811-
// here to properly cancel dragging and hide the overlays.
812-
// If we are in DraggingFloatingWidget state, it means the widget
813-
// has been dragged already but if the position is the same like
814-
// the start position, then this is an indication that the escape
815-
// key has been pressed.
816-
if (e->type() == QEvent::MouseButtonRelease || e->type() == QEvent::NonClientAreaMouseButtonRelease)
817-
{
818-
ADS_PRINT("CFloatingDockContainer::eventFilter QEvent::MouseButtonRelease or"
819-
"QEvent::NonClientAreaMouseButtonRelease" << "d->DragggingState " << d->DraggingState);
820-
qApp->removeEventFilter(this);
821-
if (d->DragStartPos == pos())
822-
{
823-
d->handleEscapeKey();
824-
return true;
825-
}
826-
return false;
827-
}
828-
829-
#if (ADS_DEBUG_LEVEL > 0)
830-
qDebug() << QTime::currentTime() << "CFloatingDockContainer::eventFilter " << e->type();
831-
#endif
832-
return false;
833-
}
834-
835-
836807
//============================================================================
837808
void CFloatingDockContainer::startFloating(const QPoint &DragStartMousePos,
838809
const QSize &Size, eDragState DragState, QWidget *MouseEventHandler)

src/FloatingDockContainer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ private slots:
180180
virtual void closeEvent(QCloseEvent *event) override;
181181
virtual void hideEvent(QHideEvent *event) override;
182182
virtual void showEvent(QShowEvent *event) override;
183-
virtual bool eventFilter(QObject *watched, QEvent *event) override;
184183

185184
#ifdef Q_OS_WIN
186185
/**

0 commit comments

Comments
 (0)