Skip to content

Commit bc47436

Browse files
committed
fixes for subcode events (xrandr being the main driver) - needs some more testing, but seems ok. Patch by anYc from Freednode.
1 parent fb03ae7 commit bc47436

File tree

5 files changed

+49
-11
lines changed

5 files changed

+49
-11
lines changed

Xlib/display.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def extension_add_event(self, code, evt, name = None):
287287
the event class. EVT will be cloned, and the attribute _code
288288
of the new event class will be set to CODE.
289289
290-
If NAME is ommitted, it will be set to the name of EVT. This
290+
If NAME is omitted, it will be set to the name of EVT. This
291291
name is used to insert an entry in the DictWrapper
292292
extension_event.
293293
"""
@@ -303,6 +303,29 @@ def extension_add_event(self, code, evt, name = None):
303303

304304
setattr(self.extension_event, name, code)
305305

306+
def extension_add_subevent(self, code, subcode, evt, name = None):
307+
"""extension_add_subevent(code, evt, [name])
308+
309+
Add an extension subevent. CODE is the numeric code, subcode
310+
is the sub-ID of this event that shares the code ID with other
311+
sub-events and EVT is the event class. EVT will be cloned, and
312+
the attribute _code of the new event class will be set to CODE.
313+
314+
If NAME is omitted, it will be set to the name of EVT. This
315+
name is used to insert an entry in the DictWrapper
316+
extension_event.
317+
"""
318+
319+
newevt = new.classobj(evt.__name__, evt.__bases__,
320+
evt.__dict__.copy())
321+
newevt._code = code
322+
323+
self.display.add_extension_event(code, newevt, subcode)
324+
325+
if name is None:
326+
name = evt.__name__
327+
328+
setattr(self.extension_event, name, code)
306329

307330
def add_extension_error(self, code, err):
308331
"""add_extension_error(code, err)

Xlib/ext/randr.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,9 +1182,9 @@ def init(disp, info):
11821182
disp.extension_add_method('display', 'xrandr_set_panning', set_panning)
11831183

11841184
disp.extension_add_event(info.first_event, ScreenChangeNotify)
1185-
disp.extension_add_event(info.first_event + 1, CrtcChangeNotify)
1186-
disp.extension_add_event(info.first_event + 2, OutputChangeNotify)
1187-
disp.extension_add_event(info.first_event + 3, OutputPropertyNotify)
1185+
disp.extension_add_subevent(info.first_event + 1, 0, CrtcChangeNotify)
1186+
disp.extension_add_subevent(info.first_event + 1, 1, OutputChangeNotify)
1187+
disp.extension_add_subevent(info.first_event + 1, 2, OutputPropertyNotify)
11881188

11891189
#disp.extension_add_error(BadRROutput, BadRROutputError)
11901190
#disp.extension_add_error(BadRRCrtc, BadRRCrtcError)

Xlib/protocol/display.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,14 @@ def set_extension_major(self, extname, major):
279279
def get_extension_major(self, extname):
280280
return self.extension_major_opcodes[extname]
281281

282-
def add_extension_event(self, code, evt):
283-
self.event_classes[code] = evt
282+
def add_extension_event(self, code, evt, subcode=None):
283+
if subcode == None:
284+
self.event_classes[code] = evt
285+
else:
286+
if not code in self.event_classes:
287+
self.event_classes[code] = {subcode: evt}
288+
else:
289+
self.event_classes[code][subcode] = evt
284290

285291
def add_extension_error(self, code, err):
286292
self.error_classes[code] = err
@@ -749,6 +755,9 @@ def parse_event_response(self, etype):
749755
# Skip bit 8 at lookup, that is set if this event came from an
750756
# SendEvent
751757
estruct = self.event_classes.get(etype & 0x7f, event.AnyEvent)
758+
if type(estruct) == dict:
759+
# this etype refers to a set of sub-events with individual subcodes
760+
estruct = estruct[ord(self.data_recv[1])]
752761

753762
e = estruct(display = self, binarydata = self.data_recv[:32])
754763

Xlib/protocol/rq.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,9 @@ def parse_binary_value(self, data, display, length, format):
817817
import event
818818

819819
estruct = display.event_classes.get(ord(data[0]) & 0x7f, event.AnyEvent)
820+
if type(estruct) == dict:
821+
# this etype refers to a set of sub-events with individual subcodes
822+
estruct = estruct[ord(data[1])]
820823

821824
return estruct(display = display, binarydata = data[:32]), buffer(data, 32)
822825

@@ -1367,7 +1370,7 @@ class TextElements16(TextElements8):
13671370

13681371

13691372

1370-
class GetAttrData:
1373+
class GetAttrData(object):
13711374
def __getattr__(self, attr):
13721375
try:
13731376
if self._data:

examples/xrandr.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,23 +148,26 @@ def loop(self):
148148
sys.exit(0)
149149

150150
# Screen information has changed
151-
elif e.type == self.d.extension_event.ScreenChangeNotify:
151+
elif e.__class__.__name__ == randr.ScreenChangeNotify.__name__:
152152
print 'Screen change'
153153
print self.pp.pprint(e._data)
154154

155155
# CRTC information has changed
156-
elif e.type == self.d.extension_event.CrtcChangeNotify:
156+
elif e.__class__.__name__ == randr.CrtcChangeNotify.__name__:
157157
print 'CRTC change'
158+
#e = randr.CrtcChangeNotify(display=display.display, binarydata = e._binary)
158159
print self.pp.pprint(e._data)
159160

160161
# Output information has changed
161-
elif e.type == self.d.extension_event.OutputChangeNotify:
162+
elif e.__class__.__name__ == randr.OutputChangeNotify.__name__:
162163
print 'Output change'
164+
#e = randr.OutputChangeNotify(display=display.display, binarydata = e._binary)
163165
print self.pp.pprint(e._data)
164166

165167
# Output property information has changed
166-
elif e.type == self.d.extension_event.OutputPropertyNotify:
168+
elif e.__class__.__name__ == randr.OutputPropertyNotify.__name__:
167169
print 'Output property change'
170+
#e = randr.OutputPropertyNotify(display=display.display, binarydata = e._binary)
168171
print self.pp.pprint(e._data)
169172

170173
# Somebody wants to tell us something

0 commit comments

Comments
 (0)