diff --git a/src/Bar.cpp b/src/Bar.cpp index 7dfef1a..669d8e7 100644 --- a/src/Bar.cpp +++ b/src/Bar.cpp @@ -104,19 +104,7 @@ namespace Bar { if (!dev.connected) continue; - std::string ico = " "; - if (dev.type == "input-keyboard") - { - ico = " "; - } - else if (dev.type == "input-mouse") - { - ico = " "; - } - else if (dev.type == "audio-headset") - { - ico = " "; - } + std::string ico = System::BTTypeToIcon(dev); tooltip += dev.name + " & "; btDev += ico; } diff --git a/src/BluetoothDevices.cpp b/src/BluetoothDevices.cpp index 33f5a22..8778f92 100644 --- a/src/BluetoothDevices.cpp +++ b/src/BluetoothDevices.cpp @@ -48,7 +48,7 @@ namespace BluetoothDevices button.RemoveClass("inactive"); state |= DeviceState::RequestConnect; - System::Connect(device.device, [&dev = device, &but = button](bool success, System::BluetoothDevice&) + System::ConnectBTDevice(device.device, [&dev = device, &but = button](bool success, System::BluetoothDevice&) { deviceMutex.lock(); if (!success) @@ -66,7 +66,7 @@ namespace BluetoothDevices button.RemoveClass("active"); state |= DeviceState::RequestDisconnect; - System::Disconnect(device.device, [&dev = device, &but = button](bool success, System::BluetoothDevice&) + System::DisconnectBTDevice(device.device, [&dev = device, &but = button](bool success, System::BluetoothDevice&) { deviceMutex.lock(); if (!success) @@ -84,7 +84,7 @@ namespace BluetoothDevices { if (device.device.name.size()) { - button.SetText(device.device.name); + button.SetText(System::BTTypeToIcon(device.device) + device.device.name); } else { @@ -239,13 +239,13 @@ namespace BluetoothDevices { button.AddClass("active"); button.RemoveClass("inactive"); - System::StartScan(); + System::StartBTScan(); } else { button.AddClass("inactive"); button.RemoveClass("active"); - System::StopScan(); + System::StopBTScan(); } } } diff --git a/src/System.cpp b/src/System.cpp index c453f3f..35ae1ef 100644 --- a/src/System.cpp +++ b/src/System.cpp @@ -264,12 +264,12 @@ namespace System } static Process btctlProcess{-1}; - void StartScan() + void StartBTScan() { - StopScan(); + StopBTScan(); btctlProcess = OpenProcess("/bin/sh", "/bin/sh", "-c", "bluetoothctl scan on", NULL); } - void StopScan() + void StopBTScan() { if (btctlProcess.pid != -1) { @@ -279,7 +279,7 @@ namespace System } } - void Connect(BluetoothDevice& device, std::function onFinish) + void ConnectBTDevice(BluetoothDevice& device, std::function onFinish) { auto thread = [&, mac = device.mac, onFinish]() { @@ -308,7 +308,7 @@ namespace System std::thread worker(thread); worker.detach(); } - void Disconnect(BluetoothDevice& device, std::function onFinish) + void DisconnectBTDevice(BluetoothDevice& device, std::function onFinish) { auto thread = [&, mac = device.mac, onFinish]() { @@ -332,6 +332,27 @@ namespace System { OpenProcess("/bin/sh", "/bin/sh", "-c", "gBar bluetooth"); } + + std::string BTTypeToIcon(const BluetoothDevice& dev) + { + if (dev.type == "input-keyboard") + { + return " "; + } + else if (dev.type == "input-mouse") + { + return " "; + } + else if (dev.type == "audio-headset") + { + return " "; + } + else if (dev.type == "input-gaming") + { + return "調 "; + } + return " "; + } #endif AudioInfo GetAudioInfo() @@ -417,7 +438,7 @@ namespace System #endif PulseAudio::Shutdown(); #ifdef HAS_BLUEZ - StopScan(); + StopBTScan(); #endif } } diff --git a/src/System.h b/src/System.h index 7ece22b..eee98b6 100644 --- a/src/System.h +++ b/src/System.h @@ -57,14 +57,16 @@ namespace System std::vector devices; }; BluetoothInfo GetBluetoothInfo(); - void StartScan(); - void StopScan(); + void StartBTScan(); + void StopBTScan(); // MT functions, callback, is from different thread - void Connect(BluetoothDevice& device, std::function onFinish); - void Disconnect(BluetoothDevice& device, std::function onFinish); + void ConnectBTDevice(BluetoothDevice& device, std::function onFinish); + void DisconnectBTDevice(BluetoothDevice& device, std::function onFinish); void OpenBTWidget(); + + std::string BTTypeToIcon(const BluetoothDevice& dev); #endif struct AudioInfo