diff --git a/flake.lock b/flake.lock index 98dc03b2d5..8d3f456967 100644 --- a/flake.lock +++ b/flake.lock @@ -210,11 +210,11 @@ ] }, "locked": { - "lastModified": 1727670871, - "narHash": "sha256-ZetKlO/gk068cleMXV4V7E2AMvjEuRpIBSOccgqS/6I=", + "lastModified": 1727854413, + "narHash": "sha256-5nysqAzKvv2Yn2eKAyR+U1zjZ535NSRuKNapICkDwfg=", "owner": "tiiuae", "repo": "ghafpkgs", - "rev": "b02f0c28ef687985ab32f8ef2aa5ddc137c4472f", + "rev": "58ab6179fce5932862707c833b57f4526503399d", "type": "github" }, "original": { diff --git a/modules/desktop/graphics/ewwbar.nix b/modules/desktop/graphics/ewwbar.nix index 4569640812..bfd58ceb91 100644 --- a/modules/desktop/graphics/ewwbar.nix +++ b/modules/desktop/graphics/ewwbar.nix @@ -7,25 +7,51 @@ ... }: let + inherit (builtins) replaceStrings; + inherit (lib) optionalString; + cfg = config.ghaf.graphics.labwc; + audio-ctrl = pkgs.callPackage ../../../packages/audio-ctrl { }; launcher-icon = "${pkgs.ghaf-artwork}/icons/launcher.svg"; - battery-0-icon = "${pkgs.ghaf-artwork}/icons/battery-empty.svg"; - battery-1-icon = "${pkgs.ghaf-artwork}/icons/battery-almost-empty.svg"; - battery-2-icon = "${pkgs.ghaf-artwork}/icons/battery-half.svg"; - battery-3-icon = "${pkgs.ghaf-artwork}/icons/battery-full.svg"; + security-icon = "${pkgs.ghaf-artwork}/icons/security-green.svg"; + + battery-0-icon = "${pkgs.ghaf-artwork}/icons/battery-0.svg"; + battery-1-icon = "${pkgs.ghaf-artwork}/icons/battery-1.svg"; + battery-2-icon = "${pkgs.ghaf-artwork}/icons/battery-2.svg"; + battery-3-icon = "${pkgs.ghaf-artwork}/icons/battery-3.svg"; battery-charging-icon = "${pkgs.ghaf-artwork}/icons/battery-charging.svg"; - bluetooth-icon = "${pkgs.ghaf-artwork}/icons/bluetooth.svg"; + wifi-0-icon = "${pkgs.ghaf-artwork}/icons/wifi-0.svg"; wifi-1-icon = "${pkgs.ghaf-artwork}/icons/wifi-1.svg"; wifi-2-icon = "${pkgs.ghaf-artwork}/icons/wifi-2.svg"; wifi-3-icon = "${pkgs.ghaf-artwork}/icons/wifi-3.svg"; - wifi-4-icon = "${pkgs.ghaf-artwork}/icons/wifi-green.svg"; - security-icon = "${pkgs.ghaf-artwork}/icons/security-green.svg"; + wifi-4-icon = "${pkgs.ghaf-artwork}/icons/wifi-4.svg"; + + volume-0-icon = "${pkgs.ghaf-artwork}/icons/volume-0.svg"; + volume-1-icon = "${pkgs.ghaf-artwork}/icons/volume-1.svg"; + volume-2-icon = "${pkgs.ghaf-artwork}/icons/volume-2.svg"; + volume-3-icon = "${pkgs.ghaf-artwork}/icons/volume-3.svg"; + + brightness-0-icon = "${pkgs.ghaf-artwork}/icons/brightness-0.svg"; + brightness-1-icon = "${pkgs.ghaf-artwork}/icons/brightness-1.svg"; + brightness-2-icon = "${pkgs.ghaf-artwork}/icons/brightness-2.svg"; + brightness-3-icon = "${pkgs.ghaf-artwork}/icons/brightness-3.svg"; + brightness-4-icon = "${pkgs.ghaf-artwork}/icons/brightness-4.svg"; + brightness-5-icon = "${pkgs.ghaf-artwork}/icons/brightness-5.svg"; + brightness-6-icon = "${pkgs.ghaf-artwork}/icons/brightness-6.svg"; + brightness-7-icon = "${pkgs.ghaf-artwork}/icons/brightness-7.svg"; + brightness-8-icon = "${pkgs.ghaf-artwork}/icons/brightness-8.svg"; + bluetooth-1-icon = "${pkgs.ghaf-artwork}/icons/bluetooth-1.svg"; + + power-icon = "${pkgs.ghaf-artwork}/icons/power.svg"; + restart-icon = "${pkgs.ghaf-artwork}/icons/restart.svg"; + suspend-icon = "${pkgs.ghaf-artwork}/icons/suspend.svg"; + + arrow-right-icon = "${pkgs.ghaf-artwork}/icons/arrow-right.svg"; # Colors ## Background - bg-primary = "#121212"; bg-secondary = "#2B2B2B"; ## Text text-base = "#FFFFFF"; @@ -41,107 +67,285 @@ let # Called by eww.yuck for updates and reloads eww = "${pkgs.eww}/bin/eww -c /etc/eww"; - ewwPopup = pkgs.writeShellScript "popup" '' - calendar() { - LOCK_FILE="$HOME/.cache/eww-calendar.lock" + cliArgs = replaceStrings [ "\n" ] [ " " ] '' + --name ${config.ghaf.givc.adminConfig.name} + --addr ${config.ghaf.givc.adminConfig.addr} + --port ${config.ghaf.givc.adminConfig.port} + ${optionalString config.ghaf.givc.enableTls "--cacert /run/givc/ca-cert.pem"} + ${optionalString config.ghaf.givc.enableTls "--cert /run/givc/gui-vm-cert.pem"} + ${optionalString config.ghaf.givc.enableTls "--key /run/givc/gui-vm-key.pem"} + ${optionalString (!config.ghaf.givc.enableTls) "--notls"} + ''; - run() { - # Update day, month and year before opening the calendar - ${eww} update calendar_day=$(date +%d) - ${eww} update calendar_month=$(date +%-m) - ${eww} update calendar_year=$(date +%Y) - ${eww} open --screen $1 calendar --logs - } + eww-popup = pkgs.writeShellApplication { + name = "eww-popup"; + runtimeInputs = [ ]; + bashOptions = [ ]; + text = '' + widgets=("calendar" "quick-settings" "power-menu") + widgets_to_close=() - # Open widgets - if [[ ! -f "$LOCK_FILE" ]]; then - touch "$LOCK_FILE" - run $1 - else - ${eww} close calendar - rm "$LOCK_FILE" - fi - } - - if [ "$1" = "wifi" ]; then - ${pkgs.nm-launcher}/bin/nm-launcher - elif [ "$1" = "calendar" ]; then - calendar $2 - fi + close-others(){ + for widget in "''${widgets[@]}"; do + if [ "$widget" != "$1" ]; then + widgets_to_close+=("$widget") + fi + done + ${eww} close "''${widgets_to_close[@]}" >/dev/null 2>&1 + } - ''; + open-widget(){ + close-others "$1" + if [ -z "$2" ]; then + ${eww} open --toggle "$1" + else + ${eww} open --toggle --screen "$2" "$1" + fi + } - ewwWifi = pkgs.writeShellScript "wifi" '' - grpcurl_cmd_get_active_connection="${pkgs.grpcurl}/bin/grpcurl -plaintext 192.168.100.1:9000 wifimanager.WifiService.GetActiveConnection" - - signal() { - signal_level=$(echo "$1" | ${pkgs.jq}/bin/jq '.Signal // empty') - echo $signal_level - } - - status() { - active_connection=$($grpcurl_cmd_get_active_connection) - ${eww} update wifi-signal-level=$(signal "$active_connection") - - connected=$(echo "$active_connection" | ${pkgs.jq}/bin/jq -r '.Connection // false') - ssid=$(echo "$active_connection" | ${pkgs.jq}/bin/jq -r '.SSID // empty') - if [ "$connected" = "false" ] || [ -z "$ssid" ]; then - echo No connection - else - ${eww} update wifi-name=$ssid - echo Connected - fi - } - - [ "$1" = "status" ] && status && exit - [ "$1" = "signal" ] && signal && exit - ''; + if [ "$1" = "calendar" ]; then + ${eww} update calendar_day="$(date +%d)" calendar_month="$(date +%-m)" calendar_year="$(date +%Y)" + fi + open-widget "$1" "$2" + ''; + }; - ewwBat = pkgs.writeShellScript "battery" '' - BATTERY_PATH="/sys/class/power_supply/BAT0" - ENERGY_NOW=$(cat "$BATTERY_PATH/energy_now") - POWER_NOW=$(cat "$BATTERY_PATH/power_now") - - remaining() { - if [ "$POWER_NOW" -eq 0 ]; then - echo "" - fi - - TIME_REMAINING=$(echo "scale=2; $ENERGY_NOW / $POWER_NOW" | ${pkgs.bc}/bin/bc ) - - HOURS=$(echo "$TIME_REMAINING" | ${pkgs.gawk}/bin/awk '{print int($1)}') - MINUTES=$(echo "($TIME_REMAINING - $HOURS) * 60" | ${pkgs.bc}/bin/bc | ${pkgs.gawk}/bin/awk '{printf "%d\n", $1}') - - # If both hours and minutes are 0, return an empty string - if [ "$HOURS" -eq 0 ] && [ "$MINUTES" -eq 0 ]; then - echo "" - else - # Display remaining time in shorthand - if [ "$HOURS" -gt 0 ] && [ "$MINUTES" -gt 0 ]; then - echo "''${HOURS}h ''${MINUTES}m" - elif [ "$HOURS" -gt 0 ]; then - echo "''${HOURS}h" - else - echo "''${MINUTES}m" - fi - fi - } - - [ "$1" = "remaining" ] && remaining && exit - ''; + eww-wifi = pkgs.writeShellApplication { + name = "eww-wifi"; + runtimeInputs = [ + pkgs.jq + pkgs.grpcurl + ]; + bashOptions = [ ]; + text = '' + grpcurl_cmd_get_active_connection="grpcurl -plaintext 192.168.100.1:9000 wifimanager.WifiService.GetActiveConnection" - ewwStart = pkgs.writeShellScript "ewwStart" '' - # Get number of connected displays using wlr-randr - connected_monitors=$(${pkgs.wlr-randr}/bin/wlr-randr --json | ${pkgs.jq}/bin/jq 'length') - echo Found connected displays: $connected_monitors - # Launch Eww bar on each screen - ${eww} kill - ${eww} daemon - for ((screen=0; screen<$connected_monitors; screen++)); do - echo Starting ewwbar for display $screen - ${eww} open --no-daemonize --screen $screen bar --id bar:$screen --arg screen=$screen - done - ''; + signal() { + signal_level=$(echo "$1" | jq '.Signal // empty') + echo "$signal_level" + } + + icon() { + if [ "$1" -lt 30 ]; then + echo "${wifi-1-icon}" + elif [ "$1" -lt 60 ]; then + echo "${wifi-2-icon}" + elif [ "$1" -lt 80 ]; then + echo "${wifi-3-icon}" + else + echo "${wifi-4-icon}" + fi + } + + get() { + active_connection=$($grpcurl_cmd_get_active_connection) + + signal=$(signal "$active_connection") + icon=$(icon "$signal") + connected=$(echo "$active_connection" | jq -r '.Connection // false') + ssid=$(echo "$active_connection" | jq -r '.SSID // empty') + + if [ "$connected" = "false" ] || [ -z "$ssid" ]; then + icon="${wifi-0-icon}" + fi + echo "{ + \"connected\": \"$connected\", + \"ssid\": \"$ssid\", + \"signal\": \"$signal\", + \"icon\": \"$icon\" + }" + } + + [ "$1" = "get" ] && get && exit + ''; + }; + + eww-bat = pkgs.writeShellApplication { + name = "eww-bat"; + runtimeInputs = [ + pkgs.gawk + pkgs.bc + ]; + bashOptions = [ ]; + text = '' + BATTERY_PATH="/sys/class/power_supply/BAT0" + ENERGY_NOW=$(cat "$BATTERY_PATH/energy_now") + POWER_NOW=$(cat "$BATTERY_PATH/power_now") + CAPACITY=$(cat "$BATTERY_PATH/capacity") + STATUS=$(cat "$BATTERY_PATH/status") + + get() { + if [ "$POWER_NOW" -eq 0 ]; then + echo "{ + \"remaining\": { \"hours\": \"0\", \"minutes_total\": \"0\", \"minutes\": \"0\" }, + \"status\": \"$STATUS\", + \"capacity\": \"$CAPACITY\" + }" + exit + fi + + TIME_REMAINING=$(echo "scale=2; $ENERGY_NOW / $POWER_NOW" | bc) + + HOURS=$(echo "$TIME_REMAINING" | awk '{print int($1)}') + MINUTES_TOTAL=$(echo "$HOURS * 60" | bc | awk '{printf "%d\n", $1}') + MINUTES_REMAINDER=$(echo "($TIME_REMAINING - $HOURS) * 60" | bc | awk '{printf "%d\n", $1}') + + # If both hours and minutes are 0, return 0 for both + if [ "$HOURS" -eq 0 ] && [ "$MINUTES" -eq 0 ]; then + HOURS=0 + MINUTES=0 + fi + + echo "{ + \"remaining\": { \"hours\": \"$HOURS\", \"minutes_total\": \"$MINUTES_TOTAL\", \"minutes\": \"$MINUTES_REMAINDER\" }, + \"status\": \"$STATUS\", + \"capacity\": \"$CAPACITY\" + }" + } + + [ "$1" = "get" ] && get && exit + ''; + }; + + eww-start = pkgs.writeShellApplication { + name = "eww-start"; + runtimeInputs = [ + pkgs.wlr-randr + pkgs.jq + ]; + bashOptions = [ ]; + text = '' + # Get number of connected displays using wlr-randr + connected_monitors=$(wlr-randr --json | jq 'length') + echo Found connected displays: "$connected_monitors" + # Launch Eww bar on each screen + ${eww} kill + ${eww} daemon + for ((screen=0; screen