From ccffa13eb210a0d703d98517b71bb89829905096 Mon Sep 17 00:00:00 2001 From: ooks-io Date: Mon, 4 Sep 2023 14:54:33 +1200 Subject: [PATCH] add: eww --- home/ooks/opt/desktop/hyprland/default.nix | 1 + .../desktop/standard/wayland/eww/default.nix | 12 +++ system/common/opt/batterynotify.nix | 79 +++++++++++-------- 3 files changed, 57 insertions(+), 35 deletions(-) create mode 100644 home/ooks/opt/desktop/standard/wayland/eww/default.nix diff --git a/home/ooks/opt/desktop/hyprland/default.nix b/home/ooks/opt/desktop/hyprland/default.nix index af4b616..14369e8 100644 --- a/home/ooks/opt/desktop/hyprland/default.nix +++ b/home/ooks/opt/desktop/hyprland/default.nix @@ -3,6 +3,7 @@ ../standard ../standard/wayland ../music + ../standard/wayland/eww ./tty-init.nix ./binds.nix diff --git a/home/ooks/opt/desktop/standard/wayland/eww/default.nix b/home/ooks/opt/desktop/standard/wayland/eww/default.nix new file mode 100644 index 0000000..5829b5a --- /dev/null +++ b/home/ooks/opt/desktop/standard/wayland/eww/default.nix @@ -0,0 +1,12 @@ +{ pkgs, config, ... }: +{ + programs.eww = { + enable = true; + package = pkgs.eww-wayland; + configDir = ./config; + }; + + + + +} diff --git a/system/common/opt/batterynotify.nix b/system/common/opt/batterynotify.nix index 961ccf3..3a1b0be 100644 --- a/system/common/opt/batterynotify.nix +++ b/system/common/opt/batterynotify.nix @@ -1,51 +1,60 @@ -{ config, lib, pkgs, ... }: +{ config, pkgs, lib, ... }: + +# Regularly check the battery status and send a notification when it discharges +# below certain thresholds. +# Implemented by calling the `acpi` program regularly. This is the simpler and +# safer approach because the battery might not send discharging events. +# author: github:Julow + +let conf = config.modules.battery-notify; -let - conf = config.modules.battery-notify; in { - options.modules.battery-notify = with lib; { enable = mkEnableOption "battery-notify"; }; config = lib.mkIf conf.enable { + # Regularly check battery status systemd.user.services.battery-notify = { wantedBy = [ "graphical-session.target" ]; script = '' - - batval=$(cat /sys/class/power_supply/BAT0/capacity) - tempbatval="/tmp/bat_val_$batval" - - if [ ! -f "$tempbatval" ]; then - case "$batval" in - 75|50|25|10|5) - ${pkgs.libnotify}/bin/notify-send -a bat-notify "battery:" "$batval" - touch "tempbatval" - ;; - esac - fi - - for level in 75 50 25 10 5; do - if [ "$batval" -gt "$level" ]; then - rm -f "/tmp/bat_val_$level" + prev_val=100 + check () { [[ $1 -ge $val ]] && [[ $1 -lt $prev_val ]]; } + get_battery_glyph() { + local val="$1" + if [[ "$val" -le 10 ]]; then + echo "" # or echo -e "\uf244" if using the Unicode code + elif [[ "$val" -le 25 ]]; then + echo "" + elif [[ "$val" -le 50 ]]; then + echo "" + elif [[ "$val" -le 75 ]]; then + echo "" + else + echo "" fi + } + + notify () { + glyph=$(get_battery_glyph $val) + ${pkgs.libnotify}/bin/notify-send -a bat-notify "$glyph $val%" + } + while true; do + IFS=: read _ bat0 < <(${pkgs.acpi}/bin/acpi -b) + IFS=\ , read status val remaining <<<"$bat0" + val=''${val%\%} + if [[ $status = Discharging ]]; then + echo "$val%, $remaining" + if check 75 || check 50 ||check 30 || check 25 || check 20; then notify + elif check 15 || [[ $val -le 10 ]]; then notify -u critical + fi + fi + prev_val=$val + # Sleep longer when battery is high to save CPU + if [[ $val -gt 30 ]]; then sleep 10m; elif [[ $val -ge 20 ]]; then sleep 5m; else sleep 1m; fi done ''; - - }; - - systemd.user.timers.battery-notify = { - wantedBy = [ "timers.target" ]; - after = [ "basic.target" ]; - requires = [ "battery-notify.service" ]; - partOf = [ "battery-notify.service" ]; - timerConfig = { - OnBootSec = "1m"; - OnUnitActiveSec = "1m"; - }; - }; }; - -} +} \ No newline at end of file