emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 0047bdeb33: Be a little more paranoid about XI 2.0 implementation


From: Po Lu
Subject: master 0047bdeb33: Be a little more paranoid about XI 2.0 implementations
Date: Thu, 10 Nov 2022 00:26:39 -0500 (EST)

branch: master
commit 0047bdeb3393d5d7acbdffd7444370fc3e4d2384
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Be a little more paranoid about XI 2.0 implementations
    
    * src/xterm.c (xi_populate_device_from_info):
    (xi_disable_devices): Do not restore valuator values if the
    valuator info has a mode of Relative and a value of 0.0.
---
 src/xterm.c | 57 +++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 39 insertions(+), 18 deletions(-)

diff --git a/src/xterm.c b/src/xterm.c
index fd04061436..a175a4a6bb 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -5339,7 +5339,7 @@ xi_populate_device_from_info (struct x_display_info 
*dpyinfo,
   struct xi_known_valuator *values, *tem;
   int actual_valuator_count, c;
   XIScrollClassInfo *info;
-  XIValuatorClassInfo *val_info;
+  XIValuatorClassInfo *valuator_info;
 #endif
 #ifdef HAVE_XINPUT2_2
   XITouchClassInfo *touch_info;
@@ -5450,12 +5450,23 @@ xi_populate_device_from_info (struct x_display_info 
*dpyinfo,
 
        case XIValuatorClass:
          {
-           val_info = (XIValuatorClassInfo *) device->classes[c];
+           valuator_info = (XIValuatorClassInfo *) device->classes[c];
            tem = SAFE_ALLOCA (sizeof *tem);
 
+           /* Avoid restoring bogus values if some driver
+              accidentally specifies relative values in scroll
+              valuator classes how the input extension spec says they
+              should be, but allow restoring values when a value is
+              set, which is how the input extension actually
+              behaves.  */
+
+           if (valuator_info->value == 0.0
+               && valuator_info->mode != XIModeAbsolute)
+             continue;
+
            tem->next = values;
-           tem->number = val_info->number;
-           tem->current_value = val_info->value;
+           tem->number = valuator_info->number;
+           tem->current_value = valuator_info->value;
 
            values = tem;
            break;
@@ -13182,22 +13193,32 @@ xi_handle_new_classes (struct x_display_info 
*dpyinfo, struct xi_device_t *devic
 
   for (i = 0; i < num_classes; ++i)
     {
-      switch (classes[i]->type)
-       {
-       case XIValuatorClass:
-         valuator_info = (XIValuatorClassInfo *) classes[i];
+      if (classes[i]->type != XIValuatorClass)
+       continue;
 
-         valuator = xi_get_scroll_valuator (device,
-                                            valuator_info->number);
-         if (valuator)
-           {
-             valuator->invalid_p = false;
-             valuator->current_value = valuator_info->value;
-             valuator->emacs_value = 0;
-           }
+      valuator_info = (XIValuatorClassInfo *) classes[i];
 
-         break;
-       }
+      /* Avoid restoring bogus values if some driver accidentally
+        specifies relative values in scroll valuator classes how the
+        input extension spec says they should be, but allow restoring
+        values when a value is set, which is how the input extension
+        actually behaves.  */
+
+      if (valuator_info->value == 0.0
+         && valuator_info->mode != XIModeAbsolute)
+       continue;
+
+      valuator = xi_get_scroll_valuator (device,
+                                        valuator_info->number);
+
+      if (!valuator)
+       continue;
+
+      valuator->invalid_p = false;
+      valuator->current_value = valuator_info->value;
+      valuator->emacs_value = 0;
+
+      break;
     }
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]