diff options
author | Daniel Drake <dsd@laptop.org> | 2011-11-25 20:05:00 (GMT) |
---|---|---|
committer | Daniel Drake <dsd@laptop.org> | 2012-04-16 20:04:05 (GMT) |
commit | d12a40da7c3ae575d8afbc78ab591f75f9392e0b (patch) | |
tree | f002c35c830541b045f1f79cda93755e8b383af2 | |
parent | 6bd87bf461020df86993ecc60e306efaccf686b8 (diff) |
Touchpad icon: update for upstream kernel API
The HGPK pentablet selection code has gone upstream, but with a
different interface from the version included in previous OLPC kernels.
The interface is now:
echo -n pentablet > hgpk_mode
Port the touchpad icon to this new API.
Compatibility with the old non-upstream API has been dropped; I don't
anticipate users running this new sugar with an old kernel.
This fixes touchpad mode selection on kernels newer than 2.6.35.
-rw-r--r-- | extensions/deviceicon/touchpad.py | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/extensions/deviceicon/touchpad.py b/extensions/deviceicon/touchpad.py index 6773afc..150e8dc 100644 --- a/extensions/deviceicon/touchpad.py +++ b/extensions/deviceicon/touchpad.py @@ -31,19 +31,15 @@ from sugar.graphics import style from jarabe.frame.frameinvoker import FrameWidgetInvoker -TOUCHPAD_MODE_CAPACITIVE = 'capacitive' -TOUCHPAD_MODE_RESISTIVE = 'resistive' -TOUCHPAD_MODES = [TOUCHPAD_MODE_CAPACITIVE, TOUCHPAD_MODE_RESISTIVE] -STATUS_TEXT = { - TOUCHPAD_MODE_CAPACITIVE: _('finger'), - TOUCHPAD_MODE_RESISTIVE: _('stylus'), -} -STATUS_ICON = { - TOUCHPAD_MODE_CAPACITIVE: 'touchpad-' + TOUCHPAD_MODE_CAPACITIVE, - TOUCHPAD_MODE_RESISTIVE: 'touchpad-' + TOUCHPAD_MODE_RESISTIVE, -} +TOUCHPAD_MODE_MOUSE = 'mouse' +TOUCHPAD_MODE_PENTABLET = 'pentablet' + +TOUCHPAD_MODES = (TOUCHPAD_MODE_MOUSE, TOUCHPAD_MODE_PENTABLET) +STATUS_TEXT = (_('finger'), _('stylus')) +STATUS_ICON = ('touchpad-capacitive', 'touchpad-resistive') + # NODE_PATH is used to communicate with the touchpad device. -NODE_PATH = '/sys/devices/platform/i8042/serio1/ptmode' +NODE_PATH = '/sys/devices/platform/i8042/serio1/hgpk_mode' class DeviceView(TrayIcon): @@ -105,7 +101,7 @@ class ResourcePalette(Palette): def toggle_mode(self): """ Toggle the touchpad mode. """ - self._mode = TOUCHPAD_MODES[1 - TOUCHPAD_MODES.index(self._mode)] + self._mode = 1 - self._mode _write_touchpad_mode(self._mode) self._update() @@ -115,24 +111,36 @@ def setup(tray): Frame. """ if os.path.exists(NODE_PATH): tray.add_device(DeviceView()) - _write_touchpad_mode(TOUCHPAD_MODE_CAPACITIVE) + _write_touchpad_mode_str(TOUCHPAD_MODE_MOUSE) -def _read_touchpad_mode(): - """ Read the touchpad mode from the node path. """ +def _read_touchpad_mode_str(): + """ Read the touchpad mode string from the node path. """ node_file_handle = open(NODE_PATH, 'r') - text = node_file_handle.read() + text = node_file_handle.read().strip().lower() node_file_handle.close() + return text - return TOUCHPAD_MODES[int(text[0])] +def _read_touchpad_mode(): + """ Read the touchpad mode and return the mode index. """ + mode_str = _read_touchpad_mode_str() + if mode_str not in TOUCHPAD_MODES: + return None + return TOUCHPAD_MODES.index(mode_str) -def _write_touchpad_mode(touchpad): + +def _write_touchpad_mode_str(mode_str): """ Write the touchpad mode to the node path. """ try: node_file_handle = open(NODE_PATH, 'w') except IOError, e: logging.error('Error opening %s for writing: %s', NODE_PATH, e) return - node_file_handle.write(str(TOUCHPAD_MODES.index(touchpad))) + node_file_handle.write(mode_str) node_file_handle.close() + + +def _write_touchpad_mode(mode_num): + """ Look up the mode (by index) and write to node path. """ + return _write_touchpad_mode_str(TOUCHPAD_MODES[mode_num]) |