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

[SDL 3.2.5, macOS 15.3] Window height and width 20px smaller than expected when using SDL_WINDOW_RESIZABLE #12228

Open
nickcernis opened this issue Feb 8, 2025 · 0 comments

Comments

@nickcernis
Copy link

nickcernis commented Feb 8, 2025

  • SDL 3.2.5 (main branch as of 69d2802, built from source)
  • macOS 15.3
  • MacBook Air M2, display resolution "default" (1710x1107)

Observed behavior

Opening a window with SDL_WINDOW_RESIZABLE results in a window size 20 pixels shorter and narrower (about the size of a scroll bar, even though none are visible?) than the usable screen space passed to SDL_CreateWindowAndRenderer sourced from SDL_GetDisplayUsableBounds.

Flags

SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE, 

Snippet (full repro code at the bottom of this report):

    SDL_Rect display_bounds;
    if (!SDL_GetDisplayUsableBounds(display, &display_bounds)) {
        SDL_Log("Couldn't get display bounds: %s", SDL_GetError());
        return SDL_APP_FAILURE;
    }

    SDL_Log("Expected window size: %d, %d", display_bounds.w, display_bounds.h);

    // Create window using available display bounds.
    if (!SDL_CreateWindowAndRenderer(
            "Demo app", display_bounds.w, display_bounds.h,
            SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE, &window, &renderer)) {
        SDL_Log("Couldn't create window/renderer: %s", SDL_GetError());
        return SDL_APP_FAILURE;
    }

    int window_width, window_height;
    SDL_GetWindowSize(window, &window_width, &window_height);
    SDL_Log("Actual window size: %d, %d", window_width, window_height);

❌ Result — empty space around window revealing desktop

Image

Logged output shows the actual window is 20px smaller in width and height than the size I passed to SDL_CreateWindowAndRenderer:

2025-02-08 22:57:26.979 sdl3test[33672:1887726] Expected window size: 1710, 1068
2025-02-08 22:57:27.002 sdl3test[33672:1887726] Actual window size: 1690, 1048

Expected behavior

I expected SDL_WINDOW_RESIZABLE to not change the initial size of the window. When it's removed, the window uses all available screen space as passed from display_bounds.w and display_bounds.h:

Flags

SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_BORDERLESS,

Snippet diff:

    SDL_Rect display_bounds;
    if (!SDL_GetDisplayUsableBounds(display, &display_bounds)) {
        SDL_Log("Couldn't get display bounds: %s", SDL_GetError());
        return SDL_APP_FAILURE;
    }

    SDL_Log("Expected window size: %d, %d", display_bounds.w, display_bounds.h);

    // Create window using available display bounds.
    if (!SDL_CreateWindowAndRenderer(
            "Demo app", display_bounds.w, display_bounds.h,
-            SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE, &window, &renderer)) {
+            SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_BORDERLESS, &window, &renderer)) {
        SDL_Log("Couldn't create window/renderer: %s", SDL_GetError());
        return SDL_APP_FAILURE;
    }

    int window_width, window_height;
    SDL_GetWindowSize(window, &window_width, &window_height);
    SDL_Log("Actual window size: %d, %d", window_width, window_height);

✅ Result — no empty space around window

Image

And logged sizes match; note that the expected window size has not changed, it's just being honoured now with SDL_WINDOW_RESIZABLE removed:

2025-02-08 22:55:10.203 sdl3test[30770:1879198] Expected window size: 1710, 1068
2025-02-08 22:55:10.224 sdl3test[30770:1879198] Actual window size: 1710, 1068

Non-workarounds

Adding SDL_WINDOW_MAXIMIZED has no effect.

Hard-coding the window height and width values to 1710 x 1068 also results in a smaller window size than expected if SDL_WINDOW_RESIZABLE is used. Hard-coding them to lower values such as 500 x 500 does not result in a size change if SDL_WINDOW_RESIZABLE is used.

Removing SDL_WINDOW_BORDERLESS still results in a gap if SDL_WINDOW_RESIZABLE is used in conjunction with SDL_GetDisplayUsableBounds:

Image

Workarounds

Removing SDL_WINDOW_RESIZABLE works but leaves the window non-resizable (can't use true full-screen).

If I switch to SDL_GetDisplayBounds from SDL_GetDisplayUsableBounds then using SDL_WINDOW_RESIZABLE does not cause size differences, but the height becomes 1107 (full screen height) instead of usable height of 1068 (full height minus the macOS status bar) so the window is taller than it needs to be (losing the top).

I can also launch with SDL_WINDOW_FULLSCREEN but it's not ideal because it doesn't give users a chance to choose monitors, and I'd prefer that they choose to go full screen on their terms.

To reproduce

Run the following:

#define SDL_MAIN_USE_CALLBACKS
#include <SDL3/SDL.h>
#include <SDL3/SDL_log.h>
#include <SDL3/SDL_main.h>

static SDL_Window* window = NULL;
static SDL_Renderer* renderer = NULL;

SDL_AppResult SDL_AppInit(void** appstate, int argc, char** argv) {
    SDL_Log("Initializing using SDL %d.%d.%d", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION);
    SDL_SetAppMetadata("Demo", "0.1.0", "com.example.demo");

    if (!SDL_Init(SDL_INIT_VIDEO)) {
        SDL_Log("Couldn't initialize SDL: %s", SDL_GetError());
        return SDL_APP_FAILURE;
    }

    SDL_DisplayID display = SDL_GetPrimaryDisplay();
    if (display == 0) {
        SDL_Log("Couldn't get primary display: %s", SDL_GetError());
        return SDL_APP_FAILURE;
    }
    SDL_Log("Display ID: %u", display);

    SDL_Rect display_bounds;
    if (!SDL_GetDisplayUsableBounds(display, &display_bounds)) {
        SDL_Log("Couldn't get display bounds: %s", SDL_GetError());
        return SDL_APP_FAILURE;
    }

    SDL_Log("Expected window size: %d, %d", display_bounds.w, display_bounds.h);

    // Create window using available display bounds.
    if (!SDL_CreateWindowAndRenderer(
            "Demo app", display_bounds.w, display_bounds.h,
            SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE, &window, &renderer)) {
        SDL_Log("Couldn't create window/renderer: %s", SDL_GetError());
        return SDL_APP_FAILURE;
    }

    int window_width, window_height;
    SDL_GetWindowSize(window, &window_width, &window_height);
    SDL_Log("Actual window size: %d, %d", window_width, window_height);

    return SDL_APP_CONTINUE;
}

SDL_AppResult SDL_AppIterate(void* appstate) {
    SDL_SetRenderDrawColor(renderer, 200, 0, 200, 255);
    SDL_RenderClear(renderer);
    SDL_RenderPresent(renderer);

    return SDL_APP_CONTINUE;
}

SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) {
    if (event->type == SDL_EVENT_QUIT) {
        return SDL_APP_SUCCESS;
    }
    return SDL_APP_CONTINUE;
}

void SDL_AppQuit(void* appstate, SDL_AppResult result) {
    SDL_Log("Quitting");
    // SDL cleans up the window and renderer, no need to manually free.
}
@nickcernis nickcernis changed the title [SDL 3.2.5, macOS 15.3] SDL_WINDOW_RESIZABLE results in 20px smaller window width/height than values passed from SDL_GetDisplayUsableBounds [SDL 3.2.5, macOS 15.3] Window height and width 20px smaller than expected when using SDL_WINDOW_RESIZABLE Feb 9, 2025
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

No branches or pull requests

1 participant