summary refs log tree commit diff
path: root/.config/waybar/modules/gamma.go
diff options
context:
space:
mode:
Diffstat (limited to '.config/waybar/modules/gamma.go')
-rwxr-xr-x.config/waybar/modules/gamma.go78
1 files changed, 0 insertions, 78 deletions
diff --git a/.config/waybar/modules/gamma.go b/.config/waybar/modules/gamma.go
deleted file mode 100755
index 9813cc8..0000000
--- a/.config/waybar/modules/gamma.go
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/usr/bin/env yaegi
-
-package main
-
-import (
-	"encoding/json"
-	"log"
-	"os"
-	"os/exec"
-	"os/signal"
-	"runtime"
-	"strings"
-	. "syscall"
-)
-
-func main() {
-	runtime.GOMAXPROCS(1)
-
-	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(uintptr(SYS_PRCTL),
-		uintptr(PR_SET_PDEATHSIG),
-		uintptr(SIGTERM),
-		0, 0, 0, 0); e != 0 {
-		log.Fatalf("error: %v", e)
-	}
-
-	lookup()
-	for {
-		select {
-		case sig := <-update:
-			switch sig {
-			case SIGUSR1:
-				printJson("day")
-				// TODO(robert): toggle wlsunset off?
-			case SIGUSR2:
-				printJson("night")
-				// TODO(robert): toggle wlsunset on?
-			case SIGHUP:
-				lookup()
-			}
-		case <-cancel:
-			log.Printf("%v exiting\n", os.Args[0])
-			os.Exit(0)
-		}
-	}
-}
-
-func printJson(phase string) {
-	_ = json.NewEncoder(os.Stdout).Encode(map[string]interface{}{
-		"class":   phase,
-		"alt":     phase,
-		"tooltip": "gamma: " + phase,
-		"text":    phase,
-	})
-}
-
-func lookup() {
-	cmdEnv, ok := os.LookupEnv("GAMMA_COMMAND")
-	if !ok {
-		printJson("unknown")
-		return
-	}
-	b, err := exec.Command("bash", "-c", cmdEnv).Output()
-	if err != nil {
-		log.Fatalf("error: %v", err)
-		return
-	}
-	phase := strings.TrimSpace(string(b))
-	printJson(phase)
-}