我在平板电脑上使用 Gnome 作为日常驱动程序。集成的虚拟键盘不能替代真实的键盘,但我正是需要它。于是我想用Onboard来代替它,并开始为Gnome Shell编写一个扩展。目标是在隐藏/显示集成虚拟键盘时隐藏和显示 Onboard。
我可以通过 DBus 显示/隐藏 Onboard,如下所示:
dbus-send --type=method_call --dest=org.onboard.Onboard /org/onboard/Onboard/Keyboard org.onboard.Onboard.Keyboard.Show
我改编了 https://wiki.gnome.org/Gjs/Examples/DBusClient 中的示例通过 DBus 测试显示/隐藏 Onboard:
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
// This the D-Bus interface as XML
const OnboardInterface = '<node> \
<interface name="org.onboard.Onboard.Keyboard"> \
<method name="ToggleVisible"> \
</method> \
<method name="Show"> \
</method> \
<method name="Hide"> \
</method> \
</interface> \
</node>';
// Declare the proxy class based on the interface
const OnboardProxy = Gio.DBusProxy.makeProxyWrapper(OnboardInterface);
let OnbProxy = new OnboardProxy(
Gio.DBus.system,
"org.onboard.Onboard",
"/org/onboard/Onboard/Keyboard"
);
OnbProxy.ShowSync()
let loop = new GLib.MainLoop(null, false);
loop.run();
遗憾的是它没有显示 Onboard,而是抛出此错误:
$ gjs ./test.js
(gjs:13144): Gjs-WARNING **: JS ERROR: Gio.DBusError: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.onboard.Onboard was not provided by any .service files
_proxyInvoker@resource:///org/gnome/gjs/modules/overrides/Gio.js:98
_makeProxyMethod/<@resource:///org/gnome/gjs/modules/overrides/Gio.js:124
@./test.js:26
JS_EvaluateScript() failed
我不知道为什么它谈论服务,而我只想通过 DBus 发送消息?这可能是一个相当愚蠢的错误,因为我对 Gnome Shell 扩展和 DBus 都没有任何经验..
Gnome 版本为 3.18.0
最佳答案
找到解决方案:用Gio.DBus.session替换Gio.DBus.system
Onboard 不是系统服务,而是在用户 session 中启动的,因此它不起作用。
该扩展程序将在https://extensions.gnome.org/上可用一旦验证通过,只需搜索“板载集成”即可。我还做了另一个相关的,“键盘滑动”正如它所说的那样(从底部滑动)
关于gnome - 用 Onboard -> Hide/Show via DBus 替换 Gnomes 虚拟键盘不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33065735/