1

I am trying to figure out how to make a script that operates in the following way:

  1. finds dimensions of the display which the mouse pointer is currently on
  2. moves the mouse pointer to the center of the left edge on that display
  3. I'd like to be able to add command arguments when running the script that would add or subtract to the center left edge position and move the mouse accordingly. For example if I ran:

python3 /path/to/script.py

then the script would place the mouse pointer on left edge of display and in the center of the vertical axis. If I ran this:

python3 /path/to/script.py 10 -10

then the script would place the mouse pointer 10px --> from left edge of screen, and -10px (down) from center of vertical axis.

I'm pretty sure xdotool and python can accomplish this, but I am a complete noob when it comes to programming anything, and even though I found this link, I'm still not sure how to proceed. If anyone feels so kind as to help me out with this, it would be greatly appreciated, but if not then no worries.

If anyone is curious as to why I want to do this: I'm setting up a tablet to use i3wm. I'm creating touch button shortcuts for i3 window management using jgmenu. Jgmenu has an option to launch at the location of the mouse pointer. I would like to use a touchegg gesture to first move the mouse pointer with this script, then launch jgmenu.

0

1 Answer 1

1

This approach uses utilities for X servers, it presumably won't work with Wayland.
Here's a little bash function for you:

line_up () 
{ 
  vc=$(( $(xwininfo -root|sed '/Height/!d;s/.* //') / 2 ));
  [[ -n $2 ]] && vc=$(( -$2 + vc ));
  xdotool mousemove $(( $1 )) $vc
}

As a oneliner:

line_up(){ vc=$(($(xwininfo -root|sed '/Height/!d;s/.* //')/2));[[ $2 ]]&&vc=$((-$2+vc));xdotool mousemove $(($1)) $vc;}

This uses the output of xwininfo to get the current display's height, divides it in half and saves it as variable cv. If $2 exists, it is subtracted. xdotool then moves the cursor to the coordinates $1,$vc. I take advantage of the fact that bash's arithmetic expression just returns 0 if $1 is not set, a plain xdotool mousemove $1 … would just throw an error in that case. As above you can call the function with as much arguments as you like, if there are none it will just move the cursor to 0,totalheight/2, if there's one to $1,totalheight/2 and if there are two or more to $1,totalheight/2-$2.

Example run

$ xwininfo -root|sed '/Height/!d' # display height is 1024 px
  Height: 1024
$ xdotool getmouselocation # current mouse location: 469,875
x:469 y:875 screen:0 window:15294612
$ line_up
$ xdotool getmouselocation # current mouse location: 0,512
x:0 y:512 screen:0 window:14680366
$ line_up 10
$ xdotool getmouselocation # current mouse location: 10,512
x:10 y:512 screen:0 window:14680366
$ line_up 20 -10
$ xdotool getmouselocation # current mouse location: 20,522
x:20 y:522 screen:0 window:14680366

Sources

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .