SDL Forum Index
SDL
Simple DirectMedia Layer Forums
Reply to topic
x11 video driver and saving window position
fau


Joined: 28 Jan 2017
Posts: 2
Reply with quote
Hi
I've been trying to implement a simple saving window position between sessions. I noticed that it works, but each time I launch my program, sdl window is appearing a bit lower than previously. Here is the issue isolated down to SDL2 API:

OS: Fedora Workstation 25, Gnome 3 running on Xorg server.

Code:

#include <SDL2/SDL.h>

int main() {
        int x, y;
        SDL_Window *win;

        SDL_Init(SDL_INIT_VIDEO);
        win = SDL_CreateWindow("test", 0, 100, 100, 100, SDL_WINDOW_SHOWN);
        SDL_PumpEvents();
        SDL_GetWindowPosition(win, &x, &y);
        SDL_DestroyWindow(win);
        SDL_Quit();
        return y;
}


Expected result:
I expect exit value to be 100 and this is what I get on windows 10, using "windows" video driver.

Obtained result:
Using x11 driver on my OS, exit value is 137 = 100 + height of window's title bar. (position returned by SDL_GetWindowPosition before SDL_PumpEvents is 100)


I'm not sure if I should report it as SDL2 bug, or am I missing something? I can workaround this problem by calling SDL_PumpEvents() and SDL_SetWindowPosition with saved position right after creating window, but this isn't perfect as window manager can have it's own legitimate reasons to change position of newly created window (for example here it makes sure the window is within desktop bounds and doesn't overlap a taskbar).[/code]
View user's profileSend private message
Dominus


Joined: 13 Oct 2009
Posts: 127
Reply with quote
I noticed similar with Exult. Cycling through scaler factors the window would gradually move lower and lower.
View user's profileSend private message
fau


Joined: 28 Jan 2017
Posts: 2
Reply with quote
Apparently this behaviour is specific to x11 video driver. What it does it that window manager adds decorations at some point after window creation and afaik there is no SDL event to tell when. When borders are added window gets shifted by their offsets and any further coordinates used eg by SDL_GetWindowPosition or SDL_SetWindowPosition are relative to parent window including decorations.

SDL_GetWindowBordersSize came to rescue. It's not perfect but I subtract border offsets when saving window position (so these coordinates can be used directly in SDL_CreateWindow).

I still think it would be better for SDL API to use window coordinates relative to borderless window, but maybe there are other considerations I don't know about. If I can discuss it with some x11 driver devs and they think the same, I would be willing to commit such changes.
View user's profileSend private message
x11 video driver and saving window position
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic