Skip to content

Commit

Permalink
Update GTK theme variant on theme enable
Browse files Browse the repository at this point in the history
  • Loading branch information
Koekelas committed Sep 26, 2021
1 parent 03e108c commit b193148
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 11 deletions.
55 changes: 48 additions & 7 deletions dotfiles.org
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,20 @@ disable turning off monitors.
xset s off
#+END_SRC

Launch [[*picom][picom]] and [[*xsettingsd][xsettingsd]].
Launch [[*picom][picom]].

#+BEGIN_SRC sh
picom &
xsettingsd -c "${XDG_CONFIG_HOME:-$HOME/.config}/xsettingsd/xsettingsd" &
#+END_SRC

Launch [[*xsettingsd][xsettingsd]].

#+BEGIN_SRC sh
xsettingsd_preset_file="${XDG_DATA_HOME:-$HOME/.local/share}/xsettingsd/presets/dark"
xsettingsd_config_file="${XDG_CONFIG_HOME:-$HOME/.config}/xsettingsd/xsettingsd"

ln -sf "$xsettingsd_preset_file" "$xsettingsd_config_file" \
&& xsettingsd -c "$xsettingsd_config_file" &
#+END_SRC

Set SSH agent.
Expand Down Expand Up @@ -232,11 +241,7 @@ Ignore system configuration.
# Intentionally empty
#+END_SRC

** xsettingsd
:PROPERTIES:
:header-args:conf: :tangle stow/xsettingsd/.config/xsettingsd/xsettingsd
:END:

** xsettingsd :setup:
For settings, see [[https://www.freedesktop.org/wiki/Specifications/XSettingsRegistry/][XSETTINGS registry (freedesktop)]]. To dump the
settings of the running XSETTINGS daemon (e.g. GNOME Settings Daemon),
run:
Expand All @@ -245,12 +250,48 @@ run:
dump_xsettings
#+END_SRC

To create the configuration directory, run:

#+BEGIN_SRC sh
mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/xsettingsd"
#+END_SRC

*** Common
:PROPERTIES:
:header-args:conf: :noweb-ref xsettingsd-common
:END:

Disable blink cursor.

#+BEGIN_SRC conf
Net/CursorBlink 0
#+END_SRC

*** Themes
Configure a light and a dark theme. For theme names, see [[file:/usr/share/themes][theme
directory]].

#+BEGIN_SRC conf :noweb-ref xsettingsd-light-theme
Net/ThemeName "Adwaita"
#+END_SRC

#+BEGIN_SRC conf :noweb-ref xsettingsd-dark-theme
Net/ThemeName "Adwaita-dark"
#+END_SRC

*** Presets
Combine common and theme configuration into a light and a dark preset.

#+BEGIN_SRC conf :tangle stow/xsettingsd/.local/share/xsettingsd/presets/light :noweb no-export
<<xsettingsd-common>>
<<xsettingsd-light-theme>>
#+END_SRC

#+BEGIN_SRC conf :tangle stow/xsettingsd/.local/share/xsettingsd/presets/dark :noweb no-export
<<xsettingsd-common>>
<<xsettingsd-dark-theme>>
#+END_SRC

* GNOME catgen :setup:
To apply configuration, run:

Expand Down
45 changes: 44 additions & 1 deletion emacs.org
Original file line number Diff line number Diff line change
Expand Up @@ -3191,6 +3191,47 @@ Bury unneeded buffers, computers have more than enough memory.
:straight t
:when (string= (getenv "XDG_CURRENT_DESKTOP") "EXWM")
:preface
(defun koek-wm/get-process-args (id)
"Return arguments of process id ID.
ID is an integer, the process id of the process."
(when-let ((args (alist-get 'args (process-attributes id))))
(let ((normalized
(thread-last args
(replace-regexp-in-string (rx "\\ ") "\N{NO-BREAK SPACE}")
(replace-regexp-in-string (rx (one-or-more " ")) "\N{NULL}")
(replace-regexp-in-string "\N{NO-BREAK SPACE}" " "))))
(split-string normalized "\N{NULL}"))))

(defun koek-wm/get-process-ids (name)
"Return process ids of process NAME.
NAME is a string, the name of the process."
(seq-filter (lambda (id)
(when-let ((args (koek-wm/get-process-args id)))
(let ((nm (thread-first args
car
(split-string "/")
last
car)))
(string-equal nm name))))
(list-system-processes)))

(defun koek-wm/set-xsettingsd-preset ()
"Set xsettingsd configuration preset.
When current theme is a dark theme, set configuration preset to
dark, else, set it to light."
(when-let ((id (car (koek-wm/get-process-ids "xsettingsd"))))
(let* ((preset (if (koek-thm/darkp) "dark" "light"))
(preset-file
(thread-last (xdg-data-home)
(expand-file-name "xsettingsd/presets/")
(expand-file-name preset)))
(config-file
(expand-file-name "xsettingsd/xsettingsd" (xdg-config-home))))
;; Third argument truthy overwrites existing link, docstring
;; only mentions not signaling an error
(make-symbolic-link preset-file config-file 'overwrite)
(signal-process id 'SIGHUP))))

;; For systemctl power management commands, see
;; https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_basic_system_settings/managing-services-with-systemd_configuring-basic-system-settings#shutting-down-suspending-hibernating-system_managing-services-with-systemd
(defun koek-wm/power-off ()
Expand Down Expand Up @@ -3229,7 +3270,9 @@ Bury unneeded buffers, computers have more than enough memory.
(bind-keys
("C-c z p" . koek-wm/kill-power-off)
("C-c z z" . koek-wm/suspend)
("C-c x C-f" . koek-wm/launch-firefox)))
("C-c x C-f" . koek-wm/launch-firefox))

(add-hook 'koek-thm/enable-hook #'koek-wm/set-xsettingsd-preset))

(use-package exwm-input
:defer t
Expand Down
45 changes: 44 additions & 1 deletion stow/emacs/.config/emacs/init.el
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,47 @@ With `\\[universal-argument]' prefix argument ARG, kill current."
:straight t
:when (string= (getenv "XDG_CURRENT_DESKTOP") "EXWM")
:preface
(defun koek-wm/get-process-args (id)
"Return arguments of process id ID.
ID is an integer, the process id of the process."
(when-let ((args (alist-get 'args (process-attributes id))))
(let ((normalized
(thread-last args
(replace-regexp-in-string (rx "\\ ") "\N{NO-BREAK SPACE}")
(replace-regexp-in-string (rx (one-or-more " ")) "\N{NULL}")
(replace-regexp-in-string "\N{NO-BREAK SPACE}" " "))))
(split-string normalized "\N{NULL}"))))

(defun koek-wm/get-process-ids (name)
"Return process ids of process NAME.
NAME is a string, the name of the process."
(seq-filter (lambda (id)
(when-let ((args (koek-wm/get-process-args id)))
(let ((nm (thread-first args
car
(split-string "/")
last
car)))
(string-equal nm name))))
(list-system-processes)))

(defun koek-wm/set-xsettingsd-preset ()
"Set xsettingsd configuration preset.
When current theme is a dark theme, set configuration preset to
dark, else, set it to light."
(when-let ((id (car (koek-wm/get-process-ids "xsettingsd"))))
(let* ((preset (if (koek-thm/darkp) "dark" "light"))
(preset-file
(thread-last (xdg-data-home)
(expand-file-name "xsettingsd/presets/")
(expand-file-name preset)))
(config-file
(expand-file-name "xsettingsd/xsettingsd" (xdg-config-home))))
;; Third argument truthy overwrites existing link, docstring
;; only mentions not signaling an error
(make-symbolic-link preset-file config-file 'overwrite)
(signal-process id 'SIGHUP))))

;; For systemctl power management commands, see
;; https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_basic_system_settings/managing-services-with-systemd_configuring-basic-system-settings#shutting-down-suspending-hibernating-system_managing-services-with-systemd
(defun koek-wm/power-off ()
Expand Down Expand Up @@ -950,7 +991,9 @@ window."
(bind-keys
("C-c z p" . koek-wm/kill-power-off)
("C-c z z" . koek-wm/suspend)
("C-c x C-f" . koek-wm/launch-firefox)))
("C-c x C-f" . koek-wm/launch-firefox))

(add-hook 'koek-thm/enable-hook #'koek-wm/set-xsettingsd-preset))

(use-package exwm-input
:defer t
Expand Down
7 changes: 6 additions & 1 deletion stow/emacs/.config/exwm/exwmrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ xset -dpms
xset s off

picom &
xsettingsd -c "${XDG_CONFIG_HOME:-$HOME/.config}/xsettingsd/xsettingsd" &

xsettingsd_preset_file="${XDG_DATA_HOME:-$HOME/.local/share}/xsettingsd/presets/dark"
xsettingsd_config_file="${XDG_CONFIG_HOME:-$HOME/.config}/xsettingsd/xsettingsd"

ln -sf "$xsettingsd_preset_file" "$xsettingsd_config_file" \
&& xsettingsd -c "$xsettingsd_config_file" &

eval $(gnome-keyring-daemon -s)
export SSH_AUTH_SOCK
Expand Down
1 change: 0 additions & 1 deletion stow/xsettingsd/.config/xsettingsd/xsettingsd

This file was deleted.

2 changes: 2 additions & 0 deletions stow/xsettingsd/.local/share/xsettingsd/presets/dark
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Net/CursorBlink 0
Net/ThemeName "Adwaita-dark"
2 changes: 2 additions & 0 deletions stow/xsettingsd/.local/share/xsettingsd/presets/light
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Net/CursorBlink 0
Net/ThemeName "Adwaita"

0 comments on commit b193148

Please sign in to comment.