| Summary: | SDL_GetWindowPosition / SDL_SetWindowPosition do not work from the same origin | ||
|---|---|---|---|
| Product: | SDL | Reporter: | sdl |
| Component: | video | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P1 | CC: | BurnSpamAddress, david, icculus |
| Version: | HG 2.0 | Keywords: | target-2.0.0 |
| Hardware: | x86_64 | ||
| OS: | Linux | ||
| Attachments: |
Test app to demonstrate the bug
Adjust window location in ConfigureNotify Adjust window location in ConfigureNotify |
||
Good patch, thanks! http://hg.libsdl.org/SDL/rev/c74f5dbcfd23 Whoops, commented on the wrong bug. (Sorry if you get a lot of copies of this email, we're touching dozens of bug reports right now.) Tagging a bunch of bugs as target-2.0.0, Priority 1. This means we're in the final stretch for an official SDL 2.0.0 release! These are the bugs we really want to fix before shipping if humanly possible. That being said, we don't promise to fix them because of this tag, we just want to make sure we don't forget to deal with them before we bless a final 2.0.0 release, and generally be organized about what we're aiming to ship. Hopefully you'll hear more about this bug soon. If you have more information (including "this got fixed at some point, nevermind"), we would love to have you come add more information to the bug report when you have a moment. Thanks! --ryan. I can't reproduce this on KWin 4.10.5 which makes me think that either it was fixed or is a WM issue. Is anyone else still getting this? -- David (In reply to comment #4) > Is anyone else still getting this? 100% reproducible on Ubuntu 12.04, Unity 2D, with latest in SDL's hg repo. --ryan. (In reply to comment #5) > 100% reproducible on Ubuntu 12.04, Unity 2D, with latest in SDL's hg repo. So this is what it's doing, fwiw: [icculus@taise ~]$ ./testwin move 66 x 52 move 67 x 80 move 68 x 108 move 69 x 136 move 70 x 164 Moves over by 1x28 pixels on each click...which is exactly the width of the left border and the height of the title bar. This is maybe a Unity bug, or a vague piece of the window manager spec? --ryan. Hmm... I can reproduce this with TWM, but not with Openbox. According to the thread here: https://mail.gnome.org/archives/wm-spec-list/1999-September/msg00026.html lots of WMs do get this wrong, and the ICCCM spec suggests that the co-ordinates for XMoveWindow and ConfigureNotify should match up. I guess you could work around it by moving the window once to find the offset, but reallly, this is something only WM devs can fix properly. -- David I haven't tried this, but could we just see where the window we created landed vs where we asked it to land, and adjust from there in future GetWindowPosition calls? --ryan. This could work as a workaround, however the offset will change depending on the window decoration.
I have implemented a solution based on _NET_FRAME_EXTENTS that works on every desktop environment / window manager I have tested on (gnome 2, gnome 3, compiz, kwin 3.x, kwin 4.x, Xfce, various more exotic ones). The code is open-source but, unfortunately, not in C, but the main idea is to subtract the top-left border size whenever you receive a ConfigureNotify event.
The code I am using is similar to the following (pseudo-C):
static Atom _atom_net_frame_extents;
...
// on startup:
_atom_net_frame_extents = XInternAtom(display, "_NET_FRAME_EXTENTS", 0);
...
// on ConfigureNotify event:
// get current border size
Atom type, format;
unsigned long nitems, bytes_after;
unsigned char *property;
XGetWindowProperty(display, window,
_atom_net_frame_extents, 0, 16, 0,
XA_CARDINAL, &type, &format,
&nitems, &bytes_after, &property);
long border_left = ((long*)property)[0];
long border_right = ((long*)property)[1];
long border_top = ((long*)property)[2];
long border_bottom = ((long*)property)[3];
// adjust window location
window_x = e->ConfigureEvent.x - border_left;
window_y = e->ConfigureEvent.y - border_top;
// no need to adjust width and height
window_w = e->ConfigureEvent.width;
window_h = e->ConfigureEvent.height;
...
Created attachment 1382 [details]
Adjust window location in ConfigureNotify
Created attachment 1383 [details]
Adjust window location in ConfigureNotify
Looks good, thanks! http://hg.libsdl.org/SDL/rev/909b0d7fe4dd |
Created attachment 697 [details] Test app to demonstrate the bug When doing something like: SDL_GetWindowPosition(window, &x, &y); SDL_SetWindowPosition(window, x, y); The window will actually move by some offset (which really look like the width & height of my window borders & title under gnome2), this kinda defeats the whole purpose of those functions :/ Attached is a small SDL app to reproduce the behavior (clicking in the window will exhibit the bug)