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
Linux: Window getPosition returning incorrect position #1228
Comments
Looks like this issue got missed somehow. We like to discuss potential issues on the forum first, as in many/most cases things turn out to be either a user error or some weird setup. See our contribution guidelines. Can you provide some examples of what decorations you use and what the differences are and any special window manager settings you use. |
I'm having a similar problem. I'm running the XMonad WM, tested on Gentoo, Fedora 25 and Fedora 26. |
Small test program here: https://gist.github.com/llongi/e02ea9d824572a0854a032c10b35d136 it just creates a 100x100 window, puts it at position 100,100 and on close prints the position as returned by getPosition(), which should be, in a perfect world, 100,100 again. So far in summary:
Just FYI, my use case is an application that can create multiple windows to show different visualizations of scientific data, and I want to be able to save how the user arranges those windows and present him with them at the same place next time he starts the program. |
I've spent a few hours digging into this and my latest attempt is at: So far it works well everywhere I tried (Xmonad, Gnome Xorg, Gnome Wayland), on Gnome it just reports 99,99 because it can't take the 1x1 window border drawn by Gnome into account, X11 simply doesn't know about it and there's no way to find out (Gnome doesn't set X11 border width, just shifts the parent negatively by the border width and then adds that to the difference between parent and window... what an inconsistent mess this all is...). I believe the above approach is the best that can be done in a generic way using the information available via X11/Xlib. One other approach I thought of was to setPosition to something known, getPosition() and then calculate the difference and apply that as offset on subsequent getPosition() calls. But that doesn't consider cases like changing the WM theme while your application is running. I experimented with ConfigureNotify X11 events to detect such changes, it's possible, but it just grows into a gigantic hack. In any case I believe the current approach is clearly wrong, from the XGetGeometry() docs: "Return the x and y coordinates that define the location of the drawable. For a window, these coordinates specify the upper-left outer corner relative to its parent's origin."; so using them as source coordinates in XTranslateCoordinates(window, root) is incorrect, as it gets the absolute position of the window respective to the root, and then adds the parent-window difference on top. That can't work, and brutally breaks down on non-reparenting WMs (there the parent is the root, so you add the amount to itself). If you had used negative xLocal/yLocal, that would have been more correct, at least on re-parenting WMs. Would still break on non-reparenting ones (result would be 0,0). |
And I believed wrong, one can do much better thanks to Extended Window Link: https://gist.github.com/llongi/c993113f0fc31db638af22a3c4784563 The below table should prove that the current code is often completely Now, we first look at the WM and get a couple of rare exceptions that give The following table documents the results of testing setPosition(100, 100) EWMH WMs (do define Frame Extents)
[1], [2]: these two WMs place the actual render window at position 100x100, Non-EWMH WMs (Frame Extents not defined)
[3]: auto-centers window ignoring any setPosition(), though before the patch I'm personally pretty happy with the code, it often just works by going the I believe this code is a clear improvement on the current one, easy to |
Thanks for all the work you've put into this! The various WMs on Linux is a bit of a nightmare to get things right. Feel free to provide a pull request with your changes, that way we can make the review easier and run it through the CI system. |
…sults on Linux depending on the used WM, as well as not returning values that are in-sync with what was given to setPosition(x, y).
Related to #346, #372
Testing on Ubuntu/GNOME 3 - getPosition() output differs quite drastically depending on if window does/doesn't have decorations
New to X11, though it seems
XTranslateCoordinates()
is meant to use (0, 0) for src_x/y as they are relative to the source window origin. Works on my build minus the decorations discussed in #372, though that's good for me.https://gist.github.com/JonesBlunt/7c396e2341b69362f0d940c1b955e0e0/revisions
The text was updated successfully, but these errors were encountered: