gpt4 book ai didi

gnome-3 - 以编程方式调用 Gnome Shell 快捷方式

转载 作者:行者123 更新时间:2023-12-01 06:30:55 30 4
gpt4 key购买 nike

Gnome Shell 有很好的快捷方式,但是,我找不到以编程方式调用它们的方法
假设我想使用 GJS 脚本启动 Google Chrome,将其移动到工作区 1,并将其最大化,然后启动 Emacs,将其移动到工作区 2,并将其最大化。
这可以使用 wm.keybindings 来完成:move-to-workspace-1、move-to-workspace-2 和最大化。但是,如何以编程方式调用它们?

我注意到在 GJS 中,Meta.prefs_get_keybinding_action('move-to-workspace-1')将返回 Action 移动到工作区 1,但我没有找到任何调用该 Action 的函数。
https://github.com/GNOME/mutter/blob/master/src/core/keybindings.c ,我找到了一个函数 meta_display_accelerator_activate,但是我找不到这个函数的 GJS 绑定(bind)。

那么,有没有办法以编程方式调用 gnome shell 快捷方式?

最佳答案

移动应用程序的最佳选择是捕获它的Meta.Window。对象,它是在它启动后创建的。

这将通过获取事件工作区、启动应用程序、然后从事件工作区获取应用程序并移动它来完成。

快速实现的示例代码:

const workspace = global.screen.get_active_workspace();
const Gio = imports.gi.Gio;

//CLIname: Name used to open app from a terminal
//wsIndex: Workspace you want it on
function openApp(CLIname, wsIndex) {
let context = new Gio.AppLaunchContext;
//use 2 to indicate URI support
//0 is no flags, 1 for terminal window,
//No 3, 4 for notification support
//null because setting a name has no use
Gio.AppInfo.create_from_commandline(CLIname, null, 2).launch([], context);
//Unfortunately, there is no way I know to grab a specific window if you don't know the index.
for(let w of workspace.list_windows()) {
//check if the window title or window manager class match the CLIname. Haven't found any that don't match either yet.
if(w.title.toLowerCase().includes(CLIname.toLowerCase() || w.get_wm_class().toLowerCase.includes(CLIname.toLowerCase()) {
//Found a match? Move it!
w.change_workspace(global.screen.get_workspace_by_index(wsIndex));
}
{
}
/*init(), enable() and disable() aren't relevant here*/

要在最后回答实际问题,可以通过强制 GNOME 屏幕键盘发出这些键,但这需要为您希望执行的每个键绑定(bind)匹配正确的键和 I/O 仿真,这可以只要用户想要它,就可以从扩展中更改。

关于gnome-3 - 以编程方式调用 Gnome Shell 快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21748730/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com