We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1300 - SDL_GetWindowPosition / SDL_SetWindowPosition do not work from the same origin
Summary: SDL_GetWindowPosition / SDL_SetWindowPosition do not work from the same origin
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.0
Hardware: x86_64 Linux
: P1 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.0
Depends on:
Blocks:
 
Reported: 2011-09-05 00:52 UTC by sdl
Modified: 2013-10-20 16:53 UTC (History)
3 users (show)

See Also:


Attachments
Test app to demonstrate the bug (1.27 KB, text/x-csrc)
2011-09-05 00:52 UTC, sdl
Details
Adjust window location in ConfigureNotify (11.71 KB, patch)
2013-10-20 15:13 UTC, BurnSpamAddress
Details | Diff
Adjust window location in ConfigureNotify (2.13 KB, text/plain)
2013-10-20 15:28 UTC, BurnSpamAddress
Details

Note You need to log in before you can comment on or make changes to this bug.
Description sdl 2011-09-05 00:52:19 UTC
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)
Comment 1 Sam Lantinga 2013-05-21 02:57:41 UTC
Good patch, thanks!
http://hg.libsdl.org/SDL/rev/c74f5dbcfd23
Comment 2 Sam Lantinga 2013-05-21 02:58:12 UTC
Whoops, commented on the wrong bug.
Comment 3 Ryan C. Gordon 2013-07-12 18:52:33 UTC
(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.
Comment 4 David Gow 2013-07-15 10:57:30 UTC
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
Comment 5 Ryan C. Gordon 2013-07-15 23:44:19 UTC
(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.
Comment 6 Ryan C. Gordon 2013-07-15 23:48:32 UTC
(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.
Comment 7 David Gow 2013-07-16 00:27:20 UTC
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
Comment 8 Ryan C. Gordon 2013-08-01 21:48:07 UTC
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.
Comment 9 BurnSpamAddress 2013-10-20 14:40:06 UTC
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;
...
Comment 10 BurnSpamAddress 2013-10-20 15:13:10 UTC
Created attachment 1382 [details]
Adjust window location in ConfigureNotify
Comment 11 BurnSpamAddress 2013-10-20 15:28:05 UTC
Created attachment 1383 [details]
Adjust window location in ConfigureNotify
Comment 12 Sam Lantinga 2013-10-20 16:53:30 UTC
Looks good, thanks!
http://hg.libsdl.org/SDL/rev/909b0d7fe4dd