This extension allows you to list current windows with some of their properties from command line, super usefull for Wayland to get current focused window.
Also, it allows you to move given window to different workspace.
Credit to dceee for providing example code in this discussion and to blueray453 for requesting additional functions and providing code example for additional properties returned by List method in issue #1;
Install extension from gnome extensions page.
To get all active windows simply run from terminal:
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.List
Call returns list of window properties. Example output:
[
{
"wm_class": "Caprine",
"wm_class_instance": "caprine",
"pid": 62901,
"id": 1610090767,
"frame_type": 0,
"window_type": 0,
"width": 1910,
"height": 2100,
"x": 10,
"y": 50,
"in_current_workspace": false,
"monitor": 0
}
]
To move given window to some workspace, in my case window with id 2205525109 to workspace number 4:
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.MoveToWorkspace 2205525109 4
List
method only returns basic information about the window. There are two more methods:
Details
, which returns detailed information about window in JSON formatGetTitle
, which returns windows title. Title can contain special characters, which can break ceratin tools likejq
when parsing JSONGetFrameBounds
, which returns windows frame bounds in JSON dictionary. This stopped working around Gnome 43, so I moved this property to additional callable function
Both methods should be invoked giving desired window's id as a parameter. Example usages:
gdbus call --session --dest org.gnome.Shell --print-reply=literal --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.Details 2205525109
Example result of calling Details
:
{
"wm_class": "Caprine",
"wm_class_instance": "caprine",
"pid": 62901,
"id": 1610090767,
"width": 1910,
"height": 2100,
"x": 10,
"y": 50,
"maximized": 0,
"focus": false,
"in_current_workspace": false,
"moveable": true,
"resizeable": true,
"canclose": true,
"canmaximize": true,
"canminimize": true,
"canshade": true,
"display": {},
"frame_type": 0,
"window_type": 0,
"layer": 2,
"monitor": 0,
"role": "browser-window",
"area": {},
"area_all": {},
"area_cust": {}
}
Resizing and moving can be done either together or separetely. There are 3 methods providing this functionality:
Resize
which takes 3 parameters: winid width heightMoveResize
which takes 3 parameters: winid x y width heightMove
which takes 3 parameters: winid x y
When calling Move
or MoveResize
you sometimes want to pass negative x or y value. In order to do so, you need to add ~~
before arguments in gdbus call like so:
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.Move ~~ 12345678908 -32 -13
Ther are 6 methods providing such functionality:
Maximize
Minimize
Unmaximize
Unminimize
Activate
Close
Each takes only one parameter, winid.
You can realize the full power of this extension when you use it with jq
or similar tool. As gdbus call returns its own structure, --print-reply=literal
is needed.
For example, To view all windows in json:
gdbus call --session --dest org.gnome.Shell --print-reply=literal --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.List | jq .
To get windowID of all windows in current workspace:
gdbus call --session --dest org.gnome.Shell --print-reply=literal --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.List | jq -c '.[] | select (.in_current_workspace == true) | .id'
To get windowID and wm_class of all windows in current workspace:
gdbus call --session --dest org.gnome.Shell --print-reply=literal --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.List | jq -c '[.[] | select (.in_current_workspace == true) | {id: .id,wm_class: .wm_class}]'
To get windowID and wm_class of all visible window:
gdbus call --session --dest org.gnome.Shell --print-reply=literal --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.List | jq -c '[.[] | select (.frame_type == 0 and .window_type == 0) | {id: .id,wm_class: .wm_class}]'
To get windowID and wm_class of all visible window in current workspace:
gdbus call --session --dest org.gnome.Shell --print-reply=literal --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.List | jq -c '[.[] | select (.in_current_workspace == true and .frame_type == 0 and .window_type == 0) | {id: .id,wm_class: .wm_class}]' | jq .