Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2012-11-01 12:27:07 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2012-11-01 12:27:07 (GMT)
commite9d682735efc52790a07ee0bf012805d1b2065b7 (patch)
tree8336bd95352eef06796aa96f42463e1cdda3a3cd
parent2e622ad05885d1309f59c5a72aa60a09a2113df8 (diff)
Read pressure in the touch test
Works with a genius tabled but not with the xo-4 yet. Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r--touch_test.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/touch_test.py b/touch_test.py
index fd82424..f35c36e 100644
--- a/touch_test.py
+++ b/touch_test.py
@@ -6,6 +6,7 @@
from gi.repository import Gtk
from gi.repository import Gdk
import math
+import logging
class TestTouch(Gtk.DrawingArea):
@@ -19,6 +20,7 @@ class TestTouch(Gtk.DrawingArea):
self.add_events(Gdk.EventMask.BUTTON_MOTION_MASK)
self.connect('draw', self.__draw_cb)
self.connect('event', self.__event_cb)
+ self._on_touch = False
def __event_cb(self, widget, event):
if event.type in (Gdk.EventType.TOUCH_BEGIN,
@@ -27,23 +29,38 @@ class TestTouch(Gtk.DrawingArea):
Gdk.EventType.BUTTON_RELEASE, Gdk.EventType.MOTION_NOTIFY):
x = event.get_coords()[1]
y = event.get_coords()[2]
- seq = str(event.touch.sequence)
+ if event.type in (Gdk.EventType.BUTTON_PRESS,
+ Gdk.EventType.BUTTON_RELEASE, Gdk.EventType.MOTION_NOTIFY):
+ seq = 'mouse'
+ else:
+ seq = str(event.touch.sequence)
+ pressure = event.get_axis(Gdk.AxisUse.PRESSURE)[1]
+ if pressure == 0:
+ pressure = 1
+
+ # workaround: discard first motion notify because can be emulated
+ if event.type == Gdk.EventType.MOTION_NOTIFY and \
+ len(self.touches) == 0:
+ return
if event.type in (Gdk.EventType.TOUCH_BEGIN,
Gdk.EventType.TOUCH_UPDATE, Gdk.EventType.BUTTON_PRESS,
Gdk.EventType.MOTION_NOTIFY):
- self.touches[seq] = (x, y)
+ self.touches[seq] = (x, y, pressure)
+ self._on_touch = True
elif event.type in (Gdk.EventType.TOUCH_END,
Gdk.EventType.BUTTON_RELEASE):
del self.touches[seq]
+ self._on_touch = False
self.queue_draw()
def __draw_cb(self, widget, ctx):
ctx.set_source_rgba(0.3, 0.3, 0.3, 0.7)
for touch in self.touches.values():
- x, y = touch
+ x, y, pressure = touch
+ logging.error('x %s y %s pressure %s', x, y, pressure)
ctx.save()
- ctx.arc(x, y, 60, 0., 2 * math.pi)
+ ctx.arc(x, y, 60 * pressure, 0., 2 * math.pi)
ctx.fill()
ctx.restore()