Skip to content

Conversation

@promag
Copy link
Contributor

@promag promag commented Aug 31, 2018

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.

@promag
Copy link
Contributor Author

promag commented Aug 31, 2018

@jonasschnelli @Sjors @ken2812221 review/test much appreciated.

@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 31, 2018

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.

@promag promag force-pushed the 2018-08-bringtofront branch from f2cd327 to eed869b Compare September 1, 2018 07:59
@laanwj
Copy link
Member

laanwj commented Sep 1, 2018

I think it would make sense, for ease of review, to split off the fix to #13829 from pure refactoring.

@promag
Copy link
Contributor Author

promag commented Sep 1, 2018

Which refactor?

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

Copy link
Member

@Sjors Sjors left a comment

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

Apple documentation suggests that this normally shouldn't be needed, which suggests there's a deeper problem somewhere.

Copy link
Member

Choose a reason for hiding this comment

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

I'd also like to know a bit more about this, and the new <objc/objc-runtime.h> #include.

Copy link
Member

Choose a reason for hiding this comment

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

@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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added comment.

Copy link
Member

Choose a reason for hiding this comment

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

According to the sel_getUid documentation:

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

On master(7504157):

  • sel_registerName used 4 times
  • sel_getUid not used at all

Could sel_getUid replace with sel_registerName?

@fanquake
Copy link
Member

fanquake commented Sep 2, 2018

Testing current master on macOS 10.13.6 2070a54.
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 eed869b.
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.

@promag
Copy link
Contributor Author

promag commented Sep 2, 2018

Thanks for the reviews! I'll fix it.

BTW, in macOS "show/hide" action could be removed since it's already there natively.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is better

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

Copy link
Contributor Author

@promag promag Sep 5, 2018

Choose a reason for hiding this comment

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

Keeping multiple connections for now for consistency with other actions.

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the window was minimized, it might need to call showNormal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be fixed.

@promag promag force-pushed the 2018-08-bringtofront branch from eed869b to 242e61f Compare September 4, 2018 14:01
@promag
Copy link
Contributor Author

promag commented Sep 4, 2018

Rebased (so that testing takes #14133) and added a fixup that s/show/showNormal after @ken2812221 #14123 (comment).

Copy link
Member

Choose a reason for hiding this comment

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

Can you move this comment back done to line 710, given it's in reference to findStartupItemInList.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, done.

Copy link
Member

Choose a reason for hiding this comment

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

According to Qt docs

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

Therefore, the safer sequence may be:

w->showNormal();  // or w->show();
w->activateWindow();
w->raise();

@hebasto
Copy link
Member

hebasto commented Sep 15, 2018

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.

@jonasschnelli
Copy link
Contributor

@promag: can you comment or address @hebasto's comments; rebase or close?

@promag promag force-pushed the 2018-08-bringtofront branch 2 times, most recently from 1aa064a to 56c61a3 Compare October 26, 2018 13:18
Copy link
Contributor

@ken2812221 ken2812221 left a comment

Choose a reason for hiding this comment

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

ACK d3becb175270d715daaffb75a037433a126a95f4

@hebasto
Copy link
Member

hebasto commented Nov 3, 2018

Tested d3becb175270d715daaffb75a037433a126a95f4:

Also a tiny nit left: #14123 (comment)

hebasto and others added 5 commits November 4, 2018 02:37
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.
Qt `setAsDockMenu()` does this work.
@promag promag force-pushed the 2018-08-bringtofront branch from d3becb1 to 0a656f8 Compare November 5, 2018 11:22
@promag
Copy link
Contributor Author

promag commented Nov 5, 2018

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

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

I think it is worth a new PR.

@Sjors
Copy link
Member

Sjors commented Nov 10, 2018

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.

@hebasto
Copy link
Member

hebasto commented Nov 10, 2018

re-tACK

Systems:

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

Commits: 5796671, 6fc21ac, 0a656f8

@laanwj laanwj merged commit 0a656f8 into bitcoin:master Nov 12, 2018
laanwj added a commit that referenced this pull request Nov 12, 2018
0a656f8 qt: All tray menu actions call showNormalIfMinimized (João Barbosa)
6fc21ac qt: Use GUIUtil::bringToFront where possible (João Barbosa)
5796671 qt: Add GUIUtil::bringToFront (João Barbosa)
6b1d297 Remove obj_c for macOS Dock icon menu (Hennadii Stepanov)
2464925 Use Qt signal for macOS Dock icon click event (Hennadii Stepanov)
53bb6be Remove obj_c for macOS Dock icon setting (Hennadii Stepanov)

Pull request description:

  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`.

Tree-SHA512: a8e301aebc359aa353821e2af352ae356f44555724921b01da907e128653ef9dc55d8764a1bff72a579e5ff96df8a681f6804bfe83acba441da92fedff974a55
promag added a commit to promag/bitcoin that referenced this pull request Dec 30, 2018
promag added a commit to promag/bitcoin that referenced this pull request Dec 30, 2018
promag added a commit to promag/bitcoin that referenced this pull request Dec 30, 2018
laanwj added a commit that referenced this pull request Jan 3, 2019
27beb83 qt: All tray menu actions call showNormalIfMinimized (João Barbosa)
c470bbd qt: Use GUIUtil::bringToFront where possible (João Barbosa)
ac73c7d qt: Add GUIUtil::bringToFront (João Barbosa)
0c2fb87 Remove obj_c for macOS Dock icon menu (Hennadii Stepanov)
9034714 Use Qt signal for macOS Dock icon click event (Hennadii Stepanov)
4d4bc37 Remove obj_c for macOS Dock icon setting (Hennadii Stepanov)
d2ed162 Clean systray icon menu for -disablewallet mode (Hennadii Stepanov)
298dc15 gui: Favor macOS show / hide action in dock menu (João Barbosa)

Pull request description:

  Backport #14123 #14133 #14383 and #14597 to 0.17 branch to fix #13606 (comment).

Tree-SHA512: 543c80e7e2130870e801e0c9a69b06b9eea27c288478fc5dddeb662f7f3ec5b56b30916e5a9a629fced3fffcb8be77e2cd155e75cfd0a4392299add9730840f4
furszy added a commit to PIVX-Project/PIVX that referenced this pull request Apr 13, 2020
a60b7cc qt: Replace objc_msgSend with native syntax (furszy)
5d6f9b5 qt: Use GUIUtil::bringToFront where possible (furszy)
9e85183 qt: Add GUIUtil::bringToFront (furszy)
188199a Remove obj_c for macOS Dock icon menu (furszy)
75a41e2 Use Qt signal for macOS Dock icon click event (furszy)
ff319ad Remove obj_c for macOS Dock icon setting. (furszy)

Pull request description:

  Updating `MacDockIconHandler` to latest upstream. Fixing #1512 .

  Back ported PRs:

  #### gui: Add GUIUtil::bringToFront [14123](bitcoin#14123):
  ```
  The sequence show -> raise -> activateWindow is factored out to the new function GUIUtil::bringToFront where a macOS fix is added in order to fix bitcoin#13829.

  Also included:

  simplification of BitcoinGUI::showNormalIfMinimized
  ```

  #### qt: Replace objc_msgSend() function calls with the native Objective-C syntax [16720](bitcoin#16720):

  ```
  Changes in Xcode 11 Objective-C Runtime cause an error (bitcoin#16387) during building on MacOS 10.15 Catalina.

  This PR fixes this issue by replacing objc_msgSend() function calls with the native Objective-C syntax.

  Refs:

  changes in objc_msgSend function
  OBJC_OLD_DISPATCH_PROTOTYPES macro
  ```

ACKs for top commit:
  random-zebra:
    utACK a60b7cc
  Fuzzbawls:
    ACK a60b7cc

Tree-SHA512: 95543a12d58187f17d27c6757351becd43a92c3edb8fcbc0a2b03a54d31cbad604ae149f2e866d82c3ce5f9a636571b8e51137fc5f639031a20080d8290889d9
UdjinM6 pushed a commit to dashpay/dash that referenced this pull request Apr 30, 2020
* Remove obj_c for macOS Dock icon setting

Qt `setWindowIcon()` does this work.

* 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.

* Remove obj_c for macOS Dock icon menu

Qt `setAsDockMenu()` does this work.

* qt: Add GUIUtil::bringToFront

* qt: Use GUIUtil::bringToFront where possible

* qt: All tray menu actions call showNormalIfMinimized

* qt: Replace objc_msgSend with native syntax

Co-authored-by: Hennadii Stepanov <[email protected]>
Co-authored-by: João Barbosa <[email protected]>
wqking pushed a commit to wqking-temp/Vitae that referenced this pull request Nov 29, 2020
a60b7cceb4d142239207ac2be2244aa999bdc1fd qt: Replace objc_msgSend with native syntax (furszy)
5d6f9b5c4c2288e1dd150c4e2722db2db2f5db5a qt: Use GUIUtil::bringToFront where possible (furszy)
9e851839737618f8215ec69768702ca6328ab9d9 qt: Add GUIUtil::bringToFront (furszy)
188199a77653bd548d293c5222e1a05773947918 Remove obj_c for macOS Dock icon menu (furszy)
75a41e2d3d7223da8381c9ce19e9454ee96a60b9 Use Qt signal for macOS Dock icon click event (furszy)
ff319ad0e3d3319fb9a98087ac73686c8b6f4e17 Remove obj_c for macOS Dock icon setting. (furszy)

Pull request description:

  Updating `MacDockIconHandler` to latest upstream. Fixing #1512 .

  Back ported PRs:

  #### gui: Add GUIUtil::bringToFront [14123](bitcoin/bitcoin#14123):
  ```
  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
  ```

  #### qt: Replace objc_msgSend() function calls with the native Objective-C syntax [16720](bitcoin/bitcoin#16720):

  ```
  Changes in Xcode 11 Objective-C Runtime cause an error (#16387) during building on MacOS 10.15 Catalina.

  This PR fixes this issue by replacing objc_msgSend() function calls with the native Objective-C syntax.

  Refs:

  changes in objc_msgSend function
  OBJC_OLD_DISPATCH_PROTOTYPES macro
  ```

ACKs for top commit:
  random-zebra:
    utACK a60b7cceb4d142239207ac2be2244aa999bdc1fd
  Fuzzbawls:
    ACK a60b7cceb4d142239207ac2be2244aa999bdc1fd

Tree-SHA512: 95543a12d58187f17d27c6757351becd43a92c3edb8fcbc0a2b03a54d31cbad604ae149f2e866d82c3ce5f9a636571b8e51137fc5f639031a20080d8290889d9

# Conflicts:
#	configure.ac
#	src/qt/macdockiconhandler.mm
gades pushed a commit to cosanta/cosanta-core that referenced this pull request Jun 26, 2021
* Remove obj_c for macOS Dock icon setting

Qt `setWindowIcon()` does this work.

* 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.

* Remove obj_c for macOS Dock icon menu

Qt `setAsDockMenu()` does this work.

* qt: Add GUIUtil::bringToFront

* qt: Use GUIUtil::bringToFront where possible

* qt: All tray menu actions call showNormalIfMinimized

* qt: Replace objc_msgSend with native syntax

Co-authored-by: Hennadii Stepanov <[email protected]>
Co-authored-by: João Barbosa <[email protected]>
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unhide QT window doesn't work when hidden with ⌘ + H

10 participants