macosui / macos_window_utils.dart

macos_window_utils is a Flutter package that provides a set of methods for modifying the NSWindow of a Flutter application on macOS.
https://pub.dev/packages/macos_window_utils
MIT License
49 stars 9 forks source link

Add BlockingToolbar #43

Open cbenhagen opened 9 months ago

cbenhagen commented 9 months ago

Use BlockingToolbar instead of NSToolbar to prevent maxmizing the window on double clicking a Flutter button. See https://github.com/macosui/macos_ui/issues/308

Adrian-Samoticha commented 9 months ago

Thanks. I will review this PR soon.

Adrian-Samoticha commented 9 months ago

I don’t fully understand the behavior of the blocking toolbar. It seems like it blocks double clicks from zooming the window when the right side of the window’s toolbar is double-clicked, while still triggering the zooming when the left side of the window is clicked. It doesn’t seem to check if a Flutter widget is blocking the toolbar from being clicked.

Unless I’m misunderstanding something, I don’t think this solves the linked issue. Ideally, there would be some way to check if a Flutter widget obstructs the toolbar at the clicked position, such that the clicks only get blocked when an actual widget is being clicked.

cbenhagen commented 9 months ago

Yes, ideally we would be able to check if a Flutter widget is in front of the toolbar and only block double clicks if this is the case. I haven't found a nice solution which allows to do this so I decided to block all double clicks to the toolbar. It is still better than zooming the window when the user double clicks a Flutter widget.

The issue you are describing is most likely due to the fact that you enable a native title in your window which will also handle the double clicks. I don't see a use case for enabling the native titles but if you do, you would most likely be better off using a completely native toolbar.

To show what is happening I added a blue background to the BlockingToolbar

Screenshot 2023-11-28 at 11 53 21 Screenshot 2023-11-28 at 11 53 17

If you see a good use case to use the native titles with a Flutter toolbar then maybe a double click blocking variant of the title could be introduced?

Adrian-Samoticha commented 9 months ago

Right, I’d argue that it is indeed unlikely that someone would want a Flutter widget to be placed on top of the native title, so I guess that’s fine the way it is. Still, disabling the double-click feature completely would irritate people who prefer to maximize their windows by double-clicking.

Perhaps a better solution would be to add an API that enables or disables the blocking toolbar? Then, a Flutter widget could enable it for a few milliseconds when it is clicked (thereby blocking the second click), thus blocking the double-click only when the cursor is placed on top of the widget.

Do you think that would be a good idea?

cbenhagen commented 8 months ago

I also played with this idea but currently have dropped it. It might work but every Flutter widget you place in the toolbar would need to be made aware of this. Maybe we can leave this as an improvement for later?

Adrian-Samoticha commented 8 months ago

I think we could just offer a wrapper widget that you can wrap around your toolbar buttons, which would then handle the toolbar clicking automatically.

cbenhagen commented 3 months ago

Can this be merged without such a wrapper widget? I think this can be improved later if anyone needs it.

Adrian-Samoticha commented 3 months ago

I’d be willing to merge it if there was a method to enable and disable the blocking toolbar. Right now I think it’s too likely that some users may rely on the double-click-to-maximize feature in their apps to completely take it away with no way to enable it again.

Looking at your commit, I think all that’s necessary to achieve this is to add some sort of parameter of some sort to the addToolbar methods on both the Dart and the Swift side which controls whether the newly added toolbar is a BlockingToolbar or a plain NSToolbar.

If you’re unfamiliar with the way the platform channels are implemented in macos_window_utils, I’d be happy to do that myself.

cbenhagen commented 3 months ago

I'd happily accept that offer. Please feel free to push to this branch.

Adrian-Samoticha commented 3 months ago

How did you add the blue background to the BlockingToolbar in the screenshots you posted above? I would like to add a debug feature that allows the user to do that, but I cannot figure out how you did it.

Adrian-Samoticha commented 2 months ago

@cbenhagen Bump, in case you missed my previous comment.

cbenhagen commented 2 months ago

Sorry, I indeed missed your comment. Unfortunately I don't remember how I did it.