Can GNOME Shell extensions move the pointer? If so, how?

I want to write an extension that does the opposite “focus-follow mouse” setting in the GNOME shell: I want to make my pointer move to the center of the current focused window.

Can this be done in the GNOME shell extension? I see some GNOME code that wraps the xfixes cursor , but I can’t find links to software pointer updates in mostly Javascript or any existing extensions, (Am I just bad on Google?)

Valid answers include (1) an example of code that does this, or (2) quoting a canonical source that says this is not possible.

+7
gnome gnome-3 gnome-shell gnome-shell-extensions
source share
2 answers

Found this code in overview.js

 Gdk = imports.gi.Gdk let display = Gdk.Display.get_default(); let deviceManager = display.get_device_manager(); let pointer = deviceManager.get_client_pointer(); let [screen, pointerX, pointerY] = pointer.get_position(); pointer.warp(screen, 10, 10); 
+2
source share

Are you ready to write your own script? If so, I found three tools that, if used together, can do the job for you.

First use xprop to get the PID of the window you clicked on.

Then use xwininfo to get the size and location information of the window based on its process id.

Finally, use xdotool to calculate the center position of the specified window and move the cursor to that exact position.

Hope this helps. I don't have enough time to write now to write a script (sorry), but that should be enough for you to get started.

EDIT: based on your comment, you want to stay in GNOME js. It’s completely clear. You can call xdotool (which is the most efficient way to move the cursor on the screen) from within GNOME js, using something like:

 const Util = imports.misc.util; Util.spawn(['/bin/bash', '-c', "xrandr --query | awk 'something'"]) # replace the code here wih your own 

This code was found in this thread.

0
source share

All Articles