tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
82.46k stars 2.48k forks source link

[feat] ability to listen to when window is going to go full screen (macOS) #7162

Open AndrewBastin opened 1 year ago

AndrewBastin commented 1 year ago

Describe the problem

Tauri provides the tauri://resize event that can emit events when the window changes size and also (in macOS) when the app has entered/left full screen (emphasis on the past tense). But there are situations where we want to know if the window is going to leave/enter full screen (as in future).

One example for such is basically, lets say you have a header area and you want to inline the window controls into the window (a common macOS design style), we need to leave space for the window controls on the top left of the window. This space is not required in full screen as window controls are not present there. With the resize event, the current situation is that, if we toggled based on the Window#isFullScreen() property on the callback for the event, we only receive the callback after the window is done animating out of the full screen mode into the windowed view. This leads to a couple of moments where the spacing is not applied eventhough the window control is coming in.

Here is a video demo of roughly what I mean, the goal is to keep the emoji rendered aside the window controls, see how on leaving full screen we have few frames where the emoji is behind the window controls:

https://github.com/tauri-apps/tauri/assets/9131943/04cbc8c3-fda5-45e3-8b9d-964cb296d111

Describe the solution you'd like

macOS does provide an event windowWillExitFullScreen and windowWillEnterFullScreen [reference] to NSWindowDelegates that I am pretty sure Tao implements but doesn't expose into the event system. I think a way to access this event will be cool.

Alternatives considered

Currently we internally literally override the NSWindowDelegate implementation Tao provides and add these as custom events but that is super brittle and weird.

Additional context

I think this maybe a Tao specific request and might need to be moved to that repo, but I leave it to the maintainers to decide that.

Hacksore commented 3 months ago

This feature could def be used to unblock https://github.com/Hacksore/overlayed/pull/108.

It would make it so that I only have to enable set_activation_policy(tauri::ActivationPolicy::Accessory) when entering fullscreen mode and I can go back to Regular upon leaving fullscreen.

As of now if I enable the activation policy as accessory it will omit app item from the CMD+Tab menu 😞.