emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/scroll-on-drag d8582732d1 29/35: Scroll the window under t


From: ELPA Syncer
Subject: [nongnu] elpa/scroll-on-drag d8582732d1 29/35: Scroll the window under the mouse cursor
Date: Thu, 7 Jul 2022 12:02:52 -0400 (EDT)

branch: elpa/scroll-on-drag
commit d8582732d1eb03c7f6bba62f39ba66af365dde2c
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>

    Scroll the window under the mouse cursor
    
    Useful to quickly scroll other windows without having to focus
    them first.
    
    This can be disabled using `scroll-on-drag-follow-mouse`.
---
 readme.rst        |  3 +++
 scroll-on-drag.el | 24 +++++++++++++++++++++---
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/readme.rst b/readme.rst
index d0adb9ff03..f26d2410c8 100644
--- a/readme.rst
+++ b/readme.rst
@@ -83,3 +83,6 @@ While the defaults seem to work well, these values can be 
customized.
    Values greater than 0.0 apply non-linear scaling,
    this gives control when scrolling individual lines while allowing much
    greater speed without having to move the mouse a long distance.
+``scroll-on-drag-follow-mouse``
+   When non-nil, scroll the window under the mouse cursor (even when it's not 
active)
+   returning focus on completion.
diff --git a/scroll-on-drag.el b/scroll-on-drag.el
index 085daeebdf..92e7805252 100644
--- a/scroll-on-drag.el
+++ b/scroll-on-drag.el
@@ -51,6 +51,10 @@
 
 (defcustom scroll-on-drag-smooth t "Use smooth (pixel) scrolling." :type 
'boolean)
 
+(defcustom scroll-on-drag-follow-mouse t
+  "Scroll the window under the mouse cursor (instead of the current active 
window)."
+  :type 'boolean)
+
 (defcustom scroll-on-drag-pre-hook nil
   "List of functions to be called when `scroll-on-drag' starts."
   :type 'hook)
@@ -147,11 +151,9 @@ Argument ALSO-MOVE-POINT When non-nil, move the POINT as 
well."
 ;; ---------------------------------------------------------------------------
 ;; Public Functions
 
-;;;###autoload
-(defun scroll-on-drag ()
+(defun scroll-on-drag-impl ()
   "Interactively scroll (typically on click event).
 Returns true when scrolling took place, otherwise nil."
-  (interactive)
   (let*
     (
       ;; Don't run unnecessary logic when scrolling.
@@ -402,6 +404,22 @@ Returns true when scrolling took place, otherwise nil."
     ;; allowing a fallback action on 'click'.
     has-scrolled-real))
 
+(defun scroll-on-drag (&optional event)
+  "Main scroll on drag function.
+
+EVENT is optionally used to find the active window
+when `scroll-on-drag-follow-mouse' is non-nil."
+  (interactive "e")
+  (let ((scroll-win nil))
+    (when scroll-on-drag-follow-mouse
+      (setq scroll-win (posn-window (or (event-start event) 
last-input-event))))
+
+    (cond
+      (scroll-win
+        (with-selected-window scroll-win (scroll-on-drag-impl)))
+      (t
+        (scroll-on-drag-impl)))))
+
 ;;;###autoload
 (defmacro scroll-on-drag-with-fallback (&rest body)
   "A macro to scroll and perform a different action on click.



reply via email to

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