From f9a2f1f9b6bb223dd1f52cf78392c2dd640730f3 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Mon, 31 May 2021 16:40:10 +0200 Subject: waybar: various updates * add extension to config file * covid: use tail vs head for historical data * remove network.vpn * gamma: change name from gammastep --- .config/waybar/config | 218 ------------------------------------ .config/waybar/config.jsonc | 216 +++++++++++++++++++++++++++++++++++ .config/waybar/modules/covid.sh | 2 +- .config/waybar/modules/gamma.go | 76 +++++++++++++ .config/waybar/modules/gammastep.go | 94 ---------------- .config/waybar/modules/weather.sh | 3 +- .config/waybar/style.css | 40 +++---- 7 files changed, 315 insertions(+), 334 deletions(-) delete mode 100644 .config/waybar/config create mode 100644 .config/waybar/config.jsonc create mode 100644 .config/waybar/modules/gamma.go delete mode 100644 .config/waybar/modules/gammastep.go diff --git a/.config/waybar/config b/.config/waybar/config deleted file mode 100644 index 544661d..0000000 --- a/.config/waybar/config +++ /dev/null @@ -1,218 +0,0 @@ -// vim: ft=json commentstring=//\ %s -{ - "layer": "top", - "position": "top", - "height": 25, - "gtk-layer-shell": true, - - "modules-left": ["sway/mode", "sway/workspaces", "sway/window", "custom/mpris"], - "modules-center": ["custom/weather", "clock#local", "clock#utc", "custom/toggl", "custom/todo"], - "modules-right": ["tray", "custom/covid", "cpu", "memory", "disk#root", "disk#home", "temperature", "idle_inhibitor", "backlight", "custom/gammastep", "pulseaudio", "network#vpn", "network#tailscale", "network", "battery"], - - "sway/workspaces": { - "disable-scroll": true, - "all-outputs": false, - "format": "{icon}", - "format-icons": { - "m": "󰎇", - "v": "󰿏", - "g": "󰺵", - "__vnc": "󱒃" - } - }, - "sway/window": { - "format": "{}", - "max-length": 100 - }, - "sway/mode": { - "format": "{}" - }, - "idle_inhibitor": { - "format": "{icon}", - "format-icons": { - "activated": "󰅶", - "deactivated": "󰾪" - } - }, - "tray": { - "spacing": 10 - }, - "clock#local": { - "format": "{:%a %d %b %H:%M}", - "tooltip-format": "TZ: {:%Z %z}\n\n{calendar}", - // "locale": "ja_JP.utf-8" - "locale": "en_US.utf-8" - }, - "clock#utc": { - "timezone": "UTC", - "format": "({:%Z %H:%M})", - "tooltip-format": "{:%Z %z}" - }, - "disk#root": { - "path": "/", - "format": "󰋊 / {percentage_used}%" - }, - "disk#home": { - "path": "/home", - "format": "/home {percentage_used}%" - }, - "cpu": { - "format": "󰊚 {}%", - "on-click": "$HOME/bin/swx -t -f -- htop --sort-key PERCENT_CPU" - }, - "memory": { - "format": "󰍛 {}%", - "on-click": "$HOME/bin/swx -t -f -- htop --sort-key PERCENT_MEM" - }, - "temperature": { - "critical-threshold": 100, - "format": "{icon} {temperatureC}℃", - "format-icons": ["󱃃", "󰔏", "󱃂", "󰸁"] - }, - "backlight": { - "format": "{icon} {percent}%", - "format-icons": ["󰹐", "󰌶", "󰛩"], - "on-scroll-down": "light -A 5", - "on-scroll-up": "light -U 5", - // save current level - // then set to minimum brightness - "on-click-right": "light -O; light -S $(light -P)", - // revert to previously saved brightness - "on-click-middle": "light -I" - }, - "battery": { - "states": { - // "good": 95, - "warning": 30, - "critical": 15 - }, - "format": "{icon} {capacity}%", - "format-charging": "󰗱 {capacity}%", - "format-plugged": "󰚥 {capacity}%", - "format-alt": "{icon} {time}", - "format-full": "󱊦", - "format-icons": ["󱃍", "󱊡", "󱊢", "󱊣"] - }, - "network": { - "format-wifi": "{icon} ({signalStrength}%)", - "format-icons": ["󰤫", "󰤟", "󰤢", "󰤥", "󰤨"], - "format-ethernet": "󰌗", - "format-linked": "󰈀 {ifname}", - "format-disconnected": "󰌙 ", - "tooltip-format": "{ifname}: {ipaddr}/{cidr}\nssid: {essid}\nsignal: {signaldBm} dbm\ndown: {bandwidthDownBits}\nup: {bandwidthUpBits}", - "tooltip-format-disconnected": "disconnected", - "on-click": "swx -t -f iwctl" - }, - "network#vpn": { - "interface": "wg0", - "format": "󰌆", - "tooltip-format": "{ifname}: {ipaddr}/{cidr}", - "tooltip-format-disconnected": "disconnected", - "on-click": "doas wg-quick up wg0", - "on-click-right": "doas wg-quick down wg0" - }, - "network#tailscale": { - "interface": "tailscale0", - "format": "󰀘", - "tooltip-format": "{ifname}: {ipaddr}/{cidr}", - "tooltip-format-disconnected": "disconnected", - "on-click": "doas rc-service tailscale start", - "on-click-right": "doas rc-service tailscale stop" - }, - "pulseaudio": { - "format": "{icon} {volume}%", - "format-bluetooth": "{icon} {volume}%", - "format-muted": "󰝟 {volume}%", - "format-source": "󰍬 {volume}%", - "format-source-muted": " {volume}%", - "format-icons": { - "headphones": "󰋋", - "handsfree": "󰜟", - "headset": "󰋎", - "phone": "󰏲", - "portable": "󰛵", - "car": "󰄋", - "default": ["󰕿", "󰖀", "󰕾"] - }, - "on-click-right": "pactl set-sink-mute @DEFAULT_SINK@ toggle", - "on-click": "swx -t -F '0.4' pulsemixer" - }, - "custom/mpris": { - "format": "{}", - "exec": "waybar-mpris --position --autofocus --interpolate --play 󰏤 --pause 󰲸", - "on-click": "waybar-mpris --send toggle", - "on-click-right": "waybar-mpris --send player-next", - "escape": true, - "max-width": 90, - "return-type": "json" - }, - "custom/toggl": { - "format": "󰔟 {}", - "exec": "$HOME/.config/waybar/modules/toggl.lua 2>/dev/null", - "interval": 60 - }, - "custom/todo": { - "format": "{icon} {}", - "format-icons": { - "off": "󰒲", - "on": "󰈻" - }, - "exec": "env WAYBAR_TODO_FILE=$HOME/.zk/todo.md $HOME/.config/waybar/modules/waybar-todo", - "on-click": "pkill -x -USR1 waybar-todo", - "on-click-right": "pkill -x -USR2 waybar-todo", - "escape": true, - "return-type": "json" - }, - "custom/gammastep": { - "format": "{icon}", - "format-icons": { - "day": "󰱌", - "night": "󰱊" - }, - "exec-if": "pgrep gammastep", - "exec": "$HOME/.config/waybar/modules/waybar-gammastep", - "return-type": "json", - "on-click": "pkill -x -USR1 gammastep", - "on-click-right": "pkill -x -HUP waybar-gammastep" - }, - "custom/weather": { - "format": "{icon} {percentage}℃", - "format-icons": { - "sunny": "󰖙", - "partlycloudy": "󰖕", - "cloudy": "󰖐", - "verycloudy": "󰼯", - "fog": "󰖑", - "lightrain": "󰖗", - "heavyrain": "󰖖", - "hail": "󰖒", - "thunder": "󰖓", - "lightsnow": "󰖘", - "heavysnow": "󰼶", - "snowrain": "󰙿" - }, - "exec": "$HOME/.config/waybar/modules/weather.sh", - "interval": 600, - "return-type": "json", - "tooltip": true, - // "signal": 4, - // "on-click-right": "pkill -SIGRTMIN+5 waybar", - "on-click": "swx -t env REPORT=1 $HOME/.config/waybar/modules/weather.sh Berlin" - }, - "custom/covid": { - "format": "{icon} {}", - "format-icons": { - "gray": "󱅼", - "green": "󱎷", - "yellow": "󱎷", - "orange": "󱎷", - "red": "󱎷", - "darkred": "󱎷", - "darkdarkred": "󰯆" - }, - "exec": "$HOME/.config/waybar/modules/covid.sh", - "interval": 86400, - "tooltip": true, - "return-type": "json" - } -} diff --git a/.config/waybar/config.jsonc b/.config/waybar/config.jsonc new file mode 100644 index 0000000..b117c3b --- /dev/null +++ b/.config/waybar/config.jsonc @@ -0,0 +1,216 @@ +{ + "layer": "top", + "position": "top", + "height": 25, + "gtk-layer-shell": true, + + // "modules-left": ["sway/mode", "sway/workspaces", "sway/window", "custom/mpris"], + "modules-left": ["sway/mode", "sway/workspaces", "custom/mpris"], + "modules-center": ["custom/weather", "clock#local", "clock#utc", "custom/toggl", "custom/todo"], + "modules-right": ["tray", "custom/covid", "cpu", "memory", "disk#root", "disk#home", "temperature", "idle_inhibitor", "backlight", "custom/gamma", "pulseaudio", "network#tailscale", "network", "battery"], + + "sway/workspaces": { + "disable-scroll": true, + "all-outputs": false, + "format": "{icon}", + "format-icons": { + "m": "󰎇", + "v": "󰿏", + "g": "󰺵", + "__vnc": "󱒃" + } + }, + "sway/window": { + "format": "{}", + "max-length": 100 + }, + "sway/mode": { + "format": "{}" + }, + "idle_inhibitor": { + "format": "{icon}", + "format-icons": { + "activated": "󰅶", + "deactivated": "󰾪" + } + }, + "tray": { + "spacing": 10 + }, + "clock#local": { + "format": "{:%a %d %b %H:%M}", + "tooltip-format": "TZ: {:%Z %z}\n\n{calendar}", + // "locale": "ja_JP.utf-8" + "locale": "en_US.utf-8" + }, + "clock#utc": { + "timezone": "UTC", + "format": "({:%Z %H:%M})", + "tooltip-format": "{:%Z %z}" + }, + "disk#root": { + "path": "/", + "format": "󰋊 / {percentage_used}%" + }, + "disk#home": { + "path": "/home", + "format": "/home {percentage_used}%" + }, + "cpu": { + "format": "󰊚 {}%", + "on-click": "$HOME/bin/swx -t -f -- htop --sort-key PERCENT_CPU" + }, + "memory": { + "format": "󰍛 {}%", + "on-click": "$HOME/bin/swx -t -f -- htop --sort-key PERCENT_MEM" + }, + "temperature": { + "critical-threshold": 100, + "format": "{icon} {temperatureC}℃", + "format-icons": ["󱃃", "󰔏", "󱃂", "󰸁"] + }, + "backlight": { + "format": "{icon} {percent}%", + "format-icons": ["󰹐", "󰌶", "󰛩"], + "on-scroll-down": "light -A 5", + "on-scroll-up": "light -U 5", + // save current level + // then set to minimum brightness + "on-click-right": "light -O; light -S $(light -P)", + // revert to previously saved brightness + "on-click-middle": "light -I" + }, + "battery": { + "states": { + // "good": 95, + "warning": 30, + "critical": 15 + }, + "format": "{icon} {capacity}%", + "format-charging": "󰗱 {capacity}%", + "format-plugged": "󰚥 {capacity}%", + "format-alt": "{icon} {time}", + "format-full": "󱊦", + "format-icons": ["󱃍", "󱊡", "󱊢", "󱊣"] + }, + "network": { + "format-wifi": "{icon} ({signalStrength}%)", + "format-icons": ["󰤫", "󰤟", "󰤢", "󰤥", "󰤨"], + "format-ethernet": "󰌗", + "format-linked": "󰈀 {ifname}", + "format-disconnected": "󰌙 ", + "tooltip-format": "{ifname}: {ipaddr}/{cidr}\nssid: {essid}\nsignal: {signaldBm} dbm\ndown: {bandwidthDownBits}\nup: {bandwidthUpBits}", + "tooltip-format-disconnected": "disconnected", + "on-click": "swx -t -f iwctl" + }, + "network#tailscale": { + "interface": "tailscale0", + "format": "󰌆", + "tooltip-format": "{ifname}: {bandwidthUpBits} {bandwidthDownBits}", + "tooltip-format-disconnected": "disconnected", + "on-click": "doas rc-service tailscale start", + "on-click-right": "doas rc-service tailscale stop" + }, + "pulseaudio": { + "format": "{icon} {volume}%", + "format-bluetooth": "{icon} {volume}%", + "format-muted": "󰝟 {volume}%", + "format-source": "󰍬 {volume}%", + "format-source-muted": " {volume}%", + "format-icons": { + "headphones": "󰋋", + "handsfree": "󰜟", + "headset": "󰋎", + "phone": "󰏲", + "portable": "󰛵", + "car": "󰄋", + "default": ["󰕿", "󰖀", "󰕾"] + }, + "on-click-right": "pactl set-sink-mute @DEFAULT_SINK@ toggle", + "on-click": "swx -t -F '0.4' pulsemixer" + }, + "custom/mpris": { + "format": "{}", + "exec": "waybar-mpris --position --autofocus --interpolate --play 󰏤 --pause 󰲸", + "on-click": "waybar-mpris --send toggle", + "on-click-right": "waybar-mpris --send player-next", + "escape": true, + "max-width": 90, + "return-type": "json" + }, + "custom/toggl": { + "format": "󰔟 {}", + "exec": "$HOME/.config/waybar/modules/toggl.lua 2>/dev/null", + "interval": 60 + }, + "custom/todo": { + "format": "{icon} {}", + "format-icons": { + "off": "󰒲", + "on": "󰈻" + }, + "exec": "env WAYBAR_TODO_FILE=$HOME/.zk/todo.md $HOME/.config/waybar/modules/waybar-todo", + "on-click": "pkill -x -USR1 waybar-todo", + "on-click-right": "pkill -x -USR2 waybar-todo", + "escape": true, + "return-type": "json" + }, + "custom/gamma": { + "format": "{icon}", + "format-icons": { + "day": "󰱌", + "night": "󰱊" + }, + "exec-if": "pgrep wlsunset", + "exec": "env GAMMA_COMMAND='wlsunset -l $HOME_LAT -L $HOME_LON -p' $HOME/.config/waybar/modules/waybar-gamma", + "return-type": "json", + "on-click": "pkill -x -USR1 gamma", + "on-click-right": "pkill -x -HUP waybar-gamma" + }, + "custom/weather": { + "format": "{icon} {percentage}℃", + "format-icons": { + "sunny": "󰖙", + "partlycloudy": "󰖕", + "cloudy": "󰖐", + "verycloudy": "󰼯", + "fog": "󰖑", + "lightrain": "󰖗", + "heavyrain": "󰖖", + "hail": "󰖒", + "thunder": "󰖓", + "lightsnow": "󰖘", + "heavysnow": "󰼶", + "snowrain": "󰙿" + }, + "exec": "$HOME/.config/waybar/modules/weather.sh", + "interval": 600, + "return-type": "json", + "tooltip": true, + // "signal": 4, + // "on-click-right": "pkill -SIGRTMIN+5 waybar", + "on-click": "swx -t env REPORT=1 $HOME/.config/waybar/modules/weather.sh" + }, + "custom/covid": { + "format": "{icon} {}", + "format-icons": { + "gray": "󱅼", + "green": "󱎷", + "yellow": "󱎷", + "orange": "󱎷", + "red": "󱎷", + "darkred": "󱎷", + "darkdarkred": "󰯆" + }, + "exec": "$HOME/.config/waybar/modules/covid.sh", + "interval": 86400, + "tooltip": true, + "return-type": "json" + }, + // "custom/im": { + // "format": "{}", + // "exec": "printf '󱌵󱌴'", + // "exec-if": "pgrep anthywl", + // "interval": 5 + // } +} diff --git a/.config/waybar/modules/covid.sh b/.config/waybar/modules/covid.sh index 558c2c5..9f1860c 100755 --- a/.config/waybar/modules/covid.sh +++ b/.config/waybar/modules/covid.sh @@ -71,7 +71,7 @@ tooltip=" last update: ${last_update} history (${trend_arrow}): -$(awk -F, '{print $1 " " $2}' ${HISTFILE} | head -n10) +$(awk -F, '{print $1 " " $2}' ${HISTFILE} | tail -n10) " jq -nr \ diff --git a/.config/waybar/modules/gamma.go b/.config/waybar/modules/gamma.go new file mode 100644 index 0000000..2a91cdb --- /dev/null +++ b/.config/waybar/modules/gamma.go @@ -0,0 +1,76 @@ +// usage: +// go build -o waybar-gammastep gammastep.go +package main + +import ( + "encoding/json" + "log" + "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 { + log.Printf("error: %v", e) + os.Exit(1) + } + + lookup() + for { + select { + case sig := <-update: + switch sig { + case SIGUSR1: + printJson("day") + case SIGUSR2: + printJson("night") + 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 + } + log.Println(cmdEnv) + b, err := exec.Command("bash", "-c", cmdEnv).Output() + if err != nil { + log.Printf("error: %v", err) + return + } + phase := strings.TrimSpace(string(b)) + printJson(phase) +} diff --git a/.config/waybar/modules/gammastep.go b/.config/waybar/modules/gammastep.go deleted file mode 100644 index c855e1b..0000000 --- a/.config/waybar/modules/gammastep.go +++ /dev/null @@ -1,94 +0,0 @@ -// usage: -// go build -o waybar-gammastep gammastep.go -package main - -import ( - "encoding/json" - "log" - "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 { - log.Printf("error: %v", e) - 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: - log.Printf("%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": "gammastep: " + tooltip, - "text": state, - }) -} - -func lookup() { - b, err := exec.Command("gammastep", "-p").CombinedOutput() - if err != nil { - log.Printf("error: %v", err) - return - } - var period string - var fds = strings.Fields(string(b)) - for idx, f := range fds { - if f == "Period:" { - period = fds[idx+1] - break - } - } - switch period { - case "Night": - printJson("night", "night") - case "Transition": - printJson("night", "transition") - case "Daytime": - printJson("day", "day") - default: - printJson("unknown", "unknown") - } -} diff --git a/.config/waybar/modules/weather.sh b/.config/waybar/modules/weather.sh index 0b83de1..929732b 100755 --- a/.config/waybar/modules/weather.sh +++ b/.config/waybar/modules/weather.sh @@ -5,7 +5,8 @@ set -e loc=$1 if [ -z "${loc}" ]; then # use /etc/localtime - loc=$(basename "$(readlink -f /etc/localtime)") + # loc=$(basename "$(readlink -f /etc/localtime)") + loc="${HOME_LAT},${HOME_LON}" fi if [ -n "$REPORT" ]; then diff --git a/.config/waybar/style.css b/.config/waybar/style.css index 74b13af..f315b12 100644 --- a/.config/waybar/style.css +++ b/.config/waybar/style.css @@ -65,7 +65,6 @@ #idle_inhibitor, #backlight, #custom-gammastep, -#network.vpn, #network.tailscale, #custom-covid { color: #777777; @@ -76,13 +75,12 @@ #backlight:hover, #idle_inhibitor:hover, #network:hover, -#network.vpn:hover, #network.tailscale:hover, #pulseaudio:hover, #custom-mpris:hover, #custom-gammastep:hover, #custom-todo:hover { - background: red; + /* background: red; */ color: @foreground; transition-property: background; transition-duration: 0.1s; @@ -99,7 +97,7 @@ color: @foreground; background: @accentdarker; transition-property: background; - transition-duration: 0.1s; + transition-duration: 0.01s; } #workspaces button.urgent { color: @background; @@ -110,7 +108,7 @@ background: @accent; color: @foreground; transition-property: background, color; - transition-duration: 0.1s; + transition-duration: 0.01s; /* https://github.com/Alexays/Waybar/wiki/FAQ#the-workspace-buttons-have-a-strange-hover-effect */ box-shadow: inherit; @@ -119,7 +117,7 @@ #workspaces button.urgent:hover { background: @foreground; transition-property: background; - transition-duration: 0.1s; + transition-duration: 0.01s; } #window { @@ -195,17 +193,12 @@ label:focus { border-top: 1px solid @urgent; color: @dimmed; } -#network.vpn.disconnected { - border-top: 1px solid @dimmeddarker; -} -#network.vpn:not(.disconnected) { - color: @foreground; - border-top: 1px solid @color11; -} +#network.tailscale.disabled, #network.tailscale.disconnected { border-top: 1px solid @dimmeddarker; } -#network.tailscale:not(.disconnected) { +#network.tailscale.ethernet, +#network.tailscale.linked { color: @foreground; border-top: 1px solid @color14; } @@ -214,6 +207,9 @@ label:focus { border-top: 1px solid @urgent; color: @dimmed; } +#pulseaudio.bluetooth { + border-top: 1px solid @color04; +} #temperature {} #temperature.critical { @@ -224,8 +220,7 @@ label:focus { #tray {} -#idle_inhibitor { -} +#idle_inhibitor {} #idle_inhibitor.activated { color: @foreground; border-top: 1px solid @color02; @@ -233,8 +228,14 @@ label:focus { #custom-mpris { color: @foreground; +} +#custom-mpris.playing { border-top: 1px solid @color04; } +#custom-mpris.paused { + border-top: 1px solid @color04; + font-style: italic; +} #custom-toggl { color: @foreground; @@ -262,7 +263,7 @@ label:focus { color: @background; } } -#custom-gammastep.night { +#custom-gamma.night { border-top: 1px solid @color12; color: @foreground; animation-name: flash; @@ -270,11 +271,10 @@ label:focus { animation-timing-function: linear; animation-iteration-count: 1; } -#custom-gammastep.day { +#custom-gamma.day { color: @dimmed; } -#custom-gammastep.off, -#custom-gammastep.unknown { +#custom-gamma.off { border-top: 1px solid @urgent; color: @dimmed; } -- cgit 1.4.1