mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-22 11:12: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)
|
if (!dev.connected)
|
||||||
continue;
|
continue;
|
||||||
std::string ico = " ";
|
std::string ico = System::BTTypeToIcon(dev);
|
||||||
if (dev.type == "input-keyboard")
|
|
||||||
{
|
|
||||||
ico = " ";
|
|
||||||
}
|
|
||||||
else if (dev.type == "input-mouse")
|
|
||||||
{
|
|
||||||
ico = " ";
|
|
||||||
}
|
|
||||||
else if (dev.type == "audio-headset")
|
|
||||||
{
|
|
||||||
ico = " ";
|
|
||||||
}
|
|
||||||
tooltip += dev.name + " & ";
|
tooltip += dev.name + " & ";
|
||||||
btDev += ico;
|
btDev += ico;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace BluetoothDevices
|
||||||
button.RemoveClass("inactive");
|
button.RemoveClass("inactive");
|
||||||
state |= DeviceState::RequestConnect;
|
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();
|
deviceMutex.lock();
|
||||||
if (!success)
|
if (!success)
|
||||||
|
@ -66,7 +66,7 @@ namespace BluetoothDevices
|
||||||
button.RemoveClass("active");
|
button.RemoveClass("active");
|
||||||
state |= DeviceState::RequestDisconnect;
|
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();
|
deviceMutex.lock();
|
||||||
if (!success)
|
if (!success)
|
||||||
|
@ -84,7 +84,7 @@ namespace BluetoothDevices
|
||||||
{
|
{
|
||||||
if (device.device.name.size())
|
if (device.device.name.size())
|
||||||
{
|
{
|
||||||
button.SetText(device.device.name);
|
button.SetText(System::BTTypeToIcon(device.device) + device.device.name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -239,13 +239,13 @@ namespace BluetoothDevices
|
||||||
{
|
{
|
||||||
button.AddClass("active");
|
button.AddClass("active");
|
||||||
button.RemoveClass("inactive");
|
button.RemoveClass("inactive");
|
||||||
System::StartScan();
|
System::StartBTScan();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
button.AddClass("inactive");
|
button.AddClass("inactive");
|
||||||
button.RemoveClass("active");
|
button.RemoveClass("active");
|
||||||
System::StopScan();
|
System::StopBTScan();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -264,12 +264,12 @@ namespace System
|
||||||
}
|
}
|
||||||
|
|
||||||
static Process btctlProcess{-1};
|
static Process btctlProcess{-1};
|
||||||
void StartScan()
|
void StartBTScan()
|
||||||
{
|
{
|
||||||
StopScan();
|
StopBTScan();
|
||||||
btctlProcess = OpenProcess("/bin/sh", "/bin/sh", "-c", "bluetoothctl scan on", NULL);
|
btctlProcess = OpenProcess("/bin/sh", "/bin/sh", "-c", "bluetoothctl scan on", NULL);
|
||||||
}
|
}
|
||||||
void StopScan()
|
void StopBTScan()
|
||||||
{
|
{
|
||||||
if (btctlProcess.pid != -1)
|
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]()
|
auto thread = [&, mac = device.mac, onFinish]()
|
||||||
{
|
{
|
||||||
|
@ -308,7 +308,7 @@ namespace System
|
||||||
std::thread worker(thread);
|
std::thread worker(thread);
|
||||||
worker.detach();
|
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]()
|
auto thread = [&, mac = device.mac, onFinish]()
|
||||||
{
|
{
|
||||||
|
@ -332,6 +332,27 @@ namespace System
|
||||||
{
|
{
|
||||||
OpenProcess("/bin/sh", "/bin/sh", "-c", "gBar bluetooth");
|
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
|
#endif
|
||||||
|
|
||||||
AudioInfo GetAudioInfo()
|
AudioInfo GetAudioInfo()
|
||||||
|
@ -417,7 +438,7 @@ namespace System
|
||||||
#endif
|
#endif
|
||||||
PulseAudio::Shutdown();
|
PulseAudio::Shutdown();
|
||||||
#ifdef HAS_BLUEZ
|
#ifdef HAS_BLUEZ
|
||||||
StopScan();
|
StopBTScan();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
src/System.h
10
src/System.h
|
@ -57,14 +57,16 @@ namespace System
|
||||||
std::vector<BluetoothDevice> devices;
|
std::vector<BluetoothDevice> devices;
|
||||||
};
|
};
|
||||||
BluetoothInfo GetBluetoothInfo();
|
BluetoothInfo GetBluetoothInfo();
|
||||||
void StartScan();
|
void StartBTScan();
|
||||||
void StopScan();
|
void StopBTScan();
|
||||||
|
|
||||||
// MT functions, callback, is from different thread
|
// MT functions, callback, is from different thread
|
||||||
void Connect(BluetoothDevice& device, std::function<void(bool, BluetoothDevice&)> onFinish);
|
void ConnectBTDevice(BluetoothDevice& device, std::function<void(bool, BluetoothDevice&)> onFinish);
|
||||||
void Disconnect(BluetoothDevice& device, std::function<void(bool, BluetoothDevice&)> onFinish);
|
void DisconnectBTDevice(BluetoothDevice& device, std::function<void(bool, BluetoothDevice&)> onFinish);
|
||||||
|
|
||||||
void OpenBTWidget();
|
void OpenBTWidget();
|
||||||
|
|
||||||
|
std::string BTTypeToIcon(const BluetoothDevice& dev);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct AudioInfo
|
struct AudioInfo
|
||||||
|
|
Loading…
Reference in a new issue