]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix handling hscroll during drag-and-drop
authorPo Lu <luangruo@yahoo.com>
Fri, 22 Jul 2022 07:37:28 +0000 (15:37 +0800)
committerPo Lu <luangruo@yahoo.com>
Fri, 22 Jul 2022 07:37:28 +0000 (15:37 +0800)
* lisp/x-dnd.el (x-dnd-hscroll-flags): Delete function.
(x-dnd-get-modifiers, x-dnd-wheel-modifier-type): New functions.
(x-dnd-mwheel-scroll): Use that to determine hscroll instead.
* src/window.c (set_window_hscroll): Mark window as needing
redisplay if the hscroll really changed.

lisp/x-dnd.el
src/window.c

index a06563946c65e22bda4e786855302b3776040148..fa045d563c34299b42a1a928493e50cd8403930f 100644 (file)
@@ -722,15 +722,27 @@ MODS is a single symbol, or a list of symbols such as `shift' or
              (setq mask (nth 2 virtual-modifiers)))))
     mask))
 
-(defun x-dnd-hscroll-flags ()
-  "Return the event state of a button press that should result in hscroll.
-Value is a mask of all the X modifier states that would normally
-cause a button press event to perform horizontal scrolling."
-  (let ((i 0))
-    (dolist (modifier mouse-wheel-scroll-amount)
-      (when (eq (cdr-safe modifier) 'hscroll)
-        (setq i (logior i (x-dnd-modifier-mask (car modifier))))))
-    i))
+(defun x-dnd-get-modifiers ()
+  "Obtain an X modifier mask containing all modifiers.
+Value is an X modifier mask containing all modifiers that can
+modify an Emacs keyboard or mouse event."
+  (let ((mods (x-get-modifier-masks))
+        (mask 5)) ; ShiftMask | ControlMask
+    (dolist (mod mods)
+      (setq mask (logior mask mod)))
+    mask))
+
+(defun x-dnd-wheel-modifier-type (flags)
+  "Return the modifier type of an X modifier mask.
+FLAGS is the X modifier mask of a turn of the mouse wheel."
+  (let ((modifiers (x-dnd-get-modifiers)))
+    (catch 'type
+      (dolist (modifier mouse-wheel-scroll-amount)
+        (when (and (consp modifier)
+                   (eq (x-dnd-modifier-mask (car modifier))
+                       (logand flags modifiers)))
+          (throw 'type (cdr modifier))))
+      nil)))
 
 (defvar x-dnd-click-count nil
   "Alist of button numbers to click counters during drag-and-drop.
@@ -760,19 +772,19 @@ Use MODIFIERS, an X modifier mask, to determine if any
 alternative operation (such as scrolling horizontally) should be
 taken.  COUNT is the number of times in quick succession BUTTON
 has been pressed."
-  (let ((hscroll (not (zerop (logand modifiers
-                                     (x-dnd-hscroll-flags)))))
-        (amt (or (and (not mouse-wheel-progressive-speed) 1)
-                 (* 1 count))))
+  (let* ((type (x-dnd-wheel-modifier-type modifiers))
+         (hscroll (eq type 'hscroll))
+         (amt (or (and (not mouse-wheel-progressive-speed) 1)
+                  (* 1 count))))
     (unless (and (not mouse-wheel-tilt-scroll)
                  (or (eq button 6) (eq button 7)))
       (let ((function (cond ((eq button 4)
                              (if hscroll
-                                 mwheel-scroll-left-function
+                                 mwheel-scroll-right-function
                                mwheel-scroll-down-function))
                             ((eq button 5)
                              (if hscroll
-                                 mwheel-scroll-right-function
+                                 mwheel-scroll-left-function
                                mwheel-scroll-up-function))
                             ((eq button 6)
                              (if mouse-wheel-flip-direction
index 8f88958558200366e6a74ae96afc347d3de2c19c..3cd2f98a850b8ef73e6f55a7858a438d85699006 100644 (file)
@@ -1275,7 +1275,10 @@ set_window_hscroll (struct window *w, EMACS_INT hscroll)
 
   /* Prevent redisplay shortcuts when changing the hscroll.  */
   if (w->hscroll != new_hscroll)
-    XBUFFER (w->contents)->prevent_redisplay_optimizations_p = true;
+    {
+      XBUFFER (w->contents)->prevent_redisplay_optimizations_p = true;
+      wset_redisplay (w);
+    }
 
   w->hscroll = new_hscroll;
   w->suspend_auto_hscroll = true;