blob: 31dda5c94936c586c7dcc45108d6c53c2ea9b187 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#!/bin/sh
set -e
[ -n "$DEBUG" ] && set -x
icon=$(iconez -n weather-sunset)
trap '{ notify-send -c error -i "$icon" -a darkmode "darkmode" "switching failed!"; }' ERR
gui__dark() {
gsettings set org.gnome.desktop.interface gtk-theme Adwaita
# gsettings set org.gnome.desktop.interface gtk-theme Adwaita-dark
gsettings set org.gnome.desktop.interface color-scheme prefer-dark
}
gui__light() {
gsettings set org.gnome.desktop.interface gtk-theme Adwaita
gsettings set org.gnome.desktop.interface color-scheme prefer-light
}
term__apply_theme() {
# stolen from https://github.com/lemnos/theme.sh/blob/master/bin/theme.sh
awk '
BEGIN {
fgesc="\033]10;#%s\007"
bgesc="\033]11;#%s\007"
curesc="\033]12;#%s\007"
colesc="\033]4;%d;#%s\007"
}
/^foreground:/ { printf fgesc, substr($2, 2) > "/dev/tty" }
/^background:/ { printf bgesc, substr($2, 2) > "/dev/tty" }
/^cursor:/ { printf curesc, substr($2, 2) > "/dev/tty" }
/^[0-9]+:/ { printf colesc, $1, substr($2, 2) > "/dev/tty" }
'
}
term__dark() {
term__apply_theme <"$XDG_CONFIG_HOME"/darkmode/night
}
term__light() {
term__apply_theme <"$XDG_CONFIG_HOME"/darkmode/day
}
# debounce dawn/dusk phasing
marker="/tmp/darkmode_transition"
case "${1}" in
dawn | dusk)
[ ! -f $marker ] && touch "$marker"
;;
day* | night)
[ -f $marker ] && rm -f "$marker"
;;
esac
# showtime...
case "${1}" in
dawn | day*)
[ -f $marker ] && exit 0
notify-send -i "${icon}" -a darkmode "darkmode" "switching to <i>${1}</i>"
gui__light
# term__light
# pkill -fe -USR1 waybar-gammastep
;;
dusk | night)
[ -f $marker ] && exit 0
notify-send -i "${icon}" -a darkmode "darkmode" "switching to <i>${1}</i>"
gui__dark
# term__dark
# pkill -fe -USR2 waybar-gammastep
;;
*)
printf "usage: %s [night|daytime]\n" "$(basename "$(readlink -f -- "$0")")"
;;
esac
|