mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-21 18:52:49 +00:00
Add icons to bluetooth widget
And add one more icon type
This commit is contained in:
parent
ddc8af62a5
commit
07b2d5e35d
4 changed files with 39 additions and 28 deletions
14
src/Bar.cpp
14
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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<void(bool, BluetoothDevice&)> onFinish)
|
||||
void ConnectBTDevice(BluetoothDevice& device, std::function<void(bool, BluetoothDevice&)> 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<void(bool, BluetoothDevice&)> onFinish)
|
||||
void DisconnectBTDevice(BluetoothDevice& device, std::function<void(bool, BluetoothDevice&)> 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
|
||||
}
|
||||
}
|
||||
|
|
10
src/System.h
10
src/System.h
|
@ -57,14 +57,16 @@ namespace System
|
|||
std::vector<BluetoothDevice> devices;
|
||||
};
|
||||
BluetoothInfo GetBluetoothInfo();
|
||||
void StartScan();
|
||||
void StopScan();
|
||||
void StartBTScan();
|
||||
void StopBTScan();
|
||||
|
||||
// MT functions, callback, is from different thread
|
||||
void Connect(BluetoothDevice& device, std::function<void(bool, BluetoothDevice&)> onFinish);
|
||||
void Disconnect(BluetoothDevice& device, std::function<void(bool, BluetoothDevice&)> onFinish);
|
||||
void ConnectBTDevice(BluetoothDevice& device, std::function<void(bool, BluetoothDevice&)> onFinish);
|
||||
void DisconnectBTDevice(BluetoothDevice& device, std::function<void(bool, BluetoothDevice&)> onFinish);
|
||||
|
||||
void OpenBTWidget();
|
||||
|
||||
std::string BTTypeToIcon(const BluetoothDevice& dev);
|
||||
#endif
|
||||
|
||||
struct AudioInfo
|
||||
|
|
Loading…
Reference in a new issue