简体   繁体   English

GNOME Shell扩展可以移动指针吗? 如果是这样,怎么样?

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

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. 我想写一个与GNOME Shell中“焦点跟随鼠标”设置相反的扩展:我想让我的指针移动到当前聚焦窗口的中心。

Can this be done in a GNOME Shell extension? 这可以在GNOME Shell扩展中完成吗? 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. 我看到一些包含xfixes游标的 GNOME代码,但我找不到核心Javascript或任何现有扩展中对程序指针更新的任何引用。 (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. 有效答案包括(1)执行此操作的示例代码或(2)引用无法完成的规范来源的引用。

Found this code in overview.js 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);

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. 首先,使用xprop获取您单击的窗口的PID。

Next, use xwininfo to get the dimensions and position information of the window based on its process ID. 接下来,使用xwininfo根据进程ID获取窗口的维度和位置信息。

Finally, use xdotool to calculate the center position of said window and move the cursor to that exact position. 最后,使用xdotool计算所述窗口的中心位置,并将光标移动到该确切位置。

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. 编辑:根据您的评论,您想留在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: 您可以通过使用以下内容从GNOME js中调用xdotool (这是在屏幕上更改光标位置的最有效方法):

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 at this thread. 此代码在此主题中找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM