Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Hard coded multitouch desktop gestures for Ubuntu/GNOME. To use it, enable the Dbus/Scale/Rotate plugins in Compiz.
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