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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# Copyright (c) 2008-2010 Thomas Thurman <tthurman@gnome.org>; GPL 2.0 or later.
# Originally based around example code in python-xlib
# by Peter Liljenberg <petli@ctrl-c.liu.se>.
import sys
import time
import re
from Xlib import X
from Xlib.protocol import display
from Xlib.protocol.event import ClientMessage
from Xlib.protocol.request import *
display = display.Display()
screen = display.info.roots[display.default_screen]
window = display.allocate_resource_id()
gc = display.allocate_resource_id()
CreateWindow(display, None,
depth = screen.root_depth,
wid = window,
parent = screen.root,
x = 100, y = 100, width = 250, height = 250, border_width = 2,
window_class = X.InputOutput, visual = X.CopyFromParent,
background_pixel = screen.white_pixel,
event_mask = (X.ExposureMask |
X.StructureNotifyMask |
X.ButtonPressMask |
X.ButtonReleaseMask |
X.Button1MotionMask),
colormap = X.CopyFromParent)
CreateGC(display, None, gc, window)
def do_event():
event = display.next_event()
if event.type == X.DestroyNotify:
sys.exit(0)
print event
for arg in sys.argv[1:]:
if arg=='map':
MapWindow(display, None, window)
elif arg=='unmap':
UnmapWindow(display, window=window)
elif arg=='sleep':
time.sleep(1)
elif arg=='event':
do_event()
elif arg=='flush':
display.flush()
elif arg=='events':
while 1:
do_event()
elif arg.startswith('send-'):
subargs = arg.split('-')
values = []
for subarg in subargs[1:]:
if subarg=='this':
values.append(window)
elif subarg=='root':
values.append(screen.root)
elif re.match('^\d+$', subarg):
values.append(int(subarg))
elif subarg.startswith('0x'):
values.append(int(subarg, 16))
else:
values.append(InternAtom(display=display,
name=subarg,
only_if_exists=True).atom)
if values[-1]==0:
print 'Warning: %s was unrecognised' % (subarg)
event = ClientMessage(window=values[1],
client_type=values[2],
data=(32,(values[3:])))
SendEvent(destination = values[0],
display = display,
propagate=True,
event = event,
event_mask = X.SubstructureRedirectMask|X.SubstructureNotifyMask)
elif arg=='raise':
CirculateWindow(display = display,
window = window,
direction = X.RaiseLowest)
else:
print 'Unknown argument: ',arg
|