<s> '''<STR_LIT>''' <EOL> __all__ = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> import os <EOL> from kivy . input . motionevent import MotionEvent <EOL> from kivy . input . shape import ShapeRect <EOL> Window = None <EOL> Keyboard = None <EOL> class HIDMotionEvent ( MotionEvent ) : <EOL> def depack ( self , args ) : <EOL> self . is_touch = True <EOL> self . sx = args [ '<STR_LIT:x>' ] <EOL> self . sy = args [ '<STR_LIT:y>' ] <EOL> self . profile = [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in args and '<STR_LIT>' in args : <EOL> self . shape = ShapeRect ( ) <EOL> self . shape . width = args [ '<STR_LIT>' ] <EOL> self . shape . height = args [ '<STR_LIT>' ] <EOL> self . profile . append ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in args : <EOL> self . pressure = args [ '<STR_LIT>' ] <EOL> self . profile . append ( '<STR_LIT>' ) <EOL> super ( HIDMotionEvent , self ) . depack ( args ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % ( self . id , self . sx , self . sy , self . device ) <EOL> if '<STR_LIT>' in os . environ : <EOL> HIDInputMotionEventProvider = None <EOL> else : <EOL> import threading <EOL> import collections <EOL> import struct <EOL> import fcntl <EOL> from kivy . input . provider import MotionEventProvider <EOL> from kivy . input . factory import MotionEventFactory <EOL> from kivy . logger import Logger <EOL> EV_SYN = <NUM_LIT> <EOL> EV_KEY = <NUM_LIT> <EOL> EV_REL = <NUM_LIT> <EOL> EV_ABS = <NUM_LIT> <EOL> EV_MSC = <NUM_LIT> <EOL> EV_SW = <NUM_LIT> <EOL> EV_LED = <NUM_LIT> <EOL> EV_SND = <NUM_LIT> <EOL> EV_REP = <NUM_LIT> <EOL> EV_FF = <NUM_LIT> <EOL> EV_PWR = <NUM_LIT> <EOL> EV_FF_STATUS = <NUM_LIT> <EOL> EV_MAX = <NUM_LIT> <EOL> EV_CNT = ( EV_MAX + <NUM_LIT:1> ) <EOL> KEY_MAX = <NUM_LIT> <EOL> SYN_REPORT = <NUM_LIT:0> <EOL> SYN_CONFIG = <NUM_LIT:1> <EOL> SYN_MT_REPORT = <NUM_LIT:2> <EOL> MSC_SERIAL = <NUM_LIT> <EOL> MSC_PULSELED = <NUM_LIT> <EOL> MSC_GESTURE = <NUM_LIT> <EOL> MSC_RAW = <NUM_LIT> <EOL> MSC_SCAN = <NUM_LIT> <EOL> MSC_MAX = <NUM_LIT> <EOL> MSC_CNT = ( MSC_MAX + <NUM_LIT:1> ) <EOL> ABS_X = <NUM_LIT> <EOL> ABS_Y = <NUM_LIT> <EOL> ABS_PRESSURE = <NUM_LIT> <EOL> ABS_MT_TOUCH_MAJOR = <NUM_LIT> <EOL> ABS_MT_TOUCH_MINOR = <NUM_LIT> <EOL> ABS_MT_WIDTH_MAJOR = <NUM_LIT> <EOL> ABS_MT_WIDTH_MINOR = <NUM_LIT> <EOL> ABS_MT_ORIENTATION = <NUM_LIT> <EOL> ABS_MT_POSITION_X = <NUM_LIT> <EOL> ABS_MT_POSITION_Y = <NUM_LIT> <EOL> ABS_MT_TOOL_TYPE = <NUM_LIT> <EOL> ABS_MT_BLOB_ID = <NUM_LIT> <EOL> ABS_MT_TRACKING_ID = <NUM_LIT> <EOL> ABS_MT_PRESSURE = <NUM_LIT> <EOL> EVIOCGNAME = <NUM_LIT> <EOL> EVIOCGBIT = <NUM_LIT> <EOL> EVIOCGABS = <NUM_LIT> <EOL> keyboard_keys = { <EOL> <NUM_LIT> : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:1>' , '<STR_LIT:!>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:2>' , '<STR_LIT:@>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:3>' , '<STR_LIT:#>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:4>' , '<STR_LIT:$>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:5>' , '<STR_LIT:%>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , '<STR_LIT:&>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , '<STR_LIT:*>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , '<STR_LIT:(>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:0>' , '<STR_LIT:)>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:->' , '<STR_LIT:_>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:=>' , '<STR_LIT:+>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT:q>' , '<STR_LIT>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:w>' , '<STR_LIT>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:e>' , '<STR_LIT:E>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:r>' , '<STR_LIT:R>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:t>' , '<STR_LIT:T>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:y>' , '<STR_LIT:Y>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:u>' , '<STR_LIT>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:i>' , '<STR_LIT:I>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:o>' , '<STR_LIT:O>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:p>' , '<STR_LIT:P>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:[>' , '<STR_LIT:{>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:]>' , '<STR_LIT:}>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:\\>' , '<STR_LIT:|>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT:a>' , '<STR_LIT:A>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:s>' , '<STR_LIT:S>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:d>' , '<STR_LIT:D>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:f>' , '<STR_LIT:F>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:g>' , '<STR_LIT>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:h>' , '<STR_LIT:H>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:k>' , '<STR_LIT>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:l>' , '<STR_LIT:L>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:;>' , '<STR_LIT::>' ) , <EOL> <NUM_LIT> : ( "<STR_LIT:'>" , '<STR_LIT:">' ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT:z>' , '<STR_LIT>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:x>' , '<STR_LIT:X>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:c>' , '<STR_LIT:C>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:v>' , '<STR_LIT>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:b>' , '<STR_LIT:B>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:n>' , '<STR_LIT:N>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:m>' , '<STR_LIT:M>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:U+002C>' , '<STR_LIT:<>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:.>' , '<STR_LIT:>>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT:/>' , '<STR_LIT:?>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , '<STR_LIT:left>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , '<STR_LIT:end>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , '<STR_LIT:right>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT:left>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT:right>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT:end>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> <NUM_LIT> : ( '<STR_LIT>' , ) , <EOL> } <EOL> keys_str = { <EOL> '<STR_LIT>' : '<STR_LIT:U+0020>' , <EOL> '<STR_LIT>' : '<STR_LIT:U+0020>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT:3>' , <EOL> '<STR_LIT>' : '<STR_LIT:4>' , <EOL> '<STR_LIT>' : '<STR_LIT:5>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : '<STR_LIT:*>' , <EOL> '<STR_LIT>' : '<STR_LIT:/>' , <EOL> '<STR_LIT>' : '<STR_LIT:+>' , <EOL> '<STR_LIT>' : '<STR_LIT:->' , <EOL> } <EOL> struct_input_event_sz = struct . calcsize ( '<STR_LIT>' ) <EOL> struct_input_absinfo_sz = struct . calcsize ( '<STR_LIT>' ) <EOL> sz_l = struct . calcsize ( '<STR_LIT>' ) <EOL> class HIDInputMotionEventProvider ( MotionEventProvider ) : <EOL> options = ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , device , args ) : <EOL> super ( HIDInputMotionEventProvider , self ) . __init__ ( device , args ) <EOL> global Window , Keyboard <EOL> if Window is None : <EOL> from kivy . core . window import Window <EOL> if Keyboard is None : <EOL> from kivy . core . window import Keyboard <EOL> self . input_fn = None <EOL> self . default_ranges = dict ( ) <EOL> args = args . split ( '<STR_LIT:U+002C>' ) <EOL> if not args : <EOL> Logger . error ( '<STR_LIT>' ) <EOL> Logger . error ( '<STR_LIT>' ) <EOL> return None <EOL> self . input_fn = args [ <NUM_LIT:0> ] <EOL> Logger . info ( '<STR_LIT>' % self . input_fn ) <EOL> for arg in args [ <NUM_LIT:1> : ] : <EOL> if arg == '<STR_LIT>' : <EOL> continue <EOL> arg = arg . split ( '<STR_LIT:=>' ) <EOL> if len ( arg ) != <NUM_LIT:2> : <EOL> Logger . error ( '<STR_LIT>' <EOL> '<STR_LIT>' % arg ) <EOL> continue <EOL> key , value = arg <EOL> if key not in HIDInputMotionEventProvider . options : <EOL> Logger . error ( '<STR_LIT>' % key ) <EOL> continue <EOL> try : <EOL> self . default_ranges [ key ] = int ( value ) <EOL> except ValueError : <EOL> err = '<STR_LIT>' % ( <EOL> key , value ) <EOL> Logger . error ( err ) <EOL> continue <EOL> Logger . info ( '<STR_LIT>' % ( <EOL> key , int ( value ) ) ) <EOL> if '<STR_LIT>' not in self . default_ranges : <EOL> self . default_ranges [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> elif self . default_ranges [ '<STR_LIT>' ] not in ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) : <EOL> Logger . error ( '<STR_LIT>' . format ( <EOL> self . default_ranges [ '<STR_LIT>' ] ) ) <EOL> self . default_ranges [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> def start ( self ) : <EOL> if self . input_fn is None : <EOL> return <EOL> self . uid = <NUM_LIT:0> <EOL> self . queue = collections . deque ( ) <EOL> self . thread = threading . Thread ( <EOL> target = self . _thread_run , <EOL> kwargs = dict ( <EOL> queue = self . queue , <EOL> input_fn = self . input_fn , <EOL> device = self . device , <EOL> default_ranges = self . default_ranges ) ) <EOL> self . thread . daemon = True <EOL> self . thread . start ( ) <EOL> def _thread_run ( self , ** kwargs ) : <EOL> input_fn = kwargs . get ( '<STR_LIT>' ) <EOL> queue = kwargs . get ( '<STR_LIT>' ) <EOL> device = kwargs . get ( '<STR_LIT>' ) <EOL> drs = kwargs . get ( '<STR_LIT>' ) . get <EOL> touches = { } <EOL> touches_sent = [ ] <EOL> point = { } <EOL> l_points = [ ] <EOL> range_min_position_x = <NUM_LIT:0> <EOL> range_max_position_x = <NUM_LIT> <EOL> range_min_position_y = <NUM_LIT:0> <EOL> range_max_position_y = <NUM_LIT> <EOL> range_min_pressure = <NUM_LIT:0> <EOL> range_max_pressure = <NUM_LIT:255> <EOL> range_min_abs_x = <NUM_LIT:0> <EOL> range_max_abs_x = <NUM_LIT:255> <EOL> range_min_abs_y = <NUM_LIT:0> <EOL> range_max_abs_y = <NUM_LIT:255> <EOL> range_min_abs_pressure = <NUM_LIT:0> <EOL> range_max_abs_pressure = <NUM_LIT:255> <EOL> invert_x = int ( bool ( drs ( '<STR_LIT>' , <NUM_LIT:0> ) ) ) <EOL> invert_y = int ( bool ( drs ( '<STR_LIT>' , <NUM_LIT:1> ) ) ) <EOL> rotation = drs ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> def assign_coord ( point , value , invert , coords ) : <EOL> cx , cy = coords <EOL> if invert : <EOL> value = <NUM_LIT:1.> - value <EOL> if rotation == <NUM_LIT:0> : <EOL> point [ cx ] = value <EOL> elif rotation == <NUM_LIT> : <EOL> point [ cy ] = value <EOL> elif rotation == <NUM_LIT> : <EOL> point [ cx ] = <NUM_LIT:1.> - value <EOL> elif rotation == <NUM_LIT> : <EOL> point [ cy ] = <NUM_LIT:1.> - value <EOL> def assign_rel_coord ( point , value , invert , coords ) : <EOL> cx , cy = coords <EOL> if invert : <EOL> value = - <NUM_LIT:1> * value <EOL> if rotation == <NUM_LIT:0> : <EOL> point [ cx ] += value <EOL> elif rotation == <NUM_LIT> : <EOL> point [ cy ] += value <EOL> elif rotation == <NUM_LIT> : <EOL> point [ cx ] += - value <EOL> elif rotation == <NUM_LIT> : <EOL> point [ cy ] += - value <EOL> def process_as_multitouch ( tv_sec , tv_usec , ev_type , <EOL> ev_code , ev_value ) : <EOL> if ev_type == EV_SYN : <EOL> if ev_code == SYN_MT_REPORT : <EOL> if '<STR_LIT:id>' not in point : <EOL> return <EOL> l_points . append ( point . copy ( ) ) <EOL> elif ev_code == SYN_REPORT : <EOL> process ( l_points ) <EOL> del l_points [ : ] <EOL> elif ev_type == EV_MSC and ev_code in ( MSC_RAW , MSC_SCAN ) : <EOL> pass <EOL> else : <EOL> if ev_code == ABS_MT_TRACKING_ID : <EOL> point . clear ( ) <EOL> point [ '<STR_LIT:id>' ] = ev_value <EOL> elif ev_code == ABS_MT_POSITION_X : <EOL> val = normalize ( ev_value , <EOL> range_min_position_x , <EOL> range_max_position_x ) <EOL> assign_coord ( point , val , invert_x , '<STR_LIT>' ) <EOL> elif ev_code == ABS_MT_POSITION_Y : <EOL> val = <NUM_LIT:1.> - normalize ( ev_value , <EOL> range_min_position_y , <EOL> range_max_position_y ) <EOL> assign_coord ( point , val , invert_y , '<STR_LIT>' ) <EOL> elif ev_code == ABS_MT_ORIENTATION : <EOL> point [ '<STR_LIT>' ] = ev_value <EOL> elif ev_code == ABS_MT_BLOB_ID : <EOL> point [ '<STR_LIT>' ] = ev_value <EOL> elif ev_code == ABS_MT_PRESSURE : <EOL> point [ '<STR_LIT>' ] = normalize ( ev_value , <EOL> range_min_pressure , <EOL> range_max_pressure ) <EOL> elif ev_code == ABS_MT_TOUCH_MAJOR : <EOL> point [ '<STR_LIT>' ] = ev_value <EOL> elif ev_code == ABS_MT_TOUCH_MINOR : <EOL> point [ '<STR_LIT>' ] = ev_value <EOL> def process_as_mouse_or_keyboard ( <EOL> tv_sec , tv_usec , ev_type , ev_code , ev_value ) : <EOL> if ev_type == EV_SYN : <EOL> if ev_code == SYN_REPORT : <EOL> process ( [ point ] ) <EOL> elif ev_type == EV_REL : <EOL> if ev_code == <NUM_LIT:0> : <EOL> assign_rel_coord ( point , <EOL> min ( <NUM_LIT:1.> , max ( - <NUM_LIT:1.> , ev_value / <NUM_LIT> ) ) , <EOL> invert_x , '<STR_LIT>' ) <EOL> elif ev_code == <NUM_LIT:1> : <EOL> assign_rel_coord ( point , <EOL> min ( <NUM_LIT:1.> , max ( - <NUM_LIT:1.> , ev_value / <NUM_LIT> ) ) , <EOL> invert_y , '<STR_LIT>' ) <EOL> elif ev_code == ABS_X : <EOL> val = normalize ( ev_value , <EOL> range_min_abs_x , <EOL> range_max_abs_x ) <EOL> assign_coord ( point , val , invert_x , '<STR_LIT>' ) <EOL> elif ev_code == ABS_Y : <EOL> val = <NUM_LIT:1.> - normalize ( ev_value , <EOL> range_min_abs_y , <EOL> range_max_abs_y ) <EOL> assign_coord ( point , val , invert_y , '<STR_LIT>' ) <EOL> elif ev_code == ABS_PRESSURE and ev_type != EV_KEY : <EOL> point [ '<STR_LIT>' ] = normalize ( ev_value , <EOL> range_min_abs_pressure , <EOL> range_max_abs_pressure ) <EOL> elif ev_type == EV_KEY : <EOL> buttons = { <EOL> <NUM_LIT> : '<STR_LIT:left>' , <EOL> <NUM_LIT> : '<STR_LIT:right>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' , <EOL> <NUM_LIT> : '<STR_LIT>' } <EOL> if ev_code in buttons . keys ( ) : <EOL> if ev_value : <EOL> if '<STR_LIT>' not in point : <EOL> point [ '<STR_LIT>' ] = buttons [ ev_code ] <EOL> point [ '<STR_LIT:id>' ] += <NUM_LIT:1> <EOL> if '<STR_LIT>' in point : <EOL> del point [ '<STR_LIT>' ] <EOL> elif '<STR_LIT>' in point : <EOL> if point [ '<STR_LIT>' ] == buttons [ ev_code ] : <EOL> del point [ '<STR_LIT>' ] <EOL> point [ '<STR_LIT:id>' ] += <NUM_LIT:1> <EOL> point [ '<STR_LIT>' ] = True <EOL> else : <EOL> if ev_value == <NUM_LIT:1> : <EOL> l = keyboard_keys [ ev_code ] [ - <NUM_LIT:1> <EOL> if '<STR_LIT>' in Window . _modifiers else <NUM_LIT:0> ] <EOL> if l == '<STR_LIT>' or l == '<STR_LIT>' : <EOL> Window . _modifiers . append ( l ) <EOL> Window . dispatch ( <EOL> '<STR_LIT>' , <EOL> Keyboard . keycodes [ l . lower ( ) ] , <EOL> ev_code , keys_str . get ( l , l ) , <EOL> Window . _modifiers ) <EOL> if ev_value == <NUM_LIT:0> : <EOL> l = keyboard_keys [ ev_code ] [ - <NUM_LIT:1> <EOL> if '<STR_LIT>' in Window . _modifiers else <NUM_LIT:0> ] <EOL> Window . dispatch ( <EOL> '<STR_LIT>' , <EOL> Keyboard . keycodes [ l . lower ( ) ] , <EOL> ev_code , <EOL> keys_str . get ( l , l ) , <EOL> Window . _modifiers ) <EOL> if l == '<STR_LIT>' : <EOL> Window . _modifiers . remove ( '<STR_LIT>' ) <EOL> def process ( points ) : <EOL> if not is_multitouch : <EOL> Window . mouse_pos = ( <EOL> points [ <NUM_LIT:0> ] [ '<STR_LIT:x>' ] * Window . width , <EOL> points [ <NUM_LIT:0> ] [ '<STR_LIT:y>' ] * Window . height ) <EOL> actives = [ args [ '<STR_LIT:id>' ] <EOL> for args in points <EOL> if '<STR_LIT:id>' in args and not '<STR_LIT>' in args ] <EOL> for args in points : <EOL> tid = args [ '<STR_LIT:id>' ] <EOL> try : <EOL> touch = touches [ tid ] <EOL> if touch . sx == args [ '<STR_LIT:x>' ] and touch . sy == args [ '<STR_LIT:y>' ] : <EOL> continue <EOL> touch . move ( args ) <EOL> if tid not in touches_sent : <EOL> queue . append ( ( '<STR_LIT>' , touch ) ) <EOL> touches_sent . append ( tid ) <EOL> queue . append ( ( '<STR_LIT>' , touch ) ) <EOL> except KeyError : <EOL> if '<STR_LIT>' not in args : <EOL> touch = HIDMotionEvent ( device , tid , args ) <EOL> touches [ touch . id ] = touch <EOL> if tid not in touches_sent : <EOL> queue . append ( ( '<STR_LIT>' , touch ) ) <EOL> touches_sent . append ( tid ) <EOL> for tid in list ( touches . keys ( ) ) [ : ] : <EOL> if tid not in actives : <EOL> touch = touches [ tid ] <EOL> if tid in touches_sent : <EOL> touch . update_time_end ( ) <EOL> queue . append ( ( '<STR_LIT:end>' , touch ) ) <EOL> touches_sent . remove ( tid ) <EOL> del touches [ tid ] <EOL> def normalize ( value , vmin , vmax ) : <EOL> return ( value - vmin ) / float ( vmax - vmin ) <EOL> fd = open ( input_fn , '<STR_LIT:rb>' ) <EOL> device_name = str ( fcntl . ioctl ( fd , EVIOCGNAME + ( <NUM_LIT> << <NUM_LIT:16> ) , <EOL> "<STR_LIT:U+0020>" * <NUM_LIT> ) ) . split ( '<STR_LIT:\x00>' ) [ <NUM_LIT:0> ] <EOL> Logger . info ( '<STR_LIT>' % device_name ) <EOL> bit = fcntl . ioctl ( fd , EVIOCGBIT + ( EV_MAX << <NUM_LIT:16> ) , '<STR_LIT:U+0020>' * sz_l ) <EOL> bit , = struct . unpack ( '<STR_LIT>' , bit ) <EOL> is_multitouch = False <EOL> for x in range ( EV_MAX ) : <EOL> if x != EV_ABS : <EOL> continue <EOL> if ( bit & ( <NUM_LIT:1> << x ) ) == <NUM_LIT:0> : <EOL> continue <EOL> sbit = fcntl . ioctl ( fd , EVIOCGBIT + x + ( KEY_MAX << <NUM_LIT:16> ) , <EOL> '<STR_LIT:U+0020>' * sz_l ) <EOL> sbit , = struct . unpack ( '<STR_LIT>' , sbit ) <EOL> for y in range ( KEY_MAX ) : <EOL> if ( sbit & ( <NUM_LIT:1> << y ) ) == <NUM_LIT:0> : <EOL> continue <EOL> absinfo = fcntl . ioctl ( fd , EVIOCGABS + y + <EOL> ( struct_input_absinfo_sz << <NUM_LIT:16> ) , <EOL> '<STR_LIT:U+0020>' * struct_input_absinfo_sz ) <EOL> abs_value , abs_min , abs_max , abs_fuzz , abs_flat , abs_res = struct . unpack ( '<STR_LIT>' , absinfo ) <EOL> if y == ABS_MT_POSITION_X : <EOL> is_multitouch = True <EOL> range_min_position_x = drs ( '<STR_LIT>' , abs_min ) <EOL> range_max_position_x = drs ( '<STR_LIT>' , abs_max ) <EOL> Logger . info ( '<STR_LIT>' + <EOL> '<STR_LIT>' % ( <EOL> device_name , abs_min , abs_max ) ) <EOL> elif y == ABS_MT_POSITION_Y : <EOL> is_multitouch = True <EOL> range_min_position_y = drs ( '<STR_LIT>' , abs_min ) <EOL> range_max_position_y = drs ( '<STR_LIT>' , abs_max ) <EOL> Logger . info ( '<STR_LIT>' + <EOL> '<STR_LIT>' % ( <EOL> device_name , abs_min , abs_max ) ) <EOL> elif y == ABS_MT_PRESSURE : <EOL> range_min_pressure = drs ( '<STR_LIT>' , abs_min ) <EOL> range_max_pressure = drs ( '<STR_LIT>' , abs_max ) <EOL> Logger . info ( '<STR_LIT>' + <EOL> '<STR_LIT>' % ( <EOL> device_name , abs_min , abs_max ) ) <EOL> elif y == ABS_X : <EOL> range_min_abs_x = drs ( '<STR_LIT>' , abs_min ) <EOL> range_max_abs_x = drs ( '<STR_LIT>' , abs_max ) <EOL> Logger . info ( '<STR_LIT>' + <EOL> '<STR_LIT>' % ( <EOL> device_name , abs_min , abs_max ) ) <EOL> elif y == ABS_Y : <EOL> range_min_abs_y = drs ( '<STR_LIT>' , abs_min ) <EOL> range_max_abs_y = drs ( '<STR_LIT>' , abs_max ) <EOL> Logger . info ( '<STR_LIT>' + <EOL> '<STR_LIT>' % ( <EOL> device_name , abs_min , abs_max ) ) <EOL> elif y == ABS_PRESSURE : <EOL> range_min_abs_pressure = drs ( <EOL> '<STR_LIT>' , abs_min ) <EOL> range_max_abs_pressure = drs ( <EOL> '<STR_LIT>' , abs_max ) <EOL> Logger . info ( '<STR_LIT>' + <EOL> '<STR_LIT>' % ( <EOL> device_name , abs_min , abs_max ) ) <EOL> if not is_multitouch : <EOL> point = { '<STR_LIT:x>' : <NUM_LIT> , '<STR_LIT:y>' : <NUM_LIT> , '<STR_LIT:id>' : <NUM_LIT:0> , '<STR_LIT>' : True } <EOL> while fd : <EOL> data = fd . read ( struct_input_event_sz ) <EOL> if len ( data ) < struct_input_event_sz : <EOL> break <EOL> for i in range ( int ( len ( data ) / struct_input_event_sz ) ) : <EOL> ev = data [ i * struct_input_event_sz : ] <EOL> infos = struct . unpack ( '<STR_LIT>' , ev [ : struct_input_event_sz ] ) <EOL> if is_multitouch : <EOL> process_as_multitouch ( * infos ) <EOL> else : <EOL> process_as_mouse_or_keyboard ( * infos ) <EOL> def update ( self , dispatch_fn ) : <EOL> try : <EOL> while True : <EOL> event_type , touch = self . queue . popleft ( ) <EOL> dispatch_fn ( event_type , touch ) <EOL> except : <EOL> pass <EOL> MotionEventFactory . register ( '<STR_LIT>' , HIDInputMotionEventProvider ) </s>
