From 09d92bc8e201c5c0d361db508a23de2ffef360aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Rivera?= Date: Sat, 13 Jun 2026 11:56:27 +0200 Subject: [PATCH] custom-performance: entire rewrite Now kills caelestia, change monitor hz and launches lightweight alternative to calestia (waybar and swaync) --- .gitignore | 9 +++ modules/applications/hyprland.nix | 8 ++- modules/applications/waybar.nix | 28 +++++++++ modules/applications/zsh.nix | 21 ++++++- modules/hardware/battery.nix | 98 +++++++++++++++++++++++++++---- modules/hosts/desktop.nix | 7 ++- modules/hosts/laptop.nix | 2 + 7 files changed, 154 insertions(+), 19 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a357584 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# Ignore build outputs from performing a nix-build or `nix build` command +result +result-* + +# Ignore automatically generated direnv output +.direnv + +# Ignore NixOS interactive test driver history +**/.nixos-test-history diff --git a/modules/applications/hyprland.nix b/modules/applications/hyprland.nix index d2c3c4a..e724657 100644 --- a/modules/applications/hyprland.nix +++ b/modules/applications/hyprland.nix @@ -198,8 +198,8 @@ "$mod_SHIFT, S, exec, caelestia shell picker open" # framework 16 rgb macropad "Ctrl+$mod, 6, exec, custom-killall" # pos 1 1 killall apps except focused one - #"Ctrl+Alt, 7, exec, custom-performance" # pos 2 1 start performance mode - "Ctrl+Alt, 7, exec, caelestia shell gameMode toggle" + "Ctrl+Alt, 7, exec, custom-performance" # pos 2 1 start performance mode + #"Ctrl+Alt, 7, exec, caelestia shell gameMode toggle" # reloads the autostart programs # pos 3 1 # we passed to caelestia-shell and stoped using that /* @@ -211,7 +211,9 @@ #"Ctrl+Alt, 1, exec, swaync-client -t" # pos 4 1 notification center "Ctrl+Alt, 1, exec, qs ipc call notifications toggle" */ - "Ctrl+Alt, 1, exec, caelestia shell drawers toggle sidebar" + # pos 4 1 notification center. + "Ctrl+Alt, 1, exec, caelestia shell drawers toggle sidebar" + "Ctrl+Alt, 1, exec, [[ -f ~/.cache/hypr-battery-saver ]] || swaync-client -t" "Ctrl+$mod, 4, exec, caelestia shell notifs toggleDnd" "Ctrl+$mod, 3, exec, pavucontrol" # pos 1 2 audiocontrol "Ctrl+Shift+Alt, 0, exec, kitty --hold --class \"custom-changeAudioOutput\" --name \"Select audio output\" zsh -c \"custom-changeAudioOutput\"" # pos 2 2 change audio output fzf diff --git a/modules/applications/waybar.nix b/modules/applications/waybar.nix index 3fbe247..9af7bcd 100644 --- a/modules/applications/waybar.nix +++ b/modules/applications/waybar.nix @@ -1,4 +1,32 @@ _: { + flake.homeModules.waybar-minimal = _: { + programs.waybar = { + enable = true; + settings = [ + { + layer = "top"; + modules-left = []; + modules-center = []; + modules-right = [ + "battery" + "clock" + ]; + + battery = { + format = "{capacity}% {icon}"; + states = { + warning = 30; + critical = 15; + }; + }; + + clock = { + format = "{:%H:%M}"; + }; + } + ]; + }; + }; flake.homeModules.waybar = _: { # replaced by caelestia programs.waybar = { diff --git a/modules/applications/zsh.nix b/modules/applications/zsh.nix index c58545b..01b5c0e 100644 --- a/modules/applications/zsh.nix +++ b/modules/applications/zsh.nix @@ -2,8 +2,25 @@ _: { flake.homeModules.zsh-laptop = _: { programs.zsh = { shellAliases = { - snrt = "git -C ~/nixos add -A && time sudo nixos-rebuild test --flake ~/nixos/#laptop && pkill shell || true && pkill caelestia-shell || true && caelestia-shell -n > /dev/null 2>&1 & disown"; - snrs = "git -C ~/nixos add -A && time sudo nixos-rebuild switch --flake ~/nixos/#laptop && pkill shell || true && pkill caelestia-shell || true && caelestia-shell -n > /dev/null 2>&1 & disown"; + snrt = '' + git -C ~/nixos add -A && + time sudo nixos-rebuild test --flake ~/nixos/#laptop && + pkill shell || true && + if [ ! -f ~/.cache/hypr-battery-saver ]; then + pkill caelestia-shell || true && + caelestia-shell -n > /dev/null 2>&1 & disown + fi + ''; + + snrs = '' + git -C ~/nixos add -A && + time sudo nixos-rebuild switch --flake ~/nixos/#laptop && + pkill shell || true && + if [ ! -f ~/.cache/hypr-battery-saver ]; then + pkill caelestia-shell || true && + caelestia-shell -n > /dev/null 2>&1 & disown + fi + ''; }; }; }; diff --git a/modules/hardware/battery.nix b/modules/hardware/battery.nix index 224aa32..882c5e0 100644 --- a/modules/hardware/battery.nix +++ b/modules/hardware/battery.nix @@ -1,7 +1,8 @@ -_: { +{self, inputs, ...}: { flake.nixosModules.battery-laptop = { lib, config, + pkgs, ... }: # https://discourse.nixos.org/t/what-is-the-best-option-for-power-management/63406/2 @@ -50,7 +51,9 @@ _: { STOP_CHARGE_THRESH_BAT1 = 80; }; }; - # }; + environment.systemPackages = [ + self.packages.${pkgs.system}.custom-performance + ]; }; perSystem = {pkgs, ...}: let NotifySound = ../../assets/battery_notify.mp3; @@ -335,28 +338,97 @@ _: { name = "custom-performance"; runtimeInputs = with pkgs; [ hyprland - gawk + brightnessctl + swaynotificationcenter + self.packages.${pkgs.system}.custom-wallpaper libnotify + inputs.caelestia-shell.packages.${pkgs.system}.default ]; text = '' - HYPRGAMEMODE=$(hyprctl getoption animations:enabled | awk 'NR==1{print $2}') - if [ "$HYPRGAMEMODE" = 1 ] ; then + 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 animation borderangle,0;\ keyword decoration:shadow:enabled 0;\ keyword decoration:blur:enabled 0;\ - keyword decoration:fullscreen_opacity 1;\ + 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:rounding 0" - notify-send -u critical -t 5000 "Performance mode [ON]" - exit - else - notify-send -u critical -t 5000 "Performance mode [OFF]" + 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 >/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 - exit 0 + + # 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 ''; }; diff --git a/modules/hosts/desktop.nix b/modules/hosts/desktop.nix index b56cb9d..05517a3 100644 --- a/modules/hosts/desktop.nix +++ b/modules/hosts/desktop.nix @@ -74,15 +74,17 @@ rofi sbb-tui ssh + swaync # used in performance mode thunderbird tomasr vivify + waybar-minimal # used in performance mode zoxide zsh zsh-desktop ]; }; - flake.nixosModules.desktop = _: { + flake.nixosModules.desktop = {pkgs, ...}: { # This value determines the NixOS release from which the default # settings for stateful data, like file locations and database versions # on your system were taken. It‘s perfectly fine and recommended to leave @@ -94,6 +96,9 @@ "nix-command" "flakes" ]; + environment.systemPackages = [ + self.packages.${pkgs.system}.custom-performance + ]; }; flake.nixosModules.home-manager-desktop = {pkgs, ...}: { imports = [ diff --git a/modules/hosts/laptop.nix b/modules/hosts/laptop.nix index 8c5132f..76ed58d 100644 --- a/modules/hosts/laptop.nix +++ b/modules/hosts/laptop.nix @@ -76,9 +76,11 @@ rofi sbb-tui ssh + swaync # used in performance mode thunderbird tomasr vivify + waybar-minimal # used in performance mode zoxide zsh zsh-laptop