Skip to content

Commit ff61d49

Browse files
committed
Fixed the update function of the keymap cache
1 parent 1e4b605 commit ff61d49

2 files changed

Lines changed: 36 additions & 19 deletions

File tree

Xlib/ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2001-01-10 <petli@cendio.se>
2+
3+
* display.py (Display._update_keymap): The first half of the
4+
update algorithm operated on an earlier type of code->sym map than
5+
the second half. Stupid, stupid. It would have been nice with a
6+
type-checker now.
7+
18
Tue Jan 9 13:03:19 2001 Peter Liljenberg <petli@cendio.se>
29

310
* display.py (Display._update_keymap): Fixed call to append with

Xlib/display.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: display.py,v 1.13 2001-01-09 12:05:06 petli Exp $
1+
# $Id: display.py,v 1.14 2001-01-11 15:13:05 petli Exp $
22
#
33
# Xlib.display -- high level display object
44
#
@@ -249,6 +249,16 @@ def add_extension_error(self, code, err):
249249
### keymap cache implementation
250250
###
251251

252+
# The keycode->keysym map is stored in a list with 256 elements.
253+
# Each element represents a keycode, and the tuple elements are
254+
# the keysyms bound to the key.
255+
256+
# The keysym->keycode map is stored in a mapping, where the keys
257+
# are keysyms. The values are a sorted list of tuples with two
258+
# elements each: (index, keycode)
259+
# keycode is the code for a key to which this keysym is bound, and
260+
# index is the keysyms index in the map for that keycode.
261+
252262
def keycode_to_keysym(self, keycode, index):
253263
try:
254264
return self._keymap_codes[keycode][index]
@@ -263,7 +273,8 @@ def keysym_to_keycode(self, keysym):
263273

264274
def keysym_to_keycodes(self, keysym):
265275
try:
266-
return map(lambda x: x[1], self._keymap_syms[keysym])
276+
# Copy the map list, reversing the arguments
277+
return map(lambda x: (x[1], x[0]), self._keymap_syms[keysym])
267278
except KeyError:
268279
return []
269280

@@ -280,37 +291,36 @@ def _update_keymap(self, first_keycode, count):
280291
# Delete all sym->code maps for the changed codes
281292

282293
lastcode = first_keycode + count
283-
for keysym, code in self._keymap_syms.items():
284-
if code >= first_keycode and code < lastcode:
285-
symcodes = self._keymap_syms[keysym]
286-
i = 0
287-
while i < len(symcodes):
288-
if symcodes[i][1] == code:
289-
del symcodes[i]
290-
else:
291-
i = i + 1
292-
293-
294+
for keysym, codes in self._keymap_syms.items():
295+
i = 0
296+
while i < len(codes):
297+
code = codes[i][1]
298+
if code >= first_keycode and code < lastcode:
299+
del codes[i]
300+
else:
301+
i = i + 1
302+
303+
# Get the new keyboard mapping
294304
keysyms = self.get_keyboard_mapping(first_keycode, count)
295305

296306
# Replace code->sym map with the new map
297307
self._keymap_codes[first_keycode:lastcode] = keysyms
298308

299309
# Update sym->code map
300-
i = first_keycode
310+
code = first_keycode
301311
for syms in keysyms:
302-
j = 0
312+
index = 0
303313
for sym in syms:
304314
if sym != X.NoSymbol:
305315
if self._keymap_syms.has_key(sym):
306316
symcodes = self._keymap_syms[sym]
307-
symcodes.append((j, i))
317+
symcodes.append((index, code))
308318
symcodes.sort()
309319
else:
310-
self._keymap_syms[sym] = [(j, i)]
320+
self._keymap_syms[sym] = [(index, code)]
311321

312-
j = j + 1
313-
i = i + 1
322+
index = index + 1
323+
code = code + 1
314324

315325

316326
###

0 commit comments

Comments
 (0)