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]

PARAMETERS

-m
    Display information about the current window manager, including its name and EWMH compliance status.

-l
    List all open windows on the current desktop, showing their window ID, desktop number, and title.

-d
    List all configured desktops, showing their ID, dimensions, and current state.

-s desktop_num
    Switch the active desktop to the specified desktop_num.

-a WIN
    Activate (raise and focus) the window identified by WIN. WIN can be a window ID, title, or part of a title/class.

-i
    Interpret the WIN argument as a hexadecimal window ID (e.g., from wmctrl -l).

-x
    Interpret the WIN argument as a resource class or resource name (as seen in xprop output).

-R WIN
    Raise the specified window WIN to the top of the stacking order without necessarily giving it focus.

-c WIN
    Close the specified window WIN by sending a close request.

-k on|off
    Toggle showing the desktop (on to minimize all windows) or restoring windows (off).

-b WIN add|remove,prop1[,prop2]
    Add or remove window states for WIN. Common properties include sticky, shaded, maximized_vert, maximized_horz, hidden, fullscreen, above, below.

-G WIN x,y,width,height
    Move and resize the specified window WIN to the given coordinates and dimensions.

-N WIN new_name
    Set the _NET_WM_NAME property (commonly displayed as the window's name) of window WIN.

-T WIN new_title
    Set the _NET_WM_VISIBLE_NAME property (commonly displayed as the window's title in taskbars) of window WIN.

DESCRIPTION

wmctrl is a command-line tool designed to interact with EWMH/NetWM compliant X Window Managers. It provides a powerful interface for automating and scripting various window and desktop management tasks. Users can employ wmctrl to list open windows, switch between virtual desktops, activate or raise specific windows, close applications, and dynamically change window properties such as size, position, and state (e.g., maximizing, minimizing, making sticky). This utility is invaluable for creating custom shortcuts, automating workflow, or integrating window management into scripts, offering programmatic control over the desktop environment.

CAVEATS

wmctrl relies on the Extended Window Manager Hints (EWMH) specification. If your window manager is not EWMH/NetWM compliant (e.g., very old or minimalist WMs), some or all commands may not function as expected.
Window identification can be ambiguous; using window IDs (obtained via wmctrl -l and used with -i) is often more reliable than matching by name or class.

HISTORY

wmctrl was developed to provide a straightforward command-line interface for managing windows and desktops under X Window Systems that adhere to the Extended Window Manager Hints (EWMH) specification. Before wmctrl, interacting with window managers programmatically often required more complex Xlib programming. Its creation aimed to simplify the scripting of desktop automation tasks, making it accessible for a wider range of users and developers, focusing on standardized communication protocols for greater compatibility across various desktop environments.

SEE ALSO

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

Copied to clipboard