#pragma once #include "ALabel.hpp" #ifdef WANT_RFKILL #include "util/rfkill.hpp" #endif #include #include #include #include namespace waybar::modules { class Bluetooth : public ALabel { struct ControllerInfo { 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_controller; std::string address; std::string address_type; // std::optional name; // just use alias instead std::string alias; std::optional icon; bool paired; bool trusted; bool blocked; bool connected; bool services_resolved; // NOTE: experimental feature in bluez std::optional battery_percentage; }; public: Bluetooth(const std::string&, const Json::Value&); virtual ~Bluetooth() = default; auto update() -> void override; private: 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; auto getDeviceProperties(GDBusObject*, DeviceInfo&) -> bool; auto getControllerProperties(GDBusObject*, ControllerInfo&) -> bool; // Returns std::nullopt if no controller could be found auto findCurController() -> std::optional; auto findConnectedDevices(const std::string&, std::vector&) -> void; #ifdef WANT_RFKILL util::Rfkill rfkill_; #endif const std::unique_ptr manager_; std::string state_; std::optional cur_controller_; std::vector connected_devices_; DeviceInfo cur_focussed_device_; std::string device_enumerate_; std::vector device_preference_; }; } // namespace waybar::modules