Skip to content

Conversation

@IPGlider
Copy link
Contributor

@IPGlider IPGlider commented Apr 7, 2019

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.

@jonasschnelli
Copy link
Contributor

Thanks!
Tested ACK 20859aef8b571542772a42b4c413c4a71a6576c5

The macOS HIG about Command+W:
https://developer.apple.com/design/human-interface-guidelines/macos/user-interaction/keyboard/

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pressing ESC also closes the dialogs (except the main window). Is this something to keep in macos? (not suggesting it though, just want to mention the redundancy)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind moving this to something like GUIUtil::handleHideShortcut(QWdiget*)? There are dialogs, like coin control dialog, transaction details, that could use the same feature.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to lambda, could just be ... , &QShortcut::activated, this, &QWidget::hide)?

@practicalswift
Copy link
Contributor

FWIW: I've verified that a disassembly of the 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).

@laanwj
Copy link
Member

laanwj commented Apr 10, 2019

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.

@IPGlider
Copy link
Contributor Author

I will do the suggested changes and add the functionality to all the windows.

Thanks for the review.

@laanwj
Copy link
Member

laanwj commented Apr 10, 2019

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?

@luke-jr
Copy link
Member

luke-jr commented Apr 18, 2019

Any reason not to enable this on all platforms?

@IPGlider IPGlider force-pushed the add_cmd_w_support_in_macos branch from 20859ae to 263c383 Compare April 19, 2019 10:25
@IPGlider
Copy link
Contributor Author

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.

@luke-jr
Copy link
Member

luke-jr commented Apr 19, 2019

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.

@luke-jr
Copy link
Member

luke-jr commented Apr 20, 2019

Note: When extending it to support other platforms, care needs to be taken that the main window is not actually hidden if there's no system tray icon. Probably should minimise in that case? Not sure...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this to be hide-able??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The criteria I followed to make windows hide-able has been what I understand is the common usage in macOS, meaning that every window that has a close button can also be closed using the CMD+W shortcut.

@luke-jr
Copy link
Member

luke-jr commented Apr 20, 2019

Probably a number of windows ought to be closed normally, not merely hidden?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked closely at this,... but is there a proper deallocation of that QShortcut?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

[0] https://doc.qt.io/qt-5/qobject.html

@hebasto
Copy link
Member

hebasto commented Aug 1, 2019

@IPGlider Could you address reviewers' comments?

@IPGlider
Copy link
Contributor Author

IPGlider commented Aug 2, 2019

Is working in this PR still worth it? I would like to finish it.

@hebasto I will address the comments in a few days.

@fanquake fanquake reopened this Aug 2, 2019
@hebasto
Copy link
Member

hebasto commented Aug 3, 2019

@IPGlider

Is working in this PR still worth it?

Yes, IMO.

@IPGlider
Copy link
Contributor Author

IPGlider commented Aug 5, 2019

@luke-jr

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?

@fanquake
Copy link
Member

fanquake commented Aug 6, 2019

@IPGlider No need for a new PR. Just update the PR title, body etc if required.

@IPGlider IPGlider changed the title gui: Add CMD+W shortcut in macOS gui: Add close window shortcut Aug 6, 2019
@IPGlider IPGlider force-pushed the add_cmd_w_support_in_macos branch 2 times, most recently from 8eec051 to ab589f0 Compare August 6, 2019 15:00
@IPGlider IPGlider force-pushed the add_cmd_w_support_in_macos branch from e0cd6f3 to fa166a9 Compare November 10, 2019 13:39
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Nov 15, 2019
CMD+W/CTRL+W is the standard shortcut to close a window without
exiting the program.

Github-Pull: bitcoin#15768
Rebased-From: e0cd6f3c9c809f9876ff7d69ae91a9e67434be58
MarkLTZ added a commit to litecoinz-core/litecoinz that referenced this pull request Nov 17, 2019
@IPGlider IPGlider force-pushed the add_cmd_w_support_in_macos branch from fa166a9 to 77b0232 Compare December 22, 2019 14:04
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Jan 5, 2020
CMD+W/CTRL+W is the standard shortcut to close a window without
exiting the program.

Github-Pull: bitcoin#15768
Rebased-From: 77b0232fcb0f7b7c28a041ebbe18b6205aea5db2
@IPGlider IPGlider force-pushed the add_cmd_w_support_in_macos branch from 77b0232 to 7d99b3b Compare January 24, 2020 06:15
MarkLTZ added a commit to litecoinz-core/litecoinz that referenced this pull request Feb 3, 2020
Fix intro dialog labels when the prune button is toggled (bitcoin#17453)
Rename debug window (bitcoin#17096)
Add close window shortcut (bitcoin#15768)
Add privacy to the Overview page (bitcoin#16432)
Remove WalletView and BitcoinGUI circular dependency (bitcoin#17937)
Force set nPruneSize in QSettings after the intro dialog (bitcoin#17696)
CMD+W/CTRL+W is the standard shortcut to close a window without
exiting the program.
Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK f5a3a5b, tested on Linux Mint 19.3 by manually opening available dialogs and sub-windows, and applying the Ctrl+W shortcut. Also tested with "Minimize on close" option enabled / disabled.

@jonasschnelli
Copy link
Contributor

Tested ACK f5a3a5b

@jonasschnelli jonasschnelli merged commit afa577c into bitcoin:master May 4, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 4, 2020
f5a3a5b gui: Add close window shortcut (Miguel Herranz)

Pull request description:

  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.

ACKs for top commit:
  jonasschnelli:
    Tested ACK f5a3a5b
  hebasto:
    ACK f5a3a5b, tested on Linux Mint 19.3 by manually opening available dialogs and sub-windows, and applying the `Ctrl+W` shortcut. Also tested with "Minimize on close" option enabled / disabled.

Tree-SHA512: 39851f6680cf97c334d5759c6f8597cb45685359417493ff8b0566672edbd32303fa15ac4260ec8ab5ea1458a600a329153014f25609e1db9cf399aa851ae2f9
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Jun 9, 2020
CMD+W/CTRL+W is the standard shortcut to close a window without
exiting the program.

Github-Pull: bitcoin#15768
Rebased-From: f5a3a5b
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jan 26, 2021
Summary:
> CMD+W/CTRL+W is the standard shortcut to close a window without
> exiting the program.

This is a backport of Core [[bitcoin/bitcoin#15768 | PR15768]]

Test Plan:
`ninja && src/qt/bitcoin-qt`

Try Ctrl+W in various dialogs (e.g. in the RPC console)

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9070
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants