Skip to content

Commit

Permalink
Add EWW scripts for workspace management, system monitoring, and batt…
Browse files Browse the repository at this point in the history
…ery status
  • Loading branch information
ryanwclark committed Dec 10, 2024
1 parent ca58000 commit 7b51f59
Show file tree
Hide file tree
Showing 34 changed files with 693 additions and 54 deletions.
56 changes: 56 additions & 0 deletions home/features/desktop/hyprland/eww/backup/scripts/workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh
workspaces() {

ws1="1"
ws2="2"
ws3="3"
ws4="4"
ws5="5"
ws6="6"

# Unoccupied
un="0"

# check if Occupied
o1=$(bspc query -D -d .occupied --names | grep "$ws1" )
o2=$(bspc query -D -d .occupied --names | grep "$ws2" )
o3=$(bspc query -D -d .occupied --names | grep "$ws3" )
o4=$(bspc query -D -d .occupied --names | grep "$ws4" )
o5=$(bspc query -D -d .occupied --names | grep "$ws5" )
o6=$(bspc query -D -d .occupied --names | grep "$ws6" )

# check if Focused
f1=$(bspc query -D -d focused --names | grep "$ws1" )
f2=$(bspc query -D -d focused --names | grep "$ws2" )
f3=$(bspc query -D -d focused --names | grep "$ws3" )
f4=$(bspc query -D -d focused --names | grep "$ws4" )
f5=$(bspc query -D -d focused --names | grep "$ws5" )
f6=$(bspc query -D -d focused --names | grep "$ws6" )

ic_1=""
ic_2=""
ic_3=""
ic_4=""
ic_5=""
ic_6=""
if [ $f1 ]; then
ic_1=""
elif [ $f2 ]; then
ic_2=""
elif [ $f3 ]; then
ic_3=""
elif [ $f4 ]; then
ic_4=""
elif [ $f5 ]; then
ic_5=""
elif [ $f6 ]; then
ic_6=""
fi

echo "(box :class \"works\" :orientation \"h\" :spacing 5 :space-evenly \"false\" (button :onclick \"bspc desktop -f $ws1\" :class \"$un$o1$f1\" \"$ic_1\") (button :onclick \"bspc desktop -f $ws2\" :class \"$un$o2$f2\" \"$ic_2\") (button :onclick \"bspc desktop -f $ws3\" :class \"$un$o3$f3\" \"$ic_3\") (button :onclick \"bspc desktop -f $ws4\" :class \"$un$o4$f4\" \"$ic_4\") (button :onclick \"bspc desktop -f $ws5\" :class \"$un$o5$f5\" \"$ic_5\") (button :onclick \"bspc desktop -f $ws6\" :class \"$un$o6$f6\" \"$ic_6\"))"

}
workspaces
bspc subscribe desktop node_transfer | while read -r _ ; do
workspaces
done
30 changes: 30 additions & 0 deletions home/features/desktop/hyprland/eww/backup/scripts/workspaces.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env lua

function trim(s)
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end

aw = io.popen("hyprctl monitors | grep active | sed 's/()/(1)/g' | sort | awk 'NR>1{print $1}' RS='(' FS=')'")
active_workspace = aw:read("*a")
aw:close()

ew = io.popen("hyprctl workspaces | grep ID | sed 's/()/(1)/g' | sort | awk 'NR>1{print $1}' RS='(' FS=')'")
existing_workspaces = ew:read("*a")
ew:close()

box = "(box :orientation \"v\" :spacing 1 :space-evenly \"true\" "

for i = 1, #existing_workspaces do
local c = existing_workspaces:sub(i,i)
if tonumber(c) == tonumber(active_workspace) then
local btn = "(button :class \"active\" :onclick \"hyprctl dispatch workspace "..c.." \" \"\")"
box = box .. btn
elseif c ~= "\n" then
local btn = "(button :class \"inactive\" :onclick \"hyprctl dispatch workspace "..c.."\" \"\")"
box = box .. btn
end
end

box = box .. ")"

print(box)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
workspaces() {
./scripts/workspaces.lua
}
workspaces
tail -f /tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/hyprland.log | grep --line-buffered "Changed to workspace" | while read -r; do
workspaces
done

118 changes: 64 additions & 54 deletions home/features/desktop/hyprland/eww/default.nix
Original file line number Diff line number Diff line change
@@ -1,59 +1,69 @@
# TODO: Configure XDG_CONFIG_HOME for config directory
{ inputs, lib, config, pkgs, ... }:
let
user = "${config.home.username}";
homeDirectory = "${config.home.homeDirectory}/.config";
in
{
programs = {
eww = {
enable = true;
package = pkgs.eww;
enableZshIntegration = true;
enableBashIntegration = true;
enableFishIntegration = true;
# configDir = "${XDG_CONFIG_HOME}/eww";
# configDir = "${homeDirectory}/eww";
};
inputs,
lib,
config,
pkgs,
...
}:


{
imports = [
./scripts
./launch_bar.nix
];

programs = {
eww = {
enable = true;
package = pkgs.eww;
enableZshIntegration = true;
enableBashIntegration = true;
enableFishIntegration = true;
configDir = "${config.home.homeDirectory}/eww";
};
};

home.packages = with pkgs; [
brightnessctl
];

# configuration
home.file.".config/eww/eww.scss".source = ./eww.scss;
home.file.".config/eww/eww.yuck".source = ./eww.yuck;
home.file.".config/eww/eww_windows.yuck".source = ./eww_windows.yuck;
home.file.".config/eww/eww_widgets.yuck".source = ./eww_widgets.yuck;
home.file.".config/eww/eww_variables.yuck".source = ./eww_variables.yuck;

# # scripts
# home.file.".config/eww/scripts" = {
# source = ./scripts;
# recursive = true;
# };

# home.file.".config/eww/scripts/battery.sh" = {
# source = ./scripts/battery.sh;
# executable = true;
# };

# home.file.".config/eww/scripts/wifi.sh" = {
# source = ./scripts/wifi.sh;
# executable = true;
# };

# home.file.".config/eww/scripts/brightness.sh" = {
# source = ./scripts/brightness.sh;
# executable = true;
# };

# home.file.".config/eww/scripts/workspaces.sh" = {
# source = ./scripts/workspaces.sh;
# executable = true;
# };

# home.packages = with pkgs; [
# brightnessctl
# (nerdfonts.override { fonts = [ "JetBrainsMono" ]; })
# ];

# configuration
# home.file.".config/eww/eww.scss".source = ./eww.scss;
# home.file.".config/eww/eww.yuck".source = ./eww.yuck;

# # scripts
# home.file.".config/eww/scripts" = {
# source = ./scripts;
# recursive = true;
# };

# home.file.".config/eww/scripts/battery.sh" = {
# source = ./scripts/battery.sh;
# executable = true;
# };

# home.file.".config/eww/scripts/wifi.sh" = {
# source = ./scripts/wifi.sh;
# executable = true;
# };

# home.file.".config/eww/scripts/brightness.sh" = {
# source = ./scripts/brightness.sh;
# executable = true;
# };

# home.file.".config/eww/scripts/workspaces.sh" = {
# source = ./scripts/workspaces.sh;
# executable = true;
# };

# home.file.".config/eww/scripts/workspaces.lua" = {
# source = ./scripts/workspaces.lua;
# executable = true;
# };
# home.file.".config/eww/scripts/workspaces.lua" = {
# source = ./scripts/workspaces.lua;
# executable = true;
# };
}
22 changes: 22 additions & 0 deletions home/features/desktop/hyprland/eww/scripts/airplane_mode.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
config,
lib,
pkgs,
...
}:

{
home.file.".config/eww/scripts/airplane_mode.sh" = {
text = ''
#!/bin/sh
status=$(nmcli n)
if [[ "$status" == "enabled" ]]; then
nmcli n off
else
nmcli n on
fi
'';
executable = true;
};
}

30 changes: 30 additions & 0 deletions home/features/desktop/hyprland/eww/scripts/battery1.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
config,
lib,
pkgs,
...
}:

{
home.file.".config/eww/scripts/battery1.sh" = {
text = ''
#!/usr/bin/env bash
battery() {
BAT=`ls /sys/class/power_supply | grep BAT | head -n 1`
cat /sys/class/power_supply/${BAT}/capacity
}
battery_stat() {
BAT=`ls /sys/class/power_supply | grep BAT | head -n 1`
cat /sys/class/power_supply/${BAT}/status
}
if [[ "$1" == "--bat" ]]; then
battery
elif [[ "$1" == "--bat-st" ]]; then
battery_stat
fi
'';
executable = true;
};
}

52 changes: 52 additions & 0 deletions home/features/desktop/hyprland/eww/scripts/battery2.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
config,
lib,
pkgs,
...
}:

{
home.file.".config/eww/scripts/battery2.sh" = {
text = ''
#!/bin/sh
bat=/sys/class/power_supply/BAT1/
per="$(cat "$bat/capacity")"
status="$(cat "$bat/status")"
if [ "$per" -gt "90" ]; then
icon=""
elif [ "$per" -gt "80" ]; then
icon=""
elif [ "$per" -gt "70" ]; then
icon=""
elif [ "$per" -gt "60" ]; then
icon=""
elif [ "$per" -gt "50" ]; then
icon=""
elif [ "$per" -gt "40" ]; then
icon=""
elif [ "$per" -gt "30" ]; then
icon=""
elif [ "$per" -gt "20" ]; then
icon=""
elif [ "$per" -gt "10" ]; then
icon=""
elif [ "$per" -gt "0" ]; then
icon=""
else
icon=""
fi
if [ -s /sys/class/power_supply/BAT1/capacity ]; then
echo "{\"percent\": \"$per\", \"icon\": \"$icon\", \"charging\": \"$charging\", \"visible\": \"true\", \"status\": \"$status\"}"
else
echo "{\"visible\": \"false\" }"
fi
'';
executable = true;
};
}
30 changes: 30 additions & 0 deletions home/features/desktop/hyprland/eww/scripts/brightness.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
config,
lib,
pkgs,
...
}:

{
home.file.".config/eww/scripts/brightness.sh" = {
text = ''
#!/bin/sh
if eww windows | grep -q "\*brightness"; then
eww update bright-level="$(brightnessctl -m -d intel_backlight | awk -F, '{print substr($4, 0, length($4)-1)}' | tr -d '%')"
else
eww close volume
eww open brightness
eww update bright-level="$(brightnessctl -m -d intel_backlight | awk -F, '{print substr($4, 0, length($4)-1)}' | tr -d '%')"
sleep 2
sleep 1
eww close brightness
fi
'';
executable = true;
};
}



24 changes: 24 additions & 0 deletions home/features/desktop/hyprland/eww/scripts/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
...
}:

{
imports = [
./airplane_mode.nix
./battery1.nix
./battery2.nix
./brightness.nix
./mem-ad.nix
./memory.nix
./music_info.nix
./pop.nix
./screenshot.nix
./search.nix
./volume.nix
./wifi1.nix
./wifi2.nix
./workspace_code.nix
./workspace.nix
./workspaces.nix
];
}
Loading

0 comments on commit 7b51f59

Please sign in to comment.