Skip to content

Commit 3806075

Browse files
authored
Merge pull request #2971 from picnoir/pic/power-profiles-daemon
Introduce a power-profiles-daemon module
2 parents 26af106 + 5578c12 commit 3806075

8 files changed

+363
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Local time
1414
- Battery
1515
- UPower
16+
- Power profiles daemon
1617
- Network
1718
- Bluetooth
1819
- Pulseaudio
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#pragma once
2+
3+
#include <fmt/format.h>
4+
5+
#include "ALabel.hpp"
6+
#include "giomm/dbusproxy.h"
7+
8+
namespace waybar::modules {
9+
10+
struct Profile {
11+
std::string name;
12+
std::string driver;
13+
};
14+
15+
class PowerProfilesDaemon : public ALabel {
16+
public:
17+
PowerProfilesDaemon(const std::string &, const Json::Value &);
18+
auto update() -> void override;
19+
void profileChangedCb(const Gio::DBus::Proxy::MapChangedProperties &,
20+
const std::vector<Glib::ustring> &);
21+
void busConnectedCb(Glib::RefPtr<Gio::AsyncResult> &r);
22+
void getAllPropsCb(Glib::RefPtr<Gio::AsyncResult> &r);
23+
void setPropCb(Glib::RefPtr<Gio::AsyncResult> &r);
24+
void populateInitState();
25+
bool handleToggle(GdkEventButton *const &e) override;
26+
27+
private:
28+
// True if we're connected to the dbug interface. False if we're
29+
// not.
30+
bool connected_;
31+
// Look for a profile name in the list of available profiles and
32+
// switch activeProfile_ to it.
33+
void switchToProfile(std::string const &);
34+
// Used to toggle/display the profiles
35+
std::vector<Profile> availableProfiles_;
36+
// Points to the active profile in the profiles list
37+
std::vector<Profile>::iterator activeProfile_;
38+
// Current CSS class applied to the label
39+
std::string currentStyle_;
40+
// Format string
41+
std::string tooltipFormat_;
42+
// DBus Proxy used to track the current active profile
43+
Glib::RefPtr<Gio::DBus::Proxy> powerProfilesProxy_;
44+
};
45+
46+
} // namespace waybar::modules
+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
waybar-power-profiles-daemon(5)
2+
3+
# NAME
4+
5+
waybar - power-profiles-daemon module
6+
7+
# DESCRIPTION
8+
9+
The *power-profiles-daemon* module displays the active power-profiles-daemon profile and cycle through the available profiles on click.
10+
11+
# FILES
12+
13+
$XDG_CONFIG_HOME/waybar/config
14+
15+
# CONFIGURATION
16+
17+
18+
[- *Option*
19+
:- *Typeof*
20+
:- *Default*
21+
:= *Description*
22+
|[ *format*
23+
:[ string
24+
:[ "{icon}"
25+
:[ Message displayed on the bar. {icon} and {profile} are respectively substituted with the icon representing the active profile and its full name.
26+
|[ *tooltip-format*
27+
:[ string
28+
:[ "Power profile: {profile}\\nDriver: {driver}"
29+
:[ Messaged displayed in the module tooltip. {icon} and {profile} are respectively substituted with the icon representing the active profile and its full name.
30+
|[ *tooltip*
31+
:[ bool
32+
:[ true
33+
:[ Display the tooltip.
34+
|[ *format-icons*
35+
:[ object
36+
:[ See default value in the example below.
37+
:[ Icons used to represent the various power-profile. *Note*: the default configuration uses the font-awesome icons. You may want to override it if you don't have this font installed on your system.
38+
39+
40+
# CONFIGURATION EXAMPLES
41+
42+
Compact display (default config):
43+
44+
```
45+
"power-profiles-daemon": {
46+
"format": "{icon}",
47+
"tooltip-format": "Power profile: {profile}\nDriver: {driver}",
48+
"tooltip": true,
49+
"format-icons": {
50+
"default": "",
51+
"performance": "",
52+
"balanced": "",
53+
"power-saver": ""
54+
}
55+
}
56+
```
57+
58+
Display the full profile name:
59+
60+
```
61+
"power-profiles-daemon": {
62+
"format": "{icon} {profile}",
63+
"tooltip-format": "Power profile: {profile}\nDriver: {driver}",
64+
"tooltip": true,
65+
"format-icons": {
66+
"default": "",
67+
"performance": "",
68+
"balanced": "",
69+
"power-saver": ""
70+
}
71+
}
72+
```

meson.build

+2-1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ if is_linux
212212
'src/modules/cpu_usage/linux.cpp',
213213
'src/modules/memory/common.cpp',
214214
'src/modules/memory/linux.cpp',
215+
'src/modules/power_profiles_daemon.cpp',
215216
'src/modules/systemd_failed_units.cpp',
216217
)
217218
man_files += files(
@@ -221,6 +222,7 @@ if is_linux
221222
'man/waybar-cpu.5.scd',
222223
'man/waybar-memory.5.scd',
223224
'man/waybar-systemd-failed-units.5.scd',
225+
'man/waybar-power-profiles-daemon.5.scd',
224226
)
225227
elif is_dragonfly or is_freebsd or is_netbsd or is_openbsd
226228
add_project_arguments('-DHAVE_CPU_BSD', language: 'cpp')
@@ -577,4 +579,3 @@ if clangtidy.found()
577579
'-p', meson.project_build_root()
578580
] + src_files)
579581
endif
580-

resources/config.jsonc

+12-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"idle_inhibitor",
2121
"pulseaudio",
2222
"network",
23+
"power-profiles-daemon",
2324
"cpu",
2425
"memory",
2526
"temperature",
@@ -147,6 +148,17 @@
147148
"battery#bat2": {
148149
"bat": "BAT2"
149150
},
151+
"power-profiles-daemon": {
152+
"format": "{icon}",
153+
"tooltip-format": "Power profile: {profile}\nDriver: {driver}",
154+
"tooltip": true,
155+
"format-icons": {
156+
"default": "",
157+
"performance": "",
158+
"balanced": "",
159+
"power-saver": ""
160+
}
161+
},
150162
"network": {
151163
// "interface": "wlp2*", // (Optional) To force the use of this interface
152164
"format-wifi": "{essid} ({signalStrength}%) ",
@@ -188,4 +200,3 @@
188200
// "exec": "$HOME/.config/waybar/mediaplayer.py --player spotify 2> /dev/null" // Filter player based on name
189201
}
190202
}
191-

resources/style.css

+20
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ button:hover {
8787
#mode,
8888
#idle_inhibitor,
8989
#scratchpad,
90+
#power-profiles-daemon,
9091
#mpd {
9192
padding: 0 10px;
9293
color: #ffffff;
@@ -139,6 +140,25 @@ button:hover {
139140
animation-direction: alternate;
140141
}
141142

143+
#power-profiles-daemon {
144+
padding-right: 15px;
145+
}
146+
147+
#power-profiles-daemon.performance {
148+
background-color: #f53c3c;
149+
color: #ffffff;
150+
}
151+
152+
#power-profiles-daemon.balanced {
153+
background-color: #2980b9;
154+
color: #ffffff;
155+
}
156+
157+
#power-profiles-daemon.power-saver {
158+
background-color: #2ecc71;
159+
color: #000000;
160+
}
161+
142162
label:focus {
143163
background-color: #000000;
144164
}

src/factory.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
#endif
8787
#if defined(__linux__)
8888
#include "modules/bluetooth.hpp"
89+
#include "modules/power_profiles_daemon.hpp"
8990
#endif
9091
#ifdef HAVE_LOGIND_INHIBITOR
9192
#include "modules/inhibitor.hpp"
@@ -282,6 +283,9 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name,
282283
if (ref == "bluetooth") {
283284
return new waybar::modules::Bluetooth(id, config_[name]);
284285
}
286+
if (ref == "power-profiles-daemon") {
287+
return new waybar::modules::PowerProfilesDaemon(id, config_[name]);
288+
}
285289
#endif
286290
#ifdef HAVE_LOGIND_INHIBITOR
287291
if (ref == "inhibitor") {

0 commit comments

Comments
 (0)