godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Emit a notification when the project's window mode changes #10228

Open naufalafif2015 opened 1 month ago

naufalafif2015 commented 1 month ago

Describe the project you are working on

An 2D Game with some out of the box puzzle

Describe the problem or limitation you are having in your project

Im having difficult to get some Notification when my current game is set into Windowed, Fullscreen, Fullscreen Exclusive, Maximized and Minimized

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add some notification for it into an func _notification(what: int):

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

This is the Example on how would it work in my mind:

func _notification(what: int):
    if what == NOTIFICATION_WINDOW_MODE_EXCLUSIVE_FULLSCREEN:
        pass
    if what == NOTIFICATION_WINDOW_MODE_FULLSCREEN:
        pass
    if what == NOTIFICATION_WINDOW_MODE_MAXIMIZED:
        pass
    if what == NOTIFICATION_WINDOW_MODE_MINIMIZED:
        pass
    if what == NOTIFICATION_WINDOW_MODE_WINDOWED:
        pass

If this enhancement will not be used often, can it be worked around with a few lines of script?

Im not so sure if there was even a work around of it. If there was, I think it would be using it in a _process that consume too many resource at once for some notification that only gonna being used once.

If you have some work around of it, feel free to tell me!

Is there a reason why this should be core and not an add-on in the asset library?

I think notification like a fullscreen or windowed will make a huge usability in the core. For Example: (when the user is using a windowed mode in the settings, it will show some of new UI for helping that User play in windowed mode. And that UI will not show up when using a fullscreen game)

bruvzg commented 1 month ago

Partially implemented in https://github.com/godotengine/godot/pull/92247 (not a notification, but Window callback, notification can be easily added to default callback handler).

lostminds commented 1 month ago

I'd appreciate this functionality, but I'd prefer implementing it as a signal from Window. For example Window.mode_changed emitted when the mode has changed. This would also allow supporting multiple windows.

There is a sort of hack you can do now using the existing Window.titlebar_changed signal, to at least detect changes between full screen and windowed mode (which also shows/hides the titlebar). But this misses maximize mode changes and a Window.mode_changed signal would feel much more reliable.

SCEManny commented 1 week ago

The problem we're seeing on macOS is that at the time we receive the viewport size_changed signal after a mode change, the window mode has not yet been updated. Getting that synced up would be more useful than a separate event. As a workaround we're bypassing Godot's window get_mode to check the NSWindow directly.