godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
86.35k stars 19.22k forks source link

HTML5 Godot will not detect FullScreen if entered via browser/f11 request. #90032

Open PeterMarques opened 3 months ago

PeterMarques commented 3 months ago

Tested versions

3.x

System information

web (Chromium)

Issue description

This behaviour mathes the one partialy described on https://stackoverflow.com/questions/27501409/exit-full-screen-using-f11-key-and-esc-key

What happen is, OS.window_fullscreen will only return True if godot itself asked for the fullscreen.

If user press f11 (when intercepted by brower, not captured inside godot), or go to hamburger menu and click fullscreen, OS.window_fullscreen will not return true.

Indeed fullscreen godot shows ESC, and fullscreen browser shows F11;

this prevents good fullscreen behaviour management.

Steps to reproduce

Acess this and enter fullscreen via input and via browser request.

Minimal reproduction project (MRP)

A single label node with the script:

extends Label
func _process(delta):
    text = str(OS.window_fullscreen)
func _input(event):
    if !OS.window_fullscreen and event is InputEventMouseMotion == false:
        OS.window_fullscreen = true

AND.

After entering via browser request one can RE-ENTER fullscreen, and detect true.

Then, one can EXIT 2 TIMES FULLSCREEEN. The first time via ESC, now detection goes back to false, but viewport is still fullscreen Then, using F11, one can really exit fullscreen. OR Diretly pressing f11 will exit "both" fullscreen at the same time.


Well, it seens that F11 put the BROWSER on fullscreen, and the engine request put the "page?".

So, maybe its 2 classes of fullscreen available. Idk.

Needs testing and a further investigation on apis.

hsandt commented 1 month ago

Godot 4 test

I tested on v4.2.1.stable.official [b09f793f5] with the equivalent DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN or DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN on itch.io (so I can click outside game and press F11 for a browser fullscreen, not in-game fullscreen) and it seems to lock DisplayServer.window_get_mode() to one value that is not fullscreen nor exclusive fullscreen (haven't debugged the exact value yet, possibly DisplayServer.WINDOW_MODE_WINDOWED). As a result both my in-game fullscreen toggle option and my keyboard shortcuts to toggle fullscreen based on current state are broken (only force setting window mode to a certain value should work).

Note: itch.io can add a custom bottom-right button on top of the HTML template to toggle "real" fullscreen (fullscreen on embedded game, not page) and this one is fully compatible with the Godot window mode change. So I'll tell users not to use browser page fullscreen for now.

Calinou commented 1 month ago

Detecting browser fullscreen sounds difficult to detect in a 100% reliable manner, unless browsers have an API they reliably use to be able to query whether the browser has just entered/exited fullscreen. You'd expect to be able to compare the canvas size to the display size whenever the canvas size changes, but there are several complications that can arise due to multi-monitor setups (I don't know how web browsers handle this).

Also, many browsers intentionally report a false screen resolution in an attempt to thwart fingerprinting.