Open cbenhagen opened 9 months ago
Thanks. I will review this PR soon.
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.
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
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?
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?
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?
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.
Can this be merged without such a wrapper widget? I think this can be improved later if anyone needs it.
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.
I'd happily accept that offer. Please feel free to push to this branch.
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.
@cbenhagen Bump, in case you missed my previous comment.
Sorry, I indeed missed your comment. Unfortunately I don't remember how I did it.
Use
BlockingToolbar
instead ofNSToolbar
to prevent maxmizing the window on double clicking a Flutter button. See https://github.com/macosui/macos_ui/issues/308