linux C Gnome Shell扩展密钥绑定
发布时间:2023-12-20 08:14:08 所属栏目:Linux 来源:DaWei
导读: (全局)将键组合(例如< Super> A)绑定到gnome shell扩展中的函数的最简单方法是什么?
检查了几个扩展,我遇到了以下代码:
global.display.add_keybinding('random-name',new Gio.Settings(
检查了几个扩展,我遇到了以下代码:
global.display.add_keybinding('random-name',new Gio.Settings(
(全局)将键组合(例如< Super> A)绑定到gnome shell扩展中的函数的最简单方法是什么? 检查了几个扩展,我遇到了以下代码: global.display.add_keybinding('random-name',new Gio.Settings({schema: 'org.gnome.shell.keybindings'}),Meta.KeyBindingFlags.NONE,function() { /* ... some code */ });我知道组合键是由schema参数指定的,并且可以创建描述组合的XML文件.有更简单的方法吗?
最佳答案
以下是我的答案here的副本 TL; DR 这是一堂课: KeyManager: new Lang.Class({ Name: 'MyKeyManager',_init: function() { this.grabbers = new Map() global.display.connect( 'accelerator-activated',Lang.bind(this,function(display,action,deviceId,timestamp){ log('Accelerator Activated: [display={},action={},deviceId={},timestamp={}]',display,timestamp) this._onAccelerator(action) })) },listenFor: function(accelerator,callback){ log('Trying to listen for hot key [accelerator={}]',accelerator) let action = global.display.grab_accelerator(accelerator) if(action == Meta.KeyBindingAction.NONE) { log('Unable to grab accelerator [binding={}]',accelerator) } else { log('Grabbed accelerator [action={}]',action) let name = Meta.external_binding_name_for_action(action) log('Received binding name for action [name={},action={}]',name,action) log('Requesting WM to allow binding [name={}]',name) Main.wm.allowKeybinding(name,Shell.ActionMode.ALL) this.grabbers.set(action,{ name: name,accelerator: accelerator,callback: callback }) } },_onAccelerator: function(action) { let grabber = this.grabbers.get(action) if(grabber) { this.grabbers.get(action).callback() } else { log('No listeners [action={}]',action) } } })这就是你如何使用它: let keyManager = new KeyManager() keyManager.listenFor("(编辑:鲜蔬坊站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Find command usage in Linux with excellent examples--re
- linux – Bash while while循环意外停止
- linux快速清空文件 比如log日志
- 在Linux环境下搭建高可用性服务器
- linux – 活动套接字的{tcp_error,Socket,etimedout}’消息
- linux – 现代cpus如何处理跨页未对齐访问?
- 如何在Linux(特别是Fedora 9)上使我的默认(或任何静态)路由
- 锁定 – 在Linux内核抢占spin_lock和mutex_lock
- 如何模拟linux中socket / tcp编程的异常情况,比如终止连接的
- php – 如何从pdf中提取文本图层和背景图层?
推荐文章
站长推荐