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

Incorrect FOCUS_GAINED in Wine when a fullscreen window is minimized from focus loss #5316

Closed
madewokherd opened this issue Feb 5, 2022 · 2 comments · Fixed by #5317
Closed
Assignees
Milestone

Comments

@madewokherd
Copy link
Contributor

In some cases, when a fullscreen window loses focus, SDL will minimize it. If this happens in Wine, starting with SDL 2.0.18 (I also tested 2.0.20 and main), the window receives SDL_WINDOWEVENT_FOCUS_GAINED when it's minimized.

Here is a test program to reproduce the bug:

#include <SDL2/SDL.h>
#include <stdio.h>

int wmain(int argc, wchar_t* argv[])
{
    SDL_Window *window;
    int is_fullscreen = 0;

    SDL_Init(SDL_INIT_EVERYTHING);

    SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "1");

    window = SDL_CreateWindow("Test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 240, 0);

    if (!window)
        return 1;

    while (1)
    {
        SDL_Event event;

        if (SDL_WaitEvent(&event))
        {
            switch (event.type)
            {
            case SDL_QUIT:
                printf("got SDL_QUIT\n");
                SDL_DestroyWindow(window);
                SDL_Quit();
                return 0;
            case SDL_MOUSEBUTTONDOWN:
                is_fullscreen = !is_fullscreen;
                printf("Setting fullscreen: %i\n", is_fullscreen);
                SDL_SetWindowFullscreen(window, is_fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
                printf("Done setting fullscreen\n");
                break;
            default:
                break;
            }
        }
        else
        {
            printf("SDL_WaitEvent failed %s\n", SDL_GetError());
        }
    }

    return 0;
}

This uses wmain because that was the easiest way I could get it to build in mingw. It should work the same with main or WinMain.

To reproduce the bug:

  • Run the test program in Wine with SDL_EVENT_LOGGING=1.
  • Click the window to fullscreen it.
  • Alt+tab to another window.
  • The last focus event logged was FOCUS_GAINED.

This appears to be a Wine bug, but I wanted to file it here so I could send in a work-around. I don't think this is really a regression, it's just that previous versions didn't detect the focus loss in Wine.

There is also a bug where the window does not restore to fullscreen correctly, but I will file that separately.

@madewokherd
Copy link
Contributor Author

Winehq bug report: https://bugs.winehq.org/show_bug.cgi?id=52519

@madewokherd
Copy link
Contributor Author

Filed #5320 for the fullscreen issue.

@flibitijibibo flibitijibibo added this to the 2.0.22 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants