Created
August 24, 2010 02:13
-
-
Save scottferg/546779 to your computer and use it in GitHub Desktop.
Hard coded multitouch desktop gestures for Ubuntu/GNOME. To use it, enable the Dbus/Scale/Rotate plugins in Compiz.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pymt import * | |
import sys, dbus, subprocess, os | |
import time | |
class Tracer(MTWidget): | |
SWIPE_X_THRESHOLD = 220 | |
SWIPE_Y_THRESHOLD = 100 | |
LEFT_SWIPE, RIGHT_SWIPE = range(2) | |
block = False | |
def dbus_message(self, plugin, action): | |
try: | |
rootwin = subprocess.Popen(['xwininfo', '-root'], | |
stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] | |
except OSError: | |
raise SystemExit('Error: xwininfo not present') | |
try: | |
rootwin_id = int(rootwin.split()[3], 0) | |
except IndexError: | |
raise SystemExit('Error: unexpectedly short output from xwininfo') | |
except ValueError: | |
raise SystemExit('Error: unable to convert "%s" to int', rootwin.split()[3]) | |
service = interface = 'org.freedesktop.compiz' | |
session_bus = dbus.SessionBus() | |
args = ['root', rootwin_id] | |
proxy = session_bus.get_object( | |
service, '/org/freedesktop/compiz/%s/allscreens/%s' %(plugin, action)) | |
obj = dbus.Interface(proxy, interface) | |
obj.activate(*args) | |
def on_touch_move(self, touch): | |
if touch.y < 150: | |
return | |
if touch.x < 100 or touch.x > 600: | |
return | |
if self.block: | |
return | |
if len(getCurrentTouches()) == 3: | |
if (touch.y - touch.oypos) < -self.SWIPE_Y_THRESHOLD: | |
self.block = True | |
self.dbus_message("scale", "initiate_key") | |
return | |
if (touch.y - touch.oypos) > self.SWIPE_Y_THRESHOLD: | |
self.block = True | |
self.dbus_message("core", "show_desktop_key") | |
return | |
if len(getCurrentTouches()) == 2: | |
if (touch.x - touch.oxpos) > self.SWIPE_X_THRESHOLD: | |
self.block = True | |
self.dbus_message("rotate", "rotate_left_key") | |
return | |
elif (touch.x - touch.oxpos) < -self.SWIPE_X_THRESHOLD: | |
self.block = True | |
self.dbus_message("rotate", "rotate_right_key") | |
return | |
def on_touch_up(self, touch): | |
self.block = False | |
runTouchApp(Tracer()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment