Skip to content

Commit 8fa3fb3

Browse files
committed
Add eco mode
1 parent 6968e39 commit 8fa3fb3

File tree

4 files changed

+80
-21
lines changed

4 files changed

+80
-21
lines changed

.config/quickshell/TopBar.qml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,23 @@ PanelWindow {
4444
property int extraPadding: 16
4545
property int animDuration: 250
4646

47+
property bool ecoMode: false
48+
4749
implicitWidth: screen.width - extraPadding
4850
implicitHeight: barHeight + extraPadding / 2
4951

5052
anchors.top: true
5153
color: "transparent"
5254

55+
IpcHandler {
56+
target: "bar"
57+
58+
function setEcoMode(eco: bool): void {
59+
root.ecoMode = eco;
60+
}
61+
62+
}
63+
5364
GlobalShortcut {
5465
name: "volume-up"
5566
onPressed: {
@@ -162,15 +173,22 @@ PanelWindow {
162173
}
163174

164175
// system stats
165-
Stats {
166-
fontSize: root.fontSize
167-
colBar: root.colDark
168-
colCpu: root.colFg
169-
colMem: root.colFg
170-
colDisk: root.colFg
176+
Loader {
177+
active: !root.ecoMode
178+
asynchronous: true
179+
180+
sourceComponent: Stats {
181+
fontSize: root.fontSize
182+
colBar: root.colDark
183+
colCpu: root.colFg
184+
colMem: root.colFg
185+
colDisk: root.colFg
186+
}
171187
}
172188

173-
BarSeparator {}
189+
BarSeparator {
190+
visible: !root.ecoMode
191+
}
174192

175193
// audio
176194
RowLayout {
@@ -216,6 +234,7 @@ PanelWindow {
216234

217235
// comms
218236
Network {
237+
ecoMode: root.ecoMode
219238
colFg: root.colFg
220239
fontSize: root.fontSize
221240
}

.config/quickshell/components/Clock.qml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ Item {
1111
property int slideDuration: 250
1212
property color colMain: "#b0b4bc"
1313
property color colBtn: "#cc0000"
14+
property color colGreen: "#9ece6a"
1415
property string fontFamily: "FiraCode Nerd Font"
1516
property int fontSize: 14
17+
property bool ecoMode: false
1618

1719
implicitWidth: (hoverDetector.containsMouse ? dateContainer.width + 8 : 0) + clockText.width
1820
implicitHeight: clockText.height
@@ -35,6 +37,12 @@ Item {
3537
Component.onCompleted: running = false
3638
}
3739

40+
Process {
41+
id: lowpowerProc
42+
command: ["lowpowermode", root.ecoMode ? 1 : 0]
43+
Component.onCompleted: running = false
44+
}
45+
3846
RowLayout {
3947
id: dateContainer
4048
anchors.right: clockContainer.left
@@ -79,11 +87,40 @@ Item {
7987
}
8088
}
8189

90+
Text {
91+
id: ecoBtn
92+
text: root.ecoMode ? "󰌪" : "󱋙"
93+
color: root.ecoMode ? root.colGreen : root.colMain
94+
Layout.bottomMargin: 2
95+
96+
font {
97+
family: "Symbols Nerd Font"
98+
pixelSize: root.fontSize + 1
99+
bold: true
100+
}
101+
102+
Behavior on color {
103+
ColorAnimation {
104+
duration: 250
105+
easing.type: Easing.OutCubic
106+
}
107+
}
108+
109+
MouseArea {
110+
anchors.fill: parent
111+
onClicked: {
112+
root.ecoMode = !root.ecoMode;
113+
lowpowerProc.running = true;
114+
}
115+
}
116+
}
117+
82118
Text {
83119
id: powerBtn
84120
text: ""
85121
color: root.colBtn
86122
Layout.bottomMargin: 2
123+
87124
font {
88125
family: "Symbols Nerd Font"
89126
pixelSize: root.fontSize + 1

.config/quickshell/components/Network.qml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ Item {
1212
property color colYellow: "#ffd700"
1313
property color colCyan: "#0db9d7"
1414
property color colOffline: "#cc0000"
15-
property color colOnline: root.isOnline ? root.colFg : root.colOffline
15+
property color colMuted: "#aa4e4e4e"
16+
1617
property bool isOnline: false
18+
property bool ecoMode: false
19+
20+
property color colOnline: root.ecoMode ? root.colMuted : root.isOnline ? root.colFg : root.colOffline
1721

1822
readonly property var devicesList: Networking.devices.values
1923
readonly property string uplinkIcon: hasActiveVpn ? "" : ""
@@ -91,8 +95,8 @@ Item {
9195

9296
Process {
9397
id: onlineCheck
94-
command: ["host", "-W", "5", "8.8.8.8"]
95-
running: true
98+
command: ["host", "-W", "1", "8.8.8.8"]
99+
running: !root.ecoMode
96100

97101
onExited: (exitCode, exitStatus) => {
98102
var randomValue = Math.floor(Math.random() * (1000 - 5000) + 5000);
@@ -104,7 +108,7 @@ Item {
104108

105109
Timer {
106110
id: tmr
107-
interval: 2000
111+
running: !root.ecoMode
108112
onTriggered: {
109113
onlineCheck.running = true;
110114
}
@@ -116,9 +120,12 @@ Item {
116120
spacing: 6
117121

118122
Text {
119-
id: ifIcon
123+
id: onlineIcon
120124
text: root.uplinkIcon
121-
color: root.isOnline ? root.colFg : root.colOffline
125+
126+
property bool isHovered: false
127+
128+
color: isHovered ? root.colCyan : root.colOnline
122129
font.family: "Symbols Nerd Font"
123130
font.pixelSize: root.fontSize
124131

@@ -134,11 +141,11 @@ Item {
134141
hoverEnabled: true
135142

136143
onEntered: {
137-
ifIcon.color = root.colCyan;
144+
onlineIcon.isHovered = true;
138145
}
139146

140147
onExited: {
141-
ifIcon.color = root.colOnline;
148+
onlineIcon.isHovered = false;
142149
}
143150

144151
onClicked: {

bin/lowpowermode

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
#!/bin/sh
22
# Toggle low power mode
33

4-
bar=$(pgrep -l quickshell)
5-
64
if [ "$1" = 0 ]; then
75
STATUS="disabled"
8-
if test -z "${bar}"; then
9-
quickshell -d
10-
fi
116

7+
quickshell ipc call bar setEcoMode false
128
hyprctl reload --quiet
139
notify-send -u low "LOW POWER MODE" "OFF" --icon=battery-full-symbolic
1410
elif [ "$1" = 1 ]; then
1511
STATUS="enabled"
16-
quickshell kill
12+
quickshell ipc call bar setEcoMode true
1713
hyprctl --quiet --batch "\
1814
keyword animations:enabled false;\
1915
keyword decoration:blur:enabled false;\

0 commit comments

Comments
 (0)