mirror of
https://github.com/tomasriveral/nixos.git
synced 2026-10-10 17:02:43 +02:00
rewrote performance mode into lua
This commit is contained in:
1 parent
1071ce70d7
commit
82bd78bc73
2 files changed
+143
-184
No files matched your search
@@ -336,184 +336,5 @@
|
||||
install -m755 qtbatticon $out/bin/
|
||||
'';
|
||||
};
|
||||
# This was replaced by caelestia shell's Game Mode
|
||||
packages.custom-performance = pkgs.writeShellApplication {
|
||||
name = "custom-performance";
|
||||
runtimeInputs = with pkgs; [
|
||||
hyprland
|
||||
brightnessctl
|
||||
swaynotificationcenter
|
||||
self.packages.${pkgs.system}.custom-wallpaper
|
||||
libnotify
|
||||
inputs.caelestia-shell.packages.${pkgs.system}.default
|
||||
];
|
||||
text = ''
|
||||
STATE="$HOME/.cache/hypr-battery-saver"
|
||||
|
||||
enable() {
|
||||
mkdir -p "$(dirname "$STATE")"
|
||||
|
||||
echo "Enabling battery saver mode..."
|
||||
|
||||
# Save brightness
|
||||
brightnessctl get > "''${STATE}.brightness" 2>/dev/null || true
|
||||
|
||||
# Kill heavy UI components
|
||||
pkill -f caelestia-shell || true
|
||||
pkill -f caelestia || true
|
||||
pkill shell || true
|
||||
pkill -f custom-wallpaper || true
|
||||
|
||||
# Start lightweight notifications
|
||||
pkill swaync || true
|
||||
swaync & disown
|
||||
|
||||
# Start lightweight waybar
|
||||
pkill waybar || true
|
||||
waybar & disown
|
||||
|
||||
# Lower refresh rate (BIGGEST win)
|
||||
hyprctl keyword monitor "eDP-1,2560x1600@60,0x0,1"
|
||||
|
||||
# Core performance toggles
|
||||
hyprctl --batch "\
|
||||
keyword animations:enabled 0;\
|
||||
keyword animation borderangle,0;\
|
||||
keyword decoration:shadow:enabled 0;\
|
||||
keyword decoration:blur:enabled 0;\
|
||||
keyword decoration:rounding 0;\
|
||||
keyword decoration:fullscreen_opacity 1;\
|
||||
keyword general:gaps_in 0;\
|
||||
keyword general:gaps_out 0;\
|
||||
keyword general:border_size 1;\
|
||||
keyword decoration:active_opacity 1;\
|
||||
keyword decoration:inactive_opacity 1;\
|
||||
keyword misc:vfr true"
|
||||
|
||||
# Lower brightness
|
||||
brightnessctl set 5% 2>/dev/null || true
|
||||
|
||||
touch "$STATE"
|
||||
|
||||
notify-send "Battery Saver" "Enabled"
|
||||
}
|
||||
|
||||
disable() {
|
||||
echo "Disabling battery saver mode..."
|
||||
|
||||
# Restore refresh rate
|
||||
hyprctl keyword monitor "eDP-1,2560x1600@165,0x0,1"
|
||||
|
||||
# Restore Caelestia
|
||||
pkill swaync || true
|
||||
pkill waybar || true
|
||||
caelestia shell -d >/dev/null 2>&1 &
|
||||
disown
|
||||
|
||||
|
||||
# Restart wallpaper
|
||||
custom-wallpaper >/dev/null 2>&1 &
|
||||
disown
|
||||
|
||||
# Restore full UI via reload (safe here on exit)
|
||||
hyprctl reload
|
||||
|
||||
# Restore brightness
|
||||
if [[ -f "''${STATE}.brightness" ]]; then
|
||||
brightnessctl set "$(cat "''${STATE}.brightness")" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
rm -f "$STATE" "''${STATE}.brightness"
|
||||
|
||||
notify-send "Battery Saver" "Disabled"
|
||||
}
|
||||
|
||||
if [[ -f "$STATE" ]]; then
|
||||
disable
|
||||
else
|
||||
enable
|
||||
fi
|
||||
'';
|
||||
};
|
||||
# Old script that was used for the battery. Might not work.
|
||||
packages.custom-olddeprecatedbatterynotify = pkgs.writeShellApplication {
|
||||
name = "custom-olddeprecatedbatterynotify";
|
||||
|
||||
runtimeInputs = with pkgs; [
|
||||
libnotify # provides notify-send
|
||||
systemd # provides systemctl
|
||||
];
|
||||
|
||||
text = ''
|
||||
set -euo pipefail
|
||||
|
||||
LOW="''${BATTERY_LOW_THRESHOLD:-20}"
|
||||
CRITICAL="''${BATTERY_CRITICAL_THRESHOLD:-5}"
|
||||
FULL="''${BATTERY_FULL_THRESHOLD:-95}"
|
||||
INTERVAL="''${BATTERY_INTERVAL:-30}"
|
||||
ACTION="''${BATTERY_CRITICAL_ACTION:-systemctl suspend}"
|
||||
|
||||
notify() {
|
||||
notify-send -a "Battery" -u "$1" "$2" "$3"
|
||||
}
|
||||
|
||||
get_info() {
|
||||
total=0
|
||||
count=0
|
||||
|
||||
for bat in /sys/class/power_supply/BAT*; do
|
||||
[ -f "$bat/capacity" ] || continue
|
||||
capacity=$(<"$bat/capacity")
|
||||
status=$(<"$bat/status")
|
||||
total=$((total + capacity))
|
||||
count=$((count + 1))
|
||||
done
|
||||
|
||||
[ "$count" -gt 0 ] || exit 0
|
||||
percentage=$((total / count))
|
||||
}
|
||||
|
||||
last_state=""
|
||||
|
||||
while true; do
|
||||
get_info
|
||||
|
||||
if [[ "$status" == "Discharging" && "$percentage" -le "$CRITICAL" ]]; then
|
||||
notify critical "Battery Critically Low" "$percentage% — suspending."
|
||||
$ACTION
|
||||
|
||||
elif [[ "$status" == "Discharging" && "$percentage" -le "$LOW" ]]; then
|
||||
if [[ "$last_state" != "low" ]]; then
|
||||
notify normal "Battery Low" "$percentage% remaining."
|
||||
last_state="low"
|
||||
fi
|
||||
|
||||
elif [[ "$status" != "Discharging" && "$percentage" -ge "$FULL" ]]; then
|
||||
if [[ "$last_state" != "full" ]]; then
|
||||
notify normal "Battery Full" "$percentage% — unplug charger."
|
||||
last_state="full"
|
||||
fi
|
||||
|
||||
else
|
||||
last_state=""
|
||||
fi
|
||||
|
||||
sleep "$INTERVAL"
|
||||
done
|
||||
'';
|
||||
};
|
||||
};
|
||||
flake.homeModules.cbatticon = _: {
|
||||
# don't works. some GTK error. I let it here if someday, someone is interest in this shit.
|
||||
# ChatGPT half baked a replacement that works on my system.
|
||||
# see qtbatticon
|
||||
services.cbatticon = {
|
||||
enable = true;
|
||||
lowLevelPercent = 20;
|
||||
criticalLevelPercent = 5;
|
||||
batteryId = "BAT1";
|
||||
hideNotification = true; # we use another script for battery notifications
|
||||
updateIntervalSeconds = 10;
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user