Skip to content

Commit 3e1e2c5

Browse files
committed
Fixed bug in event decoding
1 parent 285736b commit 3e1e2c5

4 files changed

Lines changed: 31 additions & 6 deletions

File tree

Xlib/protocol/ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2001-12-14 Peter Liljenberg <peter.liljenberg@esdgkonsult.com>
2+
3+
* display.py (Display.parse_event_response):
4+
* rq.py (Event.__init__): Fixed bug in event type decoding: bit
5+
0-6 is the event type, and bit 7 is set if the event was sent by
6+
SendEvent.
7+
8+
19
2001-01-16 <petli@cendio.se>
210

311
* event.py: Changed some class names so that they correspond

Xlib/protocol/display.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: display.py,v 1.14 2001-12-04 11:41:01 petli Exp $
1+
# $Id: display.py,v 1.15 2001-12-14 17:03:10 petli Exp $
22
#
33
# Xlib.protocol.display -- core display communication
44
#
@@ -733,9 +733,12 @@ def parse_request_response(self, request):
733733

734734

735735
def parse_event_response(self, etype):
736-
estruct = self.event_classes.get(etype, event.AnyEvent)
736+
# Skip bit 8 at lookup, that is set if this event came from an
737+
# SendEvent
738+
estruct = self.event_classes.get(etype & 0x7f, event.AnyEvent)
737739

738740
e = estruct(display = self, binarydata = self.data_recv[:32])
741+
739742
self.data_recv = buffer(self.data_recv, 32)
740743

741744
# Drop all requests having an error handler,

Xlib/protocol/rq.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rq.py,v 1.11 2001-02-19 11:16:10 petli Exp $
1+
# $Id: rq.py,v 1.12 2001-12-14 17:03:10 petli Exp $
22
#
33
# Xlib.protocol.rq -- structure primitives for request, events and errors
44
#
@@ -1383,15 +1383,19 @@ def __repr__(self):
13831383

13841384

13851385
class Event(GetAttrData):
1386-
def __init__(self, binarydata = None, display = None, **keys):
1386+
def __init__(self, binarydata = None, display = None,
1387+
**keys):
13871388
if binarydata:
13881389
self._binary = binarydata
13891390
self._data, data = self._fields.parse_binary(binarydata, display,
13901391
rawdict = 1)
1392+
# split event type into type and send_event bit
1393+
self._data['send_event'] = not not self._data['type'] & 0x80
1394+
self._data['type'] = self._data['type'] & 0x7f
13911395
else:
13921396
if self._code:
13931397
keys['type'] = self._code
1394-
1398+
13951399
keys['sequence_number'] = 0
13961400

13971401
self._binary = apply(self._fields.to_binary, (), keys)

examples/draw.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/python
22
#
3-
# $Id: draw.py,v 1.4 2000-12-21 12:23:07 petli Exp $
3+
# $Id: draw.py,v 1.5 2001-12-14 17:03:10 petli Exp $
44
#
55
# examples/draw.py -- high-level xlib test application.
66
#
@@ -61,10 +61,14 @@ def __init__(self, display):
6161

6262
# Set some WM info
6363

64+
self.WM_DELETE_WINDOW = self.d.intern_atom('WM_DELETE_WINDOW')
65+
self.WM_PROTOCOLS = self.d.intern_atom('WM_PROTOCOLS')
66+
6467
self.window.set_wm_name('Xlib example: draw.py')
6568
self.window.set_wm_icon_name('draw.py')
6669
self.window.set_wm_class('draw', 'XlibExample')
6770

71+
self.window.set_wm_protocols([self.WM_DELETE_WINDOW])
6872
self.window.set_wm_hints(flags = Xutil.StateHint,
6973
initial_state = Xutil.NormalState)
7074

@@ -106,6 +110,12 @@ def loop(self):
106110
if e.type == X.MotionNotify and current:
107111
current.motion(e)
108112

113+
if e.type == X.ClientMessage:
114+
if e.client_type == self.WM_PROTOCOLS:
115+
fmt, data = e.data
116+
if fmt == 32 and data[0] == self.WM_DELETE_WINDOW:
117+
sys.exit(0)
118+
109119
# A drawed objects, consisting of either a single
110120
# romboid, or two romboids connected by a winding line
111121

0 commit comments

Comments
 (0)