From 6ef7e0aef840affc1bd0c35165606ec4cd66c0d0 Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Wed, 19 Jun 2024 12:50:49 +0200 Subject: [PATCH] [foot] fix: (simple) theme switching --- nixos/users/tdpeuter/dotfiles.nix | 1 + scripts/toggle-light-dark.sh | 54 ++++++++++++++-- stow/foot/.config/foot/foot.ini | 8 ++- .../.config/foot/themes/tdpeuter-dark.ini | 64 +++++++++++++++++++ .../.config/foot/themes/tdpeuter-light.ini | 64 +++++++++++++++++++ stow/sway/.config/sway/input-output | 2 +- 6 files changed, 184 insertions(+), 9 deletions(-) create mode 100644 stow/foot/.config/foot/themes/tdpeuter-dark.ini create mode 100644 stow/foot/.config/foot/themes/tdpeuter-light.ini diff --git a/nixos/users/tdpeuter/dotfiles.nix b/nixos/users/tdpeuter/dotfiles.nix index 324f660..9766b08 100644 --- a/nixos/users/tdpeuter/dotfiles.nix +++ b/nixos/users/tdpeuter/dotfiles.nix @@ -21,6 +21,7 @@ in { source = ../../../stow/dunst/.config/dunst; }; ".config/foot" = { + recursive = true; source = ../../../stow/foot/.config/foot; }; ".config/fuzzel" = { diff --git a/scripts/toggle-light-dark.sh b/scripts/toggle-light-dark.sh index 34be380..ec38506 100755 --- a/scripts/toggle-light-dark.sh +++ b/scripts/toggle-light-dark.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # Toggle light- or dark-mode for your applications -# Usage: toggle [-m light|dark] +# Usage: toggle [-m light|dark] [-g] ################# ### Variables ### @@ -10,7 +10,9 @@ THEME_LIGHT='tdpeuter-light' THEME_DARK='tdpeuter-dark' THEME_DEFAULT="${THEME_LIGHT}" -STATE_FILE="${HOME}/.local/state/sisyphus/theme" +STATE_DIR="${HOME}/.local/state/sisyphus" +STATE_FILE="${STATE_DIR}/theme" +BG_DIR="${HOME}/Nextcloud/Afbeeldingen/wallpapers" declare -A theme_next theme_next[${THEME_LIGHT}]="${THEME_DARK}" @@ -20,8 +22,12 @@ declare -A gsettings_alt gsettings_alt[${THEME_LIGHT}]='default' gsettings_alt[${THEME_DARK}]='prefer-dark' +declare -A gtk_theme +gtk_theme[${THEME_LIGHT}]='Adwaita' +gtk_theme[${THEME_DARK}]='Adwaita-dark' + declare -A wallpaper -wallpaper[${THEME_LIGHT}]="bg" +wallpaper[${THEME_LIGHT}]="bg-light" wallpaper[${THEME_DARK}]="bg-dark" ############# @@ -29,7 +35,7 @@ wallpaper[${THEME_DARK}]="bg-dark" ############# # Parse options -while getopts ":m:" option; do +while getopts ":m:g" option; do case "${option}" in m) if [ "${OPTARG}" == 'light' ]; then @@ -41,6 +47,17 @@ while getopts ":m:" option; do exit 1 fi ;; + g) + previous_theme="$(cat ${STATE_FILE})" + if [ "${previous_theme}" == "${THEME_LIGHT}" ]; then + class="activated" + percentage=1 + else + percentage=0 + fi + printf '{ "class": "%s", "percentage": %d }' "${class}" "${percentage}" + exit 0 + ;; *) >&2 printf "Error: Invalid option: '%s'.\n" "${option}" exit 1 @@ -65,9 +82,33 @@ echo "${theme:=${THEME_DEFAULT}}" > "${STATE_FILE}" ### Set all themes ### ###################### -# GNOME +# Update terminal colors by sending it OSC sequences. +# Alternatively, you could use theme.sh (https://github.com/lemnos/theme.sh) +# Function below loosely based on theme.sh and https://codeberg.org/dnkl/foot/issues/708 +function update_terminal_colors() { + for pid in $(pgrep zsh); do + if [ "${theme}" == "${THEME_LIGHT}" ]; then + printf "\033]10;#000000\007" >> /proc/${pid}/fd/0 + printf "\033]11;#ffffff\007" >> /proc/${pid}/fd/0 + elif [ "${theme}" == "${THEME_DARK}" ]; then + printf "\033]10;#ffffff\007" >> /proc/${pid}/fd/0 + printf "\033]11;#000000\007" >> /proc/${pid}/fd/0 + fi + done +} + +# Foot +if [ "$(command -v foot)" ] ; then + # Make color theme switch 'permanent'. + echo "include=~/.config/foot/themes/${theme}.ini" > ~/.config/foot/theme.ini & + # We will have to change the terminal colors ourselves. + update_terminal_colors & +fi + +# GNOME (GTK) if [ "$(command -v gsettings)" ]; then gsettings set org.gnome.desktop.interface color-scheme "${gsettings_alt[${theme}]}" & + gsettings set org.gnome.desktop.interface gtk-theme "${gtk_theme[${theme}]}" & fi # Kitty @@ -77,7 +118,8 @@ fi # Sway if [ "$(command -v swaybg)" ]; then - pkill swaybg && swaybg --mode fill --image ~/Nextcloud/Afbeeldingen/wallpapers/${wallpaper[${theme}]} && swaymsg reload & + bg_path="${BG_DIR}/${wallpaper[${theme}]}" + /run/current-system/sw/bin/cp "${bg_path}" "${STATE_DIR}/bg" && swaymsg reload & fi # Vifm diff --git a/stow/foot/.config/foot/foot.ini b/stow/foot/.config/foot/foot.ini index 8ab7a49..51fdc7e 100644 --- a/stow/foot/.config/foot/foot.ini +++ b/stow/foot/.config/foot/foot.ini @@ -1,4 +1,8 @@ # -*- conf -*- +# ~/.config/foot/foot.ini + +# Include the correct color scheme +include=~/.config/foot/theme.ini # shell=$SHELL (if set, otherwise user's default shell from /etc/passwd) term=xterm-256color @@ -20,7 +24,7 @@ font=letter extended:size=10 # underline-offset= # underline-thickness= # box-drawings-uses-font-glyphs=no -# dpi-aware=no +dpi-aware=yes # initial-window-size-pixels=700x500 # Or, # initial-window-size-chars= @@ -75,7 +79,7 @@ visual=yes # long-press-delay=400 [colors] -alpha=0.9 +alpha=0.8 # background=242424 # foreground=ffffff flash=b00020 diff --git a/stow/foot/.config/foot/themes/tdpeuter-dark.ini b/stow/foot/.config/foot/themes/tdpeuter-dark.ini new file mode 100644 index 0000000..4ee35d8 --- /dev/null +++ b/stow/foot/.config/foot/themes/tdpeuter-dark.ini @@ -0,0 +1,64 @@ +[colors] +# alpha=0.8 +background=171717 +foreground=dcdfe4 +# flash=b00020 +# flash-alpha=0.5 + +## Normal/regular colors (color palette 0-7) +regular0=242424 # black +# regular0=21222c +# regular1=f62b5a # red +regular1=c86564 +regular2=47b413 # green +# regular2=b2bc68 +regular3=e3c401 # yellow +# regular3=f7e03f +# regular4=24acd4 # blue +regular4=80a2be +regular5=f2affd # magenta +# color5 #b294bb +# regular6=13c299 # cyan +regular6=8abeb7 +regular7=e6e6e6 # white +# regular7=ffffff + +## Bright colors (color palette 8-15) +# bright0=616161 # bright black +# bright0=6272a4 +# bright1=ff4d51 # bright red +# color9 #C86564 +# bright2=35d450 # bright green +# color10 #B2BC68 +# bright3=e9e836 # bright yellow +# color11 #f7e03f +# bright4=5dc5f8 # bright blue +# color12 #80A2BE +# bright5=feabf2 # bright magenta +# bright5=b294bb +# bright6=24dfc4 # bright cyan +# bright6=8abeb7 +bright7=ffffff # bright white + +## dimmed colors (see foot.ini(5) man page) +# dim0= +# ... +# dim7= + +## The remaining 256-color palette +# 16 = <256-color palette #16> +# ... +# 255 = <256-color palette #255> + +## Misc colors +# selection-foreground= +# selection-foreground=000000 +# selection-background= +# selection-background=fffacd +# jump-labels= # black-on-yellow +# scrollback-indicator= # black-on-bright-blue +# search-box-no-match= # black-on-red +# search-box-match= # black-on-yellow +# urls= +urls=0087bd + diff --git a/stow/foot/.config/foot/themes/tdpeuter-light.ini b/stow/foot/.config/foot/themes/tdpeuter-light.ini new file mode 100644 index 0000000..daeebb9 --- /dev/null +++ b/stow/foot/.config/foot/themes/tdpeuter-light.ini @@ -0,0 +1,64 @@ +[colors] +# alpha=0.8 +background=fafafa +foreground=000000 +# flash=b00020 +# flash-alpha=0.5 + +## Normal/regular colors (color palette 0-7) +# regular0=242424 # black +# color0 #383A42 +# regular1=f62b5a # red +# color1 #E45649 +# regular2=47b413 # green +# color2 #40A14F +# regular3=e3c401 # yellow +# color3 #C18401 +# regular4=24acd4 # blue +regular4=0184bc +# regular5=f2affd # magenta +# color5 #A626A4 +# regular6=13c299 # cyan +# color6 #0997B3 +# regular7=e6e6e6 # white +# color7 #FAFAFA + +## Bright colors (color palette 8-15) +# bright0=616161 # bright black +# color8 #6272a4 +# bright1=ff4d51 # bright red +# color9 #E45649 +# bright2=35d450 # bright green +# color10 #40A14F +# bright3=e9e836 # bright yellow +# color11 #C18401 +# bright4=5dc5f8 # bright blue +# color12 #0184BC +# bright5=feabf2 # bright magenta +# color13 #A626A4 +# bright6=24dfc4 # bright cyan +# color14 #0997B3 +# bright7=ffffff # bright white +# color15 #FAFAFA + +## dimmed colors (see foot.ini(5) man page) +# dim0= +# ... +# dim7= + +## The remaining 256-color palette +# 16 = <256-color palette #16> +# ... +# 255 = <256-color palette #255> + +## Misc colors +# selection-foreground= +selection-foreground=383a42 +# selection-background= +selection-background=bfceff +# jump-labels= # black-on-yellow +# scrollback-indicator= # black-on-bright-blue +# search-box-no-match= # black-on-red +# search-box-match= # black-on-yellow +urls=f0f0f0 + diff --git a/stow/sway/.config/sway/input-output b/stow/sway/.config/sway/input-output index c336c59..9c23892 100644 --- a/stow/sway/.config/sway/input-output +++ b/stow/sway/.config/sway/input-output @@ -11,7 +11,7 @@ input type:touchpad { } output * { - bg "~/Nextcloud/Afbeeldingen/wallpapers/bg" fill + bg "${HOME}/.local/state/sisyphus/bg" fill } # Vertical display