Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Editor.Spacemacs] Mouse Wheel Can't Work on Emacs Which without Any Window System #6

Open
Johnson9009 opened this issue Mar 17, 2021 · 2 comments
Assignees
Labels
P1 High

Comments

@Johnson9009
Copy link
Owner

The mouse wheel can't work when the emacs is built without any window system, but the mouse click work well no matter left/right mouse click or double click.

(if (fboundp 'x-create-frame)
    ;; Do it after loading term/foo-win.el since the value of the
    ;; mouse-wheel-*-event vars depends on those files being loaded or not.
    (load "mwheel"))

After some investigation I found above code snippet in file "lisp/loadup.el", obviously the package "mwheel" won't be loaded if the Emacs is built without any window system, this is the root cause of this issue.

From comments in above code snippet, it seems that the package "mwheel" depends on window system packages, e.g., "term/ns-win.el", because of the initialization of variables "mouse-wheel-*-event", but from the source code of package "mwheel", these variables only depends on the feature "win32-win" and "ns-win" to set the initial value, in other words, the package "mwheel" can work without any window system.

After add below code snippet to the configuration file of Emacs, the mouse wheel work well on Emacs which built without any window system.

(require 'mwheel)
(mouse-wheel-mode t)

It seems that the developer of package "mwheel" is too strict for the condition to load it, so I file a bug report to https://debbugs.gnu.org/cgi/bugreport.cgi?bug=47162.

@Johnson9009 Johnson9009 self-assigned this Mar 17, 2021
@Johnson9009 Johnson9009 added the P1 High label Mar 17, 2021
@Johnson9009
Copy link
Owner Author

After some experiments on macOS, some found as below.

  1. If the Emacs is built with window system
    • Feature "ns" and "ns-win" always exist no matter how to connect the Emacs daemon.
    • The mouse wheel event from Emacs GUI client is "wheel-up" and "wheel-down".
    • The mouse wheel event from Emacs terminal client is "mouse-4" and "mouse-5".
  2. If the Emacs is built without window system
    • Feature "ns" and "ns-win" always are nonexistent no matter how to connect the Emacs daemon.
    • The mouse wheel event from Emacs terminal client is "mouse-4" and "mouse-5".

@Johnson9009
Copy link
Owner Author

A few years ago, a sub issue of this issue is resolved by below line of code.

;; Mouse scrolling doesn't work when emacs is run in Mac OSX terminal. The
;; root cause is that mwheel.el set "mouse-wheel-up-event" and
;; "mouse-wheel-down-event" to "wheel-down" and "wheel-up" because of "ns-win"
;; always in "features" of emacs no matter emacs is launched in GUI or
;; terminal environment. In addition, the mouse wheel keys received from
;; terminal is "mouse-4" and "mouse-5", received from GUI is "wheel-up" and
;; "wheel-down". So change the values of "mouse-wheel-up-event" and
;; "mouse-wheel-down-event" can't make emacs GUI and terminal clients work
;; well at the same time when they connect to the same emacs daemon.
(if (featurep 'ns)
(progn
(global-set-key (kbd "<mouse-4>") (kbd "<wheel-up>"))
(global-set-key (kbd "<mouse-5>") (kbd "<wheel-down>"))))

That issue is happened on Emacs with window system on macOS, mouse wheel work well in the GUI client, but won't work in terminal client, the root cause is described at syl20bnr/spacemacs#4591 (comment), now this fix maybe still is needed if we use an Emacs which built with window system at someday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 High
Projects
None yet
Development

No branches or pull requests

1 participant