CMD+W is the standard shortcut in macOS to close a window without exiting the program.
This adds support to use the shortcut in both main and debug windows.
CMD+W is the standard shortcut in macOS to close a window without exiting the program.
This adds support to use the shortcut in both main and debug windows.
Thanks! Tested ACK 20859aef8b571542772a42b4c413c4a71a6576c5
The macOS HIG about Command+W: https://developer.apple.com/design/human-interface-guidelines/macos/user-interaction/keyboard/
408@@ -409,6 +409,10 @@ void BitcoinGUI::createActions()
409
410 connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C), this), &QShortcut::activated, this, &BitcoinGUI::showDebugWindowActivateConsole);
411 connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_D), this), &QShortcut::activated, this, &BitcoinGUI::showDebugWindow);
412+
413+#ifdef Q_OS_MAC
GUIUtil::handleHideShortcut(QWdiget*)
? There are dialogs, like coin control dialog, transaction details, that could use the same feature.
408@@ -409,6 +409,10 @@ void BitcoinGUI::createActions()
409
410 connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C), this), &QShortcut::activated, this, &BitcoinGUI::showDebugWindowActivateConsole);
411 connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_D), this), &QShortcut::activated, this, &BitcoinGUI::showDebugWindow);
412+
413+#ifdef Q_OS_MAC
414+ connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this), &QShortcut::activated, this, [this]() { this->hide(); });
... , &QShortcut::activated, this, &QWidget::hide)
?
bitcoind
binary built on a Ubuntu 18.04 machine with this patch applied is identical to a disassembly of the bitcoind
binary built against master
(as expected).
utACK, ideally this kind of stuff would be handled by the cross-platform windowing system, so it’s a bit disappointing that it’s not, but also, this is only a few lines and increases user friendliness.
BTW: CTRL-W is also quite a common shortcut for closing windows in applications outside of OS-X, for example in browsers it closes the tab.
I will do the suggested changes and add the functionality to all the windows.
Thanks for the review.
QShortcut
has a Qt::ApplicationShortcut
for application-global shortcuts (see https://doc.qt.io/Qt-5/qt.html#ShortcutContext-enum )—would this be useful here?
I have updated the PR with the given suggestions and added the shortcut to most windows.
The only one without this shortcut is the ‘About Qt’ as it is part of Qt and I have not been able to add the shortcut to it.
If I have missed any other window please let me know.
@laanwj Qt::ApplicationShortcut
does not work for the intended purpose. It makes the shortcut works even if it is not focused.
@luke-jr CMD+W is usually only used on macOS, more information can be found in the macOS HID posted by @jonasschnelli and in Wikepedia’s Table of keyboard shortcuts.
I use Ctrl+W on Linux all the time to close browser tabs. My IRC client seems to use it for closing tabs too.
Furthermore, if macOS is using it, we can’t use it for anything else (eg, closing wallets?).
So overall, I’d say it makes sense to just support it on all platforms.
159@@ -158,6 +160,8 @@ ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f):
160 tr("%1 is shutting down...").arg(tr(PACKAGE_NAME)) + "<br /><br />" +
161 tr("Do not shut down the computer until this window disappears.")));
162 setLayout(layout);
163+
164+ GUIUtil::handleHideShortcut(this);
370@@ -370,6 +371,13 @@ void bringToFront(QWidget* w)
371 }
372 }
373
374+void handleHideShortcut(QWidget* w)
375+{
376+#ifdef Q_OS_MAC
377+ w->connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), w), &QShortcut::activated, w, &QWidget::hide);
QShortcut
?
I have followed the official documentation in this regard[0]. If you consider that this is not a correct application please let me know a more appropriate way.
I use Ctrl+W on Linux all the time to close browser tabs. My IRC client seems to use it for closing tabs too.
Furthermore, if macOS is using it, we can’t use it for anything else (eg, closing wallets?).
So overall, I’d say it makes sense to just support it on all platforms.
I wasn’t aware that this shortcut was also commonly used in other OSs other than macOS. Considering this I will remove the ifdef to support all OSs.
Probably a number of windows ought to be closed normally, not merely hidden?
I agree and after reading the QT documentation I will replace the hide
call with a close
call.
Should I continue working on this PR considering that the name of the branch is add_cmd_w_support_in_macos
or would it be preferable to create another PR?
Two jobs failed in Travis CI during the set up:
I have not found a way to force a re-run. Nevertheless the other jobs completed successfully.
209@@ -210,6 +210,8 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
210 #ifdef Q_OS_MAC
211 m_app_nap_inhibitor = new CAppNapInhibitor;
212 #endif
213+
214+ GUIUtil::handleCloseWindowShortcut(this);
7@@ -8,6 +8,7 @@
8
9 #include <qt/splashscreen.h>
10
11+#include <qt/guiutil.h>
The rationale for adding the shortcut here is that on every window with an enabled close button the shortcut should be applicable.
It could be worth it taking into consideration disabling the close button or removing the bar all together.
114@@ -114,6 +115,8 @@ HelpMessageDialog::HelpMessageDialog(interfaces::Node& node, QWidget *parent, bo
115 ui->scrollArea->setVisible(false);
116 ui->aboutLogo->setVisible(false);
117 }
118+
119+ GUIUtil::handleCloseWindowShortcut(this);
Which of the following cases is preferable?
Two windows with their close behaviour consistent among them but inconsistent with the behaviour of the rest of them or keeping the inconsistency only on the QT window?
155@@ -153,6 +156,8 @@ ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f):
156 tr("%1 is shutting down...").arg(PACKAGE_NAME) + "<br /><br />" +
157 tr("Do not shut down the computer until this window disappears.")));
158 setLayout(layout);
159+
160+ GUIUtil::handleCloseWindowShortcut(this);
378@@ -378,6 +379,11 @@ void bringToFront(QWidget* w)
379 }
380 }
381
382+void handleCloseWindowShortcut(QWidget* w)
383+{
384+ w->connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), w), &QShortcut::activated, w, &QWidget::close);
QObject::connect()
is a static function of QObject
:
0 QObject::connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), w), &QShortcut::activated, w, &QWidget::close);
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
CMD+W/CTRL+W is the standard shortcut to close a window without
exiting the program.
Ctrl+W
shortcut. Also tested with “Minimize on close” option enabled / disabled.