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

SDL2: sometimes linux automatically rescales window to a minimum size #10270

Closed
oddbookworm opened this issue Jul 14, 2024 · 1 comment
Closed

Comments

@oddbookworm
Copy link

Sometimes, a windowresize event is immediately put out upon creation of a window that resizes it. I haven't been able to figure out the common denominator of when this happens and how to get the size it'll rescale to. I'm a maintainer of pygame-ce and this has been causing us headaches lately because when this does happen, it causes one of our tests to segfault or fail because at best, the surface we stored from the window is no longer the same size as the one that the user requested. At worst, it segfaults because the surface we stored is now garbage data.

Is there a reason for this that's already known and I missed something? Is there a reliable way to at least get the size that will be rescaled to so that we can notify our users that their screen is not the requested size?

C reproducer:

#include <stdio.h>

#include "SDL2/SDL.h"

int main()
{
    int w = 1;
    int h = 100;

    if (SDL_InitSubSystem(SDL_INIT_VIDEO))
    {
        printf("Failed to init video");
        return 1;
    }

    SDL_Window* win = SDL_CreateWindow("test window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, 0);

    if (win == NULL)
    {
        printf("win is NULL");
        return -1;
    }

    SDL_Surface* surf = SDL_GetWindowSurface(win);
    if (surf == NULL)
    {
        printf("surf is NULL");
        return -1;
    }

    printf("surf->size == %d,%d\n", surf->w, surf->h);

    SDL_Event event;
    while (SDL_PollEvent(&event) > 0)
    {
        if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_RESIZED)
        {
            printf("Resize event to (%d, %d)\n", event.window.data1, event.window.data2);
        }
    }

    surf = SDL_GetWindowSurface(win);
    if (surf == NULL)
    {
        printf("surf is NULL");
        return -1;
    }

    printf("surf->size == %d,%d\n", surf->w, surf->h);

    return 0;
}

Output on Manjaro linux, X11, KDE Plasma 6.0.5, KWin WM:

surf->size == 1,1
Resize event to (3, 30)
surf->size == 3,30
@slouken
Copy link
Collaborator

slouken commented Jul 14, 2024

It's always possible for the OS to ignore the size and position of your window. If you try to create a window smaller than the minimum size, like you do here, for example. On mobile devices, you don't have an option, the window is the size of the screen, whether you wanted it or not.

I know it's not ideal, but the real answer is that you should always be able to accommodate window resizing, even in test code.

@slouken slouken closed this as not planned Won't fix, can't repro, duplicate, stale Jul 14, 2024
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

2 participants