all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Drew Adams <drew.adams@oracle.com>
Cc: bug-gnu-emacs@gnu.org, 4478@emacsbugs.donarmstrong.com
Subject: bug#4478: 23.1; key bindings for mouse wheel - unclear
Date: Fri, 18 Sep 2009 09:34:14 -0400	[thread overview]
Message-ID: <jwv7hvwxu1w.fsf-monnier+emacsbugreports@gnu.org> (raw)
In-Reply-To: <625E5DF5465B4A1CBF3FBB6015CBB87D@us.oracle.com> (Drew Adams's message of "Fri, 18 Sep 2009 00:48:12 -0700")

> 1. Doc bug: The doc is not clear about how to bind the mouse wheel
> (rotations).

Indeed.  The way to do it is currently messy and ugly.
 
> I've been using bindings such as this:
 
> (define-key map [wheel-down]   'aaa)
> (define-key map [wheel-down]   'bbb)
> (define-key map [C-wheel-down] 'ccc)
> (define-key map [C-wheel-down] 'ddd)

IIUC this is "the right way".  And it works under w32 and ns.
Under X11, sadly, mouse-wheel events are usually represented as mouse
clicks for buttons 4 and 5, and there's no way for Emacs to know whether
these correspond to mouse clicks (on mice with more than 3 buttons) or
mouse-wheel events.  Worse yet, Emacs doesn't offer an easy way to map
all the variants of `mouse-4' and `mouse-5' (with and without each of
the possible modifiers) to wheel-up and wheel-down.

The code appended below does manage to do such a remap, but as you can
see it's ugly, and worse yet: there can only be one such thing because
it uses the "default" binding.  [ And it probably won't work with
xterm-mouse-mode. ]
 
> (define-key map (vector mouse-wheel-down-event) 'aaa)
> (define-key map (vector mouse-wheel-up-event)   'bbb)
> (define-key map
>   (vector (list 'control mouse-wheel-down-event)) 'ccc)
> (define-key map
>   (vector (list 'control mouse-wheel-up-event)) 'ddd)
 
> I haven't tested on GNU/Linux, but I'm assuming this is what to use
> for portable code. Is there a shorter or better way to say this and
> still be portable? 

I think this is about as good as it gets for now, yes.
 
> 1. If there is not, there should be (a shorter way to do this).

The [wheel-down] and friends shown above is what there should be.
 

        Stefan


(define-key function-key-map [t]
	 '(menu-item "" nil
	   :filter sm-rewrite-mwheel))

(defun sm-rewrite-mwheel (ignore)
  (let* ((events (this-single-command-raw-keys))
         (event (unless (zerop (length events))
                  (aref events (1- (length events))))))
    (message "sm-rewrite-mwheel: key=%s" event)
    (case (event-basic-type event)
      (mouse-4
       (let* ((mods (delete 'click (event-modifiers event)))
              (new-key (event-convert-list (append mods '(wheel-up))))
              (new-event (cons new-key (cdr event))))
         (vector new-event)))
      (mouse-5
       (let* ((mods (delete 'click (event-modifiers event)))
              (new-key (event-convert-list (append mods '(wheel-down))))
              (new-event (cons new-key (cdr event))))
         (vector new-event))))))






      reply	other threads:[~2009-09-18 13:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-18  7:48 bug#4478: 23.1; key bindings for mouse wheel - unclear Drew Adams
2009-09-18 13:34 ` Stefan Monnier [this message]

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

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

  git send-email \
    --in-reply-to=jwv7hvwxu1w.fsf-monnier+emacsbugreports@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=4478@emacsbugs.donarmstrong.com \
    --cc=bug-gnu-emacs@gnu.org \
    --cc=drew.adams@oracle.com \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.