[Sugar-devel] [PATCH] Touchpad icon: update for upstream kernel API
Daniel Drake
dsd at laptop.org
Fri Nov 25 15:10:04 EST 2011
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.
---
extensions/deviceicon/touchpad.py | 49 ++++++++++++++++++++++---------------
1 files changed, 29 insertions(+), 20 deletions(-)
diff --git a/extensions/deviceicon/touchpad.py b/extensions/deviceicon/touchpad.py
index 6773afc..d6b4b37 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,37 @@ 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 indice. """
+ mode_str = _read_touchpad_mode_str()
+ if not mode_str 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 indice) and write to node path. """
+ return _write_touchpad_mode_str(TOUCHPAD_MODES[mode_num])
+
--
1.7.7.3
More information about the Sugar-devel
mailing list