From 08e0136240b7768724bc183e150953136798e255 Mon Sep 17 00:00:00 2001 From: Erwin Boskma Date: Tue, 4 Jul 2023 20:24:29 +0200 Subject: [PATCH] Initial eww config --- home-manager/modules/eww/config/eww.scss | 221 +++++++++++++++++ home-manager/modules/eww/config/eww.yuck | 233 ++++++++++++++++++ .../modules/eww/config/scripts/workspaces.nu | 51 ++++ 3 files changed, 505 insertions(+) create mode 100644 home-manager/modules/eww/config/eww.scss create mode 100644 home-manager/modules/eww/config/eww.yuck create mode 100755 home-manager/modules/eww/config/scripts/workspaces.nu diff --git a/home-manager/modules/eww/config/eww.scss b/home-manager/modules/eww/config/eww.scss new file mode 100644 index 0000000..d5bcac4 --- /dev/null +++ b/home-manager/modules/eww/config/eww.scss @@ -0,0 +1,221 @@ +* { + all: unset; +} + +// Color variables +$background: #1a1b26; +$foreground: #a9b1d6; +$urgent: #c9545d; + +$black: #24283b; +$gray: #565f89; +$red: #f7768e; +$green: #73daca; +$yellow: #e0af68; +$blue: #7aa2f7; +$magenta: #bb9af7; +$cyan: #7dcfff; +$navy: #285577; +$white: $foreground; + +// EWW BAR +.eww_bar { + background-color: $background; + padding: 0.3rem; + font-family: "Iosevka Nerd Font"; + font-weight: bold; + color: $foreground; +} + +// Workspaces +.workspaces { + font-family: "Iosevka Nerd Font"; + padding: 0 1rem 0 0; + background-color: $background; + border-radius: 5px; + + .ws { + margin: 0; + padding: 0 1rem; + border-top: 2px solid transparent; + + &:hover { + background-color: $gray; + } + + &.focused { + border-color: #4c7899; + background-color: $navy; + color: #ffffff; + } + + &.urgent { + border-color: $urgent; + color: $urgent; + } + } +} + +tooltip { + background-color: $background; + font-size: 1.2rem; +} + +.ha-now-playing { + font-family: "Iosevka Nerd Font"; + font-size: 1.2rem; + padding: 0; + + .icon { + color: $magenta; + } +} + +// Control Panel +.control { + padding: 0 0.5rem; + font-family: "Iosevka Nerd Font"; + font-size: 1.2em; + border-radius: 5px; +} +.icon { + font-size: 2rem; + margin-right: 1rem; + + &.small { + font-size: 1rem; + margin-right: 0.5rem; + } +} + +.memory { + margin: 0 0.5rem; + + .icon { + color: $blue; + } +} + +.cpu { + margin: 0 0.5rem; + + .icon { + color: $green; + } +} + +.temperature { + margin: 0 0.5rem; + .icon { + color: $red; + } +} + +.volume { + .icon { + color: $yellow; + } +} +scale { + trough { + // all: unset; + background-color: $black; + border-radius: 5px; + min-width: 80px; + min-height: 10px; + margin: 0 0.3rem 0 0.3rem; + + highlight { + background-color: $yellow; + border-radius: 5px; + } + } +} +.bribar trough highlight { + background-color: $yellow; + border-radius: 5px; +} +.volbar trough highlight { + background-color: $green; + border-radius: 5px; +} + +// Clock +.time { + font-family: "Iosevka Nerd Font"; + font-size: 1.2rem; + border-radius: 5px; + padding: 0.7rem 0 0.5rem 0; + margin: 0 0.5rem; + + .icon { + color: $red; + } +} + +// Calendar +.cal-box { + background-color: $black; + font-family: "Iosevka Nerd Font"; + font-size: 1rem; + + .cal-inner-box { + padding: 1rem 1rem 0.2rem; + + .cal { + &.highlight { + padding: 10rem; + } + + padding: 0.8rem 0.25rem 0rem; + margin-left: 10px; + } + } +} + +calendar:selected { + color: $blue; +} + +calendar.header { + color: $blue; +} + +calendar.button { + color: $magenta; +} + +calendar.highlight { + color: $magenta; +} + +calendar:indeterminate { + color: $background; +} + +// Powermenu +.powermenu { + font-family: "Iosevka Nerd Font"; + font-size: 1.5rem; +} +.button-reboot, +.button-hibernate, +.button-quit, +.button-shutdown { + // padding: 0.5rem 0.2rem 0.3rem 0.2rem; + padding: 0.3rem 0.7rem; + font-size: 2rem; +} +.button-shutdown { + // margin-bottom: 0.5rem; + color: $red; +} +.button-reboot { + color: $yellow; +} +.button-quit { + color: $green; +} +.button-hibernate { + color: $blue; +} diff --git a/home-manager/modules/eww/config/eww.yuck b/home-manager/modules/eww/config/eww.yuck new file mode 100644 index 0000000..76ed5b5 --- /dev/null +++ b/home-manager/modules/eww/config/eww.yuck @@ -0,0 +1,233 @@ +;; Variables +(defvar power false) +(defvar show-date false) +(defvar show-volume false) +(defvar volume-muted false) + +(defvar ha-now-playing "/nix/store/n3364y7amwgjs94whqapvdvp9d7d3zrh-ha-now-playing-0.5.0/bin/ha-now-playing --host home.datarift.nl --token-file /run/secrets/ha_now_playing_token --entity media_player.sonos_woonkamer") +;; Polls +(defpoll volume-current + :initial 0 + :interval "1s" + `pamedia get -b`) + +;; Listen +(deflisten sonos-now-playing + :initial "{\"muted\":false,\"text\":\"\"}" + `/nix/store/n3364y7amwgjs94whqapvdvp9d7d3zrh-ha-now-playing-0.5.0/bin/ha-now-playing --host home.datarift.nl --token-file /run/secrets/ha_now_playing_token --entity media_player.sonos_woonkamer`) + +(deflisten wm-info + :initial "{\"workspaces\":[],\"mode\":\"default\",\"title\":\"\"}" + `scripts/workspaces.nu`) + +;; Widgets +(defwidget mode [] + (box :space-evenly false + :spacing 2 + :class "mode" + (label :class "icon" + :visible {wm-info.mode != "default"} + :text "󰁌") + (label :visible {wm-info.mode != "default"} + :text {wm-info.mode}))) + +(defwidget workspaces [] + (box :space-evenly false + :spacing 5 + :class "workspaces" + (box :space-evenly false + :spacing 0 + (for ws in {wm-info.workspaces} + (button :onclick "swaymsg workspace ${ws.name}" + :class "ws${ws.visible ? ' visible' : ''}${ws.focused ? ' focused' : ''}${ws.urgent ? ' urgent' : ''}" + (box :space-evenly false + :spacing 2 + (label :class "icon small" + :visible {!ws.focused && !ws.urgent} + :text "") + (label :class "icon small" + :visible {ws.focused} + :text "") + (label :class "icon small" + :visible {ws.urgent} + :text "") + (label :text "${ws.name}")))) + (mode)))) + +;; (defwidget workspaces [] +;; (box :space-evenly false +;; :spacing 5 +;; :class "workspaces" +;; (label :text {wm-info.title}))) + +(defwidget ha-now-playing [] + (eventbox :onclick "${ha-now-playing} play-pause" + :onrightclick "${ha-now-playing} ${sonos-now-playing.muted ? 'unmute' : 'mute'}" + :onscroll "${ha-now-playing} volume-{}" + (box :class "ha-now-playing" + :space-evenly false + :spacing 2 + (label :class "icon" + :text "󰐹") + (label :text {sonos-now-playing.text})))) + +(defwidget date-time [] + (eventbox :onclick "${EWW_CMD} update show-date=${!show-date}" + :cursor "pointer" + (box :class "time" + :space-evenly false + :spacing 2 + (label :visible {!show-date} + :class "icon" + :text "󰅐") + (label :visible {!show-date} + :text "${formattime(EWW_TIME, '%H:%M:%S')}") + (label :visible show-date + :class "icon" + :text "󰃭") + (label :visible show-date + :text "${formattime(EWW_TIME, '%a, %d %b %Y')}")))) + + +(defwidget memory [] + (box :class "memory" + :space-evenly false + :spacing 2 + :tooltip "${round(EWW_RAM.used_mem / 1024 / 1024 / 1024, 2)}GiB / ${round(EWW_RAM.total_mem / 1024 / 1024 / 1024, 2)}GiB used" + (label :class "icon" + :text "󰍛") + (label :text "${round(EWW_RAM.used_mem_perc, 1)}%"))) + +(defwidget cpu [] + (box :class "cpu" + :space-evenly false + :spacing 2 + :tooltip {jq(EWW_CPU, "reduce .cores[] as $core (\"\"; . + $core.core + \": \" + ($core.usage | tostring) + \"%\\n\") | {tooltip:.}").tooltip} + (label :class "icon" + :text "󰻠") + (label :text "${round(EWW_CPU.avg, 2)}%"))) + +(defwidget temperature [] + (box :class "temperature" + :space-evenly false + :spacing 2 + (label :class "icon" + :text "󰔏") + (label :text "${round(EWW_TEMPS.ZENPOWER_TDIE, 1)}°C"))) + +(defwidget volume [] + (eventbox :onhover "${EWW_CMD} update show-volume=true" + :onhoverlost "${EWW_CMD} update show-volume=false" + :onclick "pamedia mute" + :onmiddleclick "helvum" + :onrightclick "pavucontrol" + :tooltip "Volume: ${volume-current}%" + :cursor "pointer" + (box :space-evenly false + :spacing 5 + :class "volume" + (revealer :transition "slideleft" + :reveal show-volume + :duration "550ms" + (scale :class "volume-bar" + :flipped true + :value volume-current + :orientation "h" + :min 0 + :max 101 + :round-digits 0 + :tooltip "Volume: ${volume-current}%" + :onchange "pamedia set {}")) + (label :class "icon" + :visible {!volume-muted} + :text "󰕾") + (label :class "icon" + :visible volume-muted + :text "󰸈")))) + +(defwidget control [] + (box :class "control" + :space-evenly false + :spacing 2 + (volume) + (cpu) + (temperature) + (memory))) + +(defwidget power [] + (eventbox :onhover "${EWW_CMD} update power=true" + :onhoverlost "${EWW_CMD} update power=false" + :cursor "pointer" + (box :space-evenly false + :class "powermenu" + (revealer :transition "slideleft" + :reveal power + :duration "550ms" + (box :orientation "h" + :space-evenly false + + (button :class "button-reboot" + :tooltip "Reboot" + :onclick "systemctl reboot" "󰜉") + + (button :class "button-quit" + :tooltip "Logout" + :onclick "i3-msg exit" "󰗼") + + (button :class "button-hibernate" + :tooltip "Hibernate" + :onclick "systemctl hibernate" "󰤄"))) + + (button :class "button-shutdown" + :tooltip "Shutdown" + :onclick "systemctl shutdown" "󰐥")))) + +(defwidget title [] + (label :text {wm-info.title})) + +(defwidget left [] + (box :orientation "h" + :halign "start" + (workspaces) + (ha-now-playing))) + +(defwidget right [] + (box :orientation "h" + :space-evenly false + :halign "end" + (date-time) + (power))) + +(defwidget end [] + (box :orientation "h" + :halign "end" + :space-evenly false + (control) + (right))) + +(defwidget bar [] + (box :class "eww_bar" + :orientation "h" + :hexpand false + :vexpand false + (centerbox + (left) + (title) + (end)))) + +;; Bar windows +(defwindow bar-x11 + :geometry (geometry :x "0" + :y "0" + :width "100%" + :height "47px" + :anchor "top center") + :stacking "fg" + :monitor 0 + :reserve (struts :distance "47px" + :side "top") + :wm-ignore false + :hexpand false + :vexpand false + :exclusive true + (bar)) diff --git a/home-manager/modules/eww/config/scripts/workspaces.nu b/home-manager/modules/eww/config/scripts/workspaces.nu new file mode 100755 index 0000000..2178386 --- /dev/null +++ b/home-manager/modules/eww/config/scripts/workspaces.nu @@ -0,0 +1,51 @@ +#!/usr/bin/env nu + +module ipc { + +def ipcCmd [] { +if (is-sway) { + "swaymsg" +} else if (is-i3) { + "i3-msg" +} else { + error make { msg: "This script only supports sway or i3" } +} +} + +def is-sway [] { + ("SWAYSOCK" in $env) +} + +def is-i3 [] { + ("I3SOCK" in $env) +} + +export def ipc-cmd [--raw, ...parameters: string] { + let result = (run-external --redirect-stdout (ipcCmd) $parameters) + if $raw { + $result + } else { + $result | from json + } +} +} + +use ipc ipc-cmd + +def workspaces [] { + let workspaces = (ipc-cmd "-t" "get_workspaces" | select id name focused urgent visible) + let mode = (ipc-cmd "-t" "get_binding_state") + let focused_title = ((ipc-cmd --raw "-t" "get_tree") | jaq -r '.. | (.nodes? // empty)[] | select(.focused) | {name}' | from json) + + { workspaces: $workspaces, mode: $mode.name, title: $focused_title.name } +} + +def main [] { + print (workspaces | to json -r) + loop { + ipc-cmd --raw '-t' 'subscribe' '["workspace","window","mode"]' out+err> /dev/null + try { + print (workspaces | to json -r) + } + } +} \ No newline at end of file