Skip to content

Commit

Permalink
QT GUI: close window with cmd-w on macos
Browse files Browse the repository at this point in the history
this is a workaround for a workaround introduced in #4105, which fixed #4058, but caused #4309
  • Loading branch information
dyfer committed Mar 13, 2020
1 parent f6cf834 commit 28682e6
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions QtCollider/QcApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,25 @@ bool QcApplication::event(QEvent* event) {
}

bool QcApplication::notify(QObject* object, QEvent* event) {
#ifdef Q_OS_MAC
bool isCloseEvent = false;
bool isKeyEvent = false;
#endif
switch (event->type()) {
case QEvent::KeyPress: {
QKeyEvent* kevent = static_cast<QKeyEvent*>(event);
if (_handleCmdPeriod && (kevent->key() == Qt::Key_Period) && (kevent->modifiers() & Qt::ControlModifier)) {
static QString cmdPeriodCommand("CmdPeriod.run");
interpret(cmdPeriodCommand, false);
}
#ifdef Q_OS_MAC
if ((kevent->key() != Qt::Key_unknown)) {
isKeyEvent = true; // true for regular keys pressed, but not modifiers alone
}
if ((kevent->key() == Qt::Key_W) && (kevent->modifiers() == Qt::ControlModifier)) {
isCloseEvent = true;
}
#endif
break;
}
case QEvent::Wheel: {
Expand All @@ -185,8 +197,12 @@ bool QcApplication::notify(QObject* object, QEvent* event) {
// This is a hack; for a not-fully-understood reason Qt past 5.7 sends these events to the
// native window if they aren't accepted here. This caused issue #4058. Accepting them here
// seems to solve the problem, but might cause other issues since it is a heavy-handed way
// of doing this. TODO - solve more elegantly
if (result)
// of doing this.
// In order to still allow closing GUI windows with "cmd-w", we do not accept modifier keys
// alone, as well as the "cmd-w" combination itself, so that they propagate further
// (see isKeyEvent and isCloseEvent above).
// TODO - solve more elegantly
if (result && isKeyEvent && (!isCloseEvent))
event->accept();
#endif
return result;
Expand Down

0 comments on commit 28682e6

Please sign in to comment.