diff options
| author | Po Lu | 2022-02-14 11:16:38 +0800 |
|---|---|---|
| committer | Po Lu | 2022-02-14 11:16:38 +0800 |
| commit | 1bf30718dd1e4284af285e4a92c336f512564f01 (patch) | |
| tree | b7c3881895ea1e9a8bfd06d1c054640609118d32 /src | |
| parent | 27658a0a3b311ad38b87b9981c6e7b9aaae40728 (diff) | |
| download | emacs-1bf30718dd1e4284af285e4a92c336f512564f01.tar.gz emacs-1bf30718dd1e4284af285e4a92c336f512564f01.zip | |
Improve efficency of handling DeviceChanged events
* src/xterm.c (handle_one_xevent): Just update the device that
was changed on DeviceChanged and only do hierarchy recalculation
upon HierarchyChanged events.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xterm.c | 89 |
1 files changed, 82 insertions, 7 deletions
diff --git a/src/xterm.c b/src/xterm.c index a17b445701b..198aaa69e5f 100644 --- a/src/xterm.c +++ b/src/xterm.c | |||
| @@ -10783,6 +10783,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, | |||
| 10783 | XIEnterEvent *enter = (XIEnterEvent *) xi_event; | 10783 | XIEnterEvent *enter = (XIEnterEvent *) xi_event; |
| 10784 | XIFocusInEvent *focusin = (XIFocusInEvent *) xi_event; | 10784 | XIFocusInEvent *focusin = (XIFocusInEvent *) xi_event; |
| 10785 | XIFocusOutEvent *focusout = (XIFocusOutEvent *) xi_event; | 10785 | XIFocusOutEvent *focusout = (XIFocusOutEvent *) xi_event; |
| 10786 | XIDeviceChangedEvent *device_changed = (XIDeviceChangedEvent *) xi_event; | ||
| 10786 | XIValuatorState *states; | 10787 | XIValuatorState *states; |
| 10787 | double *values; | 10788 | double *values; |
| 10788 | bool found_valuator = false; | 10789 | bool found_valuator = false; |
| @@ -11861,17 +11862,91 @@ handle_one_xevent (struct x_display_info *dpyinfo, | |||
| 11861 | goto XI_OTHER; | 11862 | goto XI_OTHER; |
| 11862 | 11863 | ||
| 11863 | case XI_PropertyEvent: | 11864 | case XI_PropertyEvent: |
| 11865 | goto XI_OTHER; | ||
| 11866 | |||
| 11864 | case XI_HierarchyChanged: | 11867 | case XI_HierarchyChanged: |
| 11865 | case XI_DeviceChanged: | ||
| 11866 | #ifdef XISlaveSwitch | ||
| 11867 | if (xi_event->evtype == XI_DeviceChanged | ||
| 11868 | && (((XIDeviceChangedEvent *) xi_event)->reason | ||
| 11869 | == XISlaveSwitch)) | ||
| 11870 | goto XI_OTHER; | ||
| 11871 | #endif | ||
| 11872 | x_init_master_valuators (dpyinfo); | 11868 | x_init_master_valuators (dpyinfo); |
| 11873 | goto XI_OTHER; | 11869 | goto XI_OTHER; |
| 11874 | 11870 | ||
| 11871 | case XI_DeviceChanged: | ||
| 11872 | { | ||
| 11873 | struct xi_device_t *device; | ||
| 11874 | struct xi_touch_point_t *tem, *last; | ||
| 11875 | int c; | ||
| 11876 | |||
| 11877 | device = xi_device_from_id (dpyinfo, device_changed->sourceid); | ||
| 11878 | |||
| 11879 | if (!device) | ||
| 11880 | emacs_abort (); | ||
| 11881 | |||
| 11882 | /* Free data that we will regenerate from new | ||
| 11883 | information. */ | ||
| 11884 | device->valuators = xrealloc (device->valuators, | ||
| 11885 | (device_changed->num_classes | ||
| 11886 | * sizeof *device->valuators)); | ||
| 11887 | device->scroll_valuator_count = 0; | ||
| 11888 | device->direct_p = false; | ||
| 11889 | |||
| 11890 | for (c = 0; c < device_changed->num_classes; ++c) | ||
| 11891 | { | ||
| 11892 | switch (device_changed->classes[c]->type) | ||
| 11893 | { | ||
| 11894 | #ifdef XIScrollClass | ||
| 11895 | case XIScrollClass: | ||
| 11896 | { | ||
| 11897 | XIScrollClassInfo *info = | ||
| 11898 | (XIScrollClassInfo *) device_changed->classes[c]; | ||
| 11899 | struct xi_scroll_valuator_t *valuator; | ||
| 11900 | |||
| 11901 | if (device->master_p) | ||
| 11902 | { | ||
| 11903 | valuator = &device->valuators[device->scroll_valuator_count++]; | ||
| 11904 | valuator->horizontal | ||
| 11905 | = (info->scroll_type == XIScrollTypeHorizontal); | ||
| 11906 | valuator->invalid_p = true; | ||
| 11907 | valuator->emacs_value = DBL_MIN; | ||
| 11908 | valuator->increment = info->increment; | ||
| 11909 | valuator->number = info->number; | ||
| 11910 | } | ||
| 11911 | |||
| 11912 | break; | ||
| 11913 | } | ||
| 11914 | #endif | ||
| 11915 | |||
| 11916 | #ifdef XITouchClass | ||
| 11917 | case XITouchClass: | ||
| 11918 | { | ||
| 11919 | XITouchClassInfo *info; | ||
| 11920 | |||
| 11921 | info = (XITouchClassInfo *) device_changed->classes[c]; | ||
| 11922 | device->direct_p = info->mode == XIDirectTouch; | ||
| 11923 | } | ||
| 11924 | #endif | ||
| 11925 | default: | ||
| 11926 | break; | ||
| 11927 | } | ||
| 11928 | } | ||
| 11929 | |||
| 11930 | /* The device is no longer a DirectTouch device, so | ||
| 11931 | remove any touchpoints that we might have | ||
| 11932 | recorded. */ | ||
| 11933 | if (!device->direct_p) | ||
| 11934 | { | ||
| 11935 | tem = device->touchpoints; | ||
| 11936 | |||
| 11937 | while (tem) | ||
| 11938 | { | ||
| 11939 | last = tem; | ||
| 11940 | tem = tem->next; | ||
| 11941 | xfree (last); | ||
| 11942 | } | ||
| 11943 | |||
| 11944 | device->touchpoints = NULL; | ||
| 11945 | } | ||
| 11946 | |||
| 11947 | goto XI_OTHER; | ||
| 11948 | } | ||
| 11949 | |||
| 11875 | #ifdef XI_TouchBegin | 11950 | #ifdef XI_TouchBegin |
| 11876 | case XI_TouchBegin: | 11951 | case XI_TouchBegin: |
| 11877 | { | 11952 | { |