From 97147c08bf29d9be534cb6ef5020de6828115f4f Mon Sep 17 00:00:00 2001 From: Evie Litherland-Smith Date: Tue, 11 Apr 2023 17:00:09 +0100 Subject: [PATCH] Add EWW as status bar with initial config --- nixos/H0615-elitherl.nix | 2 +- nixos/home-manager/env/config/eww/eww.scss | 56 ++++++++++++++ nixos/home-manager/env/config/eww/eww.yuck | 77 +++++++++++++++++++ .../eww/scripts/change-active-workspace | 21 +++++ .../config/eww/scripts/get-active-workspace | 3 + .../env/config/eww/scripts/get-workspaces | 11 +++ .../env/config/eww/scripts/getram | 2 + .../env/config/eww/scripts/getvol | 2 + .../env/config/waybar/macchiato.css | 37 +++++++++ nixos/home-manager/env/hyprland.nix | 7 ++ nixos/home-manager/ukaea-elitherl.nix | 1 + 11 files changed, 218 insertions(+), 1 deletion(-) create mode 100644 nixos/home-manager/env/config/eww/eww.scss create mode 100644 nixos/home-manager/env/config/eww/eww.yuck create mode 100644 nixos/home-manager/env/config/eww/scripts/change-active-workspace create mode 100644 nixos/home-manager/env/config/eww/scripts/get-active-workspace create mode 100644 nixos/home-manager/env/config/eww/scripts/get-workspaces create mode 100644 nixos/home-manager/env/config/eww/scripts/getram create mode 100644 nixos/home-manager/env/config/eww/scripts/getvol create mode 100644 nixos/home-manager/env/config/waybar/macchiato.css diff --git a/nixos/H0615-elitherl.nix b/nixos/H0615-elitherl.nix index 775887de..8ab931cb 100644 --- a/nixos/H0615-elitherl.nix +++ b/nixos/H0615-elitherl.nix @@ -4,7 +4,7 @@ imports = [ ./common.nix ./locales/en_GB.nix - ./desktop/xfce-bspwm.nix + ./desktop/hyprland.nix ]; networking.hostName = "H0615"; # Define your hostname. diff --git a/nixos/home-manager/env/config/eww/eww.scss b/nixos/home-manager/env/config/eww/eww.scss new file mode 100644 index 00000000..633ed485 --- /dev/null +++ b/nixos/home-manager/env/config/eww/eww.scss @@ -0,0 +1,56 @@ +* { + all: unset; //Unsets everything so you can style everything from scratch +} + +//Global Styles +.bar { + background-color: #3a3a3a; + color: #b0b4bc; + padding: 10px; +} + +// Styles on classes (see eww.yuck for more information) + +.sidestuff slider { + all: unset; + color: #ffd5cd; +} + +.metric scale trough highlight { + all: unset; + background-color: #D35D6E; + color: #000000; + border-radius: 10px; +} +.metric scale trough { + all: unset; + background-color: #4e4e4e; + border-radius: 50px; + min-height: 3px; + min-width: 50px; + margin-left: 10px; + margin-right: 20px; +} +.metric scale trough highlight { + all: unset; + background-color: #D35D6E; + color: #000000; + border-radius: 10px; +} +.metric scale trough { + all: unset; + background-color: #4e4e4e; + border-radius: 50px; + min-height: 3px; + min-width: 50px; + margin-left: 10px; + margin-right: 20px; +} +.label-ram { + font-size: large; +} +.workspaces button:hover { + color: #D35D6E; +} + +// vim:ft=scss diff --git a/nixos/home-manager/env/config/eww/eww.yuck b/nixos/home-manager/env/config/eww/eww.yuck new file mode 100644 index 00000000..4a5b4a59 --- /dev/null +++ b/nixos/home-manager/env/config/eww/eww.yuck @@ -0,0 +1,77 @@ +(defwidget bar [] + (centerbox :orientation "h" + (workspaces) + (music) + (sidestuff))) + +(defwidget sidestuff [] + (box :class "sidestuff" :orientation "h" :space-evenly false :halign "end" + (metric :label "󰕾 " + :value volume + :onchange "amixer -D pulse sset Master {}%") + (metric :label "󰍛 " + :value {EWW_RAM.used_mem_perc} + :onchange "") + (metric :label " " + :value {round((1 - (EWW_DISK["/"].free / EWW_DISK["/"].total)) * 100, 0)} + :onchange "") + time)) + +(deflisten workspaces :initial "[]" "bash ~/.config/eww/scripts/get-workspaces") +(deflisten current_workspace :initial "1" "bash ~/.config/eww/scripts/get-active-workspace") +(defwidget workspaces [] + (eventbox :onscroll "bash ~/.config/eww/scripts/change-active-workspace {} ${current_workspace}" :class "workspaces-widget" + (box :space-evenly true + (label :text "${workspaces}${current_workspace}" :visible false) + (for workspace in workspaces + (eventbox :onclick "hyprctl dispatch workspace ${workspace.id}" + (box :class "workspace-entry ${workspace.id == current_workspace ? "current" : ""} ${workspace.windows > 0 ? "occupied" : "empty"}" + (label :text "${workspace.id}") + ) + ) + ) + ) + ) + ) + +(defwidget music [] + (box :class "music" + :orientation "h" + :space-evenly false + :halign "center" + {music != "" ? "🎵${music}" : ""})) + + +(defwidget metric [label value onchange] + (box :orientation "h" + :class "metric" + :space-evenly false + (box :class "label" label) + (scale :min 0 + :max 101 + :active {onchange != ""} + :value value + :onchange onchange))) + + + +(deflisten music :initial "" + "playerctl --follow metadata --format '{{ artist }} - {{ title }}' || true") + +(defpoll volume :interval "1s" + "scripts/getvol") + +(defpoll time :interval "10s" + "date '+%H:%M %b %d, %Y'") + +(defwindow bar + :monitor 0 + :windowtype "dock" + :geometry (geometry :x "0%" + :y "0%" + :width "90%" + :anchor "top center") + :reserve (struts :side "top" :distance "4%") + (bar)) + +;; vim:ft=yuck diff --git a/nixos/home-manager/env/config/eww/scripts/change-active-workspace b/nixos/home-manager/env/config/eww/scripts/change-active-workspace new file mode 100644 index 00000000..3a43646e --- /dev/null +++ b/nixos/home-manager/env/config/eww/scripts/change-active-workspace @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +function clamp { + min=$1 + max=$2 + val=$3 + python -c "print(max($min, min($val, $max)))" +} + +direction=$1 +current=$2 +if test "$direction" = "down" +then + target=$(clamp 1 10 $(($current+1))) + echo "jumping to $target" + hyprctl dispatch workspace $target +elif test "$direction" = "up" +then + target=$(clamp 1 10 $(($current-1))) + echo "jumping to $target" + hyprctl dispatch workspace $target +fi diff --git a/nixos/home-manager/env/config/eww/scripts/get-active-workspace b/nixos/home-manager/env/config/eww/scripts/get-active-workspace new file mode 100644 index 00000000..0ff4daf2 --- /dev/null +++ b/nixos/home-manager/env/config/eww/scripts/get-active-workspace @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +hyprctl monitors -j | jq --raw-output .[0].activeWorkspace.id +socat -u UNIX-CONNECT:/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock - | stdbuf -o0 grep '^workspace>>' | stdbuf -o0 awk -F '>>|,' '{print $2}' diff --git a/nixos/home-manager/env/config/eww/scripts/get-workspaces b/nixos/home-manager/env/config/eww/scripts/get-workspaces new file mode 100644 index 00000000..cdde821b --- /dev/null +++ b/nixos/home-manager/env/config/eww/scripts/get-workspaces @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +spaces (){ + WORKSPACE_WINDOWS=$(hyprctl workspaces -j | jq 'map({key: .id | tostring, value: .windows}) | from_entries') + seq 1 10 | jq --argjson windows "${WORKSPACE_WINDOWS}" --slurp -Mc 'map(tostring) | map({id: ., windows: ($windows[.]//0)})' +} + +spaces +socat -u UNIX-CONNECT:/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock - | while read -r line; do + spaces +done diff --git a/nixos/home-manager/env/config/eww/scripts/getram b/nixos/home-manager/env/config/eww/scripts/getram new file mode 100644 index 00000000..791a5a57 --- /dev/null +++ b/nixos/home-manager/env/config/eww/scripts/getram @@ -0,0 +1,2 @@ +#!/bin/sh +printf "%.0f\n" $(free -m | grep Mem | awk '{print ($3/$2)*100}') diff --git a/nixos/home-manager/env/config/eww/scripts/getvol b/nixos/home-manager/env/config/eww/scripts/getvol new file mode 100644 index 00000000..6a95077d --- /dev/null +++ b/nixos/home-manager/env/config/eww/scripts/getvol @@ -0,0 +1,2 @@ +#!/bin/sh +amixer -D pulse sget Master | grep 'Left:' | awk -F'[][]' '{ print $2 }' | tr -d '%' | head -1 diff --git a/nixos/home-manager/env/config/waybar/macchiato.css b/nixos/home-manager/env/config/waybar/macchiato.css new file mode 100644 index 00000000..12bc89c1 --- /dev/null +++ b/nixos/home-manager/env/config/waybar/macchiato.css @@ -0,0 +1,37 @@ +/* +* +* Catppuccin Mocha palette +* Maintainer: rubyowo +* +*/ + +@define-color base #24273a; +@define-color mantle #1e2030; +@define-color crust #181926; + +@define-color text #cad3f5; +@define-color subtext0 #a5adcb; +@define-color subtext1 #b8c0e0; + +@define-color surface0 #363a4f; +@define-color surface1 #494d64; +@define-color surface2 #5b6078; + +@define-color overlay0 #6e738d; +@define-color overlay1 #8087a2; +@define-color overlay2 #939ab7; + +@define-color blue #8aadf4; +@define-color lavender #b7bdf8; +@define-color sapphire #7dc4e4; +@define-color sky #91d7e3; +@define-color teal #8bd5ca; +@define-color green #a6da95; +@define-color yellow #eed49f; +@define-color peach #f5a97f; +@define-color maroon #ee99a0; +@define-color red #ed8796; +@define-color mauve #c6a0f6; +@define-color pink #f5bde6; +@define-color flamingo #f0c6c6; +@define-color rosewater #f4dbd6; diff --git a/nixos/home-manager/env/hyprland.nix b/nixos/home-manager/env/hyprland.nix index fdaf601e..e713d20e 100644 --- a/nixos/home-manager/env/hyprland.nix +++ b/nixos/home-manager/env/hyprland.nix @@ -18,6 +18,9 @@ in wofi dolphin swaybg + # For EWW + jq + socat ]; wayland.windowManager.hyprland = { enable = true; @@ -30,4 +33,8 @@ in + "\n" + builtins.readFile (./config/hypr/hyprland.conf); }; + programs.eww = { + enable = true; + configDir = ./config/eww; + }; } diff --git a/nixos/home-manager/ukaea-elitherl.nix b/nixos/home-manager/ukaea-elitherl.nix index 248ba8bf..ffed84ea 100644 --- a/nixos/home-manager/ukaea-elitherl.nix +++ b/nixos/home-manager/ukaea-elitherl.nix @@ -2,6 +2,7 @@ imports = [ ./common.nix ./env + ./env/hyprland.nix ./packages ./packages/gui ./packages/gui/ukaea.nix