Fix alt+key resulting in the upper case version of key even when shift is not pressed

Fixes #78
This commit is contained in:
Kovid Goyal 2017-05-20 08:47:02 +05:30
parent 448ba26257
commit 5525d4db49
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 16 additions and 9 deletions

View File

@ -271,12 +271,13 @@ class Boss(Thread):
@callback
def on_text_input(self, window, codepoint, mods):
data = interpret_text_event(codepoint, mods)
if data:
w = self.active_window
w = self.active_window
if w is not None:
yield w
if w is not None:
yield w
w.write_to_child(data)
data = interpret_text_event(codepoint, mods, w)
if data:
w.write_to_child(data)
@callback
def on_key(self, window, key, scancode, action, mods):

View File

@ -59,6 +59,7 @@ alt_codes = {
range(defines.GLFW_KEY_SPACE, defines.GLFW_KEY_RIGHT_BRACKET + 1)
)
}
alt_mods = (defines.GLFW_MOD_ALT, defines.GLFW_MOD_SHIFT | defines.GLFW_MOD_ALT)
rmkx_key_map = smkx_key_map.copy()
rmkx_key_map.update({
@ -143,9 +144,9 @@ def interpret_key_event(key, scancode, mods, window, action):
if mods == defines.GLFW_MOD_CONTROL and key in control_codes:
# Map Ctrl-key to ascii control code
data.extend(control_codes[key])
elif mods == defines.GLFW_MOD_ALT and key in alt_codes:
# Map Alt+key to Esc-key
data.extend(alt_codes[key])
elif mods in alt_mods and key in alt_codes:
# Handled by interpret text event
pass
else:
key_map = get_key_map(screen)
x = key_map.get(key)
@ -156,8 +157,13 @@ def interpret_key_event(key, scancode, mods, window, action):
return bytes(data)
def interpret_text_event(codepoint, mods):
def interpret_text_event(codepoint, mods, window):
screen = window.screen
if mods > defines.GLFW_MOD_SHIFT:
if mods in alt_mods and not screen.extended_keyboard:
data = chr(codepoint).encode('utf-8')
if len(data) == 1:
return b'\x1b' + data
return b'' # Handled by interpret_key_event above
data = chr(codepoint).encode('utf-8')
return data