1
votes

To do a "fake" fullscreen window in SDL2 without a modeset you can create a borderless, maximized window using something like this.

int idx = SDL_GetWindowDisplayIndex(g_displayWindow);
SDL_Rect bounds;
SDL_GetDisplayBounds(idx, &bounds);
//SDL_SetWindowResizable(g_displayWindow, SDL_FALSE);
SDL_SetWindowBordered(g_displayWindow, SDL_FALSE);
SDL_SetWindowPosition(g_displayWindow, bounds.x, bounds.y);
SDL_SetWindowSize(g_displayWindow, bounds.w, bounds.h);

For non-resizable windows, this works perfectly. On windows created with SDL_WINDOW_RESIZABLE there is an annoying grey border on the bottom and right edges of the screen (on windows). Unfortunately there isn't a SDL_SetWindowResizable function (as of SDL 2.0.4). How can we get rid of the resizing border without recreating the window?

SDL_WINDOW_FULLSCREEN_DESKTOP and SDL_WINDOW_FULLSCREEN both do a modeset which I want to avoid - it takes longer, it's harder to alt-tab out of, and if the game hits a breakpoint in the debugger it can lock up the whole system.

1
SDL_WINDOW_FULLSCREEN_DESKTOP should not be causing a full switch of the display mode like SDL_WINDOW_FULLSCREEN does. Are they behaving equivalently for you? It is intended for exactly this kind of situation where you want an undecorated window that fills the whole screen and you want it done in a crossplatform way.Jonny D
I did SDL_WINDOW_FULLSCREEN_DESKTOP. It doesn't seem to do a display mode switch. But it does lock up on a debugger break (on a single-screen system). Setting a window to the full display size, though, had the same behavior. Could get back to VS by sleeping and waking the laptop. :-/david van brink
It shouldn't ever lock up the system, ctrl+alt+delete can always get you out if the program itself isn't acting properlyNicholas Pipitone

1 Answers

3
votes

This is what I came up with - tested and works on windows.

void SDL_SetWindowResizable(SDL_Window *win, SDL_bool resizable)
{
    SDL_SysWMinfo info;
    SDL_VERSION(&info.version);
    SDL_GetWindowWMInfo(g_displayWindow, &info);

#if WIN32
    HWND hwnd = info.info.win.window;
    DWORD style = GetWindowLong(hwnd, GWL_STYLE);
    if (resizable)
        style |= WS_THICKFRAME;
    else
        style &= ~WS_THICKFRAME;
    SetWindowLong(hwnd, GWL_STYLE, style);
#endif
}