I want to write an extension that does the opposite of the "focus-follows mouse" setting in GNOME Shell: I want to make my pointer move to the center of the currently focused window.
Can this be done in a GNOME Shell extension? I see some GNOME code that wraps xfixes cursor, but I can't find any references to programmatic pointer updates in either the core Javascript or any existing extensions. (Am I just bad at Google?)
Valid answers include (1) example code that does it or (2) citation of a canonical source that says it can't be done.
Are you willing to write your own script? If you are, I have found three tools, which, if used together, can get the job done for you.
First, use
xprop
to get the PID of the window you have clicked on.Next, use
xwininfo
to get the dimensions and position information of the window based on its process ID.Finally, use
xdotool
to calculate the center position of said window and move the cursor to that exact position.Hope this helps. I don't have enough time write now to write the script (sorry), but this should be enough to get you started.
EDIT: Based on your comment, you want to stay in GNOME js. Totally understandable. You can call
xdotool
(which is the most efficient way of changing the position of the cursor on screen) from within GNOME js by use of something like:This code was found at this thread.