Skip to content

Commit c0089bf

Browse files
committed
Add global minor modes for features
* exwm-core.el (exwm--define-global-minor-mode): Macro for arranging EXWM mode hooks, deprecating enabler functions, logging. * exwm-background.el: Add global mode definition, autoloads (exwm-background-enable): remove * exwm-randr.el (randr): as above (exwm-randr-enable): as above * exwm-systemtray.el (systemtray): as above (exwm-systemtray-mode): as above * exwm-xim.el (xim): as above (exwm-xim-enable): as above * exwm-xsettings.el (xsettings): as above (exwm-xsettings-enable): as above
1 parent 3e6bfe3 commit c0089bf

6 files changed

+70
-30
lines changed

exwm-background.el

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
:initialize #'custom-initialize-default
4444
:set (lambda (symbol value)
4545
(set-default-toplevel-value symbol value)
46-
(exwm-background--update)))
46+
(when (bound-and-true-p exwm-background-mode) (exwm-background--update))))
4747

4848
(defconst exwm-background--properties '("_XROOTPMAP_ID" "_XSETROOT_ID" "ESETROOT_PMAP_ID")
4949
"The background properties to set.
@@ -188,11 +188,12 @@ may kill this connection when they replace it.")
188188
exwm-background--connection nil
189189
exwm-background--atoms nil))
190190

191-
(defun exwm-background-enable ()
192-
"Enable background support for EXWM."
193-
(exwm--log)
194-
(add-hook 'exwm-init-hook #'exwm-background--init)
195-
(add-hook 'exwm-exit-hook #'exwm-background--exit))
191+
;;;###autoload(autoload 'exwm-background-mode "exwm-background" nil t)
192+
;;;###autoload(defvar exwm-background-mode nil)
193+
;;;###autoload(custom-autoload 'exwm-background-mode "exwm-background" nil)
194+
;;;###autoload(autoload 'exwm-background-mode "exwm-background"
195+
;;;###autoload"Global minor mode for toggling EXWM Background support." t)
196+
(exwm--define-global-minor-mode background)
196197

197198
(provide 'exwm-background)
198199

exwm-core.el

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,40 @@ One of `line-mode' or `char-mode'.")
408408
right-fringe-width 0
409409
vertical-scroll-bar nil))
410410

411+
(defmacro exwm--define-global-minor-mode (name &optional init exit)
412+
"Define EXWM namespaced global minor mode with NAME.
413+
EXWM's init-hook and exit-hook are modified to call INIT and EXIT functions.
414+
If an X connection exists, the mode is immediately enabled or disabled."
415+
(declare (indent 1) (debug t))
416+
(let* ((mode (intern (format "exwm-%s-mode" name)))
417+
(enable (intern (format "exwm-%s-enable" name)))
418+
(init (or init (intern (format "exwm-%s--init" name))))
419+
(exit (or exit (intern (format "exwm-%s--exit" name))))
420+
(doc (save-excursion
421+
(when (re-search-backward "^;;;###autoload\\(.*\\)$" nil t)
422+
(replace-regexp-in-string "\"\\(.*\\)\".*"
423+
"\\1"
424+
(match-string-no-properties 1))))))
425+
`(prog1
426+
(define-minor-mode ,mode
427+
,doc
428+
:global t
429+
:group 'exwm
430+
(exwm--log)
431+
(cond
432+
(,mode
433+
(add-hook 'exwm-init-hook #',init)
434+
(add-hook 'exwm-exit-hook #',exit)
435+
(when exwm--connection (,init)))
436+
(t
437+
(remove-hook 'exwm-init-hook #',init)
438+
(remove-hook 'exwm-exit-hook #',exit)
439+
(when exwm--connection (,exit)))))
440+
(defun ,(intern (format "exwm-%s-enable" name)) nil
441+
,(format "Enable EXWM %s support." name)
442+
(,mode 1))
443+
(make-obsolete #',enable ,(format "Use `%s' instead." mode) "0.40"))))
444+
411445

412446

413447
(provide 'exwm-core)

exwm-randr.el

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,12 @@ Refresh when any RandR 1.5 monitor changes."
356356
(exwm--log)
357357
(remove-hook 'exwm-workspace-list-change-hook #'exwm-randr-refresh))
358358

359-
(defun exwm-randr-enable ()
360-
"Enable RandR support for EXWM."
361-
(exwm--log)
362-
(add-hook 'exwm-init-hook #'exwm-randr--init)
363-
(add-hook 'exwm-exit-hook #'exwm-randr--exit))
359+
;;;###autoload(autoload 'exwm-randr-mode "exwm-randr" nil t)
360+
;;;###autoload(defvar exwm-randr-mode nil)
361+
;;;###autoload(custom-autoload 'exwm-randr-mode "exwm-randr" nil)
362+
;;;###autoload(autoload 'exwm-randr-mode "exwm-randr"
363+
;;;###autoload"Global minor mode for toggling EXWM Randr support." t)
364+
(exwm--define-global-minor-mode randr)
364365

365366

366367

exwm-systemtray.el

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
"System tray."
5151
:group 'exwm)
5252

53+
;;;###autoload(autoload 'exwm-systemtray-mode "exwm-systemtray" nil t)
54+
;;;###autoload(defvar exwm-systemtray-mode nil)
55+
;;;###autoload(custom-autoload 'exwm-systemtray-mode "exwm-systemtray" nil)
56+
;;;###autoload(autoload 'exwm-systemtray-mode "exwm-systemtray"
57+
;;;###autoload"Global minor mode for toggling EXWM Systemtray support." t)
58+
(exwm--define-global-minor-mode systemtray)
59+
5360
(defcustom exwm-systemtray-height nil
5461
"System tray height.
5562
@@ -87,7 +94,8 @@ TrueColor-24\" can be used to force Emacs to use 24-bit depth."
8794
using 32-bit depth. Using `workspace-background' instead.")
8895
(setq value 'workspace-background))
8996
(set-default symbol value)
90-
(when (and exwm-systemtray--connection
97+
(when (and exwm-systemtray-mode
98+
exwm-systemtray--connection
9199
exwm-systemtray--embedder-window)
92100
;; Change the background color for embedder.
93101
(exwm-systemtray--set-background-color)
@@ -679,12 +687,6 @@ Argument DATA contains the raw event data."
679687
(when (boundp 'exwm-randr-refresh-hook)
680688
(remove-hook 'exwm-randr-refresh-hook #'exwm-systemtray--refresh-all))))
681689

682-
(defun exwm-systemtray-enable ()
683-
"Enable system tray support for EXWM."
684-
(exwm--log)
685-
(add-hook 'exwm-init-hook #'exwm-systemtray--init)
686-
(add-hook 'exwm-exit-hook #'exwm-systemtray--exit))
687-
688690

689691

690692
(provide 'exwm-systemtray)

exwm-xim.el

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -797,11 +797,12 @@ Such event would be received when the client window is destroyed."
797797
(xcb:disconnect exwm-xim--conn)
798798
(setq exwm-xim--conn nil))
799799

800-
(defun exwm-xim-enable ()
801-
"Enable XIM support for EXWM."
802-
(exwm--log)
803-
(add-hook 'exwm-init-hook #'exwm-xim--init)
804-
(add-hook 'exwm-exit-hook #'exwm-xim--exit))
800+
;;;###autoload(autoload 'exwm-xim-mode "exwm-xim" nil t)
801+
;;;###autoload(defvar exwm-xim-mode nil)
802+
;;;###autoload(custom-autoload 'exwm-xim-mode "exwm-xim" nil)
803+
;;;###autoload(autoload 'exwm-xim-mode "exwm-xim"
804+
;;;###autoload"Global minor mode for toggling EXWM XIM support." t)
805+
(exwm--define-global-minor-mode xim)
805806

806807

807808

exwm-xsettings.el

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@
5858
(defvar exwm-xsettings--selection-owner-window nil)
5959
(defvar exwm-xsettings--serial 0)
6060

61+
;;;###autoload(autoload 'exwm-xsettings-mode "exwm-xsettings" nil t)
62+
;;;###autoload(defvar exwm-xsettings-mode nil)
63+
;;;###autoload(custom-autoload 'exwm-xsettings-mode "exwm-xsettings" nil)
64+
;;;###autoload(autoload 'exwm-xsettings-mode "exwm-xsettings"
65+
;;;###autoload"Global minor mode for toggling EXWM Xsettings support." t)
66+
(exwm--define-global-minor-mode xsettings)
67+
6168
(defun exwm-xsettings--rgba-match (_widget value)
6269
"Return t if VALUE is a valid RGBA color."
6370
(and (numberp value) (<= 0 value 1)))
@@ -67,7 +74,7 @@
6774
6875
SYMBOL is the setting being updated and VALUE is the new value."
6976
(set-default-toplevel-value symbol value)
70-
(exwm-xsettings--update-settings))
77+
(when exwm-xsettings-mode (exwm-xsettings--update-settings)))
7178

7279
(defgroup exwm-xsettings nil
7380
"XSETTINGS."
@@ -325,12 +332,6 @@ SERIAL is a sequence number."
325332
exwm-xsettings--XSETTINGS_S0-atom nil
326333
exwm-xsettings--selection-owner-window nil)))
327334

328-
(defun exwm-xsettings-enable ()
329-
"Enable xsettings support for EXWM."
330-
(exwm--log)
331-
(add-hook 'exwm-init-hook #'exwm-xsettings--init)
332-
(add-hook 'exwm-exit-hook #'exwm-xsettings--exit))
333-
334335
(provide 'exwm-xsettings)
335336

336337
;;; exwm-xsettings.el ends here

0 commit comments

Comments
 (0)