Add support for custom icons

Not *everything* is implemented, two icons from the BluetoothDevices
widgets are still missing.

Implements https://github.com/scorpion-26/gBar/issues/56
This commit is contained in:
scorpion-26 2023-11-22 00:54:41 +01:00
parent 7d8a792d60
commit 964b12ed36
7 changed files with 91 additions and 27 deletions

View file

@ -49,6 +49,27 @@ DiskPartition: /
# The default symbol for the workspaces # The default symbol for the workspaces
DefaultWorkspaceSymbol:  DefaultWorkspaceSymbol: 
# All of the icons that can be modified.
# Please note that some icons require a space ("\s") (e.g. default ShutdownIcon)
ShutdownIcon: \s
RebootIcon: 󰑐
SleepIcon: 󰏤
LockIcon: 
ExitIcon: 󰗼
BTOffIcon: 󰂲
BTOnIcon: 󰂯
BTConnectedIcon: 󰂱
DevKeyboardIcon: 󰌌\s
DevMouseIcon: 󰍽\s
DevHeadsetIcon: 󰋋\s
DevControllerIcon: 󰖺\s
DevUnknownIcon: \s
SpeakerMutedIcon: 󰝟
SpeakerHighIcon: 󰕾
MicMutedIcon: 󰍭
MicHighIcon: 󰍬
PackageOutOfDateIcon: 󰏔\s
# Scroll through the workspaces of the current monitor instead of all workspaces # Scroll through the workspaces of the current monitor instead of all workspaces
WorkspaceScrollOnMonitor: true WorkspaceScrollOnMonitor: true

View file

@ -47,11 +47,11 @@ namespace AudioFlyin
muted = info.sinkMuted; muted = info.sinkMuted;
if (info.sinkMuted) if (info.sinkMuted)
{ {
icon->SetText("󰝟"); icon->SetText(Config::Get().speakerMutedIcon);
} }
else else
{ {
icon->SetText("󰕾"); icon->SetText(Config::Get().speakerHighIcon);
} }
} }
} }
@ -68,11 +68,11 @@ namespace AudioFlyin
muted = info.sourceMuted; muted = info.sourceMuted;
if (info.sourceMuted) if (info.sourceMuted)
{ {
icon->SetText("󰍭"); icon->SetText(Config::Get().micMutedIcon);
} }
else else
{ {
icon->SetText("󰍬"); icon->SetText(Config::Get().micHighIcon);
} }
} }
} }
@ -116,12 +116,12 @@ namespace AudioFlyin
if (DynCtx::type == Type::Speaker) if (DynCtx::type == Type::Speaker)
{ {
icon->SetClass("audio-icon"); icon->SetClass("audio-icon");
icon->SetText("󰕾 "); icon->SetText(Config::Get().speakerHighIcon);
} }
else if (DynCtx::type == Type::Microphone) else if (DynCtx::type == Type::Microphone)
{ {
icon->SetClass("mic-icon"); icon->SetClass("mic-icon");
icon->SetText("󰍬"); icon->SetText(Config::Get().speakerMutedIcon);
} }
DynCtx::icon = icon.get(); DynCtx::icon = icon.get();

View file

@ -198,19 +198,19 @@ namespace Bar
if (info.defaultController.empty()) if (info.defaultController.empty())
{ {
btIconText->SetClass("bt-label-off"); btIconText->SetClass("bt-label-off");
btIconText->SetText("󰂲"); btIconText->SetText(Config::Get().btOffIcon);
btDevText->SetText(""); btDevText->SetText("");
} }
else if (info.devices.empty()) else if (info.devices.empty())
{ {
btIconText->SetClass("bt-label-on"); btIconText->SetClass("bt-label-on");
btIconText->SetText("󰂯"); btIconText->SetText(Config::Get().btOnIcon);
btDevText->SetText(""); btDevText->SetText("");
} }
else else
{ {
btIconText->SetClass("bt-label-connected"); btIconText->SetClass("bt-label-connected");
btIconText->SetText("󰂱"); btIconText->SetText(Config::Get().btConnectedIcon);
std::string btDev; std::string btDev;
std::string tooltip; std::string tooltip;
for (auto& dev : info.devices) for (auto& dev : info.devices)
@ -253,7 +253,7 @@ namespace Bar
packageTextLock.lock(); packageTextLock.lock();
if (numOutdatedPackages) if (numOutdatedPackages)
{ {
text.SetText("󰏔 "); text.SetText(Config::Get().packageOutOfDateIcon);
text.SetVisible(true); text.SetVisible(true);
text.SetClass("package-outofdate"); text.SetClass("package-outofdate");
text.SetTooltip("Updates available! (" + std::to_string(numOutdatedPackages) + " packages)"); text.SetTooltip("Updates available! (" + std::to_string(numOutdatedPackages) + " packages)");
@ -315,11 +315,11 @@ namespace Bar
} }
if (info.sinkMuted) if (info.sinkMuted)
{ {
audioIcon->SetText("󰝟"); audioIcon->SetText(Config::Get().speakerMutedIcon);
} }
else else
{ {
audioIcon->SetText("󰕾"); audioIcon->SetText(Config::Get().speakerHighIcon);
} }
if (Config::Get().audioInput) if (Config::Get().audioInput)
{ {
@ -334,11 +334,11 @@ namespace Bar
} }
if (info.sourceMuted) if (info.sourceMuted)
{ {
micIcon->SetText("󰍭"); micIcon->SetText(Config::Get().micMutedIcon);
} }
else else
{ {
micIcon->SetText("󰍬"); micIcon->SetText(Config::Get().micHighIcon);
} }
} }
return TimerResult::Ok; return TimerResult::Ok;
@ -571,12 +571,12 @@ namespace Bar
{ {
case AudioType::Input: case AudioType::Input:
icon->SetClass("mic-icon"); icon->SetClass("mic-icon");
icon->SetText("󰍬"); icon->SetText(Config::Get().speakerHighIcon);
DynCtx::micIcon = icon.get(); DynCtx::micIcon = icon.get();
break; break;
case AudioType::Output: case AudioType::Output:
icon->SetClass("audio-icon"); icon->SetClass("audio-icon");
icon->SetText("󰕾 "); icon->SetText(Config::Get().micHighIcon);
if (!RotatedIcons()) if (!RotatedIcons())
Utils::SetTransform(*icon, {-1, true, Alignment::Fill, 0, 6}); Utils::SetTransform(*icon, {-1, true, Alignment::Fill, 0, 6});
DynCtx::audioIcon = icon.get(); DynCtx::audioIcon = icon.get();
@ -852,7 +852,7 @@ namespace Bar
{ {
auto exitButton = Widget::Create<Button>(); auto exitButton = Widget::Create<Button>();
exitButton->SetClass("exit-button"); exitButton->SetClass("exit-button");
exitButton->SetText("󰗼"); exitButton->SetText(Config::Get().exitIcon);
exitButton->SetAngle(Utils::GetAngle()); exitButton->SetAngle(Utils::GetAngle());
if (RotatedIcons()) if (RotatedIcons())
{ {
@ -875,7 +875,7 @@ namespace Bar
auto lockButton = Widget::Create<Button>(); auto lockButton = Widget::Create<Button>();
lockButton->SetClass("sleep-button"); lockButton->SetClass("sleep-button");
lockButton->SetText(""); lockButton->SetText(Config::Get().lockIcon);
lockButton->SetAngle(Utils::GetAngle()); lockButton->SetAngle(Utils::GetAngle());
if (RotatedIcons()) if (RotatedIcons())
{ {
@ -898,7 +898,7 @@ namespace Bar
auto sleepButton = Widget::Create<Button>(); auto sleepButton = Widget::Create<Button>();
sleepButton->SetClass("sleep-button"); sleepButton->SetClass("sleep-button");
sleepButton->SetText("󰏤"); sleepButton->SetText(Config::Get().sleepIcon);
sleepButton->SetAngle(Utils::GetAngle()); sleepButton->SetAngle(Utils::GetAngle());
if (RotatedIcons()) if (RotatedIcons())
{ {
@ -921,7 +921,7 @@ namespace Bar
auto rebootButton = Widget::Create<Button>(); auto rebootButton = Widget::Create<Button>();
rebootButton->SetClass("reboot-button"); rebootButton->SetClass("reboot-button");
rebootButton->SetText("󰑐"); rebootButton->SetText(Config::Get().rebootIcon);
rebootButton->SetAngle(Utils::GetAngle()); rebootButton->SetAngle(Utils::GetAngle());
if (!RotatedIcons()) if (!RotatedIcons())
@ -959,7 +959,7 @@ namespace Bar
auto powerButton = Widget::Create<Button>(); auto powerButton = Widget::Create<Button>();
powerButton->SetClass("power-button"); powerButton->SetClass("power-button");
powerButton->SetText(""); powerButton->SetText(Config::Get().shutdownIcon);
powerButton->SetAngle(Utils::GetAngle()); powerButton->SetAngle(Utils::GetAngle());
Utils::SetTransform(*powerButton, {24, false, Alignment::Fill}, RotatedIcons() ? 10 : 0, 0); Utils::SetTransform(*powerButton, {24, false, Alignment::Fill}, RotatedIcons() ? 10 : 0, 0);

View file

@ -258,7 +258,7 @@ namespace BluetoothDevices
headerBox->SetClass("bt-header-box"); headerBox->SetClass("bt-header-box");
{ {
auto headerText = Widget::Create<Text>(); auto headerText = Widget::Create<Text>();
headerText->SetText("󰂯 Bluetooth"); headerText->SetText(Config::Get().btOnIcon + " Bluetooth");
headerBox->AddChild(std::move(headerText)); headerBox->AddChild(std::move(headerText));
auto headerRefresh = Widget::Create<Button>(); auto headerRefresh = Widget::Create<Button>();

View file

@ -244,6 +244,26 @@ void Config::Load()
AddConfigVar("CheckPackagesCommand", config.checkPackagesCommand, lineView, foundProperty); AddConfigVar("CheckPackagesCommand", config.checkPackagesCommand, lineView, foundProperty);
AddConfigVar("DiskPartition", config.diskPartition, lineView, foundProperty); AddConfigVar("DiskPartition", config.diskPartition, lineView, foundProperty);
AddConfigVar("ShutdownIcon", config.shutdownIcon, lineView, foundProperty);
AddConfigVar("RebootIcon", config.rebootIcon, lineView, foundProperty);
AddConfigVar("sleepIcon", config.sleepIcon, lineView, foundProperty);
AddConfigVar("LockIcon", config.lockIcon, lineView, foundProperty);
AddConfigVar("ExitIcon", config.exitIcon, lineView, foundProperty);
AddConfigVar("BTOffIcon", config.btOffIcon, lineView, foundProperty);
AddConfigVar("BTOnIcon", config.btOnIcon, lineView, foundProperty);
AddConfigVar("BTConnectedIcon", config.btConnectedIcon, lineView, foundProperty);
AddConfigVar("DevKeyboardIcon", config.devKeyboardIcon, lineView, foundProperty);
AddConfigVar("DevMouseIcon", config.devMouseIcon, lineView, foundProperty);
AddConfigVar("DevHeadsetIcon", config.devHeadsetIcon, lineView, foundProperty);
AddConfigVar("DevControllerIcon", config.devControllerIcon, lineView, foundProperty);
AddConfigVar("DevUnknownIcon", config.devUnknownIcon, lineView, foundProperty);
AddConfigVar("SpeakerMutedIcon", config.speakerMutedIcon, lineView, foundProperty);
AddConfigVar("SpeakerHighIcon", config.speakerHighIcon, lineView, foundProperty);
AddConfigVar("MicMutedIcon", config.micMutedIcon, lineView, foundProperty);
AddConfigVar("MicHighIcon", config.micHighIcon, lineView, foundProperty);
AddConfigVar("PackageOutOfDateIcon", config.packageOutOfDateIcon, lineView, foundProperty);
AddConfigVar("CenterTime", config.centerTime, lineView, foundProperty); AddConfigVar("CenterTime", config.centerTime, lineView, foundProperty);
AddConfigVar("AudioInput", config.audioInput, lineView, foundProperty); AddConfigVar("AudioInput", config.audioInput, lineView, foundProperty);
AddConfigVar("AudioRevealer", config.audioRevealer, lineView, foundProperty); AddConfigVar("AudioRevealer", config.audioRevealer, lineView, foundProperty);

View file

@ -26,6 +26,29 @@ public:
std::string dateTimeLocale = ""; // use system locale std::string dateTimeLocale = ""; // use system locale
std::string diskPartition = "/"; // should be expectable on every linux system std::string diskPartition = "/"; // should be expectable on every linux system
// Icons
std::string shutdownIcon = "";
std::string rebootIcon = "󰑐";
std::string sleepIcon = "󰏤";
std::string lockIcon = "";
std::string exitIcon = "󰗼";
std::string btOffIcon = "󰂲";
std::string btOnIcon = "󰂯";
std::string btConnectedIcon = "󰂱";
std::string devKeyboardIcon = "󰌌 ";
std::string devMouseIcon = "󰍽 ";
std::string devHeadsetIcon = "󰋋 ";
std::string devControllerIcon = "󰖺 ";
std::string devUnknownIcon = "";
std::string speakerMutedIcon = "󰝟";
std::string speakerHighIcon = "󰕾";
std::string micMutedIcon = "󰍭";
std::string micHighIcon = "󰍬";
std::string packageOutOfDateIcon = "󰏔 ";
// WS is handled by workspaceSymbols
// TODO: Deprecate workspaceSymbols in favor of e.g. workspaceIcon-x
// TODO: BluetoothDevices Refresh and close icons
// Script that returns how many packages are out-of-date. The script should only print a number! // Script that returns how many packages are out-of-date. The script should only print a number!
// See data/update.sh for a human-readable version // See data/update.sh for a human-readable version
std::string checkPackagesCommand = std::string checkPackagesCommand =

View file

@ -449,21 +449,21 @@ namespace System
{ {
if (dev.type == "input-keyboard") if (dev.type == "input-keyboard")
{ {
return "󰌌 "; return Config::Get().devKeyboardIcon;
} }
else if (dev.type == "input-mouse") else if (dev.type == "input-mouse")
{ {
return "󰍽 "; return Config::Get().devMouseIcon;
} }
else if (dev.type == "audio-headset") else if (dev.type == "audio-headset")
{ {
return "󰋋 "; return Config::Get().devHeadsetIcon;
} }
else if (dev.type == "input-gaming") else if (dev.type == "input-gaming")
{ {
return "󰖺 "; return Config::Get().devControllerIcon;
} }
return ""; return Config::Get().devUnknownIcon;
} }
#endif #endif