From ce5908ed1c96ac3e8cf9e9aa471441a1d653ab3b Mon Sep 17 00:00:00 2001 From: Aargh Rai Date: Sun, 10 May 2026 14:57:19 +0530 Subject: switched from power-profiles-daemon to tlp & removed the option to manually change the power mode, tlp does it automatically now! --- nixos/configuration.nix | 1 + nixos/opt/nvidia.nix | 4 +- nixos/power-management.nix | 22 ++++++ nixos/services.nix | 1 - quickshell/BatteryInfo.qml | 139 +++++++++++++++++++++++++++++++++++++ quickshell/BatteryModeConfig.qml | 110 ----------------------------- quickshell/items/Electrons.qml | 2 +- quickshell/scripts/battery-info.py | 39 +++++++++++ quickshell/scripts/battery-info.sh | 17 +++++ quickshell/shell.qml | 12 ++-- 10 files changed, 228 insertions(+), 119 deletions(-) create mode 100644 nixos/power-management.nix create mode 100644 quickshell/BatteryInfo.qml delete mode 100644 quickshell/BatteryModeConfig.qml create mode 100644 quickshell/scripts/battery-info.py create mode 100755 quickshell/scripts/battery-info.sh diff --git a/nixos/configuration.nix b/nixos/configuration.nix index c17e4c9..8044d8e 100644 --- a/nixos/configuration.nix +++ b/nixos/configuration.nix @@ -5,6 +5,7 @@ ../hardware-configuration.nix ./cachix.nix ./boot.nix + ./power-management.nix ./services.nix ./home.nix ./desktop-environment.nix diff --git a/nixos/opt/nvidia.nix b/nixos/opt/nvidia.nix index 191fa98..4373165 100644 --- a/nixos/opt/nvidia.nix +++ b/nixos/opt/nvidia.nix @@ -7,7 +7,9 @@ nvidiaSettings = true; open = false; prime = { - + sync.enable = true; + nvidiaBusId = "PCI:1:0:0"; + intelBusId = "PCI:0:2:0"; }; }; hardware.graphics.enable32Bit = true; diff --git a/nixos/power-management.nix b/nixos/power-management.nix new file mode 100644 index 0000000..3600374 --- /dev/null +++ b/nixos/power-management.nix @@ -0,0 +1,22 @@ +{ config, pkgs, ... }: +{ + services.power-profiles-daemon.enable = false; + services.tlp = { + enable = true; + settings = { + CPU_SCALING_GOVERNOR_ON_AC = "performance"; + CPU_SCALING_GOVERNOR_ON_BAT = "powersave"; + + CPU_ENERGY_PERF_POLICY_ON_BAT = "power"; + CPU_ENERGY_PERF_POLICY_ON_AC = "performance"; + + CPU_MIN_PERF_ON_AC = 0; + CPU_MAX_PERF_ON_AC = 100; + CPU_MIN_PERF_ON_BAT = 0; + CPU_MAX_PERF_ON_BAT = 20; + + START_CHARGE_THRESH_BAT1 = 40; + STOP_CHARGE_THRESH_BAT1 = 80; + }; + }; +} diff --git a/nixos/services.nix b/nixos/services.nix index 0aa96d5..5c17b64 100644 --- a/nixos/services.nix +++ b/nixos/services.nix @@ -28,7 +28,6 @@ pulse.enable = true; wireplumber.enable = true; }; - services.power-profiles-daemon.enable = true; services.cloudflare-warp.enable = true; services.openssh.enable = true; services.flatpak.enable = true; diff --git a/quickshell/BatteryInfo.qml b/quickshell/BatteryInfo.qml new file mode 100644 index 0000000..e879d94 --- /dev/null +++ b/quickshell/BatteryInfo.qml @@ -0,0 +1,139 @@ +import QtQuick +import QtQuick.Layouts +import Quickshell +import Quickshell.Io + +Rectangle { + id: batteryInfoRect + + width: 300 + height: 120 + Layout.fillWidth: true + Layout.fillHeight: true + color: shellRoot.black + antialiasing: true + topLeftRadius: 10 + topRightRadius: 10 + property var energy: "" + property var voltage: "" + property var capacity: "" + + Timer { + interval: 0 + running: true + repeat: false + onTriggered: { + fetchProc.running = true; + } + } + + signal requestClose() + focus: true + Keys.onEscapePressed: requestClose() + + Process { + id: fetchProc + command: ["sh", "-c", "~/.config/quickshell/scripts/battery-info.sh"] + + stdout: SplitParser { + onRead: data => { + if (data.includes("energy")) { + energy = data.split(":")[1] + return + } + if (data.includes("voltage")) { + voltage = data.split(":")[1] + return + } + if (data.includes("capacity")) { + capacity = data.split(":")[1] + return + } + } + + } + Component.onCompleted: running = true + } + + RowLayout { + anchors.centerIn: parent + ColumnLayout { + anchors.left: parent + Text { + text: "Energy" + font.family: shellRoot.fontFamily + font.pixelSize: 20 + font.weight: Font.Medium + color: shellRoot.green + MouseArea { + anchors.fill: parent + onClicked: { + } + } + } + Text { + text: "Capacity" + font.family: shellRoot.fontFamily + font.pixelSize: 20 + font.weight: Font.Medium + color: shellRoot.green + MouseArea { + anchors.fill: parent + onClicked: { + } + } + } + Text { + text: "Voltage" + font.family: shellRoot.fontFamily + font.pixelSize: 20 + font.weight: Font.Medium + color: shellRoot.green + MouseArea { + anchors.fill: parent + onClicked: { + } + } + } + } + ColumnLayout { + anchors.right: parent + Text { + text: energy + font.family: shellRoot.fontFamily + font.pixelSize: 20 + font.weight: Font.Medium + color: shellRoot.white + MouseArea { + anchors.fill: parent + onClicked: { + } + } + } + Text { + text: capacity + font.family: shellRoot.fontFamily + font.pixelSize: 20 + font.weight: Font.Medium + color: shellRoot.white + MouseArea { + anchors.fill: parent + onClicked: { + } + } + } + Text { + text: voltage + font.family: shellRoot.fontFamily + font.pixelSize: 20 + font.weight: Font.Medium + color: shellRoot.white + MouseArea { + anchors.fill: parent + onClicked: { + } + } + } + } + } +} diff --git a/quickshell/BatteryModeConfig.qml b/quickshell/BatteryModeConfig.qml deleted file mode 100644 index 4ef80c5..0000000 --- a/quickshell/BatteryModeConfig.qml +++ /dev/null @@ -1,110 +0,0 @@ -import QtQuick -import QtQuick.Layouts -import Quickshell -import Quickshell.Io - -Rectangle { - id: batteryModeConfigRect - - width: 200 - height: 50 - Layout.fillWidth: true - Layout.fillHeight: true - color: shellRoot.black - antialiasing: true - topLeftRadius: 10 - topRightRadius: 10 - property int current: 1 - - Timer { - interval: 0 - running: true - repeat: false - onTriggered: { - fetchProc.running = true; - } - } - - signal requestClose() - focus: true - Keys.onEscapePressed: requestClose() - - Process { - id: fetchProc - command: ["sh", "-c", "powerprofilesctl get"] - - stdout: SplitParser { - onRead: data => { - const p = data.trim(); - if (p == "power-saver") current = 0; - else if (p == "balanced") current = 1; - else if (p == "performance") current = 2; - else current = 3; - } - } - Component.onCompleted: running = true - } - - Process { - id: saverProc - command: ["sh", "-c", "powerprofilesctl set power-saver"] - Component.onCompleted: running = false - } - Process { - id: balancedProc - command: ["sh", "-c", "powerprofilesctl set balanced"] - Component.onCompleted: running = false - } - Process { - id: perfProc - command: ["sh", "-c", "powerprofilesctl set performance"] - Component.onCompleted: running = false - } - - RowLayout { - anchors.centerIn: parent - spacing: 40 - Text { - text: "󰌪" - font.family: shellRoot.fontFamily - font.pixelSize: batteryModeConfigRect.current == 0 ? 40 : 20 - font.weight: Font.Medium - color: batteryModeConfigRect.current == 0 ? shellRoot.green : shellRoot.white - MouseArea { - anchors.fill: parent - onClicked: { - saverProc.running = true; - current = 0; - } - } - } - Text { - text: "" - font.family: shellRoot.fontFamily - font.pixelSize: batteryModeConfigRect.current == 1 ? 40 : 20 - font.weight: Font.Medium - color: batteryModeConfigRect.current == 1 ? shellRoot.green : shellRoot.white - MouseArea { - anchors.fill: parent - onClicked: { - balancedProc.running = true; - current = 1; - } - } - } - Text { - text: "󰠠" - font.family: shellRoot.fontFamily - font.pixelSize: batteryModeConfigRect.current == 2 ? 40 : 20 - font.weight: Font.Medium - color: batteryModeConfigRect.current == 2 ? shellRoot.green : shellRoot.white - MouseArea { - anchors.fill: parent - onClicked: { - perfProc.running = true; - current = 2; - } - } - } - } -} diff --git a/quickshell/items/Electrons.qml b/quickshell/items/Electrons.qml index b507509..f75c126 100644 --- a/quickshell/items/Electrons.qml +++ b/quickshell/items/Electrons.qml @@ -22,6 +22,6 @@ RowLayout { } MouseArea { anchors.fill: parent - onClicked: shellRoot.batteryModeConfig = !shellRoot.batteryModeConfig + onClicked: shellRoot.batteryInfo = !shellRoot.batteryModeConfig } } diff --git a/quickshell/scripts/battery-info.py b/quickshell/scripts/battery-info.py new file mode 100644 index 0000000..c3958f7 --- /dev/null +++ b/quickshell/scripts/battery-info.py @@ -0,0 +1,39 @@ +# this script was used to generate the battery-info.sh via chatgpt + +import subprocess + +output = subprocess.run( + ["upower", "--enumerate"], + capture_output=True +).stdout.decode('utf-8') + +target = None + +for line in output.split("\n"): + if "BAT" not in line: + continue + target = line + break + +print(line) + +output = subprocess.run( + ["upower", "-i", line], + capture_output=True +).stdout.decode('utf-8') + +energy = None +voltage = None +capacity = None + +for line in output.split("\n"): + if energy is None and "energy:" in line: + energy = line.split(":")[1].strip() + if voltage is None and "voltage:" in line: + voltage = line.split(":")[1].strip() + if capacity is None and "capacity:" in line: + capacity = line.split(":")[1].strip() + +print("energy:", energy) +print("voltage:", voltage) +print("capacity:", capacity) diff --git a/quickshell/scripts/battery-info.sh b/quickshell/scripts/battery-info.sh new file mode 100755 index 0000000..414d168 --- /dev/null +++ b/quickshell/scripts/battery-info.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +target=$(upower --enumerate | awk '/BAT/ { print; exit }') + +upower -i "$target" | awk -F: ' +/energy:/ && !e { e=$2 } +/voltage:/ && !v { v=$2 } +/capacity:/ && !c { c=$2 } +END { + gsub(/^[ \t]+/, "", e) + gsub(/^[ \t]+/, "", v) + gsub(/^[ \t]+/, "", c) + + print "energy:", e + print "voltage:", v + print "capacity:", c +}' diff --git a/quickshell/shell.qml b/quickshell/shell.qml index cab8d77..2664ac3 100644 --- a/quickshell/shell.qml +++ b/quickshell/shell.qml @@ -26,7 +26,7 @@ ShellRoot { property bool appLauncherVisible: false property bool calendarVisible: false - property bool batteryModeConfig: false + property bool batteryInfo: false property bool blink: false GlobalShortcut { @@ -178,7 +178,7 @@ ShellRoot { model: Quickshell.screens PanelWindow { - visible: shellRoot.batteryModeConfig + visible: shellRoot.batteryInfo anchors { bottom: true @@ -190,8 +190,8 @@ ShellRoot { left: Screen.width / 2 - 100 } - implicitWidth: 200 - implicitHeight: 50 + implicitWidth: 300 + implicitHeight: 120 color: "transparent" exclusiveZone: 0 @@ -203,9 +203,9 @@ ShellRoot { NumberAnimation { duration: 200; easing.type: Easing.OutCubic } } - BatteryModeConfig { + BatteryInfo { onRequestClose: { - shellRoot.batteryModeConfig = false + shellRoot.batteryInfo = false } } } -- cgit v1.2.3