Skip to content

Commit 134607d

Browse files
committed
Fix ABS range cache to accept smaller device ranges
Touchscreens with smaller ABS ranges (e.g., 0-4095) were ignored due to code only updated when device range exceeded the default 32767 range. This fix ensures devices with smaller ranges like [0, 4095] are properly recognized and used for coordinate scaling, instead of being stuck with the default [0, 32767] range that causes coordinates to collapse near the origin.
1 parent 6f611f5 commit 134607d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

backend/linux_input.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ typedef struct {
4848
int fd;
4949
int btns;
5050
int x, y;
51-
int abs_x_min, abs_y_min; /* Minimum value for ABS_X/ABS_Y from device */
52-
int abs_x_max, abs_y_max; /* Maximum value for ABS_X/ABS_Y from device */
51+
int abs_x_min, abs_y_min; /* Minimum value for ABS_X/ABS_Y from device */
52+
int abs_x_max, abs_y_max; /* Maximum value for ABS_X/ABS_Y from device */
53+
bool abs_range_initialized; /* Whether ABS range has been queried */
5354
#if TWIN_INPUT_SMOOTH_WEIGHT > 0
5455
int smooth_x, smooth_y; /* Smoothed coordinates for ABS events */
5556
bool smooth_initialized; /* Whether smoothing has been initialized */
@@ -269,12 +270,15 @@ static void twin_linux_input_query_abs(int fd, twin_linux_input_t *tm)
269270
int range = abs_info.maximum - abs_info.minimum;
270271
int current_range = tm->abs_x_max - tm->abs_x_min;
271272

272-
/* Update global range if this device has a larger range */
273-
if (range > current_range) {
273+
/* Accept first device range unconditionally, or larger ranges from
274+
* subsequent devices
275+
*/
276+
if (!tm->abs_range_initialized || range > current_range) {
274277
log_info("ABS_X range updated: [%d,%d] (device fd=%d)",
275278
abs_info.minimum, abs_info.maximum, fd);
276279
tm->abs_x_min = abs_info.minimum;
277280
tm->abs_x_max = abs_info.maximum;
281+
tm->abs_range_initialized = true;
278282
}
279283
} else {
280284
log_warn("Device fd=%d: ABS_X range invalid [%d,%d]", fd,
@@ -289,8 +293,10 @@ static void twin_linux_input_query_abs(int fd, twin_linux_input_t *tm)
289293
int range = abs_info.maximum - abs_info.minimum;
290294
int current_range = tm->abs_y_max - tm->abs_y_min;
291295

292-
/* Update global range if this device has a larger range */
293-
if (range > current_range) {
296+
/* Accept first device range unconditionally, or larger ranges from
297+
* subsequent devices
298+
*/
299+
if (!tm->abs_range_initialized || range > current_range) {
294300
log_info("ABS_Y range updated: [%d,%d] (device fd=%d)",
295301
abs_info.minimum, abs_info.maximum, fd);
296302
tm->abs_y_min = abs_info.minimum;

0 commit comments

Comments
 (0)