Skip to content

Commit 23f3685

Browse files
committed
Added emwhlib
Fixed width/height calculations in Windows
1 parent 1940511 commit 23f3685

File tree

10 files changed

+481
-550
lines changed

10 files changed

+481
-550
lines changed
-48.1 KB
Binary file not shown.
122 KB
Binary file not shown.

src/ewmhlib/Props.py

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
from enum import IntEnum
2+
import Xlib.X
3+
4+
5+
class Root:
6+
SUPPORTED = "_NET_SUPPORTED"
7+
CLIENT_LIST = "_NET_CLIENT_LIST"
8+
CLIENT_LIST_STACKING = "_NET_CLIENT_LIST_STACKING"
9+
NUMBER_OF_DESKTOPS = "_NET_NUMBER_OF_DESKTOPS"
10+
DESKTOP_GEOMETRY = "_NET_DESKTOP_GEOMETRY"
11+
DESKTOP_VIEWPORT = "_NET_DESKTOP_VIEWPORT"
12+
CURRENT_DESKTOP = "_NET_CURRENT_DESKTOP"
13+
DESKTOP_NAMES = "_NET_DESKTOP_NAMES"
14+
ACTIVE = "_NET_ACTIVE_WINDOW"
15+
WORKAREA = "_NET_WORKAREA"
16+
SUPPORTING_WM_CHECK = "_NET_SUPPORTING_WM_CHECK"
17+
VIRTUAL_ROOTS = "_NET_VIRTUAL_ROOTS"
18+
SHOWING_DESKTOP = "_NET_SHOWING_DESKTOP"
19+
DESKTOP_LAYOUT = "_NET_DESKTOP_LAYOUT"
20+
# Additional Root properties (always related to a specific window)
21+
CLOSE = "_NET_CLOSE_WINDOW"
22+
MOVERESIZE = "_NET_MOVERESIZE_WINDOW"
23+
WM_MOVERESIZE = "_NET_WM_MOVERESIZE"
24+
RESTACK = "_NET_RESTACK_WINDOW"
25+
REQ_FRAME_EXTENTS = "_NET_REQUEST_FRAME_EXTENTS"
26+
# WM_PROTOCOLS messages
27+
PROTOCOLS = "WM_PROTOCOLS"
28+
PING = "_NET_WM_PING"
29+
SYNC = "_NET_WM_SYNC_REQUEST"
30+
31+
32+
class DesktopLayout(IntEnum):
33+
ORIENTATION_HORZ = 0
34+
ORIENTATION_VERT = 1
35+
TOPLEFT = 0
36+
TOPRIGHT = 1
37+
BOTTOMRIGHT = 2
38+
BOTTOMLEFT = 3
39+
40+
41+
class Window:
42+
NAME = "_NET_WM_NAME"
43+
VISIBLE_NAME = "_NET_WM_VISIBLE_NAME"
44+
ICON_NAME = "_NET_WM_ICON_NAME"
45+
VISIBLE_ICON_NAME = "_NET_WM_VISIBLE_ICON_NAME"
46+
DESKTOP = "_NET_WM_DESKTOP"
47+
WM_WINDOW_TYPE = "_NET_WM_WINDOW_TYPE"
48+
CHANGE_STATE = "WM_CHANGE_STATE"
49+
WM_STATE = "_NET_WM_STATE"
50+
ALLOWED_ACTIONS = "_NET_WM_ALLOWED_ACTIONS"
51+
STRUT = "_NET_WM_STRUT"
52+
STRUT_PARTIAL = "_NET_WM_STRUT_PARTIAL"
53+
ICON_GEOMETRY = "_NET_WM_ICON_GEOMETRY"
54+
ICON = "_NET_WM_ICON"
55+
PID = "_NET_WM_PID"
56+
HANDLED_ICONS = "_NET_WM_HANDLED_ICONS"
57+
USER_TIME = "_NET_WM_USER_TIME"
58+
FRAME_EXTENTS = "_NET_FRAME_EXTENTS"
59+
# These are Root properties, but always related to a specific window
60+
ACTIVE = "_NET_ACTIVE_WINDOW"
61+
CLOSE = "_NET_CLOSE_WINDOW"
62+
MOVERESIZE = "_NET_MOVERESIZE_WINDOW"
63+
WM_MOVERESIZE = "_NET_WM_MOVERESIZE"
64+
RESTACK = "_NET_RESTACK_WINDOW"
65+
REQ_FRAME_EXTENTS = "_NET_REQUEST_FRAME_EXTENTS"
66+
OPAQUE_REGION = "_NET_WM_OPAQUE_REGION"
67+
BYPASS_COMPOSITOR = "_NET_WM_BYPASS_COMPOSITOR"
68+
69+
70+
class WindowType:
71+
DESKTOP = "_NET_WM_WINDOW_TYPE_DESKTOP"
72+
DOCK = "_NET_WM_WINDOW_TYPE_DOCK"
73+
TOOLBAR = "_NET_WM_WINDOW_TYPE_TOOLBAR"
74+
MENU = "_NET_WM_WINDOW_TYPE_MENU"
75+
UTILITY = "_NET_WM_WINDOW_TYPE_UTILITY"
76+
SPLASH = "_NET_WM_WINDOW_TYPE_SPLASH"
77+
DIALOG = "_NET_WM_WINDOW_TYPE_DIALOG"
78+
NORMAL = "_NET_WM_WINDOW_TYPE_NORMAL"
79+
80+
81+
class State:
82+
NULL = "0"
83+
MODAL = "_NET_WM_STATE_MODAL"
84+
STICKY = "_NET_WM_STATE_STICKY"
85+
MAXIMIZED_VERT = "_NET_WM_STATE_MAXIMIZED_VERT"
86+
MAXIMIZED_HORZ = "_NET_WM_STATE_MAXIMIZED_HORZ"
87+
SHADED = "_NET_WM_STATE_SHADED"
88+
SKIP_TASKBAR = "_NET_WM_STATE_SKIP_TASKBAR"
89+
SKIP_PAGER = "_NET_WM_STATE_SKIP_PAGER"
90+
HIDDEN = "_NET_WM_STATE_HIDDEN"
91+
FULLSCREEN = "_NET_WM_STATE_FULLSCREEN"
92+
ABOVE = "_NET_WM_STATE_ABOVE"
93+
BELOW = "_NET_WM_STATE_BELOW"
94+
DEMANDS_ATTENTION = "_NET_WM_STATE_DEMANDS_ATTENTION"
95+
FOCUSED = "_NET_WM_STATE_FOCUSED"
96+
97+
98+
class StateAction(IntEnum):
99+
REMOVE = 0
100+
ADD = 1
101+
TOGGLE = 2
102+
103+
104+
class MoveResize(IntEnum):
105+
SIZE_TOPLEFT = 0
106+
SIZE_TOP = 1
107+
SIZE_TOPRIGHT = 2
108+
SIZE_RIGHT = 3
109+
SIZE_BOTTOMRIGHT = 4
110+
SIZE_BOTTOM = 5
111+
SIZE_BOTTOMLEFT = 6
112+
SIZE_LEFT = 7
113+
MOVE = 8 # movement only
114+
SIZE_KEYBOARD = 9 # size via keyboard
115+
MOVE_KEYBOARD = 10 # move via keyboard
116+
117+
118+
class DataFormat(IntEnum):
119+
STR = 8
120+
INT = 32
121+
122+
123+
class Mode(IntEnum):
124+
REPLACE = Xlib.X.PropModeReplace
125+
APPEND = Xlib.X.PropModeAppend
126+
PREPEND = Xlib.X.PropModePrepend
127+
128+
129+
class StackMode(IntEnum):
130+
ABOVE = Xlib.X.Above
131+
BELOW = Xlib.X.Below
132+
133+
134+
class HintAction(IntEnum):
135+
KEEP = -1
136+
REMOVE = -2
137+
138+

src/ewmhlib/Structs.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from typing import List
2+
3+
from typing_extensions import TypedDict
4+
5+
from ctypes import Structure, c_int32, c_ulong, c_uint32
6+
import Xlib.xobject
7+
from Xlib.protocol.rq import Struct
8+
from Xlib.xobject.drawable import Window as XWindow
9+
10+
11+
class ScreensInfo(TypedDict):
12+
screen_number: str
13+
is_default: bool
14+
screen: Struct
15+
root: XWindow
16+
17+
18+
class DisplaysInfo(TypedDict):
19+
name: str
20+
is_default: bool
21+
screens: List[ScreensInfo]
22+
23+
24+
"""
25+
Perhaps unnecesary since structs below are defined in Xlib.xobject.icccm.*, though in a more complex way.
26+
"""
27+
class WmHints(TypedDict):
28+
# {'flags': 103, 'input': 1, 'initial_state': 1, 'icon_pixmap': <Pixmap 0x02a22304>, 'icon_window': <Window 0x00000000>, 'icon_x': 0, 'icon_y': 0, 'icon_mask': <Pixmap 0x02a2230b>, 'window_group': <Window 0x02a00001>}
29+
flags: int
30+
input_mode: int
31+
initial_state: int
32+
icon_pixmap: Xlib.xobject.drawable.Pixmap
33+
icon_window: Xlib.xobject.drawable.Window
34+
icon_x: int
35+
icon_y: int
36+
icon_mask: Xlib.xobject.drawable.Pixmap
37+
window_group: Xlib.xobject.drawable.Window
38+
39+
40+
class Aspect(TypedDict):
41+
num: int
42+
denum: int
43+
44+
45+
class WmNormalHints(TypedDict):
46+
# {'flags': 848, 'min_width': 387, 'min_height': 145, 'max_width': 0, 'max_height': 0, 'width_inc': 9, 'height_inc': 18, 'min_aspect': <class 'Xlib.protocol.rq.DictWrapper'>({'num': 0, 'denum': 0}), 'max_aspect': <class 'Xlib.protocol.rq.DictWrapper'>({'num': 0, 'denum': 0}), 'base_width': 66, 'base_height': 101, 'win_gravity': 1}
47+
flags: int
48+
min_width: int
49+
min_height: int
50+
max_width: int
51+
max_height: int
52+
width_inc: int
53+
height_inc: int
54+
min_aspect: Aspect
55+
max_aspect: Aspect
56+
base_width: int
57+
base_height: int
58+
win_gravity: int
59+
60+
61+
class _XWindowAttributes(Structure):
62+
_fields_ = [('x', c_int32), ('y', c_int32),
63+
('width', c_int32), ('height', c_int32), ('border_width', c_int32),
64+
('depth', c_int32), ('visual', c_ulong), ('root', c_ulong),
65+
('class', c_int32), ('bit_gravity', c_int32),
66+
('win_gravity', c_int32), ('backing_store', c_int32),
67+
('backing_planes', c_ulong), ('backing_pixel', c_ulong),
68+
('save_under', c_int32), ('colourmap', c_ulong),
69+
('mapinstalled', c_uint32), ('map_state', c_uint32),
70+
('all_event_masks', c_ulong), ('your_event_mask', c_ulong),
71+
('do_not_propagate_mask', c_ulong), ('override_redirect', c_int32), ('screen', c_ulong)]

src/ewmhlib/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
assert sys.platform == "linux"
5+
6+
from ._ewmhlib import (getAllDisplaysInfo, getDisplayFromRoot, getDisplayFromWindow,
7+
getProperty, getPropertyValue, changeProperty, sendMessage, _xlibGetAllWindows,
8+
defaultDisplay, defaultScreen, defaultRoot, RootWindow, defaultRootWindow, EwmhWindow
9+
)
10+
import ewmhlib.Props as Props
11+
import ewmhlib.Structs as Structs
12+
13+
__all__ = [
14+
"version", "getAllDisplaysInfo", "getDisplayFromRoot", "getDisplayFromWindow",
15+
"getProperty", "getPropertyValue", "changeProperty", "sendMessage",
16+
"defaultDisplay", "defaultScreen", "defaultRoot", "defaultRootWindow", "RootWindow", "EwmhWindow"
17+
]
18+
19+
20+
__version__ = "0.0.1"
21+
22+
23+
def version(numberOnly: bool = True):
24+
"""Returns the current version of ewmhlib module, in the form ''x.x.xx'' as string"""
25+
return ("" if numberOnly else "EWMHlib-")+__version__

0 commit comments

Comments
 (0)