From d149a7704bc481f940d73a19f9a862b4bb9bd0b4 Mon Sep 17 00:00:00 2001 From: LavaDesu Date: Tue, 16 Jan 2024 01:08:18 +0700 Subject: [PATCH] eww --- modules/user/eww.nix | 2 +- overlays/eww.nix | 2 +- res/eww/eww.yuck | 40 +++++++++--------------- res/eww/scripts/active-workspace.sh | 6 ++++ res/eww/scripts/line-workspaces.sh | 43 -------------------------- res/eww/scripts/title.sh | 15 ++++++--- res/eww/scripts/workspaces.sh | 48 ++++------------------------- users/rin/default.nix | 2 +- 8 files changed, 41 insertions(+), 117 deletions(-) create mode 100755 res/eww/scripts/active-workspace.sh delete mode 100755 res/eww/scripts/line-workspaces.sh diff --git a/modules/user/eww.nix b/modules/user/eww.nix index b0a8099..2e3e58b 100644 --- a/modules/user/eww.nix +++ b/modules/user/eww.nix @@ -1,6 +1,6 @@ # Depends on bspwm { pkgs, ... }: { - home.packages = with pkgs; [ xtitle ]; + home.packages = with pkgs; [ socat ]; programs.eww = { enable = true; configDir = ../../res/eww; diff --git a/overlays/eww.nix b/overlays/eww.nix index 8d89aa1..bea0aec 100644 --- a/overlays/eww.nix +++ b/overlays/eww.nix @@ -1,5 +1,5 @@ self: super: { - eww = super.eww.overrideAttrs (old: rec { + eww = (super.eww.override { withWayland = true; }).overrideAttrs (old: rec { patches = old.patches ++ [ # Use normal scroll events instead of smooth scroll ( due to https://bugzilla.gnome.org/show_bug.cgi?id=675959 ) ./patches/eww.patch diff --git a/res/eww/eww.yuck b/res/eww/eww.yuck index a0a433b..60e0f8a 100644 --- a/res/eww/eww.yuck +++ b/res/eww/eww.yuck @@ -1,14 +1,3 @@ -(defwindow linebar :monitor 0 - :geometry (geometry :x "30px" - :y "0%" - :width "100%" - :height "2px" - :anchor "top center") - :stacking "fg" - :windowtype "dock" - :wm-ignore false - (wlinebar)) - (defwindow mainbar :monitor 0 :geometry (geometry :x "0%" :y "0%" @@ -16,8 +5,8 @@ :height "30px" :anchor "top center") :stacking "fg" - :windowtype "dock" - :wm-ignore false + :exclusive false + :focusable false (bar)) (defvar time-extended false) ; for :run-while property of below variable @@ -34,8 +23,6 @@ :run-while time-extended `date "+:%S"`) -(deflisten lworkspaces "./scripts/workspaces.sh") -(deflisten llineworkspaces "./scripts/line-workspaces.sh") (deflisten ltitle "./scripts/title.sh") (defwidget bar [] @@ -46,15 +33,19 @@ (title) (time)))) -(defwidget wlinebar [] - (eventbox :onscroll "./scripts/scroll.sh {}" - (line_workspaces))) - +(deflisten workspaces :initial "[]" "bash ~/.config/eww/scripts/workspaces.sh") +(deflisten current_workspace :initial "1" "bash ~/.config/eww/scripts/active-workspace.sh") (defwidget workspaces [] - (literal :content lworkspaces)) - -(defwidget line_workspaces [] - (literal :content llineworkspaces)) + (box :class "widget workspaces" + :halign "start" + :valign "center" + :vexpand true + :hexpand true + (for workspace in workspaces + (eventbox :cursor "hand" + (button :class "${workspace.id == current_workspace ? "focused" : (workspace.windows > 0 ? "occupied" : "empty")}" + :onclick "hyprctl dispatch workspace ${workspace.id}" + "${workspace.id == current_workspace ? "" : (workspace.windows > 0 ? "" : "")}"))))) (defwidget title [] (literal :content ltitle)) @@ -72,6 +63,5 @@ (time_extension :text {time-extended ? petimea : ""}) (label :text ptime :class "base") - (time_extension :text {time-extended ? petimeb : ""}) - ))) + (time_extension :text {time-extended ? petimeb : ""})))) diff --git a/res/eww/scripts/active-workspace.sh b/res/eww/scripts/active-workspace.sh new file mode 100755 index 0000000..cbdf971 --- /dev/null +++ b/res/eww/scripts/active-workspace.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env sh + +hyprctl monitors -j | jq '.[] | select(.focused) | .activeWorkspace.id' + +socat -u UNIX-CONNECT:/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock - | + stdbuf -o0 awk -F '>>|,' -e '/^workspace>>/ {print $2}' -e '/^focusedmon>>/ {print $3}' diff --git a/res/eww/scripts/line-workspaces.sh b/res/eww/scripts/line-workspaces.sh deleted file mode 100755 index 960c444..0000000 --- a/res/eww/scripts/line-workspaces.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env sh - -# Checks if a list ($1) contains an element ($2) -contains() { - for e in $1; do - [ "$e" -eq "$2" ] && echo 1 && return - done - echo 0 -} - -print_workspaces() { - buf="" - desktops=$(bspc query -D --names) - focused_desktop=$(bspc query -D -d focused --names) - occupied_desktops=$(bspc query -D -d .occupied --names) - urgent_desktops=$(bspc query -D -d .urgent --names) - - for d in $desktops; do - if [ "$(contains "$focused_desktop" "$d")" -eq 1 ]; then - ws=$d - class="focused" - elif [ "$(contains "$occupied_desktops" "$d")" -eq 1 ]; then - ws=$d - class="occupied" - elif [ "$(contains "$urgent_desktops" "$d")" -eq 1 ]; then - ws=$d - class="urgent" - else - ws=$d - class="empty" - fi - - buf="$buf (eventbox :cursor \"hand\" (button :class \"$class\" :onclick \"bspc desktop -f $ws\" \"\"))" - done - - echo "(box :class \"widget line-workspaces\" :halign \"start\" :valign \"center\" :vexpand true :hexpand true $buf)" -} - -# Listen to bspwm changes -print_workspaces -bspc subscribe desktop node_transfer | while read -r _ ; do - print_workspaces -done diff --git a/res/eww/scripts/title.sh b/res/eww/scripts/title.sh index 26664ba..baaffdf 100755 --- a/res/eww/scripts/title.sh +++ b/res/eww/scripts/title.sh @@ -1,10 +1,17 @@ #!/usr/bin/env sh -xtitle -s | while read -r line ; do - trunc=$(echo $line | cut -c-85) - if [ -z "$line" ]; then +out () { + if [ -z "$1" ]; then echo "" else - echo "(box :class \"widget title\" :halign \"center\" :valign \"center\" :vexpand true :hexpand true (label :text \"${trunc}\"))" + echo "(box :class \"widget title\" :halign \"center\" :valign \"center\" :vexpand true :hexpand true (label :text \"$1\"))" fi +} + +init=$(hyprctl activewindow -j | jq --raw-output .title) +out "$init" + +socat -u UNIX-CONNECT:/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock - | stdbuf -o0 awk -F '>>|,' '/^activewindow>>/{print $3}' | while read -r line ; do + trunc=$(echo $line | cut -c-85) + out "$trunc" done diff --git a/res/eww/scripts/workspaces.sh b/res/eww/scripts/workspaces.sh index 3eb9b52..a496f8f 100755 --- a/res/eww/scripts/workspaces.sh +++ b/res/eww/scripts/workspaces.sh @@ -1,47 +1,11 @@ #!/usr/bin/env sh -# Checks if a list ($1) contains an element ($2) -contains() { - for e in $1; do - [ "$e" -eq "$2" ] && echo 1 && return - done - echo 0 +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)})' } -print_workspaces() { - buf="" - desktops=$(bspc query -D --names) - focused_desktop=$(bspc query -D -d focused --names) - occupied_desktops=$(bspc query -D -d .occupied --names) - urgent_desktops=$(bspc query -D -d .urgent --names) - - for d in $desktops; do - if [ "$(contains "$focused_desktop" "$d")" -eq 1 ]; then - ws=$d - icon="" - class="focused" - elif [ "$(contains "$occupied_desktops" "$d")" -eq 1 ]; then - ws=$d - icon="" - class="occupied" - elif [ "$(contains "$urgent_desktops" "$d")" -eq 1 ]; then - ws=$d - icon="" - class="urgent" - else - ws=$d - icon="" - class="empty" - fi - - buf="$buf (eventbox :cursor \"hand\" (button :class \"$class\" :onclick \"bspc desktop -f $ws\" \"$icon\"))" - done - - echo "(box :class \"widget workspaces\" :halign \"start\" :valign \"center\" :vexpand true :hexpand true $buf)" -} - -# Listen to bspwm changes -print_workspaces -bspc subscribe desktop node_transfer | while read -r _ ; do - print_workspaces +spaces +socat -u UNIX-CONNECT:/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock - | while read -r line; do + spaces done diff --git a/users/rin/default.nix b/users/rin/default.nix index ea23526..0f726f0 100644 --- a/users/rin/default.nix +++ b/users/rin/default.nix @@ -37,7 +37,7 @@ # spicetify dunst -# eww + eww # picom # # xorg