Merge pull request #2229 from LukashonakV/Upower_nativePath
Upower native-path filter
This commit is contained in:
commit
d367b7e1d6
|
@ -74,6 +74,7 @@ class UPower : public AModule {
|
||||||
bool showAltText;
|
bool showAltText;
|
||||||
bool upowerRunning;
|
bool upowerRunning;
|
||||||
guint upowerWatcher_id;
|
guint upowerWatcher_id;
|
||||||
|
std::string nativePath_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules::upower
|
} // namespace waybar::modules::upower
|
||||||
|
|
|
@ -11,6 +11,12 @@ compatible devices in the tooltip.
|
||||||
|
|
||||||
# CONFIGURATION
|
# CONFIGURATION
|
||||||
|
|
||||||
|
*native-path*: ++
|
||||||
|
typeof: string ++
|
||||||
|
default: ++
|
||||||
|
The battery to monitor. Refer to the https://upower.freedesktop.org/docs/UpDevice.html#UpDevice--native-path ++
|
||||||
|
Can be obtained using `upower --dump`
|
||||||
|
|
||||||
*icon-size*: ++
|
*icon-size*: ++
|
||||||
typeof: integer ++
|
typeof: integer ++
|
||||||
default: 20 ++
|
default: 20 ++
|
||||||
|
@ -68,6 +74,25 @@ depending on the charging state.
|
||||||
"tooltip-spacing": 20
|
"tooltip-spacing": 20
|
||||||
}
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
```
|
||||||
|
"upower": {
|
||||||
|
"native-path": "/org/bluez/hci0/dev_D4_AE_41_38_D0_EF",
|
||||||
|
"icon-size": 20,
|
||||||
|
"hide-if-empty": true,
|
||||||
|
"tooltip": true,
|
||||||
|
"tooltip-spacing": 20
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
```
|
||||||
|
"upower": {
|
||||||
|
"native-path": "battery_sony_controller_battery_d0o27o88o32ofcoee",
|
||||||
|
"icon-size": 20,
|
||||||
|
"hide-if-empty": true,
|
||||||
|
"tooltip": true,
|
||||||
|
"tooltip-spacing": 20
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
# STYLE
|
# STYLE
|
||||||
|
|
|
@ -6,9 +6,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "gtkmm/icontheme.h"
|
#include "gtkmm/icontheme.h"
|
||||||
#include "gtkmm/label.h"
|
|
||||||
#include "gtkmm/tooltip.h"
|
#include "gtkmm/tooltip.h"
|
||||||
#include "modules/upower/upower_tooltip.hpp"
|
|
||||||
|
|
||||||
namespace waybar::modules::upower {
|
namespace waybar::modules::upower {
|
||||||
UPower::UPower(const std::string& id, const Json::Value& config)
|
UPower::UPower(const std::string& id, const Json::Value& config)
|
||||||
|
@ -25,6 +23,8 @@ UPower::UPower(const std::string& id, const Json::Value& config)
|
||||||
box_.set_name(name_);
|
box_.set_name(name_);
|
||||||
event_box_.add(box_);
|
event_box_.add(box_);
|
||||||
|
|
||||||
|
// Device user wants
|
||||||
|
if (config_["native-path"].isString()) nativePath_ = config_["native-path"].asString();
|
||||||
// Icon Size
|
// Icon Size
|
||||||
if (config_["icon-size"].isUInt()) {
|
if (config_["icon-size"].isUInt()) {
|
||||||
iconSize = config_["icon-size"].asUInt();
|
iconSize = config_["icon-size"].asUInt();
|
||||||
|
@ -195,8 +195,26 @@ void UPower::addDevice(UpDevice* device) {
|
||||||
|
|
||||||
void UPower::setDisplayDevice() {
|
void UPower::setDisplayDevice() {
|
||||||
std::lock_guard<std::mutex> guard(m_Mutex);
|
std::lock_guard<std::mutex> guard(m_Mutex);
|
||||||
|
|
||||||
|
if (nativePath_.empty())
|
||||||
displayDevice = up_client_get_display_device(client);
|
displayDevice = up_client_get_display_device(client);
|
||||||
g_signal_connect(displayDevice, "notify", G_CALLBACK(deviceNotify_cb), this);
|
else {
|
||||||
|
g_ptr_array_foreach(
|
||||||
|
up_client_get_devices2(client),
|
||||||
|
[](gpointer data, gpointer user_data) {
|
||||||
|
UpDevice* device{static_cast<UpDevice*>(data)};
|
||||||
|
UPower* thisPtr{static_cast<UPower*>(user_data)};
|
||||||
|
gchar* nativePath;
|
||||||
|
if (!thisPtr->displayDevice) {
|
||||||
|
g_object_get(device, "native-path", &nativePath, NULL);
|
||||||
|
if (!std::strcmp(nativePath, thisPtr->nativePath_.c_str()))
|
||||||
|
thisPtr->displayDevice = device;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
this);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (displayDevice) g_signal_connect(displayDevice, "notify", G_CALLBACK(deviceNotify_cb), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UPower::removeDevices() {
|
void UPower::removeDevices() {
|
||||||
|
@ -278,14 +296,22 @@ auto UPower::update() -> void {
|
||||||
double percentage;
|
double percentage;
|
||||||
gint64 time_empty;
|
gint64 time_empty;
|
||||||
gint64 time_full;
|
gint64 time_full;
|
||||||
gchar* icon_name;
|
gchar* icon_name{(char*)'\0'};
|
||||||
|
std::string percentString{""};
|
||||||
|
std::string time_format{""};
|
||||||
|
|
||||||
|
bool displayDeviceValid{false};
|
||||||
|
|
||||||
|
if (displayDevice) {
|
||||||
g_object_get(displayDevice, "kind", &kind, "state", &state, "percentage", &percentage,
|
g_object_get(displayDevice, "kind", &kind, "state", &state, "percentage", &percentage,
|
||||||
"icon-name", &icon_name, "time-to-empty", &time_empty, "time-to-full", &time_full,
|
"icon-name", &icon_name, "time-to-empty", &time_empty, "time-to-full", &time_full,
|
||||||
NULL);
|
NULL);
|
||||||
|
/* Every Device which is handled by Upower and which is not
|
||||||
bool displayDeviceValid =
|
* UP_DEVICE_KIND_UNKNOWN (0) or UP_DEVICE_KIND_LINE_POWER (1) is a Battery
|
||||||
kind == UpDeviceKind::UP_DEVICE_KIND_BATTERY || kind == UpDeviceKind::UP_DEVICE_KIND_UPS;
|
*/
|
||||||
|
displayDeviceValid = (kind != UpDeviceKind::UP_DEVICE_KIND_UNKNOWN &&
|
||||||
|
kind != UpDeviceKind::UP_DEVICE_KIND_LINE_POWER);
|
||||||
|
}
|
||||||
|
|
||||||
// CSS status class
|
// CSS status class
|
||||||
const std::string status = getDeviceStatus(state);
|
const std::string status = getDeviceStatus(state);
|
||||||
|
@ -308,6 +334,7 @@ auto UPower::update() -> void {
|
||||||
|
|
||||||
event_box_.set_visible(true);
|
event_box_.set_visible(true);
|
||||||
|
|
||||||
|
if (displayDeviceValid) {
|
||||||
// Tooltip
|
// Tooltip
|
||||||
if (tooltip_enabled) {
|
if (tooltip_enabled) {
|
||||||
uint tooltipCount = upower_tooltip->updateTooltip(devices);
|
uint tooltipCount = upower_tooltip->updateTooltip(devices);
|
||||||
|
@ -316,13 +343,9 @@ auto UPower::update() -> void {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set percentage
|
// Set percentage
|
||||||
std::string percentString = "";
|
|
||||||
if (displayDeviceValid) {
|
|
||||||
percentString = std::to_string(int(percentage + 0.5)) + "%";
|
percentString = std::to_string(int(percentage + 0.5)) + "%";
|
||||||
}
|
|
||||||
|
|
||||||
// Label format
|
// Label format
|
||||||
std::string time_format = "";
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case UP_DEVICE_STATE_CHARGING:
|
case UP_DEVICE_STATE_CHARGING:
|
||||||
case UP_DEVICE_STATE_PENDING_CHARGE:
|
case UP_DEVICE_STATE_PENDING_CHARGE:
|
||||||
|
@ -335,6 +358,7 @@ auto UPower::update() -> void {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
std::string label_format =
|
std::string label_format =
|
||||||
fmt::format(fmt::runtime(showAltText ? format_alt : format),
|
fmt::format(fmt::runtime(showAltText ? format_alt : format),
|
||||||
fmt::arg("percentage", percentString), fmt::arg("time", time_format));
|
fmt::arg("percentage", percentString), fmt::arg("time", time_format));
|
||||||
|
|
Loading…
Reference in New Issue