def probe(self): inputs = get_inputs(self.input_path) inputs = [x for x in inputs if x.has_capability(ABS_MT_POSITION_X)] for device in inputs: pymt_logger.info('ProbeSysfs: found device: %s at %s' % ( device.name, device.device)) # must ignore ? if self.match: if not re.match(self.match, device.name, re.IGNORECASE): pymt_logger.warning('ProbeSysfs: device not match the' ' rule in config, ignoring.') continue devicename = self.device % dict(name=device.device.split(os.path.sep)[-1]) provider = TouchFactory.get(self.provider) if provider is None: pymt_logger.info('ProbeSysfs: unable to found provider %s' % self.provider) pymt_logger.info('ProbeSysfs: fallback on hidinput') provider = TouchFactory.get('hidinput') if provider is None: pymt_logger.critical('ProbeSysfs: no input provider found' ' to handle this device !') continue instance = provider(devicename, '%s,%s' % (device.device, ','.join(self.args))) if instance: pymt.pymt_providers.append(instance)
elif ev_code == ABS_MT_POSITION_Y: val = 1. - normalize(ev_value, range_min_position_y, range_max_position_y) if invert_y: val = 1. - val point['y'] = val elif ev_code == ABS_MT_ORIENTATION: point['orientation'] = ev_value elif ev_code == ABS_MT_BLOB_ID: point['blobid'] = ev_value elif ev_code == ABS_MT_PRESSURE: point['pressure'] = normalize( ev_value, range_min_pressure, range_max_pressure) elif ev_code == ABS_MT_TOUCH_MAJOR: point['size_w'] = ev_value elif ev_code == ABS_MT_TOUCH_MINOR: point['size_h'] = ev_value def update(self, dispatch_fn): # dispatch all event from threads try: while True: event_type, touch = self.queue.popleft() dispatch_fn(event_type, touch) except: pass TouchFactory.register('hidinput', HIDInputTouchProvider)
range_min_major, range_max_major) elif ev_code == MTDEV_CODE_TOUCH_MINOR: point['size_h'] = normalize(ev_value, range_min_minor, range_max_minor) elif ev_code == MTDEV_CODE_TRACKING_ID: if ev_value == -1: point['delete'] = True else: point['id'] = ev_value else: # unrecognized command, ignore. continue _changes.add(_slot) # push all changes if _changes: process([l_points[x] for x in _changes]) _changes.clear() def update(self, dispatch_fn): # dispatch all event from threads try: while True: event_type, touch = self.queue.popleft() dispatch_fn(event_type, touch) except: pass TouchFactory.register('mtdev', MTDTouchProvider)
point["pressure"] = normalize(ev_value, range_min_pressure, range_max_pressure) elif ev_code == MTDEV_CODE_TOUCH_MAJOR: point["size_w"] = normalize(ev_value, range_min_major, range_max_major) elif ev_code == MTDEV_CODE_TOUCH_MINOR: point["size_h"] = normalize(ev_value, range_min_minor, range_max_minor) elif ev_code == MTDEV_CODE_TRACKING_ID: if ev_value == -1: point["delete"] = True else: point["id"] = ev_value else: # unrecognized command, ignore. continue _changes.add(_slot) # push all changes if _changes: process([l_points[x] for x in _changes]) _changes.clear() def update(self, dispatch_fn): # dispatch all event from threads try: while True: event_type, touch = self.queue.popleft() dispatch_fn(event_type, touch) except: pass TouchFactory.register("mtdev", MTDTouchProvider)
cur = self.find_touch(rx, ry) if button == 'left' and cur and not ('ctrl' in modifiers): self.remove_touch(cur) self.current_drag = None if self.alt_touch: self.remove_touch(self.alt_touch) self.alt_touch = None return True def update(self, dispatch_fn): '''Update the mouse provider (pop event from the queue)''' if not self.window: from pymt.base import getWindow self.window = getWindow() if self.window: self.window.push_handlers(on_mouse_move=self.on_mouse_motion, on_mouse_down=self.on_mouse_press, on_mouse_up=self.on_mouse_release) if not self.window: return try: while True: event = self.waiting_event.popleft() dispatch_fn(*event) except Exception, e: pass # registers TouchFactory.register('mouse', MouseTouchProvider)
point['x'] = val elif ev_code == ABS_MT_POSITION_Y: val = 1. - normalize(ev_value, range_min_position_y, range_max_position_y) if invert_y: val = 1. - val point['y'] = val elif ev_code == ABS_MT_ORIENTATION: point['orientation'] = ev_value elif ev_code == ABS_MT_BLOB_ID: point['blobid'] = ev_value elif ev_code == ABS_MT_PRESSURE: point['pressure'] = normalize(ev_value, range_min_pressure, range_max_pressure) elif ev_code == ABS_MT_TOUCH_MAJOR: point['size_w'] = ev_value elif ev_code == ABS_MT_TOUCH_MINOR: point['size_h'] = ev_value def update(self, dispatch_fn): # dispatch all event from threads try: while True: event_type, touch = self.queue.popleft() dispatch_fn(event_type, touch) except: pass TouchFactory.register('hidinput', HIDInputTouchProvider)
if msg == WM_TOUCH: done = self._touch_handler(msg, wParam, lParam) if msg >= WM_MOUSEMOVE and msg <= WM_MOUSELAST: done = self._mouse_handler(msg, wParam, lParam) if not done: return windll.user32.CallWindowProcW(self.old_windProc, hwnd, msg, wParam, lParam) return 1 # this on pushes WM_TOUCH messages onto our event stack def _touch_handler(self, msg, wParam, lParam): touches = (TOUCHINPUT * wParam)() windll.user32.GetTouchInputInfo(wintypes.HANDLE(lParam), wParam, pointer(touches), sizeof(TOUCHINPUT)) for i in xrange(wParam): self.touch_events.appendleft(touches[i]) return True # filter fake mouse events, because touch and stylus also make mouse events def _mouse_handler(self, msg, wparam, lParam): info = windll.user32.GetMessageExtraInfo() if (info & PEN_OR_TOUCH_MASK ) == PEN_OR_TOUCH_SIGNATURE: # its a touch or a pen if info & PEN_EVENT_TOUCH_MASK: return True TouchFactory.register('wm_touch', WM_TouchProvider)
if invert_x: val = 1. - val touch_x = val changed = True elif ev_type == EV_ABS and ev_code == ABS_Y: val = 1. - normalize(ev_value, range_min_position_y, range_max_position_y) if invert_y: val = 1. - val touch_y = val changed = True elif ev_type == EV_ABS and ev_code == ABS_PRESSURE: touch_pressure = normalize(ev_value, range_min_pressure, range_max_pressure) changed = True elif ev_type == EV_ABS and ev_code == ABS_MISC: if ev_value == 0: reset_touch = True def update(self, dispatch_fn): # dispatch all event from threads try: while True: event_type, touch = self.queue.popleft() dispatch_fn(event_type, touch) except: pass TouchFactory.register('linuxwacom', LinuxWacomTouchProvider)
# increment uid _instance.lock.acquire() _instance.uid += 1 # create a touch touch = MacTouch(_instance.device, _instance.uid, args) _instance.lock.release() # create event _instance.queue.append(('down', touch)) # store touch touches[data_id] = touch else: touch = touches[data_id] # check if he really moved if data.normalized.position.x == touch.sx and \ data.normalized.position.y == touch.sy: continue touch.move(args) _instance.queue.append(('move', touch)) # delete old touchs for tid in touches.keys()[:]: if tid not in actives: touch = touches[tid] _instance.queue.append(('up', touch)) del touches[tid] return 0 TouchFactory.register('mactouch', MacTouchProvider)
device.name, device.device)) # must ignore ? if self.match: if not re.match(self.match, device.name, re.IGNORECASE): pymt_logger.warning('ProbeSysfs: device not match the' ' rule in config, ignoring.') continue devicename = self.device % dict(name=device.device.split(os.path.sep)[-1]) provider = TouchFactory.get(self.provider) if provider is None: pymt_logger.info('ProbeSysfs: unable to found provider %s' % self.provider) pymt_logger.info('ProbeSysfs: fallback on hidinput') provider = TouchFactory.get('hidinput') if provider is None: pymt_logger.critical('ProbeSysfs: no input provider found' ' to handle this device !') continue instance = provider(devicename, '%s,%s' % (device.device, ','.join(self.args))) if instance: pymt.pymt_providers.append(instance) TouchFactory.register('probesysfs', ProbeSysfsHardwareProbe)
self.hwnd = windll.user32.GetActiveWindow() # inject our own wndProc to handle messages before window manager does self.new_windProc = WNDPROC(self._pen_wndProc) self.old_windProc = windll.user32.SetWindowLongW( self.hwnd, GWL_WNDPROC, self.new_windProc) def update(self, dispatch_fn): while True: try: type, x, y = self.pen_events.pop() except: break if type == 'down': self.uid += 1 self.pen = WM_Pen(self.device, self.uid, [x, y]) if type == 'move': self.pen.move([x, y]) dispatch_fn(type, self.pen) def stop(self): self.pen = None windll.user32.SetWindowLongW(self.hwnd, GWL_WNDPROC, self.old_windProc) TouchFactory.register('wm_pen', WM_PenProvider)
self.hwnd, GWL_WNDPROC, self.new_windProc ) def update(self, dispatch_fn): while True: try: type, x, y = self.pen_events.pop() except: break if type == 'down': self.uid += 1 self.pen = WM_Pen(self.device, self.uid, [x, y]) if type == 'move': self.pen.move([x, y]) dispatch_fn(type, self.pen) def stop(self): self.pen = None windll.user32.SetWindowLongW( self.hwnd, GWL_WNDPROC, self.old_windProc ) TouchFactory.register('wm_pen', WM_PenProvider)
if button == 'left' and cur and not ('ctrl' in modifiers): self.remove_touch(cur) self.current_drag = None if self.alt_touch: self.remove_touch(self.alt_touch) self.alt_touch = None return True def update(self, dispatch_fn): '''Update the mouse provider (pop event from the queue)''' if not self.window: from pymt.base import getWindow self.window = getWindow() if self.window: self.window.push_handlers( on_mouse_move=self.on_mouse_motion, on_mouse_down=self.on_mouse_press, on_mouse_up=self.on_mouse_release ) if not self.window: return try: while True: event = self.waiting_event.popleft() dispatch_fn(*event) except Exception, e: pass # registers TouchFactory.register('mouse', MouseTouchProvider)
if msg >= WM_MOUSEMOVE and msg <= WM_MOUSELAST: done = self._mouse_handler(msg, wParam, lParam) if not done: return windll.user32.CallWindowProcW( self.old_windProc, hwnd, msg, wParam, lParam) return 1 # this on pushes WM_TOUCH messages onto our event stack def _touch_handler(self, msg, wParam, lParam): touches = (TOUCHINPUT * wParam)() windll.user32.GetTouchInputInfo(wintypes.HANDLE(lParam), wParam, pointer(touches), sizeof(TOUCHINPUT)) for i in xrange(wParam): self.touch_events.appendleft(touches[i]) return True # filter fake mouse events, because touch and stylus also make mouse events def _mouse_handler(self, msg, wparam, lParam): info = windll.user32.GetMessageExtraInfo() if (info & PEN_OR_TOUCH_MASK) == PEN_OR_TOUCH_SIGNATURE: # its a touch or a pen if info & PEN_EVENT_TOUCH_MASK: return True TouchFactory.register('wm_touch', WM_TouchProvider)
class Tuio2dObjTouch(TuioTouch): '''A 2dObj TUIO object. ''' def __init__(self, device, id, args): super(Tuio2dObjTouch, self).__init__(device, id, args) def depack(self, args): if len(args) < 5: self.sx, self.sy = args[0:2] self.profile = ('pos', ) elif len(args) == 9: self.fid, self.sx, self.sy, self.a, self.X, self.Y, self.A, self.m, self.r = args[0:9] self.Y = -self.Y self.profile = ('markerid', 'pos', 'angle', 'mov', 'rot', 'motacc', 'rotacc') else: self.fid, self.sx, self.sy, self.a, self.X, self.Y, self.A, self.m, self.r, width, height = args[0:11] self.Y = -self.Y self.profile = ('markerid', 'pos', 'angle', 'mov', 'rot', 'rotacc', 'acc', 'shape') if self.shape is None: self.shape = TouchShapeRect() self.shape.width = width self.shape.height = height self.sy = 1 - self.sy super(Tuio2dObjTouch, self).depack(args) # registers TuioTouchProvider.register('/tuio/2Dcur', Tuio2dCurTouch) TuioTouchProvider.register('/tuio/2Dobj', Tuio2dObjTouch) TouchFactory.register('tuio', TuioTouchProvider)
super(Tuio2dObjTouch, self).__init__(device, id, args) def depack(self, args): if len(args) < 5: self.sx, self.sy = args[0:2] self.profile = ('pos', ) elif len(args) == 9: self.fid, self.sx, self.sy, self.a, self.X, self.Y, self.A, self.m, self.r = args[ 0:9] self.Y = -self.Y self.profile = ('markerid', 'pos', 'angle', 'mov', 'rot', 'motacc', 'rotacc') else: self.fid, self.sx, self.sy, self.a, self.X, self.Y, self.A, self.m, self.r, width, height = args[ 0:11] self.Y = -self.Y self.profile = ('markerid', 'pos', 'angle', 'mov', 'rot', 'rotacc', 'acc', 'shape') if self.shape is None: self.shape = TouchShapeRect() self.shape.width = width self.shape.height = height self.sy = 1 - self.sy super(Tuio2dObjTouch, self).depack(args) # registers TuioTouchProvider.register('/tuio/2Dcur', Tuio2dCurTouch) TuioTouchProvider.register('/tuio/2Dobj', Tuio2dObjTouch) TouchFactory.register('tuio', TuioTouchProvider)