Browse Source

Make EXWM global key overrides customizable

If EXWM is mainly used in line-mode, it is useful to add the
bindings to the list of global prefix keys instead of setting them globally.
This way, they become accessible via the minor mode map, and can also be
deactivated again.
master
timor 8 months ago
committed by Damien Cassou
parent
commit
cd51452889
2 changed files with 52 additions and 7 deletions
  1. +16
    -0
      README.org
  2. +36
    -7
      desktop-environment.el

+ 16
- 0
README.org View File

@@ -131,6 +131,22 @@ done by adding the following to your configuration file:
(setq desktop-environment-brightness-small-decrement "-U 5")
#+end_src

**** EXWM Compatibility

The customizable variable ~desktop-environment-update-exwm-global-keys~ can be
used to control how key bindings should be handled when EXWM is loaded.

If set to ~:global~ (the default), the key bindings will be set via
`exwm-input-set-key`. This ensures that these are global bindings which work
regardless of char-mode or line-mode.

When predominantly working with line mode, however, it may make sense to set it
to the value ~:prefix~ instead. This way, EXWM knows to forward the bindings to
the minor mode map in line mode. This way, when disabling
~desktop-environment-mode~, the bindings are deactivated again.

Set to ~nil~ to disable any kind of special behavior in the presence of EXWM.

** License

See [[file:COPYING][COPYING]]. Copyright (c) 2018 Damien Cassou.


+ 36
- 7
desktop-environment.el View File

@@ -176,6 +176,16 @@ portion of the screen."
"Shell command toggling bluetooth."
:type 'string)

;;; Customization - EXWM keybindings

(defcustom desktop-environment-update-exwm-global-keys :global
"Determines interacting with EXWM bindings when enabling/disabling the mode."
:type '(radio
(const :tag "Global" :doc "Use `exwm-input-set-key' on mode activation to set bindings." :global)
(const :tag "Prefix" :doc "Add/Remove keys to `exwm-input-prefix-keys' when enabling/disabling the mode." :prefix)
(const :tag "Off" :doc "Do not touch EXWM key bindings." nil)))

;;; Helper functions - brightness

(defun desktop-environment-brightness-get ()
@@ -411,12 +421,32 @@ the screen."

(declare-function exwm-input-set-key "ext:exwm-input")

(defun desktop-environment-exwm-set-global-keybindings ()
"When using EXWM, add `desktop-environment-mode-map' to global keys."
(defun desktop-environment-exwm-set-global-keybindings (enable)
"When using EXWM, add `desktop-environment-mode-map' to global keys.

When ENABLE is non-nil, the bindings will be installed depending
on the value of `desktop-environment-update-exwm-global-keys'.
If set to `:prefix', the bindings will be disabled when ENABLE is
nil."
(when (featurep 'exwm-input)
(map-keymap (lambda (event definition)
(exwm-input-set-key (vector event) definition))
desktop-environment-mode-map)))
(cl-case desktop-environment-update-exwm-global-keys
(:global
(when enable
(map-keymap (lambda (event definition)
(exwm-input-set-key (vector event) definition))
desktop-environment-mode-map)))
(:prefix
(when (boundp 'exwm-input-prefix-keys)
(map-keymap (lambda (event definition)
(ignore definition)
(setq exwm-input-prefix-keys (if enable
(cons event exwm-input-prefix-keys)
(delq event exwm-input-prefix-keys))))
desktop-environment-mode-map)))
((nil) nil)
(t
(message "Ignoring unknown value %s for `desktop-environment-update-exwm-global-keys'"
desktop-environment-update-exwm-global-keys)))))

;;;###autoload
(define-minor-mode desktop-environment-mode
@@ -426,8 +456,7 @@ the screen."
:global t
:require 'desktop-environment
:lighter " DE"
(when desktop-environment-mode
(desktop-environment-exwm-set-global-keybindings)))
(desktop-environment-exwm-set-global-keybindings desktop-environment-mode))

(provide 'desktop-environment)
;;; desktop-environment.el ends here

Loading…
Cancel
Save