From 26d248d971fa0e6e278f4dda5fe40ab9fbcc59a8 Mon Sep 17 00:00:00 2001 From: LavaDesu Date: Thu, 14 Apr 2022 11:51:30 +0700 Subject: [PATCH] user/eww: add linebar --- modules/user/bspwm.nix | 2 +- res/eww/eww.scss | 23 ++++++++++++++++ res/eww/eww.yuck | 19 +++++++++++++ res/eww/scripts/line-workspaces.sh | 43 ++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100755 res/eww/scripts/line-workspaces.sh diff --git a/modules/user/bspwm.nix b/modules/user/bspwm.nix index 71367c5..a17e743 100644 --- a/modules/user/bspwm.nix +++ b/modules/user/bspwm.nix @@ -13,7 +13,7 @@ ${pkgs.feh}/bin/feh --no-fehbg --bg-fill ~/Pictures/Wallpapers/current ${pkgs.procps}/bin/pkill -SIGINT eww - ${pkgs.eww}/bin/eww open mainbar + ${pkgs.eww}/bin/eww open linebar ''; }; } diff --git a/res/eww/eww.scss b/res/eww/eww.scss index 885b761..5f5b9a8 100644 --- a/res/eww/eww.scss +++ b/res/eww/eww.scss @@ -47,3 +47,26 @@ window { } } +.widget.line-workspaces { + color: transparent; + padding: 0; + border-radius: 0; + font-size: 0; + + button { + padding: 0 17px; + } + + .empty { + background-color: $background; + } + + .occupied { + background-color: $accent; + } + + .focused { + background-color: $foreground; + } +} + diff --git a/res/eww/eww.yuck b/res/eww/eww.yuck index b3d0208..6ad5ed9 100644 --- a/res/eww/eww.yuck +++ b/res/eww/eww.yuck @@ -1,3 +1,14 @@ +(defwindow linebar :monitor 0 + :geometry (geometry :x "35px" + :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%" @@ -24,6 +35,7 @@ `date "+:%S"`) (deflisten lworkspaces "./scripts/workspaces.sh") +(deflisten llineworkspaces "./scripts/line-workspaces.sh") (deflisten ltitle "./scripts/title.sh") (defwidget bar [] @@ -34,9 +46,16 @@ (title) (time)))) +(defwidget wlinebar [] + (eventbox :onscroll "./scripts/scroll.sh {}" + (line_workspaces))) + (defwidget workspaces [] (literal :content lworkspaces)) +(defwidget line_workspaces [] + (literal :content llineworkspaces)) + (defwidget title [] (literal :content ltitle)) diff --git a/res/eww/scripts/line-workspaces.sh b/res/eww/scripts/line-workspaces.sh new file mode 100755 index 0000000..960c444 --- /dev/null +++ b/res/eww/scripts/line-workspaces.sh @@ -0,0 +1,43 @@ +#!/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