[PATCH] #447: Enable grab/scroll button functionality.
Erik Garrison
erik at laptop.org
Wed Jul 9 18:48:33 EDT 2008
---
src/view/keyhandler.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/src/view/keyhandler.py b/src/view/keyhandler.py
index 44ea759..d1140be 100644
--- a/src/view/keyhandler.py
+++ b/src/view/keyhandler.py
@@ -62,6 +62,8 @@ _actions_table = {
'<alt><shift>o' : 'open_search',
'<alt><shift>r' : 'rotate',
'<alt><shift>s' : 'say_text',
+ 'Super_L' : 'grab_button_pressed',
+ 'Super_R' : 'grab_button_pressed',
}
J_DBUS_SERVICE = 'org.laptop.Journal'
@@ -78,6 +80,8 @@ class KeyHandler(object):
self._key_pressed = None
self._keycode_pressed = 0
self._keystate_pressed = 0
+ self._mouse_xy = [None, None]
+ self._grab_key_mouse_delta = 10
self._speech_proxy = None
self._key_grabber = KeyGrabber()
@@ -85,6 +89,8 @@ class KeyHandler(object):
self._key_pressed_cb)
self._key_grabber.connect('key-released',
self._key_released_cb)
+ self._key_grabber.connect('motion-notify',
+ self._motion_notify_cb)
self._tabbing_handler = TabbingHandler(_TABBING_MODIFIER)
@@ -137,6 +143,13 @@ class KeyHandler(object):
self._get_speech_proxy().SayText(text, reply_handler=lambda: None, \
error_handler=self._on_speech_err)
+ def handle_grab_button_pressed(self):
+ self._key_grabber.grab_pointer()
+
+ def handle_grab_button_released(self):
+ self._key_grabber.ungrab_pointer()
+ self._mouse_xy = [None, None]
+
def handle_say_text(self):
clipboard = gtk.clipboard_get(selection="PRIMARY")
clipboard.request_text(self._primary_selection_cb)
@@ -278,6 +291,10 @@ class KeyHandler(object):
return False
def _key_released_cb(self, grabber, keycode, state):
+ logging.debug('_key_released_cb: %i %i' % (keycode, state))
+ if keycode in [133, 134]: # handle grab button
+ self.handle_grab_button_released()
+ return True
if self._tabbing_handler.is_tabbing():
# We stop tabbing and switch to the new window as soon as the
# modifier key is raised again.
@@ -287,3 +304,32 @@ class KeyHandler(object):
return True
return False
+ def _fake_button_event(self, event):
+ self._key_grabber.ungrab_pointer()
+ self._key_grabber.fake_button_event(event)
+ self._key_grabber.grab_pointer()
+
+ def _motion_notify_cb(self, grabber, x, y):
+ logging.debug('_motion_notify_cb: %i %i' % (x, y))
+ if self._mouse_xy == [None, None]:
+ logging.debug('_motion_notify_cb: first hit')
+ self._mouse_xy = [x, y]
+ else:
+ x_prev, y_prev = self._mouse_xy
+
+ if y_prev - y > self._grab_key_mouse_delta:
+ self._fake_button_event(4)
+ self._mouse_xy[1] = y
+ elif y - y_prev > self._grab_key_mouse_delta:
+ self._fake_button_event(5)
+ self._mouse_xy[1] = y
+
+ if x_prev - x > self._grab_key_mouse_delta:
+ self._fake_button_event(6)
+ self._mouse_xy[0] = x
+ elif x - x_prev > self._grab_key_mouse_delta:
+ self._fake_button_event(7)
+ self._mouse_xy[0] = x
+
+
+
--
1.5.4.3
--XMCwj5IQnwKtuyBG
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="sugar-toolkit-add-grab-button.patch"
More information about the Sugar
mailing list