Skip to content

Commit

Permalink
Properly handle Escape key in native Window event handling function i…
Browse files Browse the repository at this point in the history
…f event WM_EXITSIZEMOVE occurs
  • Loading branch information
githubuser0xFFFF committed May 27, 2020
1 parent 277e066 commit dfb8543
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 41 deletions.
51 changes: 11 additions & 40 deletions src/FloatingDockContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
namespace ads
{
#ifdef Q_OS_WIN
#if 0 // set to 1 if you need this function for debugging
/**
* Just for debuging to convert windows message identifiers to strings
*/
Expand Down Expand Up @@ -350,6 +351,7 @@ static const char* windowsMessageString(int MessageId)
return "unknown WM_ message";
}
#endif
#endif


static unsigned int zOrderCounter = 0;
Expand Down Expand Up @@ -713,7 +715,6 @@ bool CFloatingDockContainer::nativeEvent(const QByteArray &eventType, void *mess
if (d->isState(DraggingMousePressed))
{
ADS_PRINT("CFloatingDockContainer::nativeEvent WM_ENTERSIZEMOVE" << e->type());
qApp->installEventFilter(this);
d->setState(DraggingFloatingWidget);
d->updateDropOverlays(QCursor::pos());
}
Expand All @@ -722,8 +723,15 @@ bool CFloatingDockContainer::nativeEvent(const QByteArray &eventType, void *mess
case WM_EXITSIZEMOVE:
if (d->isState(DraggingFloatingWidget))
{
ADS_PRINT("CFloatingDockContainer::nativeEvent WM_EXITSIZEMOVE" << e->type());;
d->titleMouseReleaseEvent();
ADS_PRINT("CFloatingDockContainer::nativeEvent WM_EXITSIZEMOVE" << e->type());
if (GetAsyncKeyState(VK_ESCAPE) & 0x8000)
{
d->handleEscapeKey();
}
else
{
d->titleMouseReleaseEvent();
}
}
break;
}
Expand Down Expand Up @@ -796,43 +804,6 @@ void CFloatingDockContainer::showEvent(QShowEvent *event)
}


//============================================================================
bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *e)
{
Q_UNUSED(watched);
// I have not found a way to detect non client area key press events to
// handle escape key presses. On Windows, if the escape key is pressed while
// dragging around a widget, the widget position is reset to its start position
// which in turn generates a QEvent::NonClientAreaMouseButtonRelease event
// if the mouse is outside of the widget after the move to its initial position
// or a QEvent::MouseButtonRelease event, if the mouse is inside of teh widget
// after the position has been reset.
// So we can install an event filter on the application to get these events
// here to properly cancel dragging and hide the overlays.
// If we are in DraggingFloatingWidget state, it means the widget
// has been dragged already but if the position is the same like
// the start position, then this is an indication that the escape
// key has been pressed.
if (e->type() == QEvent::MouseButtonRelease || e->type() == QEvent::NonClientAreaMouseButtonRelease)
{
ADS_PRINT("CFloatingDockContainer::eventFilter QEvent::MouseButtonRelease or"
"QEvent::NonClientAreaMouseButtonRelease" << "d->DragggingState " << d->DraggingState);
qApp->removeEventFilter(this);
if (d->DragStartPos == pos())
{
d->handleEscapeKey();
return true;
}
return false;
}

#if (ADS_DEBUG_LEVEL > 0)
qDebug() << QTime::currentTime() << "CFloatingDockContainer::eventFilter " << e->type();
#endif
return false;
}


//============================================================================
void CFloatingDockContainer::startFloating(const QPoint &DragStartMousePos,
const QSize &Size, eDragState DragState, QWidget *MouseEventHandler)
Expand Down
1 change: 0 additions & 1 deletion src/FloatingDockContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ private slots:
virtual void closeEvent(QCloseEvent *event) override;
virtual void hideEvent(QHideEvent *event) override;
virtual void showEvent(QShowEvent *event) override;
virtual bool eventFilter(QObject *watched, QEvent *event) override;

#ifdef Q_OS_WIN
/**
Expand Down

0 comments on commit dfb8543

Please sign in to comment.