Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/rpms/sugar/0040-Globalkey-for-touchpad-device-icon.patch
blob: 9b595acc55479696b43ff410a782ee3f7ae3ad4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
From 2d77d002d70ce8a4f7cd53567592e538654a7ac7 Mon Sep 17 00:00:00 2001
From: Martin Abente <martin.abente.lahaye@gmail.com>
Date: Wed, 3 Nov 2010 18:27:30 -0300
Subject: [PATCH sugar 40/74] Globalkey for touchpad device icon

Add a new keyboard shortcut as a globalkey, this will
toggle the touchpad mode when <Alt + m> is pressed.

Also change DeviceView.palette indentifier for
DeviceView._palette. Palette was not showing
because of that.

Dextrose version
---
 extensions/deviceicon/touchpad.py |   16 ++++++++++------
 extensions/globalkey/Makefile.am  |    1 +
 extensions/globalkey/touchpad.py  |   33 +++++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 6 deletions(-)
 create mode 100644 extensions/globalkey/touchpad.py

diff --git a/extensions/deviceicon/touchpad.py b/extensions/deviceicon/touchpad.py
index 6773afc..ba02037 100644
--- a/extensions/deviceicon/touchpad.py
+++ b/extensions/deviceicon/touchpad.py
@@ -45,6 +45,8 @@
 # NODE_PATH is used to communicate with the touchpad device.
 NODE_PATH = '/sys/devices/platform/i8042/serio1/ptmode'
 
+_view = None
+
 
 class DeviceView(TrayIcon):
     """ Manage the touchpad mode from the device palette on the Frame. """
@@ -66,14 +68,14 @@ def create_palette(self):
         """ Create a palette for this icon; called by the Sugar framework
         when a palette needs to be displayed. """
         label = glib.markup_escape_text(_('My touchpad'))
-        self.palette = ResourcePalette(label, self.icon)
-        self.palette.set_group_id('frame')
-        return self.palette
+        self._palette = ResourcePalette(label, self.icon)
+        self._palette.set_group_id('frame')
+        return self._palette
 
     def __button_release_event_cb(self, widget, event):
         """ Callback for button release event; used to invoke touchpad-mode
         change. """
-        self.palette.toggle_mode()
+        self._palette.toggle_mode()
         return True
 
 
@@ -111,10 +113,12 @@ def toggle_mode(self):
 
 
 def setup(tray):
-    """ Initialize the devic icon; called by the shell when initializing the
+    """ Initialize the device icon; called by the shell when initializing the
     Frame. """
+    global _view
     if os.path.exists(NODE_PATH):
-        tray.add_device(DeviceView())
+        _view = DeviceView()
+        tray.add_device(_view)
         _write_touchpad_mode(TOUCHPAD_MODE_CAPACITIVE)
 
 
diff --git a/extensions/globalkey/Makefile.am b/extensions/globalkey/Makefile.am
index b44626e..e3aaa8a 100644
--- a/extensions/globalkey/Makefile.am
+++ b/extensions/globalkey/Makefile.am
@@ -4,5 +4,6 @@ sugar_PYTHON = 		\
 	__init__.py	\
 	magnifier.py	\
 	screenshot.py	\
+	touchpad.py	\
 	viewsource.py	\
 	virtualkeyboard.py
diff --git a/extensions/globalkey/touchpad.py b/extensions/globalkey/touchpad.py
new file mode 100644
index 0000000..eeaba40
--- /dev/null
+++ b/extensions/globalkey/touchpad.py
@@ -0,0 +1,33 @@
+# Copyright (C) 2010, Martin Abente
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+import logging
+
+BOUND_KEYS = ['<alt>m']
+touchpad = None
+
+def handle_key_press(key):
+    global touchpad
+    if touchpad is None:
+        try:
+            touchpad = __import__('deviceicon.touchpad', globals(),
+                                   locals(), ['touchpad'])
+        except Exception:
+            logging.error('Could not import touchpad module.')
+            return
+
+    if touchpad._view is not None:
+        touchpad._view._palette.toggle_mode()
-- 
1.7.6