gnome-shell-extensions - 从 activateResult 运行多个 xdtool 命令
问题描述
我正在创建一个 gnome shell 扩展并实现搜索提供程序。在 activateResult 方法中,我想运行一些代码,例如
GLib.spawn_command_line_sync('xdotool windowactivate ' + window_id);
GLib.spawn_command_line_sync('xdotool key "ctrl+r"');
GLib.spawn_command_line_sync('xdotool type ' + some_text);
问题是只有第一个命令有效,我收到一些错误,例如:
Jul 27 20:05:09 comp org.gnome.Shell.desktop[3334]: Window manager warning: Received a NET_CURRENT_DESKTOP message from a broken (outdated) client who sent a 0 timestamp
Jul 27 20:05:09 comp org.gnome.Shell.desktop[3334]: Window manager warning: Buggy client sent a _NET_ACTIVE_WINDOW message with a timestamp of 0 for 0x2e00001 (somestuff)
Jul 27 20:05:09 comp org.gnome.Shell.desktop[3334]: Window manager warning: last_focus_time (93207838) is greater than comparison timestamp (93207584). This most likely represents a buggy client sending inaccurate timestamps in messages such as _NET_ACTIVE_WINDOW. Trying to work around...
Jul 27 20:05:09 comp org.gnome.Shell.desktop[3334]: Window manager warning: last_user_time (93207838) is greater than comparison timestamp (93207584). This most likely represents a buggy client sending inaccurate timestamps in messages such as _NET_ACTIVE_WINDOW. Trying to work around...
Jul 27 20:05:09 comp org.gnome.Shell.desktop[3334]: Window manager warning: 0x2e00001 (somestuff) appears to be one of the offending windows with a timestamp of 93207838. Working around..
我尝试的一件事是将所有 xdotool 命令组合在一起bash -c "... ... ..."
,但没有运气。
选择搜索结果后,如何切换到窗口并模拟按键?
(我对 gnome 的东西、gjs 的东西,甚至 JS 都是全新的,但是,每天都要写 python)
编辑:刚试过spawn_command_line_async
,它的工作原理。感觉草率,有经验的人可能会有更好的答案。
解决方案
如果您正在编写 GNOME Shell 扩展,值得注意的是有许多 GNOME 平台库可供您使用。
对于模拟鼠标和键盘事件,Atspi 将在大多数情况下工作。作为模拟按键的简单示例a
:
const Atspi = import.gi.Atspi;
Atspi.generate_keyboard_event(0, 'a', Atspi.KeySynthType.STRING);
另一方面,激活窗口可能最好使用内置的窗口管理器函数来完成,但是这些没有记录在案,您必须检查GNOME Shell JavaScript 源代码或执行此操作的另一个扩展程序的源代码.
推荐阅读
- carousel - 在引导程序 myCarousel 中拉伸的图像
- reporting-services - 引用“无”时切换功能未返回正确值
- django - 将 2 个缓存条目合并为一个
- wordpress - 在其他用户不工作的情况下在 Mac 上运行 XAMPP
- javascript - 有没有办法从两个范围输入中获取值并给方程一个自定义值?
- javascript - 在映射之前按属性对对象数组进行排序
- mysql - 我如何使用 Sequelize 在 NODE 中执行多个查询(UPDATE)?
- laravel-5 - 在 laravel 的刀片模板中的单个视图上分别从多个表中显示多个变量数据
- php - 如果为空,如何添加默认值?
- c# - 尝试进行 GET 网络申请,但未处理 ProtocolViolationException