Somewhat functional hyprland workspace indicator

This commit is contained in:
Daniel Flanagan 2024-03-28 16:47:42 -05:00
parent 9fba494811
commit 7f6894bf39
6 changed files with 56 additions and 58 deletions

View file

@ -332,22 +332,6 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs-next": {
"locked": {
"lastModified": 1711646189,
"narHash": "sha256-+fnMLzJhiLAY/2ACsWPnLkstUpR0PKEVjlsCWH2aFGg=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "5d44454602e6964b5e582edc81098aac06f8ecbe",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "staging-next",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-stable": { "nixpkgs-stable": {
"locked": { "locked": {
"lastModified": 1711124224, "lastModified": 1711124224,
@ -461,7 +445,6 @@
"home-manager": "home-manager", "home-manager": "home-manager",
"hyprland": "hyprland", "hyprland": "hyprland",
"nixpkgs": "nixpkgs_3", "nixpkgs": "nixpkgs_3",
"nixpkgs-next": "nixpkgs-next",
"nixpkgs-stable": "nixpkgs-stable", "nixpkgs-stable": "nixpkgs-stable",
"nixpkgsForIosevka": "nixpkgsForIosevka", "nixpkgsForIosevka": "nixpkgsForIosevka",
"pre-commit-hooks": "pre-commit-hooks", "pre-commit-hooks": "pre-commit-hooks",

View file

@ -4,7 +4,7 @@
nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-23.11"; nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-23.11";
nixpkgs-next.url = "github:nixos/nixpkgs/staging-next"; # nixpkgs-next.url = "github:nixos/nixpkgs/staging-next";
# I have this as a separate input so I don't rebuild the font every time I # I have this as a separate input so I don't rebuild the font every time I
# want to upgrade nixpkgs # want to upgrade nixpkgs
@ -48,7 +48,7 @@
outputs = { outputs = {
self, self,
nixpkgs, nixpkgs,
nixpkgs-next, # nixpkgs-next,
nixpkgsForIosevka, nixpkgsForIosevka,
home-manager, home-manager,
hardware, hardware,
@ -147,7 +147,7 @@
}) (import ./nixos)) }) (import ./nixos))
// { // {
# TODO: stabilize "appliance"-type hosts on stable nixpkgs ASAP to avoid breakages # TODO: stabilize "appliance"-type hosts on stable nixpkgs ASAP to avoid breakages
beefcake = nixpkgs-next.lib.nixosSystem { beefcake = nixpkgs.lib.nixosSystem {
system = "x86_64-linux"; system = "x86_64-linux";
specialArgs = { specialArgs = {
inherit inputs outputs api-lyte-dev hardware; inherit inputs outputs api-lyte-dev hardware;

View file

@ -93,6 +93,13 @@ $rosewater: #f5e0dc;
color: $text; color: $text;
} }
.workspace.occupied.active,
.workspace.active {
color: $base;
background-color: $subtext1;
}
.workspace.occupied.focused.active,
.workspace.occupied.focused, .workspace.occupied.focused,
.workspace.focused { .workspace.focused {
color: $base; color: $base;

View file

@ -49,6 +49,7 @@
) )
{" ${round(EWW_CPU["avg"], 0)}%"} {" ${round(EWW_CPU["avg"], 0)}%"}
{" ${round(EWW_RAM["used_mem_perc"], 0)}%"} {" ${round(EWW_RAM["used_mem_perc"], 0)}%"}
; TODO: have these "widgets" be omitted entirely instead of just empty strings
{(showBrightness == "true") ? (" ${brightness}%") : ""} {(showBrightness == "true") ? (" ${brightness}%") : ""}
{(showBattery == "true") ? ("󱊣 ${EWW_BATTERY["BAT1"]["capacity"]}% (${batteryTime})") : ""} {(showBattery == "true") ? ("󱊣 ${EWW_BATTERY["BAT1"]["capacity"]}% (${batteryTime})") : ""}
(box :orientation "h" :space-evenly false :halign "start" :valign "center" (workspaces)) (box :orientation "h" :space-evenly false :halign "start" :valign "center" (workspaces))

View file

@ -1,49 +1,52 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# TODO: we're mixing bash arrays and not-arrays - get it together
#define icons for workspaces 1-9 #define icons for workspaces 1-9
ic=(1 2 3 4 5 6 7 8 9) ic=(1 2 3 4 5 6 7 8 9)
#initial check for occupied workspaces occ() { export o"$1"="occupied"; }
for num in $(hyprctl workspaces | grep ID | sed 's/()/(1)/g' | awk 'NR>1{print $1}' RS='(' FS=')'); do unocc() { unset -v o"$1"; }
export o"$num"=" occupied"
done
#initial check for focused workspace active() { export a"$1"="active"; }
for num in $(hyprctl monitors | grep active | sed 's/()/(1)/g' | awk 'NR>1{print $1}' RS='(' FS=')'); do unactive() { unset -v a"$1"; }
export f"$num"=" focused"
export fnum=f"$num" focus() { export f"$1"="focused"; }
done unfocus() { unset -v f"$1"; }
workspaces() { workspaces() {
if [[ ${1:0:9} == "workspace" ]]; then for num in 1 2 3 4 5 6 7 8 9; do
# set focused workspace unfocus $num
unset -v "$fnum" unactive $num
num=${1:11} unocc $num
export f"$num"=" focused" done
export fnum=f"$num"
elif [[ ${1:0:15} == "createworkspace" ]]; then # TODO: avoid recomputing these each time and actually listen to the events?
# set occupied workspace mons_json=$(hyprctl monitors -j)
num=${1:17} for num in $(hyprctl workspaces -j | jq -r '.[] | select(.windows > 0) | .id'); do
export o"$num"=" occupied" occ "$num"
export f"$num"=" focused" done
elif [[ ${1:0:16} == "destroyworkspace" ]]; then
# unset occupied workspace for num in $(echo "$mons_json" | jq -r '.[].activeWorkspace.id'); do
num=${1:18} active "$num"
unset -v o"$num" f"$num" done
fi
for num in $(echo "$mons_json" | jq -r '.[] | select(.focused) | .activeWorkspace.id'); do
focus "$num"
done
# render eww widget # render eww widget
echo "(eventbox :onscroll \"echo {} | sed -e 's/up/-1/g' -e 's/down/+1/g' | xargs hyprctl dispatch workspace\" \ echo "(eventbox :onscroll \"echo {} | sed -e 's/up/-1/g' -e 's/down/+1/g' | xargs hyprctl dispatch workspace\" \
(box :class \"workspaces\" :orientation \"h\" :spacing 0 :space-evenly \"true\" \ (box :class \"workspaces\" :orientation \"h\" :spacing 0 :space-evenly \"true\" \
(button :onclick \"hyprctl dispatch workspace 1\" :onrightclick \"hyprctl dispatch workspace 1\" :class \"workspace$o1$f1\" \"${ic[0]}\") \ (button :onclick \"hyprctl dispatch workspace 1\" :onrightclick \"hyprctl dispatch workspace 1\" :class \"workspace $a1 $o1 $f1\" \"${ic[0]}\") \
(button :onclick \"hyprctl dispatch workspace 2\" :onrightclick \"hyprctl dispatch workspace 2\" :class \"workspace$o2$f2\" \"${ic[1]}\") \ (button :onclick \"hyprctl dispatch workspace 2\" :onrightclick \"hyprctl dispatch workspace 2\" :class \"workspace $a2 $o2 $f2\" \"${ic[1]}\") \
(button :onclick \"hyprctl dispatch workspace 3\" :onrightclick \"hyprctl dispatch workspace 3\" :class \"workspace$o3$f3\" \"${ic[2]}\") \ (button :onclick \"hyprctl dispatch workspace 3\" :onrightclick \"hyprctl dispatch workspace 3\" :class \"workspace $a3 $o3 $f3\" \"${ic[2]}\") \
(button :onclick \"hyprctl dispatch workspace 4\" :onrightclick \"hyprctl dispatch workspace 4\" :class \"workspace$o4$f4\" \"${ic[3]}\") \ (button :onclick \"hyprctl dispatch workspace 4\" :onrightclick \"hyprctl dispatch workspace 4\" :class \"workspace $a4 $o4 $f4\" \"${ic[3]}\") \
(button :onclick \"hyprctl dispatch workspace 5\" :onrightclick \"hyprctl dispatch workspace 5\" :class \"workspace$o5$f5\" \"${ic[4]}\") \ (button :onclick \"hyprctl dispatch workspace 5\" :onrightclick \"hyprctl dispatch workspace 5\" :class \"workspace $a5 $o5 $f5\" \"${ic[4]}\") \
(button :onclick \"hyprctl dispatch workspace 6\" :onrightclick \"hyprctl dispatch workspace 6\" :class \"workspace$o6$f6\" \"${ic[5]}\") \ (button :onclick \"hyprctl dispatch workspace 6\" :onrightclick \"hyprctl dispatch workspace 6\" :class \"workspace $a6 $o6 $f6\" \"${ic[5]}\") \
(button :onclick \"hyprctl dispatch workspace 7\" :onrightclick \"hyprctl dispatch workspace 7\" :class \"workspace$o7$f7\" \"${ic[6]}\") \ (button :onclick \"hyprctl dispatch workspace 7\" :onrightclick \"hyprctl dispatch workspace 7\" :class \"workspace $a7 $o7 $f7\" \"${ic[6]}\") \
(button :onclick \"hyprctl dispatch workspace 8\" :onrightclick \"hyprctl dispatch workspace 8\" :class \"workspace$o8$f8\" \"${ic[7]}\") \ (button :onclick \"hyprctl dispatch workspace 8\" :onrightclick \"hyprctl dispatch workspace 8\" :class \"workspace $a8 $o8 $f8\" \"${ic[7]}\") \
(button :onclick \"hyprctl dispatch workspace 9\" :onrightclick \"hyprctl dispatch workspace 9\" :class \"workspace$o9$f9\" \"${ic[8]}\") \ (button :onclick \"hyprctl dispatch workspace 9\" :onrightclick \"hyprctl dispatch workspace 9\" :class \"workspace $a9 $o9 $f9\" \"${ic[8]}\") \
) \ ) \
)" )"
} }
@ -52,6 +55,10 @@ workspaces() {
workspaces workspaces
# listen to events and re-render # listen to events and re-render
socat - UNIX-CONNECT:/tmp/hypr/"${HYPRLAND_INSTANCE_SIGNATURE}"/.socket2.sock | while read -r event; do while true; do
workspaces "$event" # TODO: not sure why this socat | read invocation seems to stop?
socat - "UNIX-CONNECT:/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" | while read -r line; do
workspaces "$line"
done done
done
echo '(box "DONE")'

View file

@ -1,3 +1,3 @@
{pkgs, ...}: { {pkgs, ...}: {
environment.systemPackages = with pkgs; [eww upower]; environment.systemPackages = with pkgs; [eww upower jq];
} }