You are not logged in.
Following code come from https://github.com/ickyicky/window-call … #L254-L261
A gnome extension which can active a window by a window id. (as the wmctrl for Xorg)
Activate(winid) {
let win = this._get_window_by_wid(winid).meta_window;
if (win) {
win.activate(Math.floor(Date.now() / 1000));
} else {
throw new Error('Not found');
}
}
But, it not work well on my arch, when i activate window use above function, the specified window raised to foreground as expect, but the cursor is not focus.
I saw several extension both use code like `window.activate` for this purpose, though, i don't understand the argument "Math.floor(Date.now() / 1000)“ is stand for.
but, i can assume those extension should work, so, maybe somethings is breaking on my laptop?
so, can anyone help for test it? or, if be proved it really not work, any idea?
Following is the process to test it.
1. ensure you are using wayland
2. install this extension
3. run following code
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.List |cut -c 3- | rev | cut -c4- | rev | jq -c '[.[] | select (.in_current_workspace == true and .frame_type == 0 and .window_type == 0) | {id: .id,wm_class: .wm_class,pid: .pid}]'|jq
you need jq be installed to get following output:
[
{
"id": 2752131049,
"wm_class": "org.gnome.Extensions",
"pid": 33634
},
{
"id": 2752130997,
"wm_class": "Emacs",
"pid": 4488
},
{
"id": 2752131051,
"wm_class": "TelegramDesktop",
"pid": 1440
},
{
"id": 2752130996,
"wm_class": "firefox",
"pid": 3074
},
{
"id": 2752130993,
"wm_class": "konsole",
"pid": 1427
}
]
4. we assume you are current run command in konsole, so, you are try to activate the emacs window, it id is: 2752130997
so, you can run following command to check if it can active the emacs window and focus the cursor.
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.Activate 2752130997
On my laptop, emacs window is active, but the cursor is not focus, i have to click it use mouse to focus it.
Thank you.
Last edited by zw963 (2022-10-14 17:28:22)
Offline
Hi, i fixed after change to "win.activate(0);"
I don't know why, but it works!
Offline