bbatsov / prelude

Prelude is an enhanced Emacs 25.1+ distribution that should make your experience with Emacs both more pleasant and more powerful.
https://prelude.emacsredux.com
5.1k stars 1.85k forks source link

super keybindings not working under windows #1375

Open treopop opened 2 years ago

treopop commented 2 years ago

None of the super keybindings are being recognized by Emacs despite setting prelude-super-keybindings to t.
I found that adding the following lines to prelude-windows.el (just below the modifier keys section) resolves the problem:

(when prelude-super-keybindings
  (w32-register-hot-key [s-])
  (w32-register-hot-key [A-]))  ; same for Alt-Tab etc

This disables all Windows hotkeys except Win+L. Alternatively, it is possible to register only the ones that are used in Emacs. Not sure what the preference here is. Personally I don't like to have e.g. windows explorer pop up accidentally, but of course I can always override any more specific default settings in my personal folder.

Tested with Emacs 28.1 on Win11 (21H2)

bbatsov commented 2 years ago

The super keybindings were mostly intended for macOS, to avoid conflicts with Windows global keybindings and the keybindings in most Linux desktops (like GNOME), that have similar keybindings to Windows making heavy use of the Win key.

I guess it makes sense to make them behave better on Windows now that there's a flag to enable/disable them. Or at least to document this better.

treopop commented 2 years ago

I agree, documenting it for windows users would already help. The main problem, at least for me, was that I expected it to work and couldn't quickly figure out why it didn't. However the current settings already do affect the Win key when pressed solely. The windows start menu doesn't open, which added to the confusion.

Also I realize that prelude so far requires Emacs 25.1 or newer, while w32-register-hot-key was only introduced with 26.1.

IMHO the best default settings are the ones that are least surprising. Here is an idea for the section in prelude-windows.el:

(when prelude-super-keybindings
  (if (version< emacs-version "26.1")
      (message "Super keybindings on Windows only available for Emacs 26.1 or newer")
    (progn
      ;; Teach Emacs how to interpret various modifier keys
      (setq w32-pass-lwindow-to-system nil)
      (setq w32-lwindow-modifier 'super) ; Left Windows key

      (setq w32-pass-rwindow-to-system nil)
      (setq w32-rwindow-modifier 'super) ; Right Windows key

      (setq w32-pass-apps-to-system nil)
      (setq w32-apps-modifier 'hyper) ; Menu/App key

      ;; register all prelude super hotkeys defined in prelude-mode.el
      ;; unused bindings like [s-e] still will open windows explorer
      (w32-register-hot-key [s-p])
      (w32-register-hot-key [s-r])
      ;; ...
      ;; maybe there is a way to do this without manually duplicating
      ;; the s- key bindings defined in prelude-mode.el?
      )))

To disable windows hot-keys completely while working in Emacs, I can put (w32-register-hot-key [s-]) in my personal settings.