From 30451238df36d238fea816f01ca987853c6562a5 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Thu, 11 Feb 2021 13:45:25 +0100 Subject: waybar: update 2021-02-11T12:46:11Z --- .config/waybar/modules/redshift.go | 89 -------------------------------------- 1 file changed, 89 deletions(-) delete mode 100644 .config/waybar/modules/redshift.go (limited to '.config/waybar/modules/redshift.go') diff --git a/.config/waybar/modules/redshift.go b/.config/waybar/modules/redshift.go deleted file mode 100644 index b336748..0000000 --- a/.config/waybar/modules/redshift.go +++ /dev/null @@ -1,89 +0,0 @@ -// usage: -// go build -o waybar-redshift redshift.go -package main - -import ( - "encoding/json" - "fmt" - "os" - "os/exec" - "os/signal" - "strings" - - . "syscall" -) - -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") - case SIGUSR2: - // redshift on - printJson("night", "night") - case SIGHUP: - lookup() - } - case <-cancel: - fmt.Fprintf(os.Stderr, "%v exiting\n", os.Args[0]) - os.Exit(0) - } - } -} - -func printJson(state, tooltip string) { - _ = json.NewEncoder(os.Stdout).Encode(map[string]interface{}{ - "class": state, - "alt": state, - "tooltip": "redshift: " + tooltip, - "text": state, - }) -} - -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") - case "Transition": - printJson("night", "transition") - case "Daytime": - printJson("day", "day") - } -} -- cgit 1.4.1