2020-01-21 16:04:54 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-02-03 03:17:06 +00:00
|
|
|
#include "ALabel.hpp"
|
2022-05-02 16:11:21 +00:00
|
|
|
#ifdef WANT_RFKILL
|
2020-01-23 16:17:29 +00:00
|
|
|
#include "util/rfkill.hpp"
|
2022-05-02 16:11:21 +00:00
|
|
|
#endif
|
|
|
|
#include <gio/gio.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <optional>
|
2020-01-22 10:37:47 +00:00
|
|
|
|
2020-01-21 16:04:54 +00:00
|
|
|
namespace waybar::modules {
|
|
|
|
|
|
|
|
class Bluetooth : public ALabel {
|
2022-05-02 16:11:21 +00:00
|
|
|
struct AdapterInfo
|
|
|
|
{
|
|
|
|
std::string path;
|
|
|
|
std::string address;
|
|
|
|
std::string address_type;
|
|
|
|
// std::string name; // just use alias instead
|
|
|
|
std::string alias;
|
|
|
|
bool powered;
|
|
|
|
bool discoverable;
|
|
|
|
bool pairable;
|
|
|
|
bool discovering;
|
|
|
|
};
|
|
|
|
|
|
|
|
// NOTE: there are some properties that not all devices provide
|
|
|
|
struct DeviceInfo
|
|
|
|
{
|
|
|
|
std::string path;
|
|
|
|
std::string paired_adapter;
|
|
|
|
std::string address;
|
|
|
|
std::string address_type;
|
|
|
|
// std::optional<std::string> name; // just use alias instead
|
|
|
|
std::string alias;
|
|
|
|
std::optional<std::string> icon;
|
|
|
|
bool paired;
|
|
|
|
bool trusted;
|
|
|
|
bool blocked;
|
|
|
|
bool connected;
|
|
|
|
bool services_resolved;
|
|
|
|
// TODO: make experimental in waybar as it is also a experimental feature in bluez
|
|
|
|
std::optional<unsigned char> battery_percentage;
|
|
|
|
};
|
|
|
|
|
2020-01-21 16:04:54 +00:00
|
|
|
public:
|
|
|
|
Bluetooth(const std::string&, const Json::Value&);
|
|
|
|
~Bluetooth() = default;
|
|
|
|
auto update() -> void;
|
|
|
|
|
|
|
|
private:
|
2022-05-02 16:11:21 +00:00
|
|
|
static auto onInterfaceAddedOrRemoved(GDBusObjectManager*, GDBusObject*, GDBusInterface*, gpointer) -> void;
|
|
|
|
static auto onInterfaceProxyPropertiesChanged(GDBusObjectManagerClient*, GDBusObjectProxy*, GDBusProxy*, GVariant*, const gchar* const*, gpointer) -> void;
|
|
|
|
|
|
|
|
auto getDeviceBatteryPercentage(GDBusObject*) -> std::optional<unsigned char>;
|
|
|
|
auto getDeviceProperties(GDBusObject*, DeviceInfo&) -> bool;
|
|
|
|
auto getAdapterProperties(GDBusObject*, AdapterInfo&) -> bool;
|
|
|
|
|
|
|
|
auto findCurAdapter(AdapterInfo&) -> bool;
|
|
|
|
auto findConnectedDevices(const std::string&, std::vector<DeviceInfo>&) -> void;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef WANT_RFKILL
|
2021-02-03 04:10:27 +00:00
|
|
|
util::Rfkill rfkill_;
|
2022-05-02 16:11:21 +00:00
|
|
|
#endif
|
|
|
|
const std::unique_ptr<GDBusObjectManager, void (*)(GDBusObjectManager*)> manager_;
|
|
|
|
|
|
|
|
std::string state_;
|
|
|
|
AdapterInfo cur_adapter_;
|
|
|
|
std::vector<DeviceInfo> connected_devices_;
|
|
|
|
DeviceInfo cur_focussed_device_;
|
2022-05-04 16:27:29 +00:00
|
|
|
std::string device_enumerate_;
|
2022-05-02 16:11:21 +00:00
|
|
|
|
|
|
|
std::vector<std::string> device_preference_;
|
2020-01-21 16:04:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace waybar::modules
|