-
Notifications
You must be signed in to change notification settings - Fork 149
/
tinywm.py
36 lines (31 loc) · 1.42 KB
/
tinywm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# TinyWM is written by Nick Welch <[email protected]> in 2005 & 2011.
#
# This software is in the public domain
# and is provided AS IS, with NO WARRANTY.
from Xlib.display import Display
from Xlib import X, XK
dpy = Display()
dpy.screen().root.grab_key(dpy.keysym_to_keycode(XK.string_to_keysym("F1")), X.Mod1Mask, 1,
X.GrabModeAsync, X.GrabModeAsync)
dpy.screen().root.grab_button(1, X.Mod1Mask, 1, X.ButtonPressMask|X.ButtonReleaseMask|X.PointerMotionMask,
X.GrabModeAsync, X.GrabModeAsync, X.NONE, X.NONE)
dpy.screen().root.grab_button(3, X.Mod1Mask, 1, X.ButtonPressMask|X.ButtonReleaseMask|X.PointerMotionMask,
X.GrabModeAsync, X.GrabModeAsync, X.NONE, X.NONE)
start = None
while 1:
ev = dpy.next_event()
if ev.type == X.KeyPress and ev.child != X.NONE:
ev.child.configure(stack_mode = X.Above)
elif ev.type == X.ButtonPress and ev.child != X.NONE:
attr = ev.child.get_geometry()
start = ev
elif ev.type == X.MotionNotify and start:
xdiff = ev.root_x - start.root_x
ydiff = ev.root_y - start.root_y
start.child.configure(
x = attr.x + (start.detail == 1 and xdiff or 0),
y = attr.y + (start.detail == 1 and ydiff or 0),
width = max(1, attr.width + (start.detail == 3 and xdiff or 0)),
height = max(1, attr.height + (start.detail == 3 and ydiff or 0)))
elif ev.type == X.ButtonRelease:
start = None