@@ -53,6 +53,8 @@ static void Event_Rel(EvdevPtr, struct input_event*);
5353
5454static void Event_Get_Time (struct timeval * , bool );
5555
56+ static int Event_Is_Valid (struct input_event * );
57+
5658const char *
5759Evdev_Get_Version () {
5860 return VCSID ;
@@ -180,19 +182,25 @@ Event_Get_Slot_Count(EvdevPtr device)
180182int
181183Event_Get_Button_Left (EvdevPtr device )
182184{
183- return TestBit ( BTN_LEFT , device -> key_state_bitmask );
185+ return Event_Get_Button ( device , BTN_LEFT );
184186}
185187
186188int
187189Event_Get_Button_Middle (EvdevPtr device )
188190{
189- return TestBit ( BTN_MIDDLE , device -> key_state_bitmask );
191+ return Event_Get_Button ( device , BTN_MIDDLE );
190192}
191193
192194int
193195Event_Get_Button_Right (EvdevPtr device )
194196{
195- return TestBit (BTN_RIGHT , device -> key_state_bitmask );
197+ return Event_Get_Button (device , BTN_RIGHT );
198+ }
199+
200+ int
201+ Event_Get_Button (EvdevPtr device , int button )
202+ {
203+ return TestBit (button , device -> key_state_bitmask );
196204}
197205
198206#define CASE_RETURN (s ) \
@@ -249,6 +257,10 @@ Event_To_String(int type, int code) {
249257 CASE_RETURN (BTN_LEFT );
250258 CASE_RETURN (BTN_RIGHT );
251259 CASE_RETURN (BTN_MIDDLE );
260+ CASE_RETURN (BTN_BACK );
261+ CASE_RETURN (BTN_FORWARD );
262+ CASE_RETURN (BTN_EXTRA );
263+ CASE_RETURN (BTN_SIDE );
252264 CASE_RETURN (BTN_TOUCH );
253265 CASE_RETURN (BTN_TOOL_FINGER );
254266 CASE_RETURN (BTN_TOOL_DOUBLETAP );
@@ -389,9 +401,11 @@ Event_Sync_State(EvdevPtr device)
389401 MT_Slot_Sync (device , & req );
390402 }
391403
392- /* Get current slot id */
393- if (EvdevProbeAbsinfo (device , ABS_MT_SLOT ) == Success )
404+ /* Get current slot id for multi-touch devices*/
405+ if (TestBit (ABS_MT_SLOT , device -> info .abs_bitmask ) &&
406+ (EvdevProbeAbsinfo (device , ABS_MT_SLOT ) == Success )) {
394407 MT_Slot_Set (device , device -> info .absinfo [ABS_MT_SLOT ].value );
408+ }
395409
396410 Event_Get_Time (& device -> after_sync_time , device -> info .is_monotonic );
397411
@@ -453,6 +467,12 @@ bool
453467Event_Process (EvdevPtr device , struct input_event * ev )
454468{
455469 Event_Print (device , ev );
470+ if (Event_Is_Valid (ev )) {
471+ if (!(ev -> type == EV_SYN && ev -> code == SYN_REPORT ))
472+ device -> got_valid_event = 1 ;
473+ } else {
474+ return false;
475+ }
456476
457477 switch (ev -> type ) {
458478 case EV_SYN :
@@ -480,14 +500,19 @@ Event_Process(EvdevPtr device, struct input_event* ev)
480500 * Dump the log of input events to disk
481501 */
482502void
483- Event_Dump_Debug_Log (void * vinfo )
503+ Event_Dump_Debug_Log (void * vinfo ) {
504+ Event_Dump_Debug_Log_To (vinfo , "/var/log/xorg/cmt_input_events.dat" );
505+ }
506+
507+ void
508+ Event_Dump_Debug_Log_To (void * vinfo , const char * filename )
484509{
485510 EvdevPtr device = (EvdevPtr ) vinfo ;
486511 size_t i ;
487512 int ret ;
488513 EventStatePtr evstate = device -> evstate ;
489514
490- FILE * fp = fopen ("/var/log/xorg/cmt_input_events.dat" , "wb" );
515+ FILE * fp = fopen (filename , "wb" );
491516 if (!fp ) {
492517 LOG_ERROR (device , "fopen() failed for debug log" );
493518 return ;
@@ -512,6 +537,19 @@ Event_Dump_Debug_Log(void* vinfo)
512537 fclose (fp );
513538}
514539
540+ /**
541+ * Clear Debug Buffer
542+ */
543+ void
544+ Event_Clear_Debug_Log (void * vinfo )
545+ {
546+ EvdevPtr device = (EvdevPtr ) vinfo ;
547+ EventStatePtr evstate = device -> evstate ;
548+
549+ memset (evstate -> debug_buf , 0 , sizeof (evstate -> debug_buf ));
550+ evstate -> debug_buf_tail = 0 ;
551+ }
552+
515553/**
516554 * Clear EV_REL event state. This function should be called after a EV_SYN
517555 * event is processed because EV_REL event state is not accumulative.
@@ -557,11 +595,13 @@ static void
557595Event_Syn_Report (EvdevPtr device , struct input_event * ev )
558596{
559597 EventStatePtr evstate = device -> evstate ;
560- device -> syn_report (device -> syn_report_udata , evstate , & ev -> time );
598+ if (device -> got_valid_event )
599+ device -> syn_report (device -> syn_report_udata , evstate , & ev -> time );
561600
562601 MT_Print_Slots (device );
563602
564603 Event_Clear_Ev_Rel_State (device );
604+ device -> got_valid_event = 0 ;
565605}
566606
567607static void
@@ -656,3 +696,12 @@ Event_Rel(EvdevPtr device, struct input_event* ev)
656696 break ;
657697 }
658698}
699+
700+ static int Event_Is_Valid (struct input_event * ev )
701+ {
702+ /* Key repeats are invalid. They're handled by X anyway */
703+ if (ev -> type == EV_KEY &&
704+ ev -> value == 2 )
705+ return 0 ;
706+ return 1 ;
707+ }
0 commit comments