Skip to content

Add global minor modes for EXWM's features #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions exwm-background.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

(require 'exwm-core)

(defvar exwm-background-mode)

(defcustom exwm-background-color nil
"Background color for Xorg."
:type '(choice
Expand All @@ -43,7 +45,7 @@
:initialize #'custom-initialize-default
:set (lambda (symbol value)
(set-default-toplevel-value symbol value)
(exwm-background--update)))
(when 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 +190,9 @@ 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)
(exwm--define-global-minor-mode background
"Global minor mode for toggling EXWM background support.")

(provide 'exwm-background)

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

(defmacro exwm--define-global-minor-mode (name doc &optional init exit)
"Define global minor mode named exwm-NAME-mode.
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 (doc-string 2) (indent 1) (debug t))
(let* ((mode (intern (format "exwm-%s-mode" name)))
(enable (intern (format "exwm-%s-enable" name)))
(enabledoc (format "Enable %s support for EXWM." name))
(deprecation (format "Use `%s' instead." mode))
(init (or init (intern (format "exwm-%s--init" name))))
(exit (or exit (intern (format "exwm-%s--exit" name)))))
`(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 ,enable () ,enabledoc (,mode 1))
(make-obsolete #',enable ,deprecation "0.40"))))


(provide 'exwm-core)
Expand Down
8 changes: 3 additions & 5 deletions exwm-randr.el
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,9 @@ 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)
(exwm--define-global-minor-mode randr
"Global minor mode for toggling EXWM RandR support.")



Expand Down
13 changes: 7 additions & 6 deletions exwm-systemtray.el
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

(declare-function exwm-workspace--workarea "exwm-workspace.el" (frame))

(defvar exwm-systemtray-mode)

(defclass exwm-systemtray--icon ()
((width :initarg :width)
(height :initarg :height)
Expand Down Expand Up @@ -87,7 +89,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,11 +682,9 @@ 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))
;;;###autoload(autoload 'exwm-systemtray-mode "exwm-systemtray" nil t)
(exwm--define-global-minor-mode systemtray
"Global minor mode for toggling EXWM systemtray.")



Expand Down
8 changes: 3 additions & 5 deletions exwm-xim.el
Original file line number Diff line number Diff line change
Expand Up @@ -797,11 +797,9 @@ 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)
(exwm--define-global-minor-mode xim
"Global minor mode for toggling EXWM XIM support.")



Expand Down
12 changes: 6 additions & 6 deletions exwm-xsettings.el
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
(defvar exwm-xsettings--XSETTINGS_S0-atom nil)
(defvar exwm-xsettings--selection-owner-window nil)
(defvar exwm-xsettings--serial 0)
(defvar exwm-xsettings-mode)

(defun exwm-xsettings--rgba-match (_widget value)
"Return t if VALUE is a valid RGBA color."
Expand All @@ -67,7 +68,8 @@

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,11 +327,9 @@ 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))
;;;###autoload(autoload 'exwm-xsettings-mode "exwm-xsettings" nil t)
(exwm--define-global-minor-mode xsettings
"Global minor mode for toggling EXWM Xsettings support.")

(provide 'exwm-xsettings)

Expand Down