gui: Add GUIUtil::bringToFront #14123

pull promag wants to merge 6 commits into bitcoin:master from promag:2018-08-bringtofront changing 7 files +76 −159
  1. promag commented at 10:39 pm on August 31, 2018: member

    The sequence show -> raise -> activateWindow is factored out to the new function GUIUtil::bringToFront where a macOS fix is added in order to fix #13829.

    Also included:

    • simplification of BitcoinGUI::showNormalIfMinimized
    • simplified some connections to BitcoinGUI::showNormalIfMinimized
    • added missing connections to BitcoinGUI::showNormalIfMinimized.
  2. promag commented at 10:41 pm on August 31, 2018: member
    @jonasschnelli @Sjors @ken2812221 review/test much appreciated.
  3. DrahtBot commented at 10:45 pm on August 31, 2018: member

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #14594 (qt:Fix minimized window bug on Linux by hebasto)
    • #11625 (Add BitcoinApplication & RPCConsole tests by ryanofsky)

    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.

  4. fanquake added the label GUI on Aug 31, 2018
  5. in src/qt/bitcoingui.cpp:275 in f2cd3275dd outdated
    273@@ -274,15 +274,15 @@ void BitcoinGUI::createActions()
    274     // can be triggered from the tray menu, and need to show the GUI to be useful.
    275     connect(overviewAction, &QAction::triggered, this, static_cast<void (BitcoinGUI::*)()>(&BitcoinGUI::showNormalIfMinimized));
    


    ken2812221 commented at 6:24 am on September 1, 2018:
    Any reason to keep this one?

    promag commented at 7:53 am on September 1, 2018:
    Thanks.
  6. promag force-pushed on Sep 1, 2018
  7. laanwj commented at 9:41 am on September 1, 2018: member
    I think it would make sense, for ease of review, to split off the fix to #13829 from pure refactoring.
  8. promag commented at 10:02 am on September 1, 2018: member

    Which refactor?

    Note that the issue is observed in more places than the one reported in #13829.

  9. in src/qt/guiutil.cpp:370 in eed869b834 outdated
    366@@ -357,6 +367,21 @@ bool isObscured(QWidget *w)
    367         && checkPoint(QPoint(w->width() / 2, w->height() / 2), w));
    368 }
    369 
    370+void bringToFront(QWidget *w)
    371+{
    372+#ifdef Q_OS_MAC
    373+    id app = objc_msgSend((id) objc_getClass("NSApplication"), sel_registerName("sharedApplication"));
    374+    objc_msgSend(app, sel_getUid("activateIgnoringOtherApps:"), YES);
    


    Sjors commented at 7:38 am on September 2, 2018:
    Apple documentation suggests that this normally shouldn’t be needed, which suggests there’s a deeper problem somewhere.

    fanquake commented at 8:15 am on September 2, 2018:
    I’d also like to know a bit more about this, and the new <objc/objc-runtime.h> #include.

    fanquake commented at 10:24 am on October 28, 2018:

    @promag Can you comment here on why we need to manually do this? For reference Apples docs state:

    You rarely need to invoke this method. Under most circumstances, AppKit takes care of proper activation. However, you might find this method useful if you implement your own methods for inter-app communication.

    so I’d have thought this would be something handled by Qt. There are a couple mentions of this specific flag in the cocoa integration plugin, as well as use in the QCocoaWindow::raise() method.


    promag commented at 11:05 am on October 29, 2018:
    Sure.

    promag commented at 12:14 pm on October 29, 2018:
    Added comment.

    hebasto commented at 9:02 pm on November 2, 2018:

    According to the sel_getUid documentation:

    The implementation of this method is identical to the implementation of sel_registerName.

    On master(750415701):

    • sel_registerName used 4 times
    • sel_getUid not used at all

    Could sel_getUid replace with sel_registerName?

  10. Sjors approved
  11. Sjors commented at 7:43 am on September 2, 2018: member

    tACK eed869b on macOS, this indeed fixes #13829.

    The change from static_cast<void (BitcoinGUI::*)()> to [this] is most eye pleasing :-)

    I think @laanwj is referring to e.g. the new bringToFront() function which contains both existing and new code. I didn’t find it too confusing though.

  12. fanquake commented at 8:14 am on September 2, 2018: member

    Testing current master on macOS 10.13.6 https://github.com/bitcoin/bitcoin/commit/2070a545e2c4e8c2dff4c0fb40b8fd2f68fc2ca. If Command + H or the menu item is used to hide the window:

    • Clicking the task bar icon shows the window.
    • Clicking show/hide does not work.
    • Clicking show (bottom of the menu ) does work.
    • If Send or Receive is clicked, the window changes to the correct tab, but the window is not shown.
    • Sign, Verify & Debug all unhide and show the correct dialog.

    Testing https://github.com/bitcoin/bitcoin/pull/14123/commits/eed869b834a0d19318733420ed32f2f0df94d6be. If Command + H or the menu item is used to hide the window:

    • Clicking the task bar icon shows the window.
    • Clicking show/hide does work.
    • Click show (bottom of the menu ) does work.
    • If Send or Receive is clicked, the window changes to the correct tab, and unhides.
    • Sign, Verify & Debug all unhide and show the correct dialog. (this has also fixed the annoying “attention” bounce behaviour that was present before.)
    • When the window has been minimised (CMD + M, which doesn’t actually work at the moment..), only the sign, verify and debug items work, and they only display the sub window, the main window remains minimised. This seems to be a regression, as the options work with current master.
  13. promag commented at 9:41 am on September 2, 2018: member

    Thanks for the reviews! I’ll fix it.

    BTW, in macOS “show/hide” action could be removed since it’s already there natively.

  14. in src/qt/bitcoingui.cpp:352 in eed869b834 outdated
    348@@ -349,7 +349,9 @@ void BitcoinGUI::createActions()
    349         connect(encryptWalletAction, &QAction::triggered, walletFrame, &WalletFrame::encryptWallet);
    350         connect(backupWalletAction, &QAction::triggered, walletFrame, &WalletFrame::backupWallet);
    351         connect(changePassphraseAction, &QAction::triggered, walletFrame, &WalletFrame::changePassphrase);
    352+        connect(signMessageAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
    353         connect(signMessageAction, &QAction::triggered, [this]{ gotoSignMessageTab(); });
    354+        connect(verifyMessageAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
    355         connect(verifyMessageAction, &QAction::triggered, [this]{ gotoVerifyMessageTab(); });
    


    ken2812221 commented at 3:48 am on September 4, 2018:

    I think this is better

    0connect(signMessageAction, &QAction::triggered, [this]{ showNormalIfMinimized(); gotoSignMessageTab(); });
    1connect(verifyMessageAction, &QAction::triggered, [this]{ showNormalIfMinimized(); gotoSignMessageTab(); });
    

    promag commented at 0:11 am on September 5, 2018:
    Keeping multiple connections for now for consistency with other actions.

    gwillen commented at 6:57 pm on November 2, 2018:
    I assume the other actions are only done that way for historical reasons – prior to Qt5/C++11 this was not possible, and we only switched to using lambdas instead of the older syntax in 0.17 I believe.
  15. in src/qt/bitcoingui.cpp:1157 in eed869b834 outdated
    1159-    }
    1160-    else if(fToggleHidden)
    1161+    if (!isHidden() && !isMinimized() && !GUIUtil::isObscured(this) && fToggleHidden) {
    1162         hide();
    1163+    } else {
    1164+        GUIUtil::bringToFront(this);
    


    ken2812221 commented at 3:56 am on September 4, 2018:
    If the window was minimized, it might need to call showNormal.

    promag commented at 0:09 am on September 5, 2018:
    This should be fixed.
  16. promag force-pushed on Sep 4, 2018
  17. promag commented at 2:02 pm on September 4, 2018: member
    Rebased (so that testing takes #14133) and added a fixup that s/show/showNormal after @ken2812221 #14123 (review).
  18. MarcoFalke added the label Refactoring on Sep 4, 2018
  19. MarcoFalke removed the label Refactoring on Sep 4, 2018
  20. in src/qt/guiutil.cpp:68 in 242e61fedb outdated
    61@@ -62,6 +62,16 @@
    62 #include <QFontDatabase>
    63 #endif
    64 
    65+#if defined(Q_OS_MAC)
    66+#pragma GCC diagnostic push
    67+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
    68+// based on: https://github.com/Mozketo/LaunchAtLoginController/blob/master/LaunchAtLoginController.m
    


    fanquake commented at 1:23 am on September 5, 2018:
    Can you move this comment back done to line 710, given it’s in reference to findStartupItemInList.

    promag commented at 12:52 pm on September 10, 2018:
    Sure, done.
  21. promag force-pushed on Sep 10, 2018
  22. in src/qt/guiutil.cpp:380 in d5284edab7 outdated
    373+    objc_msgSend(app, sel_getUid("activateIgnoringOtherApps:"), YES);
    374+#endif
    375+
    376+    if (w) {
    377+        // activateWindow() (sometimes) helps with keyboard focus on Windows
    378+        w->activateWindow();
    


    hebasto commented at 5:28 am on September 15, 2018:

    According to Qt docs

    Note that the window must be visible, otherwise activateWindow() has no effect.

    Therefore, the safer sequence may be:

    0w->showNormal();  // or w->show();
    1w->activateWindow();
    2w->raise();
    
  23. in src/qt/guiutil.cpp:379 in d5284edab7 outdated
    374+#endif
    375+
    376+    if (w) {
    377+        // activateWindow() (sometimes) helps with keyboard focus on Windows
    378+        w->activateWindow();
    379+        w->showNormal();
    


    hebasto commented at 5:37 am on September 15, 2018:
    Always showNormal() will break cases when then main window is maximized.
  24. hebasto commented at 5:50 am on September 15, 2018: member
    IMO show()/showNormal() should not be aggregated with activateWindow()->raise() sequence in a single function. Rationale: show() is reverse to hide(), but showNormal() restores the widget after it has been maximized or minimized.
  25. DrahtBot added the label Needs rebase on Sep 25, 2018
  26. jonasschnelli commented at 6:54 pm on October 17, 2018: contributor
    @promag: can you comment or address @hebasto’s comments; rebase or close?
  27. promag force-pushed on Oct 26, 2018
  28. promag force-pushed on Oct 26, 2018
  29. promag commented at 1:18 pm on October 26, 2018: member
    Rebased and addressed review comments.
  30. DrahtBot removed the label Needs rebase on Oct 26, 2018
  31. hebasto commented at 7:12 pm on October 26, 2018: member

    tACK 56c61a3

    macOS 10.13.6 (17G65) + Qt 5.11.2 - works as expected, i.e. #13829 fixed

  32. ken2812221 commented at 2:12 pm on October 27, 2018: contributor
    Tested ACK 56c61a33dd7f1bca4e5005654dd776ffe69c4c3b
  33. promag force-pushed on Oct 29, 2018
  34. promag commented at 12:15 pm on October 29, 2018: member
    Rebased with #14597.
  35. Remove obj_c for macOS Dock icon setting
    Qt `setWindowIcon()` does this work.
    53bb6be3f8
  36. hebasto commented at 8:11 pm on November 2, 2018: member

    @promag

    Rebased with #14597.

    The e0d1883d0e98c265db09b6a48b9c124f45edf898 commit you picked has a bug: #14597 (comment) See: #14597 (comment)

  37. in src/qt/guiutil.cpp:68 in 69e0470bbf outdated
    59@@ -60,6 +60,15 @@
    60 #include <QFontDatabase>
    61 #endif
    62 
    63+#if defined(Q_OS_MAC)
    64+#pragma GCC diagnostic push
    65+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
    66+
    67+#include <objc/objc-runtime.h>
    68+#include <CoreFoundation/CoreFoundation.h>
    


    hebasto commented at 9:12 pm on November 2, 2018:
    This header is redundant.
  38. promag force-pushed on Nov 3, 2018
  39. promag force-pushed on Nov 3, 2018
  40. promag commented at 3:22 pm on November 3, 2018: member
    @hebasto thanks, rebased.
  41. ken2812221 approved
  42. ken2812221 commented at 6:05 pm on November 3, 2018: contributor
    ACK d3becb175270d715daaffb75a037433a126a95f4
  43. hebasto commented at 9:46 pm on November 3, 2018: member

    Tested d3becb175270d715daaffb75a037433a126a95f4:

    • on Windows 10: bug #14222 fixed
    • on macOS 10.13.6: bug #13829 fixed There is a new bug on macOS: obscure main window with another app window, click Dock icon; main windows appears and hides. Investigating… Fixed: #14597 (comment) Would you mind rebasing one more time?
    • on Linux Mint 19 @promag is it worth to combine a Linux-specific bugfix #14591 into this PR?

    Also a tiny nit left: #14123 (review)

  44. Use Qt signal for macOS Dock icon click event
    This moves the Dock icon click reaction code to the common place and
    allows some cleanup in obj_c code.
    
    According to the Apple's docs `class_replaceMethod` behaves as
    `class_addMethod`, if the method identified by name does not yet exist;
    or as `method_setImplementation`, if it does exist.
    2464925e7b
  45. Remove obj_c for macOS Dock icon menu
    Qt `setAsDockMenu()` does this work.
    6b1d2972bf
  46. qt: Add GUIUtil::bringToFront 5796671e1d
  47. qt: Use GUIUtil::bringToFront where possible 6fc21aca6d
  48. qt: All tray menu actions call showNormalIfMinimized 0a656f85a9
  49. promag force-pushed on Nov 5, 2018
  50. promag commented at 11:25 am on November 5, 2018: member

    Rebased to account for the new fix and applied suggestion #14123 (review).

    @promag is it worth to combine a Linux-specific bugfix #14591 into this PR?

    I think it is worth a new PR.

  51. Sjors commented at 9:11 am on November 10, 2018: member

    re-tACK 0a656f8 on macOS 10.14.1 QT 5.11.2 (I didn’t check the commits inherited from #14597)

    Also +1 on doing Linux in another PR, it’s already quite difficult to get any macOS changes through review.

  52. hebasto commented at 8:57 pm on November 10, 2018: member

    re-tACK

    Systems:

    • Linux Mint 19 + Qt 5.9.5
    • macOS 10.13.6 + Qt 5.11.2

    Commits: 5796671e1dd8a2d0b1e750c2dce19a10af624095, 6fc21aca6d5e16c3ece104fec8e5b3df116893b4, 0a656f85a9c694f25b06c6464d6e986816eecd58

  53. laanwj merged this on Nov 12, 2018
  54. laanwj closed this on Nov 12, 2018

  55. laanwj referenced this in commit 48223256cf on Nov 12, 2018
  56. promag referenced this in commit ac73c7d433 on Dec 30, 2018
  57. promag referenced this in commit c470bbd19d on Dec 30, 2018
  58. promag referenced this in commit 27beb83222 on Dec 30, 2018
  59. laanwj referenced this in commit 5ff7b372cd on Jan 3, 2019
  60. furszy referenced this in commit 24bc866346 on Apr 13, 2020
  61. UdjinM6 referenced this in commit 124824da41 on Apr 30, 2020
  62. 10xcryptodev referenced this in commit 8d279ab3bc on May 14, 2020
  63. michelvankessel referenced this in commit 5e796e2c7f on Oct 25, 2020
  64. wqking referenced this in commit d0b34513a5 on Nov 29, 2020
  65. ckti referenced this in commit abcf559ce3 on Mar 28, 2021
  66. gades referenced this in commit 278055c051 on Jun 26, 2021
  67. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-18 18:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me