all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* recommended way to bind mouse-wheel events
@ 2009-02-16 22:41 Drew Adams
  2009-02-17  1:54 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: Drew Adams @ 2009-02-16 22:41 UTC (permalink / raw)
  To: 'Emacs-Devel devel'

I've read the Elisp manual, node Misc Events, and I've looked at the little bit
of vanilla Elisp code that uses the mouse wheel, but I still have a question
about binding the wheel.

In various places, I've come across code such as this:

(defvar my-map
  (let ((my-map (make-sparse-keymap)))
    (when mouse-wheel-mode
      (mapc (lambda (key)
              (define-key my-map key 'my-scroll))
            '([mouse-4]   [mouse-5]
              [C-mouse-4] [C-mouse-5]
              [S-mouse-4] [S-mouse-5])))
    my-map)
  "...")

On Windows, at least with my 5-button mouse, that doesn't work: `mouse-4' and
`mouse-5' are separate mouse buttons.

This works for me, on Windows:

(defvar my-map
  (let ((my-map (make-sparse-keymap)))
    (when mouse-wheel-mode
      (mapc (lambda (key)
              (define-key my-map key 'my-scroll))
            (list (vector mouse-wheel-up-event)
                  (vector mouse-wheel-down-event)
                  (vector (list 'control mouse-wheel-up-event))
                  (vector (list 'control mouse-wheel-down-event))
                  (vector (list 'shift mouse-wheel-up-event))
                  (vector (list 'shift mouse-wheel-down-event)))))
    my-map)
  "...")

Questions:

Will this code, which uses the event variables, work also on non-Windows
platforms? If so, is this a good way to do it, or is there a better way? 

Shouldn't this be documented? (Mice with wheels have been around for decades.)







^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: recommended way to bind mouse-wheel events
  2009-02-16 22:41 recommended way to bind mouse-wheel events Drew Adams
@ 2009-02-17  1:54 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2009-02-17  1:54 UTC (permalink / raw)
  To: Drew Adams; +Cc: 'Emacs-Devel devel'

> Will this code, which uses the event variables, work also on non-Windows
> platforms? If so, is this a good way to do it, or is there a better way? 

IIUC it should work more or less everywhere, and while it's not great
it's the best we have so far.

> Shouldn't this be documented? (Mice with wheels have been around
> for decades.)

I'd rather not document this ugly hack.  We should indeed remap mouse-4
and mouse-5 to wheel-up and wheel-down (on X11) so those events can be
used everywhere.


        Stefan




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-02-17  1:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-16 22:41 recommended way to bind mouse-wheel events Drew Adams
2009-02-17  1:54 ` Stefan Monnier

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.