Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emscripten: fix fullscreen toggle when user presses Escape #65

Closed
wants to merge 1 commit into from

Conversation

@Beuc
Copy link
Contributor

@Beuc Beuc commented Nov 26, 2018

Hi!

When fullscreen is toggled e.g. by pressing 'F' in the application, and if the user goes back to windowed mode not by pressing 'F' again, but by obeying the browser and pressing 'Escape', then SDL gets in an inconsistent state.
The user will then need to press 'F' (or otherwise request fullscreen toggle) 3 times to get actual fullscreen back, the first 2 times will be ignored.

This patch fixes SDL's state when the user presses "Escape".

@Beuc
Copy link
Contributor Author

@Beuc Beuc commented Nov 26, 2018

@Daft-Freak
Copy link
Member

@Daft-Freak Daft-Freak commented Nov 30, 2018

Alternative fix:

    SDL_VideoDisplay *display;

...

        display = SDL_GetDisplayForWindow(window_data->window);

        if (display->fullscreen_window == window_data->window) {
            display->fullscreen_window = NULL;
        }

(I'm not sure if it's a good idea to call something like SDL_SetWindowFullscreen in a video backend)

@Beuc
Copy link
Contributor Author

@Beuc Beuc commented Nov 30, 2018

Do you have this as a patch that can be tested?

@Daft-Freak
Copy link
Member

@Daft-Freak Daft-Freak commented Dec 1, 2018

diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c
index 4ba8453ec..ce2fc18a1 100644
--- a/src/video/emscripten/SDL_emscriptenevents.c
+++ b/src/video/emscripten/SDL_emscriptenevents.c
@@ -551,6 +551,8 @@ static EM_BOOL
 Emscripten_HandleFullscreenChange(int eventType, const EmscriptenFullscreenChangeEvent *fullscreenChangeEvent, void *userData)
 {
     SDL_WindowData *window_data = userData;
+    SDL_VideoDisplay *display;
+
     if(fullscreenChangeEvent->isFullscreen)
     {
         window_data->window->flags |= window_data->requested_fullscreen_mode;
@@ -563,6 +565,12 @@ Emscripten_HandleFullscreenChange(int eventType, const EmscriptenFullscreenChang
     else
     {
         window_data->window->flags &= ~FULLSCREEN_MASK;
+
+        display = SDL_GetDisplayForWindow(window_data->window);
+
+        if (display->fullscreen_window == window_data->window) {
+            display->fullscreen_window = NULL;
+        }
     }
 
     return 0;

I did a quick check and it seemed to work.

@Beuc
Copy link
Contributor Author

@Beuc Beuc commented Dec 1, 2018

This works for me as well.

Daft-Freak added a commit that referenced this issue Dec 8, 2018
If the browser left fullscreen mode by the user pressing ESC, the next
call to SDL_SetWindowFullscreen(1) will fail as it thinks the window is
already fullscreen. (#65)
@Beuc Beuc closed this Dec 30, 2018
@Beuc Beuc deleted the patch-3 branch Dec 30, 2018
dos1 pushed a commit to dos1/SDL2 that referenced this issue Feb 12, 2019
If the browser left fullscreen mode by the user pressing ESC, the next
call to SDL_SetWindowFullscreen(1) will fail as it thinks the window is
already fullscreen. (emscripten-ports#65)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants