From c0089bf7e5d3f4f9b5a20cec95c318355304b8bb Mon Sep 17 00:00:00 2001 From: Nicholas Vollmer Date: Wed, 29 May 2024 13:58:45 -0400 Subject: [PATCH] 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 --- exwm-background.el | 13 +++++++------ exwm-core.el | 34 ++++++++++++++++++++++++++++++++++ exwm-randr.el | 11 ++++++----- exwm-systemtray.el | 16 +++++++++------- exwm-xim.el | 11 ++++++----- exwm-xsettings.el | 15 ++++++++------- 6 files changed, 70 insertions(+), 30 deletions(-) diff --git a/exwm-background.el b/exwm-background.el index fa663d8..aaae59b 100644 --- a/exwm-background.el +++ b/exwm-background.el @@ -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. @@ -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) diff --git a/exwm-core.el b/exwm-core.el index a7fdfce..815ea35 100644 --- a/exwm-core.el +++ b/exwm-core.el @@ -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) diff --git a/exwm-randr.el b/exwm-randr.el index 7f0e505..9280215 100644 --- a/exwm-randr.el +++ b/exwm-randr.el @@ -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) diff --git a/exwm-systemtray.el b/exwm-systemtray.el index 2b46568..0888a73 100644 --- a/exwm-systemtray.el +++ b/exwm-systemtray.el @@ -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. @@ -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) @@ -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) diff --git a/exwm-xim.el b/exwm-xim.el index 1f0c9c4..a8fdf52 100644 --- a/exwm-xim.el +++ b/exwm-xim.el @@ -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) diff --git a/exwm-xsettings.el b/exwm-xsettings.el index 596588b..4d5641c 100644 --- a/exwm-xsettings.el +++ b/exwm-xsettings.el @@ -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))) @@ -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." @@ -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