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

SDL_GetWindowPosition / SDL_SetWindowPosition do not work from the same origin #480

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Closed

Comments

@SDLBugzilla
Copy link
Collaborator

@SDLBugzilla SDLBugzilla commented Feb 10, 2021

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: HG 2.0
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2011-09-05 00:52:19 +0000, wrote:

Created attachment 697
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)

On 2013-05-21 02:57:41 +0000, Sam Lantinga wrote:

Good patch, thanks!
http://hg.libsdl.org/SDL/rev/c74f5dbcfd23

On 2013-05-21 02:58:12 +0000, Sam Lantinga wrote:

Whoops, commented on the wrong bug.

On 2013-07-12 18:52:33 +0000, Ryan C. Gordon wrote:

(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.

On 2013-07-15 10:57:30 +0000, David Gow wrote:

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

On 2013-07-15 23:44:19 +0000, Ryan C. Gordon wrote:

(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.

On 2013-07-15 23:48:32 +0000, Ryan C. Gordon wrote:

(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.

On 2013-07-16 00:27:20 +0000, David Gow wrote:

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

On 2013-08-01 21:48:07 +0000, Ryan C. Gordon wrote:

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.

On 2013-10-20 14:40:06 +0000, wrote:

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;
...

On 2013-10-20 15:13:10 +0000, wrote:

Created attachment 1382
Adjust window location in ConfigureNotify

On 2013-10-20 15:28:05 +0000, wrote:

Created attachment 1383
Adjust window location in ConfigureNotify

On 2013-10-20 16:53:30 +0000, Sam Lantinga wrote:

Looks good, thanks!
http://hg.libsdl.org/SDL/rev/909b0d7fe4dd

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

1 participant