Skip to content

Commit 05fc7ac

Browse files
committed
Fixed incorrect event handling for INCR selections, and handle all ATOM outputs.
1 parent 78a817b commit 05fc7ac

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

examples/selection.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ def main():
6666

6767
# Create ourselves a window and a property for the returned data
6868
w = d.screen().root.create_window(
69-
0, 0, 10, 10, 0, X.CopyFromParent,
70-
event_mask = X.PropertyChangeMask)
69+
0, 0, 10, 10, 0, X.CopyFromParent)
7170
data_atom = d.get_atom('SEL_DATA')
7271

7372
# The data_atom should not be set according to ICCCM, and since
@@ -103,7 +102,7 @@ def main():
103102

104103
# Can the data be used directly or read incrementally
105104
if r.property_type == d.get_atom('INCR'):
106-
log('reading data incrementally: >{0} bytes', r.value[0])
105+
log('reading data incrementally: at least {0} bytes', r.value[0])
107106
handle_incr(d, w, data_atom, target_name)
108107
else:
109108
output_data(d, r, target_name)
@@ -117,10 +116,7 @@ def handle_incr(d, w, data_atom, target_name):
117116
# getting a notification of that, and then setting the property
118117
# again with more data. To notice that, we must listen for
119118
# PropertyNotify events.
120-
121-
# To ensure that we are in sync, just throw away any queued events
122-
while d.pending_events() > 0:
123-
e = d.next_event()
119+
w.change_attributes(event_mask = X.PropertyChangeMask)
124120

125121
while True:
126122
# Delete data property to tell owner to give us more data
@@ -147,20 +143,19 @@ def handle_incr(d, w, data_atom, target_name):
147143

148144

149145
def output_data(d, r, target_name):
150-
log('got {0}/{1}, length {2}',
146+
log('got {0}:{1}, length {2}',
151147
d.get_atom_name(r.property_type),
152148
r.format,
153149
len(r.value))
154150

155151
if r.format == 8:
156152
sys.stdout.write(r.value)
157153

158-
elif r.format == 32 and target_name == 'TARGETS':
159-
# convert to atoms - might do this for more types
154+
elif r.format == 32 and r.property_type == Xatom.ATOM:
160155
for v in r.value:
161156
sys.stdout.write('{0}\n'.format(d.get_atom_name(v)))
162157

163-
elif r.format == 16:
158+
else:
164159
for v in r.value:
165160
sys.stdout.write('{0}\n'.format(v))
166161

0 commit comments

Comments
 (0)