移动应用程序的最佳选择是抓取它的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 屏幕键盘发出这些键,但这需要为您希望执行的每个键绑定匹配正确的键和 I/O 仿真,这可以只要用户想要它,就可以从扩展中更改。