diff options
| -rwxr-xr-x | .config/redshift/hooks/notif.sh | 10 | ||||
| -rw-r--r-- | .config/waybar/config | 9 | ||||
| -rwxr-xr-x | .config/waybar/modules/mediaplayer.py (renamed from .config/waybar/mediaplayer.py) | 0 | ||||
| -rw-r--r-- | .config/waybar/modules/redshift.go | 92 | ||||
| -rwxr-xr-x | .config/waybar/modules/toggl.lua (renamed from .config/waybar/toggl.lua) | 0 | ||||
| -rw-r--r-- | .config/waybar/style.css | 24 |
6 files changed, 128 insertions, 7 deletions
diff --git a/.config/redshift/hooks/notif.sh b/.config/redshift/hooks/notif.sh index 667f9e1..de04d6c 100755 --- a/.config/redshift/hooks/notif.sh +++ b/.config/redshift/hooks/notif.sh @@ -2,11 +2,9 @@ case "$1" in period-changed) - notify-send "redshift" "changed to $3" - if [ "$3" = "night" ]; then - ogurictl output --image ~/.background_night '*' - else - ogurictl output --image ~/.background '*' - fi + case "$3" in + transition|night) pkill -USR2 waybar-redshift ;; + none|day) pkill -USR1 waybar-redshift ;; + esac ;; esac diff --git a/.config/waybar/config b/.config/waybar/config index a8cb36a..9e3dfec 100644 --- a/.config/waybar/config +++ b/.config/waybar/config @@ -6,7 +6,7 @@ "modules-left": ["sway/mode", "sway/workspaces", "sway/window"], "modules-center": ["custom/media", "custom/toggl", "clock#local", "clock#utc"], - "modules-right": ["tray", "cpu", "memory", "disk#root", "disk#home", "temperature", "idle_inhibitor", "backlight", "pulseaudio", "network#wg", "network", "battery"], + "modules-right": ["tray", "cpu", "memory", "disk#root", "disk#home", "temperature", "idle_inhibitor", "backlight", "custom/redshift", "pulseaudio", "network#wg", "network", "battery"], "sway/workspaces": { "disable-scroll": true, "all-outputs": false, @@ -130,6 +130,13 @@ "exec": "$HOME/.config/waybar/toggl.lua 2>/dev/null", "interval": 30 }, + "custom/redshift": { + "exec-if": "pgrep redshift", + "exec": "$HOME/devel/projects/waybar-bites/redshift/waybar-redshift", + "return-type": "json", + "on-click": "pkill -x -USR1 redshift", + "on-click-right": "pkill -x -HUP waybar-redshift" + }, "mpd": { "format": "{stateIcon} {artist} - {title} ({elapsedTime:%M:%S}/{totalTime:%M:%S})", "format-disconnected": "", diff --git a/.config/waybar/mediaplayer.py b/.config/waybar/modules/mediaplayer.py index 4d80ffa..4d80ffa 100755 --- a/.config/waybar/mediaplayer.py +++ b/.config/waybar/modules/mediaplayer.py diff --git a/.config/waybar/modules/redshift.go b/.config/waybar/modules/redshift.go new file mode 100644 index 0000000..43b623c --- /dev/null +++ b/.config/waybar/modules/redshift.go @@ -0,0 +1,92 @@ +// usage: +// go build -o waybar-redshift redshift.go +package main + +import ( + "encoding/json" + "fmt" + "os" + "os/exec" + "os/signal" + "strings" + + . "syscall" +) + +const ( + ICON = "" +) + +func main() { + var ( + update = make(chan os.Signal, 1) + cancel = make(chan os.Signal, 1) + ) + signal.Notify(update, SIGUSR1, SIGUSR2, SIGHUP) + signal.Notify(cancel, SIGTERM, SIGINT) + + // could use golang.org/x/sys/unix.Prctl here + // but I want to avoid the dependency + if _, _, e := Syscall6(SYS_PRCTL, + uintptr(PR_SET_PDEATHSIG), + uintptr(SIGTERM), + 0, 0, 0, 0); e != 0 { + os.Exit(1) + } + // if err := Prctl(PR_SET_PDEATHSIG, + // SIGTERM, + // 0, 0, 0); err != nil { + // fmt.Fprintln(os.Stderr, err) + // os.Exit(1) + // } + + lookup() + for { + select { + case sig := <-update: + switch sig { + case SIGUSR1: + // redshift off + printJson("day", "day", ICON) + case SIGUSR2: + // redshift on + printJson("night", "night", ICON) + case SIGHUP: + lookup() + } + case <-cancel: + fmt.Fprintln(os.Stderr, "bye") + os.Exit(0) + } + } +} + +func printJson(class, tooltip, text string) { + _ = json.NewEncoder(os.Stdout).Encode(map[string]string{ + "class": class, + "tooltip": "redshift: " + tooltip, + "text": text, + }) +} + +func lookup() { + b, err := exec.Command("redshift", "-p").Output() + if err != nil { + return + } + fds := strings.Fields(string(b)) + for idx, f := range fds { + if f == "Period:" { + fds = fds[idx+1:] + break + } + } + switch fds[0] { + case "Night": + printJson("night", "night", ICON) + case "Transition": + printJson("night", "transition", ICON) + case "Day": + printJson("day", "day", ICON) + } +} diff --git a/.config/waybar/toggl.lua b/.config/waybar/modules/toggl.lua index e44fce2..e44fce2 100755 --- a/.config/waybar/toggl.lua +++ b/.config/waybar/modules/toggl.lua diff --git a/.config/waybar/style.css b/.config/waybar/style.css index 0b7016c..6fbbb03 100644 --- a/.config/waybar/style.css +++ b/.config/waybar/style.css @@ -26,6 +26,7 @@ #pulseaudio, #custom-media, #custom-toggl, +#custom-redshift, #mpd, #tray, #idle_inhibitor { @@ -178,6 +179,29 @@ label:focus { border-top: 2px solid #DB4D60; } +@keyframes flash { + 50% { + background: rgba(255,174,66, 0.7); + color: @background; + } +} +#custom-redshift.night { + border-top: 2px solid #ffae42; + color: @foreground; + animation-name: flash; + animation-duration: 0.3s; + animation-timing-function: linear; + animation-iteration-count: 1; +} +#custom-redshift.day { + color: @dimmed; +} +#custom-redshift.off, +#custom-redshift.unknown { + border-top: 2px solid @urgent; + color: @dimmed; +} + #mpd { color: @foreground; border-top: 2px solid #d75f00; |