Extended Window Manager Hints implementation in Python 3
Project description
EWMH-lib
Extended Window Manager Hints implementation in Python 3 and python-xlib, which allows to easily query and control Window Managers following these standards.
It also adds some additional, useful features like managing hints and handling events.
For more information, refer to official documentation at: https://specifications.freedesktop.org/wm-spec/latest/
This module has been tested OK in Ubuntu/GNOME, Mint/Cinnamon and Manjaro/KDE. If you have issues in other EWMH-compliant environments, do not hesitate to open an issue in the project homepage
Warning: new Display Server used by GNOME in Ubuntu, Wayland, is not EWMH-compliant, so many features will not work
EwmhRoot: Root queries, changes and messages
Class to access root features.
If you need to address default root window, you can simply use defaultRootWindow
object, which will give you
instant access to all root-related features (it is equivalent to: myRoot = EwmhRoot()
)
To get a EwmhRoot object it is necessary to pass the target root id. This can be achieved in several ways:
- You already have a root, so pass root.id param
- You have some criteria to select a root, so use the convenience function
getAllDisplaysInfo()
, to look for all roots and select the desired one - You have a target window, so use the convenience function getDisplayFromWindow(window.id), so you will retrieve the associated display connection and root window
- Instantiate this class with no param (None), so it will retrieve the default display and root
Note that, even though a regular (application) window has the same type than a root window, these methods will not work with it, so avoid passing it to instantiate this class.
Apart from given methods, you can access these other values to be used with python-xlib:
- display: XDisplay connection
- screen: screen Struct
- root: root X Window object
- id: root window id
WM Protocols
WM_PROTOCOLS messages (PING/SYNC) are accessible using wmProtocols subclass (EwmhRoot.wmProtocols.Ping/Sync)
EwmhWindow: Window queries, changes and messages
Class to access application window features.
To instantiate this class only a window id is required. It is possible to retrieve this value in several ways:
- Target a specific window using an external module (e.g.
PyWinCtl.getAllWindowsWithTitle(title)
) - Retrieve it from your own application (e.g. PyQt's
winId()
or TKinter'sframe()
)
Note that, although a root is also a window, most of these methods will not likely work with it.
Apart from given methods, there are some values you can use with python-xlib:
- display: XDisplay connection
- screen: screen Struct
- root: root X Window object
- rootWindow: object to access EwmhRoot methods
- xWindow: X Window object associated to current window
- id: current window id
Additional, non-EWMH features, related to low-level window properties like hints, protocols and events are available using extensions subclass (EwmhWindow.extensions.*), see below.
Extensions: Geometry, Hints, Protocols and Events
Additional, non-EWMH features, related to low-level window properties like geometry, hints, protocols and events.
Events loop example:
import time
import Xlib.protocol
import Xlib.X
from ewmhlib import EwmhRoot, EwmhWindow
root = EwmhRoot()
w = root.getActiveWindow()
if w:
win = EwmhWindow(w)
def callback(event: Xlib.protocol.rq.Event):
print("EVENT RECEIVED", event)
win.extensions.checkEvents.start([Xlib.X.ConfigureNotify, Xlib.X.ConfigureRequest, Xlib.X.ClientMessage],
Xlib.X.StructureNotifyMask | Xlib.X.SubstructureNotifyMask,
callback)
print("MOVE AND RESIZE ACTIVE WINDOW")
print("Press Ctl-C to exit")
while True:
try:
time.sleep(0.1)
except KeyboardInterrupt:
break
win.extensions.checkEvents.stop()
General variables
As their names suggest, these general variables will give access to the default display, screen and root objects, allowing to perform all Xlib-related functions.
Objects |
---|
defaultDisplay |
defaultScreen |
defaultRoot |
Display functions
These functions will allow to manage/find proper display and screen, in a multi-display or multi-screen environment (not the usual scenario, so the default objects above will be enough in most cases).
Display functions |
---|
getAllDisplays |
getDisplayFromRoot |
getDisplayFromWindow |
Properties and Messages functions
This set of functions will allow to directly query and control application or root windows, without the need of instantiating their corresponding classes described above.
These are very similar to their Xlib equivalent functions (more complex to use), and therefore will allow custom, more advanced, perhaps more specific and/or non fully EWMH standard features; but they add some useful help in order to simplify handling replies, values, atoms and so on.
Property functions |
---|
getProperty |
getPropertyValue |
changeProperty |
sendMessage |
Properties, atoms and hints values
These values are accessible through Props
class (ewmhlib.Props.*).
They include all properties, atoms and hints values recognized by EWMH specs, so makes it easier
to find, enumerate or use them.
They have been organized in different subclasses, according to their type or when they should be used.
Data Structs
Aimed to facilitate understanding and handling complex reply data structures and fields.
Data Structs |
---|
DisplaysInfo |
ScreensInfo |
WmHints |
WmNormalHints |
INSTALL
To install this module on your system, you can use pip:
pip3 install ewmhlib
or
python3 -m pip install ewmhlib
Alternatively, you can download the wheel file (.whl) available in the Download page and the dist folder, and run this (don't forget to replace 'x.x.xx' with proper version number):
pip install EWMHlib-x.x.xx-py3-none-any.whl
You may want to add --force-reinstall
option to be sure you are installing the right dependencies version.
Then, you can use it on your own projects just importing it:
import ewmhlib
SUPPORT
In case you have a problem, comments or suggestions, do not hesitate to open issues on the project homepage
USING THIS CODE
If you want to use this code or contribute, you can either:
- Create a fork of the repository, or
- Download the repository, uncompress, and open it on your IDE of choice (e.g. PyCharm)
Be sure you install all dependencies described on "docs/requirements.txt" by using pip
TEST
To test this module on your own system, cd to "tests" folder and run:
python3 test_ewmhlib.py
List of window managers that support Extended Window Manager Hints
An (likely) incomplete list of EWMH-compliant window managers is (via Wikipedia, here and here):
Name | Comments |
---|---|
aewm | |
awesome | |
Blackbox | (1) |
bspwm | Partial |
CTWM | (2) |
Compiz | |
echinus | |
edewm | |
Enlightenment | |
evilwm | Partial (3) |
EXWM | Partial |
Fluxbox | |
FVWM | |
goomwwm | |
herbstluftwm | |
i3 | |
IceWM | |
interfacewm | |
JWM | |
KWin (KDE) | |
LeftWM | |
Marco | |
Matchbox | |
Metacity (GNOME) | |
Mutter (GNOME/MeeGo) | |
Notion | |
Openbox | |
PekWM | Partial |
PlayWM | |
Qtile | |
Sawfish | Partial |
spectrwm | |
subtle | |
Window Maker | Partial |
Wingo | |
WMFS | |
wmii | |
Xfwm (Xfce) | |
xmonad | (4) |
(1) Through 0.65 / from 0.70 (2) As of 4.0.0 (3) Releases following and including version 1.1.0 follow the EWMH standard (4) Must activate EWMH (XMonad.Hooks.EwmhDesktops)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file EWMHlib-0.1-py3-none-any.whl
.
File metadata
- Download URL: EWMHlib-0.1-py3-none-any.whl
- Upload date:
- Size: 52.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c9a24ca3f623cb0ff1f2bef86ab0e3388dd87c9249545ac6a4d2b536a18faad |
|
MD5 | 9564099ddbaa8408422916d621f34b78 |
|
BLAKE2b-256 | 6c13ed6c350cc07753ef7f09c3b2ee8cc4b4c89fff34083ee7bbd2d6710b9419 |