]> git.eshelyaron.com Git - emacs.git/commitdiff
Simplify scroll valuator reset handling
authorPo Lu <luangruo@yahoo.com>
Fri, 28 Oct 2022 12:06:06 +0000 (20:06 +0800)
committerPo Lu <luangruo@yahoo.com>
Fri, 28 Oct 2022 12:06:06 +0000 (20:06 +0800)
* src/xterm.c (xi_populate_device_from_info)
(xi_reset_scroll_valuators_for_device_id, xi_handle_device_changed)
(handle_one_xevent):
* src/xterm.h (struct xi_scroll_valuator_t): Get rid of
`pending_enter_reset', which was extremely convoluted and kept
hitting server bugs.  Now, valuators are reset upon all crossing
events.

src/xterm.c
src/xterm.h

index f2d6be5d46b86d7bdff8ba0ea2a29293e0a2d842..f1bccddb6c3e2bed4bc192177257c194dc038707 100644 (file)
@@ -5369,7 +5369,6 @@ xi_populate_device_from_info (struct xi_device_t *xi_device,
            valuator->emacs_value = DBL_MIN;
            valuator->increment = info->increment;
            valuator->number = info->number;
-           valuator->pending_enter_reset = false;
 
            break;
          }
@@ -5415,7 +5414,6 @@ xi_populate_device_from_info (struct xi_device_t *xi_device,
            {
              xi_device->valuators[c].invalid_p = false;
              xi_device->valuators[c].current_value = tem->current_value;
-             xi_device->valuators[c].pending_enter_reset = true;
            }
        }
     }
@@ -5609,8 +5607,8 @@ xi_find_touch_point (struct xi_device_t *device, int detail)
 #ifdef HAVE_XINPUT2_1
 
 static void
-xi_reset_scroll_valuators_for_device_id (struct x_display_info *dpyinfo, int id,
-                                        bool pending_only)
+xi_reset_scroll_valuators_for_device_id (struct x_display_info *dpyinfo,
+                                        int id)
 {
   struct xi_device_t *device = xi_device_from_id (dpyinfo, id);
   struct xi_scroll_valuator_t *valuator;
@@ -5624,11 +5622,6 @@ xi_reset_scroll_valuators_for_device_id (struct x_display_info *dpyinfo, int id,
   for (int i = 0; i < device->scroll_valuator_count; ++i)
     {
       valuator = &device->valuators[i];
-
-      if (pending_only && !valuator->pending_enter_reset)
-       continue;
-
-      valuator->pending_enter_reset = false;
       valuator->invalid_p = true;
       valuator->emacs_value = 0.0;
     }
@@ -13113,14 +13106,6 @@ xi_handle_device_changed (struct x_display_info *dpyinfo,
                {
                  valuator->invalid_p = false;
                  valuator->current_value = valuator_info->value;
-
-                 /* Make sure that this is reset if the pointer moves
-                    into a window of ours.
-
-                    Otherwise the valuator state could be left
-                    invalid if the DeviceChange event happened with
-                    the pointer outside any Emacs frame. */
-                 valuator->pending_enter_reset = true;
                }
 
              break;
@@ -21412,8 +21397,8 @@ handle_one_xevent (struct x_display_info *dpyinfo,
                  && enter->mode != XINotifyGrab
                  && enter->mode != XINotifyPassiveGrab
                  && enter->mode != XINotifyPassiveUngrab)
-               xi_reset_scroll_valuators_for_device_id (dpyinfo, enter->deviceid,
-                                                        true);
+               xi_reset_scroll_valuators_for_device_id (dpyinfo,
+                                                        enter->deviceid);
 #endif
 
              {
@@ -21526,13 +21511,18 @@ handle_one_xevent (struct x_display_info *dpyinfo,
                 retrieve the value of a valuator outside of each motion
                 event.
 
-                As such, to prevent wildly inaccurate results when the
-                valuators have changed outside Emacs, we reset our
-                records of each valuator's value whenever the pointer
-                moves out of a frame (and not into one of its
-                children, which we know about).  */
+                As such, to prevent wildly inaccurate results when
+                the valuators have changed outside Emacs, we reset
+                our records of each valuator's value whenever the
+                pointer moves out of a frame.  Ideally, this would
+                ignore events with a detail of XINotifyInferior, as
+                the window the pointer moved to would be one known to
+                Emacs, but the code to keep track of which valuators
+                had to be reset upon the corresponding XI_Enter event
+                was very complicated and kept running into server
+                bugs.  */
 #ifdef HAVE_XINPUT2_1
-             if (leave->detail != XINotifyInferior && any
+             if (any
                  /* xfwm4 selects for button events on the frame
                     window, resulting in passive grabs being
                     generated along with the delivery of emulated
@@ -21547,7 +21537,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
                  && leave->mode != XINotifyPassiveUngrab
                  && leave->mode != XINotifyPassiveGrab)
                xi_reset_scroll_valuators_for_device_id (dpyinfo,
-                                                        leave->deviceid, false);
+                                                        leave->deviceid);
 #endif
 
              x_display_set_last_user_time (dpyinfo, leave->time,
@@ -21584,13 +21574,12 @@ handle_one_xevent (struct x_display_info *dpyinfo,
                 just looks up a top window on Xt builds.  */
 
 #ifdef HAVE_XINPUT2_1
-             if (leave->detail != XINotifyInferior && f
-                 && leave->mode != XINotifyUngrab
+             if (f && leave->mode != XINotifyUngrab
                  && leave->mode != XINotifyGrab
                  && leave->mode != XINotifyPassiveUngrab
                  && leave->mode != XINotifyPassiveGrab)
                xi_reset_scroll_valuators_for_device_id (dpyinfo,
-                                                        leave->deviceid, false);
+                                                        leave->deviceid);
 #endif
 
              if (!f)
index 537cabc9577cc4dbba8c7e61bf7ce3c934d30e5f..1124dcceb4a236fe65b224be96df79cf5ef22555 100644 (file)
@@ -213,20 +213,32 @@ struct color_name_cache_entry
 #ifdef HAVE_XINPUT2
 
 #ifdef HAVE_XINPUT2_1
+
 struct xi_scroll_valuator_t
 {
-  bool invalid_p;
-  bool pending_enter_reset;
+  /* The ID of the valuator.  */
+  int number;
+
+  /* Whether or not it represents X axis movement.  */
+  bool_bf horizontal : 1;
+
+  /* Whether or not the value is currently invalid.  */
+  bool_bf invalid_p : 1;
+
+  /* The current value.  */
   double current_value;
+
+  /* Value used to tally up deltas until a threshold is met.  */
   double emacs_value;
-  double increment;
 
-  int number;
-  int horizontal;
+  /* The scroll increment.  */
+  double increment;
 };
+
 #endif
 
 #ifdef HAVE_XINPUT2_2
+
 struct xi_touch_point_t
 {
   struct xi_touch_point_t *next;
@@ -234,6 +246,7 @@ struct xi_touch_point_t
   int number;
   double x, y;
 };
+
 #endif
 
 struct xi_device_t