首页 > 解决方案 > 从 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-extensionsxdotoolgjscustom-search-provider

解决方案


如果您正在编写 GNOME Shell 扩展,值得注意的是有许多 GNOME 平台库可供您使用。

对于模拟鼠标和键盘事件,Atspi 将在大多数情况下工作。作为模拟按键的简单示例a

const Atspi = import.gi.Atspi;

Atspi.generate_keyboard_event(0, 'a', Atspi.KeySynthType.STRING);

另一方面,激活窗口可能最好使用内置的窗口管理器函数来完成,但是这些没有记录在案,您必须检查GNOME Shell JavaScript 源代码或执行此操作的另一个扩展程序的源代码.


推荐阅读