64
64
#include <errno.h>
65
65
#endif
66
66
67
- #define TOUCH_MAX_SLOTS 15
68
- #define TOUCH_SAMPLES_READ 5
67
+ #define TOUCH_MAX_SLOTS 10 /* fallback if not found */
68
+ #define TOUCH_SAMPLES_READ 3 /* up to, if available */
69
69
#define MAXBUTTONS 11 /* > 10 */
70
70
71
71
#if GET_ABI_MAJOR (ABI_XINPUT_VERSION ) >= 23
@@ -79,6 +79,8 @@ struct ts_priv {
79
79
struct ts_sample last ;
80
80
ValuatorMask * valuators ;
81
81
int8_t abs_x_only ;
82
+ uint16_t slots ;
83
+ uint32_t * touchids ;
82
84
83
85
#ifdef TSLIB_VERSION_MT
84
86
struct ts_sample_mt * * samp_mt ;
@@ -128,12 +130,11 @@ static void ReadHandleMTSample(InputInfoPtr local, int nr, int slot)
128
130
struct ts_priv * priv = (struct ts_priv * ) (local -> private );
129
131
int type ;
130
132
static unsigned int next_touchid ;
131
- static unsigned int touchids [TOUCH_MAX_SLOTS ] = {0 };
132
133
ValuatorMask * m = priv -> valuators ;
133
134
134
135
if (priv -> last_mt [slot ].pressure == 0 && priv -> samp_mt [nr ][slot ].pressure > 0 ) {
135
136
type = XI_TouchBegin ;
136
- touchids [slot ] = next_touchid ++ ;
137
+ priv -> touchids [slot ] = next_touchid ++ ;
137
138
} else if (priv -> last_mt [slot ].pressure > 0 && priv -> samp_mt [nr ][slot ].pressure == 0 ) {
138
139
type = XI_TouchEnd ;
139
140
} else if (priv -> last_mt [slot ].pressure > 0 && priv -> samp_mt [nr ][slot ].pressure > 0 ) {
@@ -147,7 +148,7 @@ static void ReadHandleMTSample(InputInfoPtr local, int nr, int slot)
147
148
valuator_mask_set_double (m , 1 , priv -> samp_mt [nr ][slot ].y );
148
149
}
149
150
150
- xf86PostTouchEvent (local -> dev , touchids [slot ], type , 0 , m );
151
+ xf86PostTouchEvent (local -> dev , priv -> touchids [slot ], type , 0 , m );
151
152
}
152
153
153
154
static void ReadInputMT (InputInfoPtr local )
@@ -158,14 +159,14 @@ static void ReadInputMT(InputInfoPtr local)
158
159
159
160
while (1 ) {
160
161
ret = ts_read_mt (priv -> ts , priv -> samp_mt ,
161
- TOUCH_MAX_SLOTS , TOUCH_SAMPLES_READ );
162
+ priv -> slots , TOUCH_SAMPLES_READ );
162
163
if (ret == - ENOSYS ) /* tslib module_raw without MT support */
163
164
ReadInputLegacy (local );
164
165
else if (ret <= 0 )
165
166
return ;
166
167
167
168
for (i = 0 ; i < ret ; i ++ ) {
168
- for (j = 0 ; j < TOUCH_MAX_SLOTS ; j ++ ) {
169
+ for (j = 0 ; j < priv -> slots ; j ++ ) {
169
170
if (priv -> samp_mt [i ][j ].valid != 1 )
170
171
continue ;
171
172
@@ -290,7 +291,7 @@ static int xf86TslibControlProc(DeviceIntPtr device, int what)
290
291
}
291
292
292
293
if (InitTouchClassDeviceStruct (device ,
293
- TOUCH_MAX_SLOTS ,
294
+ priv -> slots ,
294
295
XIDirectTouch ,
295
296
2 /* axes */ ) == FALSE) {
296
297
xf86IDrvMsg (pInfo , X_ERROR ,
@@ -362,8 +363,7 @@ static int xf86TslibInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
362
363
struct ts_priv * priv ;
363
364
char * s ;
364
365
int i ;
365
- struct input_absinfo abs_x ;
366
- struct input_absinfo abs_y ;
366
+ struct input_absinfo absinfo ;
367
367
#ifdef TSLIB_VERSION_MT
368
368
struct ts_lib_version_data * ver = ts_libversion ();
369
369
#endif
@@ -409,6 +409,8 @@ static int xf86TslibInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
409
409
}
410
410
#endif
411
411
412
+ priv -> slots = 0 ;
413
+
412
414
pInfo -> fd = ts_fd (priv -> ts );
413
415
414
416
/* process generic options */
@@ -419,28 +421,53 @@ static int xf86TslibInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
419
421
if (!priv -> valuators )
420
422
return BadValue ;
421
423
424
+ if (ioctl (pInfo -> fd , EVIOCGBIT (EV_ABS , sizeof (absbit )), absbit ) < 0 ) {
425
+ xf86IDrvMsg (pInfo , X_ERROR , "ioctl EVIOCGBIT failed" );
426
+ return BadValue ;
427
+ }
428
+
429
+ if (absbit [BIT_WORD (ABS_MT_SLOT )] & BIT_MASK (ABS_MT_SLOT )) {
430
+ if (ioctl (pInfo -> fd , EVIOCGABS (ABS_X ), & absinfo ) < 0 ) {
431
+ xf86IDrvMsg (pInfo , X_ERROR , "ioctl EVIOGABS failed" );
432
+ return BadValue ;
433
+ }
434
+ priv -> slots = absinfo .maximum ;
435
+ } else {
436
+ priv -> slots = TOUCH_MAX_SLOTS ;
437
+ }
438
+
422
439
#ifdef TSLIB_VERSION_MT
423
- priv -> samp_mt = malloc (TOUCH_SAMPLES_READ * sizeof (struct ts_sample_mt * ));
440
+ priv -> samp_mt = malloc (priv -> slots * sizeof (struct ts_sample_mt * ));
424
441
if (!priv -> samp_mt )
425
442
return BadValue ;
426
443
427
444
for (i = 0 ; i < TOUCH_SAMPLES_READ ; i ++ ) {
428
- priv -> samp_mt [i ] = calloc (TOUCH_MAX_SLOTS , sizeof (struct ts_sample_mt ));
445
+ priv -> samp_mt [i ] = calloc (priv -> slots , sizeof (struct ts_sample_mt ));
429
446
if (!priv -> samp_mt [i ])
430
447
return BadValue ;
431
448
}
432
449
433
- priv -> last_mt = calloc (TOUCH_MAX_SLOTS , sizeof (struct ts_sample_mt ));
434
- if (!priv -> last_mt )
450
+ priv -> last_mt = calloc (priv -> slots , sizeof (struct ts_sample_mt ));
451
+ if (!priv -> last_mt ) {
452
+ for (i = 0 ; i < TOUCH_SAMPLES_READ ; i ++ )
453
+ free (priv -> samp_mt [i ]);
454
+
455
+ free (priv -> samp_mt );
435
456
return BadValue ;
457
+ }
436
458
437
- #endif /* TSLIB_VERSION_MT */
459
+ priv -> touchids = calloc (priv -> slots , sizeof (uint32_t ));
460
+ if (!priv -> touchids ) {
461
+ for (i = 0 ; i < TOUCH_SAMPLES_READ ; i ++ )
462
+ free (priv -> samp_mt [i ]);
438
463
439
- if ( ioctl ( pInfo -> fd , EVIOCGBIT ( EV_ABS , sizeof ( absbit )), absbit ) < 0 ) {
440
- xf86IDrvMsg ( pInfo , X_ERROR , "ioctl EVIOCGBIT failed" );
464
+ free ( priv -> samp_mt );
465
+ free ( priv -> last_mt );
441
466
return BadValue ;
442
467
}
443
468
469
+ #endif /* TSLIB_VERSION_MT */
470
+
444
471
if (!(absbit [BIT_WORD (ABS_MT_POSITION_X )] & BIT_MASK (ABS_MT_POSITION_X )) ||
445
472
!(absbit [BIT_WORD (ABS_MT_POSITION_Y )] & BIT_MASK (ABS_MT_POSITION_Y ))) {
446
473
if (!(absbit [BIT_WORD (ABS_X )] & BIT_MASK (ABS_X )) ||
@@ -455,27 +482,29 @@ static int xf86TslibInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
455
482
}
456
483
457
484
if (priv -> abs_x_only ) {
458
- if (ioctl (pInfo -> fd , EVIOCGABS (ABS_X ), & abs_x ) < 0 ) {
485
+ if (ioctl (pInfo -> fd , EVIOCGABS (ABS_X ), & absinfo ) < 0 ) {
459
486
xf86IDrvMsg (pInfo , X_ERROR , "ioctl EVIOGABS failed" );
460
487
return BadValue ;
461
488
}
462
- if (ioctl (pInfo -> fd , EVIOCGABS (ABS_Y ), & abs_y ) < 0 ) {
489
+ priv -> width = absinfo .maximum ;
490
+
491
+ if (ioctl (pInfo -> fd , EVIOCGABS (ABS_Y ), & absinfo ) < 0 ) {
463
492
xf86IDrvMsg (pInfo , X_ERROR , "ioctl EVIOGABS failed" );
464
493
return BadValue ;
465
494
}
466
- priv -> width = abs_x .maximum ;
467
- priv -> height = abs_y .maximum ;
495
+ priv -> height = absinfo .maximum ;
468
496
} else {
469
- if (ioctl (pInfo -> fd , EVIOCGABS (ABS_MT_POSITION_X ), & abs_x ) < 0 ) {
497
+ if (ioctl (pInfo -> fd , EVIOCGABS (ABS_MT_POSITION_X ), & absinfo ) < 0 ) {
470
498
xf86IDrvMsg (pInfo , X_ERROR , "ioctl EVIOGABS failed" );
471
499
return BadValue ;
472
500
}
473
- if (ioctl (pInfo -> fd , EVIOCGABS (ABS_MT_POSITION_Y ), & abs_y ) < 0 ) {
501
+ priv -> width = absinfo .maximum ;
502
+
503
+ if (ioctl (pInfo -> fd , EVIOCGABS (ABS_MT_POSITION_Y ), & absinfo ) < 0 ) {
474
504
xf86IDrvMsg (pInfo , X_ERROR , "ioctl EVIOGABS failed" );
475
505
return BadValue ;
476
506
}
477
- priv -> width = abs_x .maximum ;
478
- priv -> height = abs_y .maximum ;
507
+ priv -> height = absinfo .maximum ;
479
508
}
480
509
481
510
/* Return the configured device */
0 commit comments