mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
feat(bluetooth): add format-icons
This commit is contained in:
parent
00c11c64ca
commit
a475be7cf7
@ -42,6 +42,12 @@ Addressed by *bluetooth*
|
|||||||
typeof: string ++
|
typeof: string ++
|
||||||
This format is used when the displayed controller is connected to at least 1 device.
|
This format is used when the displayed controller is connected to at least 1 device.
|
||||||
|
|
||||||
|
*format-icons*: ++
|
||||||
|
typeof: array/object ++
|
||||||
|
Based on the current battery percentage (see section *EXPERIMENTAL BATTERY PERCENTAGE FEATURE*), the corresponding icon gets selected. ++
|
||||||
|
The order is *low* to *high*. Will only show the current battery percentage icon in the *\*-connected-battery* config options. ++
|
||||||
|
Or by the state if it is an object. It will fall back to the enabled state if its derivatives are not defined (on, off, connected).
|
||||||
|
|
||||||
*rotate*: ++
|
*rotate*: ++
|
||||||
typeof: integer ++
|
typeof: integer ++
|
||||||
Positive value to rotate the text label.
|
Positive value to rotate the text label.
|
||||||
@ -115,6 +121,8 @@ Addressed by *bluetooth*
|
|||||||
|
|
||||||
*{status}*: Status of the bluetooth device.
|
*{status}*: Status of the bluetooth device.
|
||||||
|
|
||||||
|
*{icon}*: Icon, as defined in *format-icons*.
|
||||||
|
|
||||||
*{num_connections}*: Number of connections the displayed controller has.
|
*{num_connections}*: Number of connections the displayed controller has.
|
||||||
|
|
||||||
*{controller_address}*: Address of the displayed controller.
|
*{controller_address}*: Address of the displayed controller.
|
||||||
|
@ -152,11 +152,22 @@ auto waybar::modules::Bluetooth::update() -> void {
|
|||||||
#ifdef WANT_RFKILL
|
#ifdef WANT_RFKILL
|
||||||
if (rfkill_.getState()) state = "disabled";
|
if (rfkill_.getState()) state = "disabled";
|
||||||
#endif
|
#endif
|
||||||
|
bool battery_available = state == "connected" && cur_focussed_device_.battery_percentage.has_value();
|
||||||
|
|
||||||
|
#ifdef WANT_RFKILL
|
||||||
|
// also adds enabled icon if icon for state is not defined
|
||||||
|
std::vector<std::string> states = { state, rfkill_.getState() ? "disabled" : "enabled" };
|
||||||
|
std::string icon = getIcon(0, states);
|
||||||
|
#else
|
||||||
|
std::string icon = getIcon(0, state);
|
||||||
|
#endif
|
||||||
|
std::string icon_label = icon;
|
||||||
|
std::string icon_tooltip = icon;
|
||||||
|
|
||||||
if (!alt_) {
|
if (!alt_) {
|
||||||
if (state == "connected" && cur_focussed_device_.battery_percentage.has_value() &&
|
if (battery_available && config_["format-connected-battery"].isString()) {
|
||||||
config_["format-connected-battery"].isString()) {
|
|
||||||
format_ = config_["format-connected-battery"].asString();
|
format_ = config_["format-connected-battery"].asString();
|
||||||
|
icon_label = getIcon(cur_focussed_device_.battery_percentage.value_or(0));
|
||||||
} else if (config_["format-" + state].isString()) {
|
} else if (config_["format-" + state].isString()) {
|
||||||
format_ = config_["format-" + state].asString();
|
format_ = config_["format-" + state].asString();
|
||||||
} else if (config_["format"].isString()) {
|
} else if (config_["format"].isString()) {
|
||||||
@ -167,6 +178,7 @@ auto waybar::modules::Bluetooth::update() -> void {
|
|||||||
}
|
}
|
||||||
if (battery_available && config_["tooltip-format-connected-battery"].isString()) {
|
if (battery_available && config_["tooltip-format-connected-battery"].isString()) {
|
||||||
tooltip_format = config_["tooltip-format-connected-battery"].asString();
|
tooltip_format = config_["tooltip-format-connected-battery"].asString();
|
||||||
|
icon_tooltip = getIcon(cur_focussed_device_.battery_percentage.value_or(0));
|
||||||
} else if (config_["tooltip-format-" + state].isString()) {
|
} else if (config_["tooltip-format-" + state].isString()) {
|
||||||
tooltip_format = config_["tooltip-format-" + state].asString();
|
tooltip_format = config_["tooltip-format-" + state].asString();
|
||||||
} else if (config_["tooltip-format"].isString()) {
|
} else if (config_["tooltip-format"].isString()) {
|
||||||
@ -199,6 +211,7 @@ auto waybar::modules::Bluetooth::update() -> void {
|
|||||||
fmt::arg("device_address", cur_focussed_device_.address),
|
fmt::arg("device_address", cur_focussed_device_.address),
|
||||||
fmt::arg("device_address_type", cur_focussed_device_.address_type),
|
fmt::arg("device_address_type", cur_focussed_device_.address_type),
|
||||||
fmt::arg("device_alias", cur_focussed_device_.alias),
|
fmt::arg("device_alias", cur_focussed_device_.alias),
|
||||||
|
fmt::arg("icon", icon_label),
|
||||||
fmt::arg("device_battery_percentage", cur_focussed_device_.battery_percentage.value_or(0))));
|
fmt::arg("device_battery_percentage", cur_focussed_device_.battery_percentage.value_or(0))));
|
||||||
|
|
||||||
if (tooltipEnabled()) {
|
if (tooltipEnabled()) {
|
||||||
@ -211,14 +224,19 @@ auto waybar::modules::Bluetooth::update() -> void {
|
|||||||
if ((tooltip_enumerate_connections_battery_ && dev.battery_percentage.has_value()) ||
|
if ((tooltip_enumerate_connections_battery_ && dev.battery_percentage.has_value()) ||
|
||||||
tooltip_enumerate_connections_) {
|
tooltip_enumerate_connections_) {
|
||||||
ss << "\n";
|
ss << "\n";
|
||||||
std::string enumerate_format =
|
std::string enumerate_format;
|
||||||
(tooltip_enumerate_connections_battery_ && dev.battery_percentage.has_value())
|
std::string enumerate_icon;
|
||||||
? config_["tooltip-format-enumerate-connected-battery"].asString()
|
if (tooltip_enumerate_connections_battery_ && dev.battery_percentage.has_value()) {
|
||||||
: config_["tooltip-format-enumerate-connected"].asString();
|
enumerate_format = config_["tooltip-format-enumerate-connected-battery"].asString();
|
||||||
|
enumerate_icon = getIcon(dev.battery_percentage.value_or(0));
|
||||||
|
} else {
|
||||||
|
enumerate_format = config_["tooltip-format-enumerate-connected"].asString();
|
||||||
|
}
|
||||||
ss << fmt::format(
|
ss << fmt::format(
|
||||||
enumerate_format, fmt::arg("device_address", dev.address),
|
enumerate_format, fmt::arg("device_address", dev.address),
|
||||||
fmt::arg("device_address_type", dev.address_type),
|
fmt::arg("device_address_type", dev.address_type),
|
||||||
fmt::arg("device_alias", dev.alias),
|
fmt::arg("device_alias", dev.alias),
|
||||||
|
fmt::arg("icon", enumerate_icon),
|
||||||
fmt::arg("device_battery_percentage", dev.battery_percentage.value_or(0)));
|
fmt::arg("device_battery_percentage", dev.battery_percentage.value_or(0)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -237,6 +255,7 @@ auto waybar::modules::Bluetooth::update() -> void {
|
|||||||
fmt::arg("device_address", cur_focussed_device_.address),
|
fmt::arg("device_address", cur_focussed_device_.address),
|
||||||
fmt::arg("device_address_type", cur_focussed_device_.address_type),
|
fmt::arg("device_address_type", cur_focussed_device_.address_type),
|
||||||
fmt::arg("device_alias", cur_focussed_device_.alias),
|
fmt::arg("device_alias", cur_focussed_device_.alias),
|
||||||
|
fmt::arg("icon", icon_tooltip),
|
||||||
fmt::arg("device_battery_percentage", cur_focussed_device_.battery_percentage.value_or(0)),
|
fmt::arg("device_battery_percentage", cur_focussed_device_.battery_percentage.value_or(0)),
|
||||||
fmt::arg("device_enumerate", device_enumerate_)));
|
fmt::arg("device_enumerate", device_enumerate_)));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user