SDL2: two displays, two windows and fullscreen mod

2019-05-25 04:17发布

问题:

I'm trying to create two windows on two displays. But I have a problem: the second window is displayed in full screen mode, but the first window is minimized, and I need to click on it on the taskbar to expand to full screen.

I create windows in loop with code:

windows_data.window = SDL_CreateWindow("Title", SDL_WINDOWPOS_CENTERED_DISPLAY(i),
            SDL_WINDOWPOS_CENTERED_DISPLAY(i), width, height, SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_SHOWN);

Adding the flag SDL_WINDOW_MAXIMIZED does not solve the problem.

My system is Windows 8.1 Proffesional.

回答1:

I debug step by step and found the reason in SDL_video.c::SDL_OnWindowFocusLost(SDL_Window * window)

SDL_OnWindowFocusLost(SDL_Window * window)
{
    if (window->gamma && _this->SetWindowGammaRamp) {
        _this->SetWindowGammaRamp(_this, window, window->saved_gamma);
    }

    SDL_UpdateWindowGrab(window);

    if (ShouldMinimizeOnFocusLoss(window)) {
        SDL_MinimizeWindow(window);
    }
}

So the problem is here "if (ShouldMinimizeOnFocusLoss(window))".

To solve the problem, I add the following code before creating the window:

SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");