diff --git a/modules/hardware/battery.nix b/modules/hardware/battery.nix index 4c8d88c..271c408 100644 --- a/modules/hardware/battery.nix +++ b/modules/hardware/battery.nix @@ -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; - }; }; } diff --git a/other/hyprland/hyprland.lua b/other/hyprland/hyprland.lua index 0cb42b0..164ffa5 100644 --- a/other/hyprland/hyprland.lua +++ b/other/hyprland/hyprland.lua @@ -38,6 +38,7 @@ local function close_other_windows() end end +local wallpapers_enabled = true local wallpapers = { [1] = "WALLPAPER1/PATH/PLACEHOLDER", [2] = "WALLPAPER2/PATH/PLACEHOLDER", @@ -51,13 +52,144 @@ local wallpapers = { [10] = "WALLPAPER5/PATH/PLACEHOLDER", } -hl.on("workspace.active", function(workspace) +local function set_wallpaper(workspace) + if not wallpapers_enabled then + return + end + local wallpaper = wallpapers[workspace.id] if wallpaper then hl.exec_cmd("awww img -t none " .. wallpaper) end -end) +end + +hl.on("workspace.active", set_wallpaper) + +local performance_mode = false +local saved_brightness = nil + +local function get_brightness() + local handle = io.popen("brightnessctl get 2>/dev/null") + + if not handle then + return nil + end + + local value = handle:read("*a") + handle:close() + + if not value then + return nil + end + + value = value:gsub("%s+$", "") + return tonumber(value) +end + +local function set_performance_mode() + if performance_mode then + hl.monitor({ + output = "eDP-1", + mode = "2560x1600@165", + position = "0x0", + scale = 1, + }) + + hl.exec_cmd("pkill swaync || true") + hl.exec_cmd("pkill waybar || true") + hl.exec_cmd("caelestia shell -d") + + if saved_brightness then + hl.exec_cmd("brightnessctl set " .. saved_brightness) + end + + saved_brightness = nil + wallpapers_enabled = true + performance_mode = false + + hl.exec_cmd("hyprctl reload") + + local workspace = hl.get_active_workspace() + if workspace then + set_wallpaper(workspace) + end + + hl.notification.create({ + text = "Battery Saver", + subtext = "Disabled", + timeout = 3000, + }) + + return + end + -- Save current brightness. + saved_brightness = get_brightness() + + -- Lower refresh rate. + hl.monitor({ + output = "eDP-1", + mode = "2560x1600@60", + position = "0x0", + scale = 1, + }) + + -- Stop heavy UI components. + hl.exec_cmd("pkill -f caelestia-shell || true") + hl.exec_cmd("pkill -f caelestia || true") + + -- Start lightweight notification daemon. + hl.exec_cmd("pkill swaync || true") + hl.exec_cmd("swaync") + + -- Start lightweight status bar. + hl.exec_cmd("pkill waybar || true") + hl.exec_cmd("waybar") + + -- Disable expensive Hyprland effects. + hl.config({ + animations = { + enabled = false, + }, + + decoration = { + shadow = { + enabled = false, + }, + blur = { + enabled = false, + }, + rounding = 0, + fullscreen_opacity = 1, + active_opacity = 1, + inactive_opacity = 1, + }, + + general = { + gaps_in = 0, + gaps_out = 0, + border_size = 1, + }, + + misc = { + vfr = 1, + }, + }) + + -- Lower brightness. + hl.exec_cmd("brightnessctl set 5%") + + -- Disable workspace wallpaper switching. + wallpapers_enabled = false + + performance_mode = true + + hl.notification.create({ + text = "Battery Saver", + subtext = "Enabled", + timeout = 3000, + }) +end hl.curve("wind", { type = "bezier", points = { { 0.05, 0.9 }, { 0.1, 1.05 } } }) hl.curve("winIn", { type = "bezier", points = { { 0.1, 1.1 }, { 0.1, 1.1 } } }) @@ -171,12 +303,19 @@ hl.bind(mod .. " + F", hl.dsp.exec_cmd(browser)) hl.bind(mod .. " + N", hl.dsp.exec_cmd(notes)) hl.bind(mod .. " + SHIFT + A", hl.dsp.exec_cmd("caelestia shell drawers toggle launcher")) hl.bind(mod .. " + Q", close_or_move_special) -hl.bind("CTRL + ALT + W", hl.dsp.exec_cmd("caelestia shell drawers toggle sidebar")) +local function toggle_sidebar() + if performance_mode then + hl.exec_cmd("swaync-client -t") + else + hl.exec_cmd("caelestia shell drawers toggle sidebar") + end +end +hl.bind("CTRL + ALT + W", toggle_sidebar) hl.bind(mod .. " + L", hl.dsp.exec_cmd("caelestia shell lock lock")) hl.bind("F11", hl.dsp.exec_cmd("caelestia screenshot")) hl.bind(mod .. " + SHIFT + S", hl.dsp.exec_cmd("caelestia shell picker open")) hl.bind(mod .. " + CTRL + 6", close_other_windows) -hl.bind("CTRL + ALT + 7", hl.dsp.exec_cmd("custom-performance")) +hl.bind("CTRL + ALT + 7", set_performance_mode) hl.bind("CTRL + ALT + 1", hl.dsp.exec_cmd("caelestia shell drawers toggle sidebar")) hl.bind(mod .. " + CTRL + 4", hl.dsp.exec_cmd("caelestia shell notifs toggleDnd")) hl.bind(mod .. " + CTRL + 3", hl.dsp.exec_cmd("pavucontrol")) @@ -794,7 +933,6 @@ hl.on("hyprland.start", function() hl.exec_cmd("custom-batterywarning") hl.exec_cmd("awww img WALLPAPER/PATH/PLACEHOLDER") hl.exec_cmd("awww-daemon") - hl.exec_cmd("sleep 1 && custom-wallpaper") hl.exec_cmd("custom-checkKdrive && custom-mountkdrive") hl.exec_cmd("custom-gitnotify") hl.exec_cmd("sleep 4 & caelestia-shell")