From 7ff798534a6fb9c99611d18ee22757346798ef61 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Wed, 23 Aug 2023 06:47:03 +0300 Subject: eww: Add an eww configuration --- .config/eww/eww.scss | 75 ++++++++++++++++++ .config/eww/eww.yuck | 105 ++++++++++++++++++++++++++ .config/eww/scripts/active-workspace-listener | 15 ++++ .config/eww/scripts/backlight-listener | 7 ++ .config/eww/scripts/battery | 37 +++++++++ .config/eww/scripts/datetime-listener | 7 ++ .config/eww/scripts/keymap-listener | 16 ++++ .config/eww/scripts/toggle | 17 +++++ .config/eww/scripts/volume-listener | 34 +++++++++ .config/eww/scripts/wireless | 3 + .config/eww/scripts/workspace-list-listener | 28 +++++++ 11 files changed, 344 insertions(+) create mode 100644 .config/eww/eww.scss create mode 100644 .config/eww/eww.yuck create mode 100755 .config/eww/scripts/active-workspace-listener create mode 100755 .config/eww/scripts/backlight-listener create mode 100755 .config/eww/scripts/battery create mode 100755 .config/eww/scripts/datetime-listener create mode 100755 .config/eww/scripts/keymap-listener create mode 100755 .config/eww/scripts/toggle create mode 100755 .config/eww/scripts/volume-listener create mode 100755 .config/eww/scripts/wireless create mode 100755 .config/eww/scripts/workspace-list-listener diff --git a/.config/eww/eww.scss b/.config/eww/eww.scss new file mode 100644 index 0000000..0fc9f02 --- /dev/null +++ b/.config/eww/eww.scss @@ -0,0 +1,75 @@ +* { + all: unset; + font-family: 'Iosevka Smooth'; + font-size: 18px; + color: #FFF; +} + +.bar { + background-color: rgba(43, 48, 59, 0.5); + border-bottom: 3px solid rgba(100, 114, 125, 0.5); +} + +.end { + > box { + padding: 0 8px; + + > label:first-child { + padding-right: 16px; + } + } + + box:not(:last-child) > label:last-child { + margin-right: 12px; + } +} + +.cal { + $bg: rgba(43, 48, 59, 1); + $blue: #9CDCFE; + $yellow: #F0E68C; + + font-size: 28px; + + .button { + -gtk-icon-source: none; + } + + .view { + background-color: $bg; + border-radius: 4px; + border: 3px solid rgba(100, 114, 125, .5); + } + + .highlight { + color: $blue; + font-weight: bold; + } + + :indeterminate { + color: #999; + } + + :selected { + background-color: #414859; + border-radius: 4px; + } +} + +.workspaces button { + label { + padding: 0 13px; + } + + &:hover { + background: rgba(0, 0, 0, 0.2); + } + + &.active { + background: rgba(0, 0, 0, 0.4); + } + + &:hover, &.active { + box-shadow: inset 0 -3px #FAA14F; + } +} diff --git a/.config/eww/eww.yuck b/.config/eww/eww.yuck new file mode 100644 index 0000000..0257506 --- /dev/null +++ b/.config/eww/eww.yuck @@ -0,0 +1,105 @@ +;; Listeners +(deflisten active-workspace + `scripts/active-workspace-listener`) + +(deflisten workspace-list :initial "[1]" + `scripts/workspace-list-listener`) + +(deflisten datetime + `scripts/datetime-listener`) + +(deflisten brightness + `scripts/backlight-listener`) + +(deflisten volume + `scripts/volume-listener`) + +(deflisten keymap + `scripts/keymap-listener`) + +;; Pollers +(defpoll battery :interval "1s" + `scripts/battery`) + +(defpoll wireless :interval "1s" + `scripts/wireless`) + +;; Windows +(defwindow bar + :monitor 0 + :stacking "fg" + :exclusive true + :geometry (geometry :width "100%" :height "40px" :anchor "top center") + (bar)) + +(defwindow calendar-1 + :monitor 0 + :geometry (geometry :x "10%" :width "20%" :anchor "center left") + (calendar :class "cal" + :month {datetime.month - 1})) + +(defwindow calendar-2 + :monitor 0 + :geometry (geometry :width "20%" :anchor "center") + (calendar :class "cal")) + +(defwindow calendar-3 + :monitor 0 + :geometry (geometry :x "10%" :width "20%" :anchor "center right") + (calendar :class "cal" + :month {datetime.month + 1})) + +(defwidget bar [] + (centerbox + (start) + (middle) + (end))) + +(defwidget start [] + (workspaces)) + +(defwidget middle [] + (clock)) + +(defwidget end [] + (box :halign "end" + :class "end" + :space-evenly false + (keymap) + (wireless) + (brightness) + (volume) + (battery))) + +(defwidget workspaces [] + (box :class "workspaces" + :space-evenly false + (for id in workspace-list + (button :class {active-workspace == id ? "active" : ""} + :onclick `hyprctl dispatch workspace ${id}` + id)))) + +(defwidget clock [] + (box (button :onclick `scripts/toggle calendar-1 calendar-2 calendar-3` + {datetime.pretty}))) + +(defwidget wireless [] + (pair :icon "" :text wireless)) + +(defwidget keymap [] + (pair :icon "" :text keymap)) + +(defwidget brightness [] + (pair :icon "" :text brightness)) + +(defwidget volume [] + (pair :icon {volume.icon} :text {volume.percentage})) + +(defwidget battery [] + (pair :icon {battery.icon} :text {battery.percentage})) + +(defwidget pair [icon text] + (box :width 70 + :space-evenly false + (label :text icon) + (label :text text))) diff --git a/.config/eww/scripts/active-workspace-listener b/.config/eww/scripts/active-workspace-listener new file mode 100755 index 0000000..09a8298 --- /dev/null +++ b/.config/eww/scripts/active-workspace-listener @@ -0,0 +1,15 @@ +#!/bin/sh + +set -e + +readonly IPC=/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock + +hyprctl -j activeworkspace | jq -r '.name' +socat -u UNIX-CONNECT:"$IPC" - \ + | stdbuf -oL grep '^workspace>>' \ + | while IFS= read -r line + do + IFS='>>' + set -- $line + echo $3 + done diff --git a/.config/eww/scripts/backlight-listener b/.config/eww/scripts/backlight-listener new file mode 100755 index 0000000..82b5a55 --- /dev/null +++ b/.config/eww/scripts/backlight-listener @@ -0,0 +1,7 @@ +#!/bin/sh + +while : +do + lux | xargs printf '%g%%\n' + inotifywait -qqe modify /sys/class/backlight/*/brightness +done diff --git a/.config/eww/scripts/battery b/.config/eww/scripts/battery new file mode 100755 index 0000000..0db4adb --- /dev/null +++ b/.config/eww/scripts/battery @@ -0,0 +1,37 @@ +#!/bin/sh + +set -e + +acpi | awk ' + { + sub(/Battery [0-9]+: /, "") + FS = "[, ]+" + n = NF + sub(/%$/, "", $n) + printf "percentage=%d%%\n", $n + printf "icon=" + $n = int($n) + if ($1 == "Charging") + print "󰂄" + else if ($n >= 90) + print "󰁹" + else if ($n >= 80) + print "󰂂" + else if ($n >= 70) + print "󰂁" + else if ($n >= 60) + print "󰁿" + else if ($n >= 50) + print "󰁾" + else if ($n >= 40) + print "󰁽" + else if ($n >= 30) + print "󰁼" + else if ($n >= 20) + print "󰁻" + else if ($n >= 10) + print "󰁺" + else + print "󰂎" + }' \ + | jo diff --git a/.config/eww/scripts/datetime-listener b/.config/eww/scripts/datetime-listener new file mode 100755 index 0000000..c21dd02 --- /dev/null +++ b/.config/eww/scripts/datetime-listener @@ -0,0 +1,7 @@ +#!/bin/sh + +while : +do + date +'pretty=%d %B %Y (%A) — %T %Z%nmonth=%m' | jo + date +%s.%N | dc -e "? d 1 + 1 / r - p" | xargs sleep +done diff --git a/.config/eww/scripts/keymap-listener b/.config/eww/scripts/keymap-listener new file mode 100755 index 0000000..a9666aa --- /dev/null +++ b/.config/eww/scripts/keymap-listener @@ -0,0 +1,16 @@ +#!/bin/sh + +set -e + +readonly IPC=/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock + +hyprctl devices | sed -En '/Keyboard at/ { + :loop + n + /active keymap:/! b loop + s/.*active keymap: //p + q +} +' + +socat -u UNIX-CONNECT:"$IPC" - | sed -En 's/^activelayout>>[^,]+,//p' diff --git a/.config/eww/scripts/toggle b/.config/eww/scripts/toggle new file mode 100755 index 0000000..8ce7bcc --- /dev/null +++ b/.config/eww/scripts/toggle @@ -0,0 +1,17 @@ +#!/bin/sh + +set -e + +# Open a file descriptor for writing to create the lock if it doesn’t exist. We +# need a lock because of race-conditions that could occur if you spam a toggle +# over and over. +exec 3>"${XDG_RUNTIME_DIR:-/run/user/`id -u`}/eww-toggle.lock" +flock 3 + +for arg in "$@"; do + { + eww windows | grep -q "^\\*$arg$" && f=close || f=open + eww $f "$arg" + } & +done +wait diff --git a/.config/eww/scripts/volume-listener b/.config/eww/scripts/volume-listener new file mode 100755 index 0000000..9c0368c --- /dev/null +++ b/.config/eww/scripts/volume-listener @@ -0,0 +1,34 @@ +#!/bin/sh + +stdbuf -oL amixer events \ + | stdbuf -oL sed 's/event value: //' \ + | while IFS= read -r line + do + IFS='=,' + set -- $line + x=${6#\'} + x=${x%\'} + case "$x" in + 'Master Playback'*) + wpctl get-volume @DEFAULT_AUDIO_SINK@ \ + | awk ' + /MUTED/ { + print "icon=" + print "percentage=Muted" + exit + } + { + printf "icon=" + if ($2 < 0.33) + print "" + else if ($2 <= 0.66) + print "" + else + print "" + printf "percentage=%s%d%%\n", pad, $2 * 100 + } + ' \ + | jo + ;; + esac + done diff --git a/.config/eww/scripts/wireless b/.config/eww/scripts/wireless new file mode 100755 index 0000000..4221fe5 --- /dev/null +++ b/.config/eww/scripts/wireless @@ -0,0 +1,3 @@ +#!/bin/sh + +sudo wpa_cli status | sed -n 's/^ssid=//p' diff --git a/.config/eww/scripts/workspace-list-listener b/.config/eww/scripts/workspace-list-listener new file mode 100755 index 0000000..2024509 --- /dev/null +++ b/.config/eww/scripts/workspace-list-listener @@ -0,0 +1,28 @@ +#!/bin/sh + +set -e + +readonly IPC=/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock + +spaces="`hyprctl -j workspaces | jq -r 'sort_by(.id) | .[] | .name'`" +jo -a $spaces + +socat -u UNIX-CONNECT:"$IPC" - \ + | stdbuf -oL grep -E '^(create|destroy)workspace>>' \ + | while IFS= read -r line + do + oifs="$IFS" + IFS='>>' + set -- $line + IFS="$oifs" + + case "$1" in + c*) + spaces="`printf '%s\n%s\n' "$spaces" $3 | sort -V`" + ;; + d*) + spaces="`echo "$spaces" | grep -v "^$3$"`" + ;; + esac + jo -a $spaces + done -- cgit v1.2.3