Skip to content

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Oct 28, 2018

The Objective-C MacDockIconHandler class currently does such jobs on macOS:

  1. Set the Dock icon
  2. Support the Dock icon menu
  3. Handle the Dock icon click event

Qt does the first job natively.
Qt has native support the Dock icon menu only since version 5.2
Qt does not handle applicationShouldHandleReopen event. And this brakes all Qt support for the Dock icon click event.

This PR:

  • removes Objective-C code for the Dock icon setting. Qt setWindowIcon() does this work
  • removes Objective-C code for the Dock icon menu. Qt setAsDockMenu() does this work
  • uses Qt signal for the Dock icon click event

@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 28, 2018

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

Conflicts

No conflicts as of last run.

@promag
Copy link
Contributor

promag commented Oct 29, 2018

Concept ACK.

@practicalswift
Copy link
Contributor

Concept ACK

Net change: -189 lines. Nice cleanup!

@fanquake
Copy link
Member

Concept ACK

There's at least one bug here. Using e0d1883, if you close the main window using the red cross, you can no longer bring the window back by clicking on the dock icon.
This might be solved by one of the other GUI related PRs, possibly #14123.

@promag
Copy link
Contributor

promag commented Oct 30, 2018

This might be solved by one of the other GUI related PRs, possibly #14123.

@fanquake no it doesn't solve it. But using a dock menu action, like "Send", it reopens.

@bitcoin bitcoin deleted a comment from ismail120572 Oct 30, 2018
@bitcoin bitcoin deleted a comment from ismail120572 Oct 30, 2018
@hebasto hebasto changed the title qt: Remove old MacDockIconHandler class [WIP] qt: Remove old MacDockIconHandler class Oct 30, 2018
Qt `setWindowIcon()` does this work.
@hebasto hebasto force-pushed the 20181028-macos-dock-overhaul branch from e0d1883 to b913e68 Compare October 31, 2018 19:38
@hebasto hebasto changed the title [WIP] qt: Remove old MacDockIconHandler class [WIP] qt: Cleanup MacDockIconHandler class Oct 31, 2018
@hebasto hebasto force-pushed the 20181028-macos-dock-overhaul branch from b913e68 to 43627b9 Compare October 31, 2018 20:05
@hebasto
Copy link
Member Author

hebasto commented Oct 31, 2018

@fanquake @promag @practicalswift
Thank you for your reviews.
The original goal of this PR (to completely remove MacDockIconHandler class) has revealed inaccessible.
So PR has be reworked. Would you mind re-reviewing?

@hebasto hebasto changed the title [WIP] qt: Cleanup MacDockIconHandler class qt: Cleanup MacDockIconHandler class Oct 31, 2018
@@ -49,61 +44,22 @@ void setupDockClickHandler() {
setupDockClickHandler();
this->m_dummyWidget = new QWidget();
this->m_dockMenu = new QMenu(this->m_dummyWidget);
this->setMainWindow(nullptr);
#if QT_VERSION >= 0x050200
Copy link
Member

@fanquake fanquake Nov 2, 2018

Choose a reason for hiding this comment

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

You can drop the QT_VERSION check here, as our next release will require at least 5.2. master currently requires 5.4 IIRC.

@hebasto hebasto force-pushed the 20181028-macos-dock-overhaul branch from 461806f to 14e7e16 Compare November 2, 2018 09:14
@hebasto hebasto changed the title qt: Cleanup MacDockIconHandler class [WIP] qt: Cleanup MacDockIconHandler class Nov 2, 2018
@hebasto hebasto force-pushed the 20181028-macos-dock-overhaul branch from 14e7e16 to efb681d Compare November 2, 2018 09:32
@hebasto hebasto changed the title [WIP] qt: Cleanup MacDockIconHandler class qt: Cleanup MacDockIconHandler class Nov 2, 2018
@hebasto
Copy link
Member Author

hebasto commented Nov 2, 2018

@fanquake Your comment is addressed. Please re-review.

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 efb681d on macOS 10.14.1, thanks for reducing the amount of OS specific code we need to reason about!

class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:");
else
class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler,"B@:");
class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:");
Copy link
Member

Choose a reason for hiding this comment

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

Why did/do we need this class_replaceMethod stuff?

Copy link
Member Author

@hebasto hebasto Nov 2, 2018

Choose a reason for hiding this comment

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

This implements the method of the application delegate which handles the reopen application event (i.e., the user clicks application icon in the Dock).
Ref: How Cocoa Applications Handle Apple Events

Qt cannot handle the reopen application event for now.

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.
@hebasto hebasto force-pushed the 20181028-macos-dock-overhaul branch from efb681d to 6b1d297 Compare November 4, 2018 00:47
@hebasto
Copy link
Member Author

hebasto commented Nov 4, 2018

Fixed bug with hidden/inactive/obscured main window: toggleHidden() does not work on macOS properly.
cc: @promag

@jonasschnelli
Copy link
Contributor

This needs proper testing on macOS 10.9 up till 10.14. Also, I'm not sure that this works reliable with older Qt5 versions. We should probably also test against Qt5.4 till Qt5.9.

@hebasto
Copy link
Member Author

hebasto commented Nov 4, 2018

@jonasschnelli

This needs proper testing on macOS 10.9 up till 10.14. Also, I'm not sure that this works reliable with older Qt5 versions. We should probably also test against Qt5.4 till Qt5.9.

https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes.md:

From 0.17.0 onwards macOS <10.10 is no longer supported. 0.17.0 is built using Qt 5.9.x, which doesn't support versions of macOS older than 10.10.

What is the reason to choose so wide range of the tested platforms?

@bitcoin bitcoin deleted a comment from ismail120572 Nov 4, 2018
@bitcoin bitcoin deleted a comment from ismail120572 Nov 4, 2018
@jonasschnelli
Copy link
Contributor

This needs proper testing on macOS 10.9 up till 10.14. Also, I'm not sure that this works reliable with older Qt5 versions. We should probably also test against Qt5.4 till Qt5.9.
https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes.md:

The "official" binaries are using Qt5.9 which doesn't mean that we drop support self-compilation with an older Qt version.

We should at least do some tests on something between OSX 10.10 and 10.14 with Qt5.5 and Qt5.9 (and not just only 10.14&Qt5.9).

@Sjors
Copy link
Member

Sjors commented Nov 10, 2018

I'm not a fan of testing older macOS versions, at least not every PR. There's very few core devs that work on both macOS and the GUI (very on the GUI period) and have old versions of macOS lying around. Meanwhile Apple hasn't increased hardware requirements for their recent OS updates and they make it really easy.

I think this leads to a bit of vicious circle where work on the GUI is very slow, leading to very few people using it, leading to very few devs working on it. I think it would be better for users if each major release only supports the current macOS version. If there's a killer feature that we really want people on older macOS versions to have, we could always backport that.

@laanwj laanwj merged commit 6b1d297 into bitcoin:master Nov 12, 2018
@hebasto hebasto deleted the 20181028-macos-dock-overhaul branch November 12, 2018 21:44
promag pushed a commit to promag/bitcoin that referenced this pull request Dec 30, 2018
Qt `setWindowIcon()` does this work.

Github-Pull: bitcoin#14597
Rebased-From: 53bb6be
promag pushed a commit to promag/bitcoin that referenced this pull request Dec 30, 2018
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.

Github-Pull: bitcoin#14597
Rebased-From: 2464925
promag pushed a commit to promag/bitcoin that referenced this pull request Dec 30, 2018
Qt `setAsDockMenu()` does this work.

Github-Pull: bitcoin#14597
Rebased-From: 6b1d297
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
@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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants