LinuxCommandLibrary

wmctrl

Control and query window manager settings

TLDR

List all windows, managed by the window manager

$ wmctrl -l
copy

Switch to the first window whose (partial) title matches
$ wmctrl -a [window_title]
copy

Move a window to the current workspace, raise it and give it focus
$ wmctrl -R [window_title]
copy

Switch to a workspace
$ wmctrl -s [workspace_number]
copy

Select a window and toggle fullscreen
$ wmctrl -r [window_title] -b toggle,fullscreen
copy

Select a window and move it to a workspace
$ wmctrl -r [window_title] -t [workspace_number]
copy

SYNOPSIS

wmctrl [options] [command] [arguments]

PARAMETERS

-m
    Display information about the window manager.

-d
    Display information about the desktops.

-l
    List all managed windows.

-i
    Interpret window and desktop IDs as decimal numbers instead of hexadecimal.

-r
    Specify the target window. can be the window ID (in hexadecimal or decimal, depending on -i), part of the window title, or the resource name of the application.

-a
    Activate the window specified by .

-e ,,,,
    Move and resize the window specified by . is a number between 0 and 9 representing the placement of the window. , are coordinates, and are dimensions.

-b ,,,
    Manipulate window properties. can be add, remove, or toggle. , , and are the names of the properties.

-c
    Close the window specified by .

-x
    Print window class and machine name along with normal output.

-F
    Force command execution even if window manager doesn't support EWMH.

DESCRIPTION

wmctrl is a command-line tool that allows you to interact with a running X Window System window manager. It provides a way to query information about windows, desktops, and the window manager itself, and also provides functionality to control these elements. This control includes operations like moving, resizing, activating, closing, and changing the state of windows.
It communicates with the window manager using the Extended Window Manager Hints (EWMH) and NetWM protocols, aiming to provide a consistent interface across different window managers that support these standards. This makes wmctrl a valuable tool for scripting and automating window management tasks. Using this tool is very useful for automation scripts where you can control the window placement and state of applications.
It's especially useful in environments where a graphical interface isn't readily available or where you need to perform window management operations programmatically.

CAVEATS

wmctrl's effectiveness depends on the window manager's adherence to EWMH and NetWM standards. Some window managers might not fully support these standards, leading to unpredictable behavior.
Window IDs are volatile and change upon window creation/destruction.

WINDOW IDENTIFICATION

wmctrl identifies windows using a combination of window ID, part of the window title, or the resource name of the application. When specifying a window by title, ensure the title is unique to avoid ambiguity. The '-x' option can assist in finding the correct window class name to use.

GRAVITY VALUES FOR -E OPTION

The gravity value in the '-e' option determines how the window's position is adjusted relative to its new size. Common values:
0: NorthWest
1: North
2: NorthEast
3: West
4: Center
5: East
6: SouthWest
7: South
8: SouthEast
9: Static

SEE ALSO

xdotool(1), xprop(1), xwininfo(1)

Copied to clipboard