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

x11: Don't force position windows with an undefined position #12068

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

Kontrabant
Copy link
Contributor

An undefined position means that the window manager can handle placement, so SDL shouldn't override that by forcing a position when showing a window.

Allows for removing a fair bit of now-unnecessary code as well.

Fixes #12060

An undefined position means that the window manager can handle placement, so SDL shouldn't override that by forcing a position when showing a window.

Allows for removing a fair bit of now-unnecessary code as well.
@Kontrabant Kontrabant merged commit d0ae093 into libsdl-org:main Jan 23, 2025
2 checks passed
@Kontrabant Kontrabant deleted the x11_undef_pos branch January 23, 2025 19:36
@milq
Copy link

milq commented Jan 26, 2025

@Kontrabant, currently, my window does not center properly; instead, it remains positioned in a corner. This behavior is observed on my Debian 12 system with Xfce. I attach a video. Below is the code I am using, which is the default:

SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
{
    SDL_Renderer * renderer = NULL;
    SDL_Window * window = NULL;

    SDL_SetAppMetadata("Game", "1.0", "io.itch.milq.game");

    if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
        SDL_Log("SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) failed: %s", SDL_GetError());
        return SDL_APP_FAILURE;
    }

    if (!SDL_CreateWindowAndRenderer("Game", 1280, 720, 0, &window, &renderer)) {
        SDL_Log("SDL_CreateWindowAndRenderer() failed: %s", SDL_GetError());
        return SDL_APP_FAILURE;
    }

    // Etc.

Video: https://github.com/user-attachments/assets/bf218864-5595-48c9-8d72-fe1ad579b173

@Kontrabant
Copy link
Contributor Author

SDL_CreateWindowAndRenderer() doesn't have parameters to set an explicit window position, so it is left up to the window manager to position the window. If you need the window in a specific position, you need to create a window with the position properties set. Forcing the window to center by default in this case was actually incorrect behavior.

@milq
Copy link

milq commented Feb 2, 2025

Okay, it's just that I thought SDL with SDL_CreateWindowAndRenderer centered the window by default. Thanks, @Kontrabant.

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 this pull request may close these issues.

SDL_CreateWindowAndRenderer does not center window on creation at first in Debian GNU/Linux
2 participants