summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2022-04-09 09:02:24 +0800
committerPo Lu <luangruo@yahoo.com>2022-04-09 09:02:24 +0800
commit33d68da534ef4d6f7c4a6db3eaada8508c29f961 (patch)
tree9ebacd8cf29b2f03e7cef81502c3f6c7c5e94b7f
parent6449179822543b794ed3b1d0b06087c1fe33ee15 (diff)
downloademacs-33d68da534ef4d6f7c4a6db3eaada8508c29f961.tar.gz
emacs-33d68da534ef4d6f7c4a6db3eaada8508c29f961.tar.bz2
emacs-33d68da534ef4d6f7c4a6db3eaada8508c29f961.zip
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.
-rw-r--r--src/xterm.c65
1 files changed, 28 insertions, 37 deletions
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++;