Skip to content

On Web, fix async Window::set_fullscreen#2751

Merged
daxpedda merged 1 commit intorust-windowing:masterfrom
daxpedda:web-set-fullscreen
May 31, 2023
Merged

On Web, fix async Window::set_fullscreen#2751
daxpedda merged 1 commit intorust-windowing:masterfrom
daxpedda:web-set-fullscreen

Conversation

@daxpedda
Copy link
Copy Markdown
Member

@daxpedda daxpedda commented Mar 26, 2023

Currently the behavior of Window::set_fullscreen() on Web queues the request to the current or next keyboard or mouse event. This doesn't work if Window::set_fullscreen() is called asynchronously outside the event loop.

This was probably done to satisfy the transient activation requirement for requestFullscreen(). But transient activation doesn't run out during the event loop, it's time based, usually one second.

This PR adjusts Window::set_fullscreen() to immediately call requestFullscreen(), only on failure a request is queued. This required some custom imports because the API was changed in the spec to return a Promise and web-sys doesn't reflect that change. Additionally Safari doesn't reflect that change before 16.4 (which came out today (2023-03-28)) too. So both APIs are now supported.

Additionally I noticed that the behavior of Window::set_fullscreen() on Web was undocumented, so I added some.

@daxpedda daxpedda changed the title On Web, fix no-op for Window::set_fullscreen On Web, fix async Window::set_fullscreen Mar 26, 2023
@daxpedda daxpedda force-pushed the web-set-fullscreen branch 2 times, most recently from 22dc402 to 2352a8f Compare March 28, 2023 14:33
@daxpedda
Copy link
Copy Markdown
Member Author

I decided to go ahead and implement properly handling the return value of Element.requestFullscreen().
It was possible that fullscreen mode could be exited by the user without Winit, for example by pressing the button "Exit" that browsers show when you enter fullscreen, so any click or keyboard input afterwards would trigger the queued fullscreen mode again.

I had to pull in js-sys for this, which is not an additional dependency, web-sys was already relying on it. Additionally I noted in the OP and in the code on why we needed additional custom imports.

@daxpedda daxpedda closed this Apr 18, 2023
@daxpedda daxpedda reopened this Apr 18, 2023
@daxpedda daxpedda added the DS - web Affects the Web backend (WebAssembly/WASM) label May 28, 2023
@daxpedda daxpedda force-pushed the web-set-fullscreen branch from 2352a8f to 6969e94 Compare May 31, 2023 13:07
@daxpedda daxpedda merged commit ba5ad3b into rust-windowing:master May 31, 2023
@daxpedda daxpedda mentioned this pull request Jun 11, 2023
25 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DS - web Affects the Web backend (WebAssembly/WASM)

Development

Successfully merging this pull request may close these issues.

1 participant