Can I listen for OS.window_fullscreen change instead of polling?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mburkard

I have a toggle fullscreen button, the button has an icon that switches depending on whether the screen is fullscreen or not.

func _button_pressed() -> void:
    OS.window_fullscreen = !OS.window_fullscreen
    icon = _fullscreen_exit_icon if OS.window_fullscreen else _fullscreen_icon

My problem is that there can be other ways to exit fullscreen, for example, when this runs in a browser the user can hit escape to exit fullscreen. When this happens the fullscreen button will have the wrong icon.

I can constantly update the icon with:

func _process(_delta) -> void:
    icon = _fullscreen_exit_icon if OS.window_fullscreen else _fullscreen_icon

But it seems very inefficient to be doing this up to 60 times per second every second when it’s not needed 99.99% of the time.

Is there a way I can listen for a change in OS.window_fullscreen instead of constantly polling it?

:bust_in_silhouette: Reply From: jgodfrey

The viewport has a size_changed() signal that might work for your needs…