2020-01-21 17:04:54 +01:00
|
|
|
#pragma once
|
|
|
|
|
2022-11-24 12:28:52 +01:00
|
|
|
#include "ALabel.hpp"
|
2022-05-02 18:11:21 +02:00
|
|
|
#ifdef WANT_RFKILL
|
2020-01-23 17:17:29 +01:00
|
|
|
#include "util/rfkill.hpp"
|
2022-05-02 18:11:21 +02:00
|
|
|
#endif
|
|
|
|
#include <gio/gio.h>
|
2022-05-06 17:01:43 +02:00
|
|
|
|
2022-05-02 18:11:21 +02:00
|
|
|
#include <optional>
|
2022-05-06 17:01:43 +02:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2020-01-22 11:37:47 +01:00
|
|
|
|
2020-01-21 17:04:54 +01:00
|
|
|
namespace waybar::modules {
|
|
|
|
|
2022-11-24 12:28:52 +01:00
|
|
|
class Bluetooth : public ALabel {
|
2022-05-06 17:01:43 +02:00
|
|
|
struct ControllerInfo {
|
2022-05-02 18:11:21 +02:00
|
|
|
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
|
2022-05-06 17:01:43 +02:00
|
|
|
struct DeviceInfo {
|
2022-05-02 18:11:21 +02:00
|
|
|
std::string path;
|
2022-05-06 00:38:04 +02:00
|
|
|
std::string paired_controller;
|
2022-05-02 18:11:21 +02:00
|
|
|
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;
|
2022-05-06 16:17:11 +02:00
|
|
|
// NOTE: experimental feature in bluez
|
2022-05-02 18:11:21 +02:00
|
|
|
std::optional<unsigned char> battery_percentage;
|
|
|
|
};
|
|
|
|
|
2020-01-21 17:04:54 +01:00
|
|
|
public:
|
|
|
|
Bluetooth(const std::string&, const Json::Value&);
|
2023-03-02 14:57:07 +01:00
|
|
|
virtual ~Bluetooth() = default;
|
|
|
|
auto update() -> void override;
|
2020-01-21 17:04:54 +01:00
|
|
|
|
|
|
|
private:
|
2022-05-06 17:01:43 +02:00
|
|
|
static auto onInterfaceAddedOrRemoved(GDBusObjectManager*, GDBusObject*, GDBusInterface*,
|
|
|
|
gpointer) -> void;
|
|
|
|
static auto onInterfaceProxyPropertiesChanged(GDBusObjectManagerClient*, GDBusObjectProxy*,
|
|
|
|
GDBusProxy*, GVariant*, const gchar* const*,
|
|
|
|
gpointer) -> void;
|
2022-05-02 18:11:21 +02:00
|
|
|
|
|
|
|
auto getDeviceBatteryPercentage(GDBusObject*) -> std::optional<unsigned char>;
|
|
|
|
auto getDeviceProperties(GDBusObject*, DeviceInfo&) -> bool;
|
2022-05-06 00:38:04 +02:00
|
|
|
auto getControllerProperties(GDBusObject*, ControllerInfo&) -> bool;
|
2022-05-02 18:11:21 +02:00
|
|
|
|
2023-08-16 15:34:06 +02:00
|
|
|
// Returns std::nullopt if no controller could be found
|
|
|
|
auto findCurController() -> std::optional<ControllerInfo>;
|
2022-05-02 18:11:21 +02:00
|
|
|
auto findConnectedDevices(const std::string&, std::vector<DeviceInfo>&) -> void;
|
|
|
|
|
|
|
|
#ifdef WANT_RFKILL
|
2021-02-03 05:10:27 +01:00
|
|
|
util::Rfkill rfkill_;
|
2022-05-02 18:11:21 +02:00
|
|
|
#endif
|
|
|
|
const std::unique_ptr<GDBusObjectManager, void (*)(GDBusObjectManager*)> manager_;
|
|
|
|
|
|
|
|
std::string state_;
|
2023-08-16 15:34:06 +02:00
|
|
|
std::optional<ControllerInfo> cur_controller_;
|
2022-05-02 18:11:21 +02:00
|
|
|
std::vector<DeviceInfo> connected_devices_;
|
|
|
|
DeviceInfo cur_focussed_device_;
|
2022-05-04 18:27:29 +02:00
|
|
|
std::string device_enumerate_;
|
2022-05-02 18:11:21 +02:00
|
|
|
|
|
|
|
std::vector<std::string> device_preference_;
|
2020-01-21 17:04:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace waybar::modules
|