Merge pull request #1576 from daangoossens22/fix_bluetooth

This commit is contained in:
Alex 2022-05-28 15:28:20 +02:00 committed by GitHub
commit c27dab9379
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 10 deletions

View File

@ -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.

View File

@ -152,11 +152,23 @@ 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()) {
@ -165,7 +177,10 @@ auto waybar::modules::Bluetooth::update() -> void {
format_ = default_format_; format_ = default_format_;
} }
} }
if (config_["tooltip-format-" + state].isString()) { if (battery_available && config_["tooltip-format-connected-battery"].isString()) {
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()) {
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()) {
tooltip_format = config_["tooltip-format"].asString(); tooltip_format = config_["tooltip-format"].asString();
@ -196,7 +211,7 @@ auto waybar::modules::Bluetooth::update() -> void {
fmt::arg("controller_alias", cur_controller_.alias), fmt::arg("controller_alias", cur_controller_.alias),
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()) {
@ -209,14 +224,18 @@ 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)));
} }
} }
@ -234,7 +253,7 @@ auto waybar::modules::Bluetooth::update() -> void {
fmt::arg("controller_alias", cur_controller_.alias), fmt::arg("controller_alias", cur_controller_.alias),
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_)));
} }