Skip to content

Commit 6a79540

Browse files
committed
Treat subcodes as tuples in the (infrequently used) extension list. Minor documentation points.
1 parent 78f9242 commit 6a79540

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

Xlib/display.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ def __init__(self, display = None):
9797
self.class_extension_dicts = {}
9898
self.display_extension_methods = {}
9999

100+
# a dict that maps the event name to the code
101+
# or, when it's an event with a subcode, to a tuple of (event,subcode)
102+
# note this wraps the dict so you address it as
103+
# extension_event.EXTENSION_EVENT_NAME rather than
104+
# extension_event["EXTENSION_EVENT_NAME"]
100105
self.extension_event = rq.DictWrapper({})
101106

102107
exts = self.list_extensions()
@@ -325,7 +330,9 @@ def extension_add_subevent(self, code, subcode, evt, name = None):
325330
if name is None:
326331
name = evt.__name__
327332

328-
setattr(self.extension_event, name, code)
333+
# store subcodes as a tuple of (event code, subcode) in the
334+
# extension dict maintained in the display object
335+
setattr(self.extension_event, name, (code,subcode))
329336

330337
def add_extension_error(self, code, err):
331338
"""add_extension_error(code, err)

Xlib/ext/randr.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
Version 1.2 of the protocol is documented at:
2727
http://cgit.freedesktop.org/xorg/proto/randrproto/tree/randrproto.txt
2828
29+
Version 1.3.1 here:
30+
http://www.x.org/releases/X11R7.5/doc/randrproto/randrproto.txt
31+
2932
"""
3033

3134

examples/xrandr.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -152,23 +152,29 @@ def loop(self):
152152
print 'Screen change'
153153
print self.pp.pprint(e._data)
154154

155-
# CRTC information has changed
156-
elif e.__class__.__name__ == randr.CrtcChangeNotify.__name__:
157-
print 'CRTC change'
158-
#e = randr.CrtcChangeNotify(display=display.display, binarydata = e._binary)
159-
print self.pp.pprint(e._data)
160-
161-
# Output information has changed
162-
elif e.__class__.__name__ == randr.OutputChangeNotify.__name__:
163-
print 'Output change'
164-
#e = randr.OutputChangeNotify(display=display.display, binarydata = e._binary)
165-
print self.pp.pprint(e._data)
166-
167-
# Output property information has changed
168-
elif e.__class__.__name__ == randr.OutputPropertyNotify.__name__:
169-
print 'Output property change'
170-
#e = randr.OutputPropertyNotify(display=display.display, binarydata = e._binary)
171-
print self.pp.pprint(e._data)
155+
# check if we're getting one of the RandR event types with subcodes
156+
elif e.type == self.d.extension_event.CrtcChangeNotify[0]:
157+
# yes, check the subcodes
158+
159+
# CRTC information has changed
160+
if (e.type, e.sub_code) == self.d.extension_event.CrtcChangeNotify:
161+
print 'CRTC change'
162+
#e = randr.CrtcChangeNotify(display=display.display, binarydata = e._binary)
163+
print self.pp.pprint(e._data)
164+
165+
# Output information has changed
166+
elif (e.type, e.sub_code) == self.d.extension_event.OutputChangeNotify:
167+
print 'Output change'
168+
#e = randr.OutputChangeNotify(display=display.display, binarydata = e._binary)
169+
print self.pp.pprint(e._data)
170+
171+
# Output property information has changed
172+
elif (e.type, e.sub_code) == self.d.extension_event.OutputPropertyNotify:
173+
print 'Output property change'
174+
#e = randr.OutputPropertyNotify(display=display.display, binarydata = e._binary)
175+
print self.pp.pprint(e._data)
176+
else:
177+
print "Unrecognised subcode", e.sub_code
172178

173179
# Somebody wants to tell us something
174180
elif e.type == X.ClientMessage:

0 commit comments

Comments
 (0)