From: Po Lu Date: Sat, 9 Apr 2022 01:02:24 +0000 (+0800) Subject: Clean up XI2 scroll valuator tracking code X-Git-Tag: emacs-29.0.90~1931^2~692 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=33d68da534ef4d6f7c4a6db3eaada8508c29f961;p=emacs.git Clean up XI2 scroll valuator tracking code * src/xterm.c (x_get_scroll_valuator_delta): Accept a pointer to a device instead of the device id. (handle_one_xevent): Pass the previously found device. --- diff --git a/src/xterm.c b/src/xterm.c index da671731863..038dbcfe87d 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -3974,58 +3974,49 @@ x_init_master_valuators (struct x_display_info *dpyinfo) #ifdef HAVE_XINPUT2_1 /* Return the delta of the scroll valuator VALUATOR_NUMBER under - DEVICE_ID in the display DPYINFO with VALUE. The valuator's - valuator will be set to VALUE afterwards. In case no scroll - valuator is found, or if the valuator state is invalid (see the - comment under XI_Enter in handle_one_xevent), or if device_id is - not known to Emacs, DBL_MAX is returned. Otherwise, the valuator - is returned in VALUATOR_RETURN. */ + DEVICE in the display DPYINFO with VALUE. The valuator's valuator + will be set to VALUE afterwards. In case no scroll valuator is + found, or if the valuator state is invalid (see the comment under + XI_Enter in handle_one_xevent). Otherwise, the valuator is + returned in VALUATOR_RETURN. */ static double -x_get_scroll_valuator_delta (struct x_display_info *dpyinfo, int device_id, +x_get_scroll_valuator_delta (struct x_display_info *dpyinfo, + struct xi_device_t *device, int valuator_number, double value, struct xi_scroll_valuator_t **valuator_return) { - block_input (); + struct xi_scroll_valuator_t *sv; + double delta; + int i; - for (int i = 0; i < dpyinfo->num_devices; ++i) + for (i = 0; i < device->scroll_valuator_count; ++i) { - struct xi_device_t *device = &dpyinfo->devices[i]; + sv = &device->valuators[i]; - if (device->device_id == device_id) + if (sv->number == valuator_number) { - for (int j = 0; j < device->scroll_valuator_count; ++j) - { - struct xi_scroll_valuator_t *sv = &device->valuators[j]; + *valuator_return = sv; - if (sv->number == valuator_number) - { - if (sv->invalid_p) - { - sv->current_value = value; - sv->invalid_p = false; - *valuator_return = sv; + if (sv->increment == 0) + return DBL_MAX; - unblock_input (); - return DBL_MAX; - } - else - { - double delta = (sv->current_value - value) / sv->increment; - sv->current_value = value; - *valuator_return = sv; + if (sv->invalid_p) + { + sv->current_value = value; + sv->invalid_p = false; - unblock_input (); - return delta; - } - } + return DBL_MAX; } + else + { + delta = (sv->current_value - value) / sv->increment; + sv->current_value = value; - unblock_input (); - return DBL_MAX; + return delta; + } } } - unblock_input (); return DBL_MAX; } @@ -16186,7 +16177,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, /* See the comment on top of x_init_master_valuators for more details on how scroll wheel movement is reported on XInput 2. */ - delta = x_get_scroll_valuator_delta (dpyinfo, xev->deviceid, + delta = x_get_scroll_valuator_delta (dpyinfo, device, i, *values, &val); values++;