Skip to content

Latest commit

 

History

History
194 lines (149 loc) · 7.07 KB

Readme.md

File metadata and controls

194 lines (149 loc) · 7.07 KB

Window Commander

This extension aims to provide only what is neccessary for the ulauncher-window-manager to work properly. If you don't plan to use the ulauncher-window-manager, the extension window-call by ickyicky might be a better option for you.

Installation

  1. Install from gnome extensions page.
  2. Or clone the repo and run make install

Usage

List Windows

To get a list of all the active windows run from terminal:

gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/WindowCommander --method org.gnome.Shell.Extensions.WindowCommander.List

Example output:

[
    {
        "id": 1139090783,
        "monitor": 0,
        "focus": false,
        "in_current_workspace": false,
    },
    {
        "id": 8734090787,
        "monitor": 0,
        "focus": true,
        "in_current_workspace": true,
    }
]

Get extra information about a window

  • GetDetails, which returns detailed information about window in JSON format
  • GetFrameRect, which returns the rectangle that bounds window that is what the user thinks of as the edge of the window.
  • GetBufferRect, which returns the rectangle that the pixmap or buffer of window occupies. For x11 this is the server-side geometry of the toplevel window. For wayland this is the bounding rectangle of the attached buffer.

These methods should be invoked giving the desired window's id as a parameter. Example usages:

GetDetails

gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/WindowCommander --method org.gnome.Shell.Extensions.WindowCommander.GetDetails 8734090787

GetFrameRect

gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/WindowCommander --method org.gnome.Shell.Extensions.WindowCommander.GetFrameRect 8734090787

GetBufferRect

gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/WindowCommander --method org.gnome.Shell.Extensions.WindowCommander.GetBufferRect 8734090787

Example result of calling GetDetails:

{
    "id": 8734090787,
    "monitor": 0,
    "wm_class": "gnome-terminal-server",
    "wm_class_instance": "gnome-terminal-server",
    "maximized": 3,
    "focus": true,
    "canMove": true,
    "canResize": false,
    "canClose": true,
    "canMaximize": true,
    "canMinimize": true,
    "windowArea": {
        "x": 0,
        "y": 34,
        "width": 1920,
        "height": 1166
    },
    "currentMonitorWorkArea": {
        "x": 0,
        "y": 34,
        "width": 1920,
        "height": 1166
    },
    "allMonitorsWorkArea": {
        "x": 0,
        "y": 34,
        "width": 1920,
        "height": 1166
    },
    "in_current_workspace": true
}

Example result of calling GetFrameRect or GetBufferRect:

{
    "x": 0,
    "y": 34,
    "width": 1920,
    "height": 1166
}

Place Window

Placing a window resizes and moves the provided window simultaneously.

  • Place takes 5 parameters: winid x y width height

Example usage:

gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/WindowCommander --method org.gnome.Shell.Extensions.WindowCommander.Place 8734090787 0 34 800 600

Move window to next or previous workspace

To move the given window to the next(right or left for the previous) workspace:

gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/WindowCommander --method org.gnome.Shell.Extensions.WindowCommander.MoveToWorkspace 8734090787 right

Move window to left/right/up/down monitor

To move the given window to another monitor (left/right/up/down):

gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/WindowCommander --method org.gnome.Shell.Extensions.WindowCommander.MoveToMonitor 8734090787 right

Maximize, Unmaximize, Minimize, Unminimize, Close

These 5 Methods provide the functionality their name implies. They should be invoked giving the desired window's id as a parameter. Example usages:

  • Maximize
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/WindowCommander --method org.gnome.Shell.Extensions.WindowCommander.Maximize 8734090787
  • Minimize
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/WindowCommander --method org.gnome.Shell.Extensions.WindowCommander.Minimize 8734090787

etc...

Using With jq

Because the gdbus call returns its own structure, which is not JSON parsable, you might want to use cut or gawk in order to retrieve pure JSON output from the call. For example, to get the window list in json you can run:

gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/WindowCommander --method org.gnome.Shell.Extensions.WindowCommander.List | cut -c 3- | rev | cut -c4- | rev | jq .

To get the window id of all windows in current workspace:

gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/WindowCommander --method org.gnome.Shell.Extensions.WindowCommander.List | cut -c 3- | rev | cut -c4- | rev | jq -c '.[] | select (.in_current_workspace == true) | .id'

To get the window id and focus of all windows in current workspace:

gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/WindowCommander --method org.gnome.Shell.Extensions.WindowCommander.List | cut -c 3- | rev | cut -c4- | rev | jq -c '[.[] | select (.in_current_workspace == true) | {id: .id,wm_class: .focus}]'

etc...

Using with gawk

You can also use gawk to capture the desired JSON values. It has to be paired with sed in order to replace escaping done by qawk on quotes. For List gawk should look for JSON list:

gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/WindowCommander --method org.gnome.Shell.Extensions.WindowCommander.List | gawk 'match($0, /\[.*\]/, a) {print a[0]}' | sed 's/\\"/"/g' | jq .

And for Details you want to find just one dictionary:

gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/WindowCommander --method org.gnome.Shell.Extensions.WindowCommander.Details 1610090767 | gawk 'match($0, /\{.*\}/, a) {print a[0]}' | sed 's/\\"/"/g' | jq .

Credits

To ickyicky for the original repository, which served as the foundation of this project.

Credits section copied over from the original repository: 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