feat: display all connected devices in tooltip

pull/1540/head
Daan Goossens 2022-05-04 18:27:29 +02:00
parent 638b4e6573
commit 794610a1ca
3 changed files with 57 additions and 15 deletions

View File

@ -70,6 +70,7 @@ class Bluetooth : public ALabel {
AdapterInfo cur_adapter_;
std::vector<DeviceInfo> connected_devices_;
DeviceInfo cur_focussed_device_;
std::string device_enumerate_;
std::vector<std::string> device_preference_;
};

View File

@ -114,6 +114,15 @@ Addressed by *bluetooth*
typeof: string ++
This format is used when the selected connected device, defined by the config option *format-device-preference*, provides is battery percentage. This needs the experimental features of bluez to be enabled to work.
*tooltip-format-enumerate-connected*: ++
typeof: string ++
This format is used to define how each connected device should be displayed within the *device_enumerate* format replacement in the tooltip menu.
*tooltip-format-enumerate-connected-battery*: ++
typeof: string ++
This format is used to define how each connected device with a battery should be displayed within the *device_enumerate* format replacement in the tooltip menu. When this config option is not defined, the *tooltip-format-enumerate-connected* format will be used also for the connected devices with a battery.
# FORMAT REPLACEMENTS
*{status}*: Status of the bluetooth device.
@ -134,25 +143,31 @@ Addressed by *bluetooth*
*{device_battery_percentage}*: Battery percentage of the current selected device if available. Only use in the *format-connected-battery* and *tooltip-format-connected-battery*.
# EXAMPLES
*{device_enumerate}*: Show a list of all connected devices in the tooltip, each on a seperate line. Only applicable in the *connected* state. Define the format of each device with the *tooltip-format-enumerate-connected* or/and *tooltip-format-enumerate-connected-battery* config options.
```
"bluetooth": {
"format": " {status}",
"format-connected": " {device_alias}",
"format-connected-battery": " {device_battery_percentage}%",
"tooltip-format": "{adapter_alias} {adapter_address}"
}
```
# EXAMPLES
```
"bluetooth": {
// "adapter-alias": "adapter1", // specify the adapter alias (name) if there are more than 1 on the system
"format": " {status}",
"format-connected": " {num_connections} connected",
// TODO: make it so that it shows all connected devices in the tooltip
// "tooltip-format-connected": "{device_alias}",
// "tooltip-format-connected-battery": "{device_alias} {device_battery_percentage}%",
"format-connected": " {num_connections} connected",
"tooltip-format": "{adapter_alias}\t{adapter_address}",
"tooltip-format-connected": "{adapter_alias}\t{adapter_address}\n\n{device_enumerate}",
"tooltip-format-enumerate-connected": "{device_alias}\t{device_address}",
"tooltip-format-enumerate-connected-battery": "{device_alias}\t{device_address}\t{device_battery_percentage}%"
}
```
```
"bluetooth": {
"format": " {status}",
"format-connected": " {device_alias}",
"format-connected-battery": " {device_alias} {device_battery_percentage}%",
// "format-device-preference": [ "alias1", "alias2" ], // preference list deciding which device to show in format-connected format-connected-battery
"tooltip-format": "{adapter_alias}\t{adapter_address}\n\n{num_connections} connected\n\n{device_enumerate}",
"tooltip-format-enumerate-connected": "{device_alias}\t{device_address}",
"tooltip-format-enumerate-connected-battery": "{device_alias}\t{device_address}\t{device_battery_percentage}%"
}
```

View File

@ -1,6 +1,7 @@
#include "modules/bluetooth.hpp"
#include <algorithm>
#include <sstream>
#include <spdlog/spdlog.h>
#include <fmt/format.h>
@ -199,8 +200,32 @@ auto waybar::modules::Bluetooth::update() -> void {
fmt::arg("device_battery_percentage", cur_focussed_device_.battery_percentage.value_or(0))
));
// TODO: make possible to show information about all connected devices in the tooltip
if (tooltipEnabled()) {
bool tooltip_enumerate_connections_ = config_["tooltip-format-enumerate-connected"].isString();
bool tooltip_enumerate_connections_battery_ = config_["tooltip-format-enumerate-connected-battery"].isString();
if (tooltip_enumerate_connections_ || tooltip_enumerate_connections_battery_) {
std::stringstream ss;
for (DeviceInfo dev : connected_devices_) {
if (tooltip_enumerate_connections_battery_ && dev.battery_percentage.has_value()) {
ss << "\n";
ss << fmt::format(config_["tooltip-format-enumerate-connected-battery"].asString(),
fmt::arg("device_address", dev.address),
fmt::arg("device_address_type", dev.address_type),
fmt::arg("device_alias", dev.alias),
fmt::arg("device_battery_percentage", dev.battery_percentage.value_or(0)));
} else if (tooltip_enumerate_connections_) {
ss << "\n";
ss << fmt::format(config_["tooltip-format-enumerate-connected"].asString(),
fmt::arg("device_address", dev.address),
fmt::arg("device_address_type", dev.address_type),
fmt::arg("device_alias", dev.alias));
}
}
device_enumerate_ = ss.str();
if (!device_enumerate_.empty()) {
device_enumerate_.erase(0, 1);
}
}
label_.set_tooltip_text(fmt::format(tooltip_format,
fmt::arg("status", state_),
fmt::arg("num_connections", connected_devices_.size()),
@ -210,7 +235,8 @@ auto waybar::modules::Bluetooth::update() -> void {
fmt::arg("device_address", cur_focussed_device_.address),
fmt::arg("device_address_type", cur_focussed_device_.address_type),
fmt::arg("device_alias", cur_focussed_device_.alias),
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_)
));
}