The Python `wmctrl` library (version 0.5) provides a wrapper around the `wmctrl` command-line utility, enabling programmatic control of windows within the X Window System. It allows Python scripts to query window information, activate windows, and perform actions like resizing or moving. The library follows a stable release cadence, with updates typically occurring years apart, reflecting its role as an interface to a mature external tool.
pip install wmctrlVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to list active windows and all open windows using the `wmctrl` library's `get_windows()` and `get_active_window()` functions. It also shows how to activate a window and includes an example of directly invoking the `wmctrl` command-line utility via `subprocess` for more granular control like moving and resizing. Ensure the `wmctrl` command-line utility is installed on your system.
Install the `wmctrl` command-line utility appropriate for your Linux distribution before using the Python library.
Implement a delay (e.g., `time.sleep()`) or a polling mechanism to wait for the target window to appear and be ready before attempting to control it. You can poll `get_windows()` until the expected window is found.
Explicitly set `DISPLAY` (e.g., `:0` or `:1`) and `XAUTHORITY` (e.g., `/home/youruser/.Xauthority`) environment variables for the process running `wmctrl`. You may also need to use `xhost +local:` to allow access.
There is no direct fix within `wmctrl` for this limitation, as it's often a behavior dictated by the fullscreen application or window manager. Consider alternative X11 tools like `xdotool` if this is a critical requirement, or ensure the target application is not truly fullscreen if possible.