diff options
author | Erik Garrison <erik@laptop.org> | 2008-06-04 22:25:22 (GMT) |
---|---|---|
committer | Erik Garrison <erik@laptop.org> | 2008-06-04 22:25:22 (GMT) |
commit | 605fe4561f7ea6b1a9ef8b770cfd8c7a2414e20b (patch) | |
tree | 77c6235204a6c7503e9927146b1083d16f93188d /src/view | |
parent | 754b4c5d460db45555a36bbc0cddcb385ea071e0 (diff) |
Patched src/view/keyhandler.py to rotate the dpad keys when the screen rotate button is pressed.
Diffstat (limited to 'src/view')
-rw-r--r-- | src/view/keyhandler.py | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/src/view/keyhandler.py b/src/view/keyhandler.py index 306bb21..dcb00c8 100644 --- a/src/view/keyhandler.py +++ b/src/view/keyhandler.py @@ -18,6 +18,7 @@ import os import signal import logging import subprocess +import errno import dbus import gtk @@ -186,14 +187,45 @@ class KeyHandler(object): def handle_frame(self): view.Shell.get_instance().get_frame().notify_key_press() + def handle_rotate(self): + """ + Handles rotation of the display (using xrandr) and of the d-pad. + + Notes: default mappings for keypad on MP + KP_Up 80 + KP_Right 85 + KP_Down 88 + KP_Left 83 + """ + states = [ 'normal', 'left', 'inverted', 'right'] + keycodes = (80, 85, 88, 83, 80, 85, 88, 83) + keysyms = ("KP_Up", "KP_Right", "KP_Down", "KP_Left") self._screen_rotation += 1 - if self._screen_rotation == len(states): - self._screen_rotation = 0 + self._screen_rotation %= 4 + + actual_keycodes = keycodes[self._screen_rotation:self._screen_rotation + 4] + # code_pairs now contains a mapping of keycode -> keysym in the current + # orientation + code_pairs = zip(actual_keycodes, keysyms) + + # Using the mappings in code_pairs, we dynamically build up an xmodmap + # command to rotate the dpad keys. + argv = ['xmodmap'] + for arg in [('-e', 'keycode %i = %s' % p) for p in code_pairs]: + argv.extend(arg) + + # If either the xmodmap or xrandr command fails, check_call will fail + # with CalledProcessError, which we raise. + try: + subprocess.check_call(argv) + subprocess.check_call(['xrandr', '-o', states[self._screen_rotation]]) + except OSError, e: + if e.errno != errno.EINTR: + raise - subprocess.Popen(['xrandr', '-o', states[self._screen_rotation]]) def handle_quit_emulator(self): if os.environ.has_key('SUGAR_EMULATOR_PID'): |