diff options
| author | Po Lu | 2022-11-20 21:01:10 +0800 |
|---|---|---|
| committer | Po Lu | 2022-11-20 21:03:18 +0800 |
| commit | 8874cd908c0ea0e2200f6f4f596bf645e76a0c0c (patch) | |
| tree | 74ce2acccfbf8ef434d428377a000a8003947465 /src | |
| parent | 16318bfb518aa7bc06e502e6fad7e53ec91067f9 (diff) | |
| download | emacs-8874cd908c0ea0e2200f6f4f596bf645e76a0c0c.tar.gz emacs-8874cd908c0ea0e2200f6f4f596bf645e76a0c0c.zip | |
Coalesce duplicate scroll valuator handling code
Also, write more commentary.
* src/xterm.c (xi_populate_scroll_valuator): New function.
Describe the meaning of each field in xi_scroll_valuator_t.
(xi_populate_device_from_info, xi_handle_new_classes): Factor
out duplicate code to that function.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xterm.c | 62 |
1 files changed, 45 insertions, 17 deletions
diff --git a/src/xterm.c b/src/xterm.c index 500d80cad7f..af652a0d856 100644 --- a/src/xterm.c +++ b/src/xterm.c | |||
| @@ -5323,6 +5323,46 @@ struct xi_known_valuator | |||
| 5323 | struct xi_known_valuator *next; | 5323 | struct xi_known_valuator *next; |
| 5324 | }; | 5324 | }; |
| 5325 | 5325 | ||
| 5326 | /* Populate the scroll valuator at INDEX in DEVICE with the scroll | ||
| 5327 | valuator information provided in INFO. | ||
| 5328 | |||
| 5329 | The information consists of: | ||
| 5330 | |||
| 5331 | - whether or not the valuator is horizontal. | ||
| 5332 | |||
| 5333 | - whether or not the valuator's value is currently unknown, | ||
| 5334 | until the next XI_Motion event is received or the valuator's | ||
| 5335 | value is restored by the caller upon encountering valuator | ||
| 5336 | class data. | ||
| 5337 | |||
| 5338 | - what the current value of the valuator is. This is set to | ||
| 5339 | DBL_MIN for debugging purposes, but can be any value, as | ||
| 5340 | invalid_p is currently true. | ||
| 5341 | |||
| 5342 | - the increment, which defines the amount of movement equal to a | ||
| 5343 | single unit of scrolling. For example, if the increment is | ||
| 5344 | 2.0, then a WHEEL_DOWN or WHEEL_UP event will be sent every | ||
| 5345 | time the valuator value changes by 2.0, unless | ||
| 5346 | mwheel-coalesce-scroll-events is nil. | ||
| 5347 | |||
| 5348 | - the number used in XI_Motion events and elsewhere to identify | ||
| 5349 | the valuator. */ | ||
| 5350 | |||
| 5351 | static void | ||
| 5352 | xi_populate_scroll_valuator (struct xi_device_t *device, | ||
| 5353 | int index, XIScrollClassInfo *info) | ||
| 5354 | { | ||
| 5355 | struct xi_scroll_valuator_t *valuator; | ||
| 5356 | |||
| 5357 | valuator = &device->valuators[index]; | ||
| 5358 | valuator->horizontal | ||
| 5359 | = (info->scroll_type == XIScrollTypeHorizontal); | ||
| 5360 | valuator->invalid_p = true; | ||
| 5361 | valuator->emacs_value = DBL_MIN; | ||
| 5362 | valuator->increment = info->increment; | ||
| 5363 | valuator->number = info->number; | ||
| 5364 | } | ||
| 5365 | |||
| 5326 | #endif | 5366 | #endif |
| 5327 | 5367 | ||
| 5328 | static void | 5368 | static void |
| @@ -5331,7 +5371,6 @@ xi_populate_device_from_info (struct x_display_info *dpyinfo, | |||
| 5331 | XIDeviceInfo *device) | 5371 | XIDeviceInfo *device) |
| 5332 | { | 5372 | { |
| 5333 | #ifdef HAVE_XINPUT2_1 | 5373 | #ifdef HAVE_XINPUT2_1 |
| 5334 | struct xi_scroll_valuator_t *valuator; | ||
| 5335 | struct xi_known_valuator *values, *tem; | 5374 | struct xi_known_valuator *values, *tem; |
| 5336 | int actual_valuator_count, c; | 5375 | int actual_valuator_count, c; |
| 5337 | XIScrollClassInfo *info; | 5376 | XIScrollClassInfo *info; |
| @@ -5432,15 +5471,8 @@ xi_populate_device_from_info (struct x_display_info *dpyinfo, | |||
| 5432 | case XIScrollClass: | 5471 | case XIScrollClass: |
| 5433 | { | 5472 | { |
| 5434 | info = (XIScrollClassInfo *) device->classes[c]; | 5473 | info = (XIScrollClassInfo *) device->classes[c]; |
| 5435 | 5474 | xi_populate_scroll_valuator (xi_device, actual_valuator_count++, | |
| 5436 | valuator = &xi_device->valuators[actual_valuator_count++]; | 5475 | info); |
| 5437 | valuator->horizontal | ||
| 5438 | = (info->scroll_type == XIScrollTypeHorizontal); | ||
| 5439 | valuator->invalid_p = true; | ||
| 5440 | valuator->emacs_value = DBL_MIN; | ||
| 5441 | valuator->increment = info->increment; | ||
| 5442 | valuator->number = info->number; | ||
| 5443 | |||
| 5444 | break; | 5476 | break; |
| 5445 | } | 5477 | } |
| 5446 | 5478 | ||
| @@ -13164,13 +13196,9 @@ xi_handle_new_classes (struct x_display_info *dpyinfo, struct xi_device_t *devic | |||
| 13164 | case XIScrollClass: | 13196 | case XIScrollClass: |
| 13165 | scroll = (XIScrollClassInfo *) classes[i]; | 13197 | scroll = (XIScrollClassInfo *) classes[i]; |
| 13166 | 13198 | ||
| 13167 | valuator = &device->valuators[device->scroll_valuator_count++]; | 13199 | xi_populate_scroll_valuator (device, |
| 13168 | valuator->horizontal = (scroll->scroll_type | 13200 | device->scroll_valuator_count++, |
| 13169 | == XIScrollTypeHorizontal); | 13201 | scroll); |
| 13170 | valuator->invalid_p = true; | ||
| 13171 | valuator->emacs_value = 0; | ||
| 13172 | valuator->increment = scroll->increment; | ||
| 13173 | valuator->number = scroll->number; | ||
| 13174 | break; | 13202 | break; |
| 13175 | 13203 | ||
| 13176 | #ifdef HAVE_XINPUT2_2 | 13204 | #ifdef HAVE_XINPUT2_2 |