Skip to content

Commit

Permalink
Add global minor modes for features
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
progfolio committed Jun 4, 2024
1 parent 3e6bfe3 commit c0089bf
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 30 deletions.
13 changes: 7 additions & 6 deletions exwm-background.el
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
:initialize #'custom-initialize-default
:set (lambda (symbol value)
(set-default-toplevel-value symbol value)
(exwm-background--update)))
(when (bound-and-true-p exwm-background-mode) (exwm-background--update))))

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

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

(provide 'exwm-background)

Expand Down
34 changes: 34 additions & 0 deletions exwm-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,40 @@ One of `line-mode' or `char-mode'.")
right-fringe-width 0
vertical-scroll-bar nil))

(defmacro exwm--define-global-minor-mode (name &optional init exit)
"Define EXWM namespaced global minor mode with NAME.
EXWM's init-hook and exit-hook are modified to call INIT and EXIT functions.
If an X connection exists, the mode is immediately enabled or disabled."
(declare (indent 1) (debug t))
(let* ((mode (intern (format "exwm-%s-mode" name)))
(enable (intern (format "exwm-%s-enable" name)))
(init (or init (intern (format "exwm-%s--init" name))))
(exit (or exit (intern (format "exwm-%s--exit" name))))
(doc (save-excursion
(when (re-search-backward "^;;;###autoload\\(.*\\)$" nil t)
(replace-regexp-in-string "\"\\(.*\\)\".*"
"\\1"
(match-string-no-properties 1))))))
`(prog1
(define-minor-mode ,mode
,doc
:global t
:group 'exwm
(exwm--log)
(cond
(,mode
(add-hook 'exwm-init-hook #',init)
(add-hook 'exwm-exit-hook #',exit)
(when exwm--connection (,init)))
(t
(remove-hook 'exwm-init-hook #',init)
(remove-hook 'exwm-exit-hook #',exit)
(when exwm--connection (,exit)))))
(defun ,(intern (format "exwm-%s-enable" name)) nil
,(format "Enable EXWM %s support." name)
(,mode 1))
(make-obsolete #',enable ,(format "Use `%s' instead." mode) "0.40"))))



(provide 'exwm-core)
Expand Down
11 changes: 6 additions & 5 deletions exwm-randr.el
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,12 @@ Refresh when any RandR 1.5 monitor changes."
(exwm--log)
(remove-hook 'exwm-workspace-list-change-hook #'exwm-randr-refresh))

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



Expand Down
16 changes: 9 additions & 7 deletions exwm-systemtray.el
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@
"System tray."
:group 'exwm)

;;;###autoload(autoload 'exwm-systemtray-mode "exwm-systemtray" nil t)
;;;###autoload(defvar exwm-systemtray-mode nil)
;;;###autoload(custom-autoload 'exwm-systemtray-mode "exwm-systemtray" nil)
;;;###autoload(autoload 'exwm-systemtray-mode "exwm-systemtray"
;;;###autoload"Global minor mode for toggling EXWM Systemtray support." t)
(exwm--define-global-minor-mode systemtray)

(defcustom exwm-systemtray-height nil
"System tray height.
Expand Down Expand Up @@ -87,7 +94,8 @@ TrueColor-24\" can be used to force Emacs to use 24-bit depth."
using 32-bit depth. Using `workspace-background' instead.")
(setq value 'workspace-background))
(set-default symbol value)
(when (and exwm-systemtray--connection
(when (and exwm-systemtray-mode
exwm-systemtray--connection
exwm-systemtray--embedder-window)
;; Change the background color for embedder.
(exwm-systemtray--set-background-color)
Expand Down Expand Up @@ -679,12 +687,6 @@ Argument DATA contains the raw event data."
(when (boundp 'exwm-randr-refresh-hook)
(remove-hook 'exwm-randr-refresh-hook #'exwm-systemtray--refresh-all))))

(defun exwm-systemtray-enable ()
"Enable system tray support for EXWM."
(exwm--log)
(add-hook 'exwm-init-hook #'exwm-systemtray--init)
(add-hook 'exwm-exit-hook #'exwm-systemtray--exit))



(provide 'exwm-systemtray)
Expand Down
11 changes: 6 additions & 5 deletions exwm-xim.el
Original file line number Diff line number Diff line change
Expand Up @@ -797,11 +797,12 @@ Such event would be received when the client window is destroyed."
(xcb:disconnect exwm-xim--conn)
(setq exwm-xim--conn nil))

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



Expand Down
15 changes: 8 additions & 7 deletions exwm-xsettings.el
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
(defvar exwm-xsettings--selection-owner-window nil)
(defvar exwm-xsettings--serial 0)

;;;###autoload(autoload 'exwm-xsettings-mode "exwm-xsettings" nil t)
;;;###autoload(defvar exwm-xsettings-mode nil)
;;;###autoload(custom-autoload 'exwm-xsettings-mode "exwm-xsettings" nil)
;;;###autoload(autoload 'exwm-xsettings-mode "exwm-xsettings"
;;;###autoload"Global minor mode for toggling EXWM Xsettings support." t)
(exwm--define-global-minor-mode xsettings)

(defun exwm-xsettings--rgba-match (_widget value)
"Return t if VALUE is a valid RGBA color."
(and (numberp value) (<= 0 value 1)))
Expand All @@ -67,7 +74,7 @@
SYMBOL is the setting being updated and VALUE is the new value."
(set-default-toplevel-value symbol value)
(exwm-xsettings--update-settings))
(when exwm-xsettings-mode (exwm-xsettings--update-settings)))

(defgroup exwm-xsettings nil
"XSETTINGS."
Expand Down Expand Up @@ -325,12 +332,6 @@ SERIAL is a sequence number."
exwm-xsettings--XSETTINGS_S0-atom nil
exwm-xsettings--selection-owner-window nil)))

(defun exwm-xsettings-enable ()
"Enable xsettings support for EXWM."
(exwm--log)
(add-hook 'exwm-init-hook #'exwm-xsettings--init)
(add-hook 'exwm-exit-hook #'exwm-xsettings--exit))

(provide 'exwm-xsettings)

;;; exwm-xsettings.el ends here

0 comments on commit c0089bf

Please sign in to comment.