unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Kangas <stefan@marxist.se>
To: Eli Zaretskii <eliz@gnu.org>
Cc: "Tak Kunihiro" <homeros.misasa@gmail.com>,
	"Juri Linkov" <juri@linkov.net>, "Richard Stallman" <rms@gnu.org>,
	28182@debbugs.gnu.org, "積丹尼 Dan Jacobson" <jidanni@jidanni.org>
Subject: bug#28182: maybe implement CTRL++ to zoom text
Date: Wed, 9 Oct 2019 23:56:22 +0200	[thread overview]
Message-ID: <CADwFkmmd1Qdwqeih-BWLWD61kphbBKJcPJDbEdXMNJv8xUmkuA@mail.gmail.com> (raw)
In-Reply-To: <83mueawiwi.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 374 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

> Please don't forget mentioning this in NEWS (and in the manual, if
> applicable).

Thanks.  Is something like the attached okay?  I'm not sure exactly
what you had in mind, since this mostly preserves previous behaviour
also for changing the font size.

(I checked the manual, but it is fine as is, IMO.)

Best regards,
Stefan Kangas

[-- Attachment #2: 0001-Change-font-size-in-correct-window-using-mouse-wheel.patch --]
[-- Type: text/x-patch, Size: 6993 bytes --]

From 01cac92927782e889c6e65dc0df70733e9ffa12f Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Tue, 8 Oct 2019 23:53:14 +0200
Subject: [PATCH] Change font size in correct window using mouse wheel

* lisp/mwheel.el (mouse-wheel--get-scroll-window): New function
extracted from...
(mwheel-scroll): ...here.
(mouse-wheel-text-scale): New function to change face height in
the correct window, depending on the value of
'mouse-wheel-follows-mouse'.  (Bug#28182)
(mouse-wheel-mode): Bind 'mouse-wheel-text-scale' instead of
'text-scale-increase' and 'text-scale-decrease'.
---
 etc/NEWS       |  5 ++++
 lisp/mwheel.el | 80 +++++++++++++++++++++++++++++++-------------------
 2 files changed, 54 insertions(+), 31 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 2ca681ff9b..53b9c1eec2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2335,6 +2335,11 @@ To get the old behaviour back, customize the variable
 (customize-set-variable 'mouse-wheel-scroll-amount
                         '(5 ((shift) . 1) ((control) . nil)))
 
+By default, the font size will be changed in the window that the mouse
+pointer is over.  To change this behaviour, you can customize the
+option 'mouse-wheel-follow-mouse'.  Note that this will also affect
+scrolling.
+
 \f
 * Lisp Changes in Emacs 27.1
 
diff --git a/lisp/mwheel.el b/lisp/mwheel.el
index 9b67e71886..8c1927950a 100644
--- a/lisp/mwheel.el
+++ b/lisp/mwheel.el
@@ -137,7 +137,8 @@ mouse-wheel-progressive-speed
 
 (defcustom mouse-wheel-follow-mouse t
   "Whether the mouse wheel should scroll the window that the mouse is over.
-This can be slightly disconcerting, but some people prefer it."
+This affects both the commands for scrolling and changing the
+face height."
   :group 'mouse
   :type 'boolean)
 
@@ -210,34 +211,40 @@ mouse-wheel-right-event
     (intern "mouse-7"))
   "Event used for scrolling right.")
 
+(defun mouse-wheel--get-scroll-window (event)
+  "Return window for mouse wheel event EVENT.
+If `mouse-wheel-follow-mouse' is non-nil, return the window that
+the mouse pointer is over.  Otherwise, return the currently
+active window."
+  (or (catch 'found
+        (let* ((window (if mouse-wheel-follow-mouse
+                           (mwheel-event-window event)
+                         (selected-window)))
+               (frame (when (window-live-p window)
+                        (frame-parameter
+                         (window-frame window) 'mouse-wheel-frame))))
+          (when (frame-live-p frame)
+            (let* ((pos (mouse-absolute-pixel-position))
+                   (pos-x (car pos))
+                   (pos-y (cdr pos)))
+              (walk-window-tree
+               (lambda (window-1)
+                 (let ((edges (window-edges window-1 nil t t)))
+                   (when (and (<= (nth 0 edges) pos-x)
+                              (<= pos-x (nth 2 edges))
+                              (<= (nth 1 edges) pos-y)
+                              (<= pos-y (nth 3 edges)))
+                     (throw 'found window-1))))
+               frame nil t)))))
+      (mwheel-event-window event)))
+
 (defun mwheel-scroll (event)
   "Scroll up or down according to the EVENT.
 This should be bound only to mouse buttons 4, 5, 6, and 7 on
 non-Windows systems."
   (interactive (list last-input-event))
   (let* ((selected-window (selected-window))
-         (scroll-window
-          (or (catch 'found
-                (let* ((window (if mouse-wheel-follow-mouse
-                                   (mwheel-event-window event)
-                                 (selected-window)))
-                       (frame (when (window-live-p window)
-                                (frame-parameter
-                                 (window-frame window) 'mouse-wheel-frame))))
-                  (when (frame-live-p frame)
-                    (let* ((pos (mouse-absolute-pixel-position))
-                           (pos-x (car pos))
-                           (pos-y (cdr pos)))
-                      (walk-window-tree
-                       (lambda (window-1)
-                         (let ((edges (window-edges window-1 nil t t)))
-                           (when (and (<= (nth 0 edges) pos-x)
-                                      (<= pos-x (nth 2 edges))
-                                      (<= (nth 1 edges) pos-y)
-                                      (<= pos-y (nth 3 edges)))
-                             (throw 'found window-1))))
-                       frame nil t)))))
-              (mwheel-event-window event)))
+         (scroll-window (mouse-wheel--get-scroll-window event))
 	 (old-point
           (and (eq scroll-window selected-window)
 	       (eq (car-safe transient-mark-mode) 'only)
@@ -322,6 +329,20 @@ mwheel-scroll
 
 (put 'mwheel-scroll 'scroll-command t)
 
+(defun mouse-wheel-text-scale (event)
+  "Increase or decrease the height of the default face according to the EVENT."
+  (interactive (list last-input-event))
+  (let ((selected-window (selected-window))
+        (scroll-window (mouse-wheel--get-scroll-window event))
+        (button (mwheel-event-button event)))
+    (select-window scroll-window 'mark-for-redisplay)
+    (unwind-protect
+        (cond ((eq button mouse-wheel-down-event)
+               (text-scale-decrease 1))
+              ((eq button mouse-wheel-up-event)
+               (text-scale-increase 1)))
+      (select-window selected-window))))
+
 (defvar mwheel-installed-bindings nil)
 (defvar mwheel-installed-text-scale-bindings nil)
 
@@ -347,8 +368,7 @@ mouse-wheel-mode
   (mouse-wheel--remove-bindings mwheel-installed-bindings
                                 '(mwheel-scroll))
   (mouse-wheel--remove-bindings mwheel-installed-text-scale-bindings
-                                '(text-scale-increase
-                                  text-scale-decrease))
+                                '(mouse-wheel-text-scale))
   (setq mwheel-installed-bindings nil)
   (setq mwheel-installed-text-scale-bindings nil)
   ;; Setup bindings as needed.
@@ -357,12 +377,10 @@ mouse-wheel-mode
       (cond
        ;; Bindings for changing font size.
        ((and (consp binding) (eq (cdr binding) 'text-scale))
-        (let ((increase-key `[,(list (caar binding) mouse-wheel-down-event)])
-              (decrease-key `[,(list (caar binding) mouse-wheel-up-event)]))
-          (global-set-key increase-key 'text-scale-increase)
-          (global-set-key decrease-key 'text-scale-decrease)
-          (push increase-key mwheel-installed-text-scale-bindings)
-          (push decrease-key mwheel-installed-text-scale-bindings)))
+        (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event))
+          (let ((key `[,(list (caar binding) event)]))
+            (global-set-key key 'mouse-wheel-text-scale)
+            (push key mwheel-installed-text-scale-bindings))))
        ;; Bindings for scrolling.
        (t
         (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event
-- 
2.20.1


  reply	other threads:[~2019-10-09 21:56 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-29 23:06 bug#39847: Document how users can make text-zoom keys same as browser 積丹尼 Dan Jacobson
2020-03-01  3:39 ` Eli Zaretskii
2020-03-01  5:23   ` 積丹尼 Dan Jacobson
2020-03-01 15:45     ` Eli Zaretskii
2020-03-02  0:23       ` 積丹尼 Dan Jacobson
2020-03-03  3:37   ` Richard Stallman
2020-03-03 15:32     ` Drew Adams
2020-03-03 16:31       ` 積丹尼 Dan Jacobson
2020-03-03 19:55       ` Stefan Kangas
2017-08-22  3:05         ` bug#28182: maybe implement CTRL++ to zoom text 積丹尼 Dan Jacobson
2017-08-22 12:30           ` Nathan Moreau
2017-08-22 14:30           ` Eli Zaretskii
2017-08-23 14:16             ` Richard Stallman
2017-08-23 17:55               ` Eli Zaretskii
2017-08-23 23:05               ` Tak Kunihiro
2017-08-23 23:23                 ` Drew Adams
2017-08-23 14:57           ` 積丹尼 Dan Jacobson
2017-08-23 15:55             ` Drew Adams
2017-08-23 16:05           ` 積丹尼 Dan Jacobson
2017-08-23 16:19             ` Drew Adams
2017-08-23 23:11           ` 積丹尼 Dan Jacobson
2017-08-23 23:28             ` Drew Adams
2019-08-21  1:51           ` Stefan Kangas
2019-08-21  2:12             ` Drew Adams
2019-08-21 13:19               ` Stefan Kangas
2019-08-24 22:06                 ` Juri Linkov
2019-08-27  0:40                   ` Stefan Kangas
2019-08-27 21:13                     ` Juri Linkov
2019-09-28 13:09                       ` Stefan Kangas
2019-09-28 13:48                         ` Eli Zaretskii
2019-09-28 14:15                           ` Stefan Kangas
2019-09-29  1:09                             ` Richard Stallman
2019-09-29  1:40                               ` Stefan Kangas
2019-09-29  7:36                                 ` Eli Zaretskii
2019-09-29 15:33                                   ` Richard Stallman
2019-09-29 15:40                                     ` Eli Zaretskii
2019-09-29 15:37                                 ` Richard Stallman
2019-09-29 15:44                                   ` Eli Zaretskii
2019-09-29 23:36                                     ` Richard Stallman
2019-09-30  3:52                                       ` Lars Ingebrigtsen
2019-09-30  6:16                                       ` Eli Zaretskii
2019-09-30  9:02                                         ` Robert Pluim
2019-09-30  9:16                                           ` Eli Zaretskii
2019-10-02 20:17                                             ` Alan Third
2019-09-30 14:57                                         ` Richard Stallman
2019-10-15  6:42                                           ` Stefan Kangas
2019-10-15 14:15                                             ` Drew Adams
2019-10-16  3:29                                               ` Richard Stallman
2019-10-15 17:51                                             ` Juri Linkov
2019-10-16  3:27                                             ` Richard Stallman
2019-10-05 23:56                             ` Stefan Kangas
2019-10-06 17:28                               ` Eli Zaretskii
2019-10-06 19:59                                 ` Stefan Kangas
2019-10-07 18:22                                   ` Juri Linkov
2019-10-08 14:56                                     ` Stefan Kangas
2019-10-08 21:58                                       ` Stefan Kangas
2019-10-09  6:08                                         ` Eli Zaretskii
2019-10-09 21:56                                           ` Stefan Kangas [this message]
2019-10-10  7:26                                             ` Eli Zaretskii
2019-10-11  0:18                                               ` Stefan Kangas
2019-10-10  8:00                                             ` Robert Pluim
2019-10-11  0:24                                               ` Stefan Kangas
2019-10-11  5:53                                                 ` Robert Pluim
2019-10-13 22:05                                                   ` Stefan Kangas
2019-10-09 20:54                                         ` Juri Linkov
2020-03-03 20:03           ` bug#28182: bug#39847: Document how users can make text-zoom keys same as browser 積丹尼 Dan Jacobson
2020-03-03 20:24         ` Drew Adams
2020-03-03 20:51           ` Stefan Kangas
2020-03-03 21:04             ` 積丹尼 Dan Jacobson
2020-03-03 21:13             ` Drew Adams
2020-08-05 12:08         ` bug#28182: " Lars Ingebrigtsen
     [not found] <<87y3qcs3nf.fsf@jidanni.org>
     [not found] ` <<831so3bror.fsf@gnu.org>
     [not found]   ` <<E1dkWS3-0005Wd-6g@fencepost.gnu.org>
2017-08-23 14:29     ` bug#28182: maybe implement CTRL++ to zoom text Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADwFkmmd1Qdwqeih-BWLWD61kphbBKJcPJDbEdXMNJv8xUmkuA@mail.gmail.com \
    --to=stefan@marxist.se \
    --cc=28182@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=homeros.misasa@gmail.com \
    --cc=jidanni@jidanni.org \
    --cc=juri@linkov.net \
    --cc=rms@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).