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

xdo_get_window_location provides correct location #289

Merged
merged 1 commit into from
Aug 8, 2020

Conversation

E-Heerschap
Copy link
Contributor

The previous implementation interpreted of xdo_get_window_location the first set of x,y coordinates to XTranslateCoordinates as being relative to the parent origin. This translated the real x,y coordinates location by attr.x and attr.y respectively where attr is the window attributes. However, it is relative to the screen origin. See: XTranslateCoordinates Documentation; specifically the src_x and src_y fields:

Specify the x and y coordinates within the source window.

Practical example - Point the mouse cursor at the window origin (in this case xclock) and then to the very edge border pixel:

Old:
xdoold

New:
newxdo

Script run in gifs:

#!/bin/bash
xclock &
sleep 1
pid=$(ps -a | grep xclock | awk '{print $1}')
window=$(xdotool search --pid ${pid})
location=$(xdotool getwindowgeometry $window | awk '/,/ {print $2}')
x=$(echo ${location} | awk '{split($1,a,","); print a[1];}')
y=$(echo ${location} | awk '{split($1,a,","); print a[2];}')
xdotool mousemove $x $y
sleep 3
let y-=45
xdotool mousemove $x $y
#45 from XWindowAttributes.y (Dist from parent)

@jordansissel
Copy link
Owner

whew the X API can be confusing. Thank you for this fix.

I also really appreciate this PR can be reviewed without me even opening a terminal because of your example script and before/after gifs. Thank you for going so far to make this very simple to review <3

@jordansissel jordansissel merged commit d969274 into jordansissel:master Aug 8, 2020
@adamws
Copy link

adamws commented Oct 29, 2020

@kingpulse, @jordansissel Hi, I'm having issue similar to the one described as old (but using latest master) which I reported to i3/i3#4234 - I cannot exactly tell if that is a problem with window manager or xdotool. Maybe you can take a look?

@E-Heerschap
Copy link
Contributor Author

@adamws Hi, I had a look into the code and there were some minor differences between some functions which may be causing the issue. I have not installed i3; If this doesn't fix the issue i'll install it and see if I can find a fix for you ☺️. So far this patch works fine for me using Gnome 3 + Mutter. See if this branch has fixed the bug

buldi pushed a commit to buldi/xdotool that referenced this pull request Apr 23, 2022
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

Successfully merging this pull request may close these issues.

3 participants