mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-25 04:32:10 +00:00
Add option to have right-side up icons and text
The margins are still not perfect, but it at least acceptable. SensorTooltips is required, as the sensor texts break due to being right-side up. Implements https://github.com/scorpion-26/gBar/issues/48
This commit is contained in:
parent
a2117475da
commit
6c8f57238a
6 changed files with 116 additions and 37 deletions
|
@ -69,6 +69,10 @@ UseHyprlandIPC: true
|
||||||
# Values are: L (Left), R (Right), T (Top), B (bottom)
|
# Values are: L (Left), R (Right), T (Top), B (bottom)
|
||||||
Location: T
|
Location: T
|
||||||
|
|
||||||
|
# When the location is set to side, this option forces everything (even text) to be right-side up.
|
||||||
|
# *Always* make sure to enable SensorTooltips when enabling this option. Failure to do so *will* cause graphical issues.
|
||||||
|
IconsAlwaysUp: false
|
||||||
|
|
||||||
# Forces the time to be centered.
|
# Forces the time to be centered.
|
||||||
# This can cause the right widget to clip outside, if there is not enough space on screen (e.g. when opening the text)
|
# This can cause the right widget to clip outside, if there is not enough space on screen (e.g. when opening the text)
|
||||||
# Setting this to false will definitely fix this issue, but it won't look very good, since it will be off-center.
|
# Setting this to false will definitely fix this issue, but it won't look very good, since it will be off-center.
|
||||||
|
|
133
src/Bar.cpp
133
src/Bar.cpp
|
@ -9,6 +9,38 @@
|
||||||
|
|
||||||
namespace Bar
|
namespace Bar
|
||||||
{
|
{
|
||||||
|
enum Side
|
||||||
|
{
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Center
|
||||||
|
};
|
||||||
|
|
||||||
|
Alignment SideToAlignment(Side side)
|
||||||
|
{
|
||||||
|
switch (side)
|
||||||
|
{
|
||||||
|
case Left: return Alignment::Left;
|
||||||
|
case Right: return Alignment::Right;
|
||||||
|
case Center: return Alignment::Fill;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TransitionType SideToDefaultTransition(Side side)
|
||||||
|
{
|
||||||
|
switch (side)
|
||||||
|
{
|
||||||
|
case Right:
|
||||||
|
case Center: return TransitionType::SlideLeft;
|
||||||
|
case Left: return TransitionType::SlideRight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RotatedIcons()
|
||||||
|
{
|
||||||
|
return (Config::Get().location == 'L' || Config::Get().location == 'R') && Config::Get().iconsAlwaysUp;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t monitorID;
|
static int32_t monitorID;
|
||||||
|
|
||||||
namespace DynCtx
|
namespace DynCtx
|
||||||
|
@ -184,10 +216,18 @@ namespace Bar
|
||||||
std::string ico = System::BTTypeToIcon(dev);
|
std::string ico = System::BTTypeToIcon(dev);
|
||||||
tooltip += dev.name + " & ";
|
tooltip += dev.name + " & ";
|
||||||
btDev += ico;
|
btDev += ico;
|
||||||
|
|
||||||
|
if (RotatedIcons())
|
||||||
|
{
|
||||||
|
btDev += "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Delete last delim
|
// Delete last delim
|
||||||
if (tooltip.size())
|
if (tooltip.size())
|
||||||
tooltip.erase(tooltip.end() - 3, tooltip.end());
|
tooltip.erase(tooltip.end() - 3, tooltip.end());
|
||||||
|
if (btDev.size() && btDev.back() == '\n')
|
||||||
|
btDev.erase(btDev.end() - 1);
|
||||||
|
|
||||||
btDevText->SetTooltip(tooltip);
|
btDevText->SetTooltip(tooltip);
|
||||||
btDevText->SetText(std::move(btDev));
|
btDevText->SetText(std::move(btDev));
|
||||||
}
|
}
|
||||||
|
@ -373,33 +413,6 @@ namespace Bar
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Side
|
|
||||||
{
|
|
||||||
Left,
|
|
||||||
Right,
|
|
||||||
Center
|
|
||||||
};
|
|
||||||
|
|
||||||
Alignment SideToAlignment(Side side)
|
|
||||||
{
|
|
||||||
switch (side)
|
|
||||||
{
|
|
||||||
case Left: return Alignment::Left;
|
|
||||||
case Right: return Alignment::Right;
|
|
||||||
case Center: return Alignment::Fill;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TransitionType SideToDefaultTransition(Side side)
|
|
||||||
{
|
|
||||||
switch (side)
|
|
||||||
{
|
|
||||||
case Right:
|
|
||||||
case Center: return TransitionType::SlideLeft;
|
|
||||||
case Left: return TransitionType::SlideRight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WidgetSensor(Widget& parent, TimerCallback<Sensor>&& callback, const std::string& sensorClass, const std::string& textClass, Text*& textPtr,
|
void WidgetSensor(Widget& parent, TimerCallback<Sensor>&& callback, const std::string& sensorClass, const std::string& textClass, Text*& textPtr,
|
||||||
Side side)
|
Side side)
|
||||||
{
|
{
|
||||||
|
@ -441,7 +454,7 @@ namespace Bar
|
||||||
case 'T':
|
case 'T':
|
||||||
case 'B': angle = -90; break;
|
case 'B': angle = -90; break;
|
||||||
case 'L':
|
case 'L':
|
||||||
case 'R': angle = 0; break;
|
case 'R': angle = RotatedIcons() ? -90 : 0; break;
|
||||||
}
|
}
|
||||||
sensor->SetStyle({angle});
|
sensor->SetStyle({angle});
|
||||||
sensor->AddTimer<Sensor>(std::move(callback), DynCtx::updateTime);
|
sensor->AddTimer<Sensor>(std::move(callback), DynCtx::updateTime);
|
||||||
|
@ -559,6 +572,7 @@ namespace Bar
|
||||||
case AudioType::Output:
|
case AudioType::Output:
|
||||||
icon->SetClass("audio-icon");
|
icon->SetClass("audio-icon");
|
||||||
icon->SetText(" ");
|
icon->SetText(" ");
|
||||||
|
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();
|
||||||
break;
|
break;
|
||||||
|
@ -626,6 +640,13 @@ namespace Bar
|
||||||
text->SetClass("package-empty");
|
text->SetClass("package-empty");
|
||||||
text->SetAngle(Utils::GetAngle());
|
text->SetAngle(Utils::GetAngle());
|
||||||
text->AddTimer<Text>(DynCtx::UpdatePackages, 1000 * Config::Get().checkUpdateInterval, TimerDispatchBehaviour::ImmediateDispatch);
|
text->AddTimer<Text>(DynCtx::UpdatePackages, 1000 * Config::Get().checkUpdateInterval, TimerDispatchBehaviour::ImmediateDispatch);
|
||||||
|
|
||||||
|
// Fix alignment when icons are always upside
|
||||||
|
if (RotatedIcons())
|
||||||
|
{
|
||||||
|
Utils::SetTransform(*text, Transform{}, 10, 0);
|
||||||
|
}
|
||||||
|
|
||||||
parent.AddChild(std::move(text));
|
parent.AddChild(std::move(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -641,15 +662,31 @@ namespace Bar
|
||||||
devText->SetAngle(Utils::GetAngle());
|
devText->SetAngle(Utils::GetAngle());
|
||||||
DynCtx::btDevText = devText.get();
|
DynCtx::btDevText = devText.get();
|
||||||
devText->SetClass("bt-num");
|
devText->SetClass("bt-num");
|
||||||
if (side == Side::Left)
|
if (side == Side::Left && !RotatedIcons())
|
||||||
|
{
|
||||||
Utils::SetTransform(*devText, {-1, true, Alignment::Fill, 6, 0});
|
Utils::SetTransform(*devText, {-1, true, Alignment::Fill, 6, 0});
|
||||||
|
}
|
||||||
|
else if(RotatedIcons())
|
||||||
|
{
|
||||||
|
Utils::SetTransform(*devText, {}, 6, 0);
|
||||||
|
}
|
||||||
|
|
||||||
auto iconText = Widget::Create<Button>();
|
auto iconText = Widget::Create<Button>();
|
||||||
iconText->OnClick(DynCtx::OnBTClick);
|
iconText->OnClick(DynCtx::OnBTClick);
|
||||||
iconText->SetAngle(Utils::GetAngle());
|
iconText->SetAngle(Utils::GetAngle());
|
||||||
Utils::SetTransform(*iconText, {-1, true, Alignment::Fill, 0, 6});
|
|
||||||
DynCtx::btIconText = iconText.get();
|
DynCtx::btIconText = iconText.get();
|
||||||
|
|
||||||
|
if (!RotatedIcons())
|
||||||
|
{
|
||||||
|
// Only add end margin when icon is rotated with the bar.
|
||||||
|
Utils::SetTransform(*iconText, {-1, true, Alignment::Fill, 0, 6});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Align it more properly
|
||||||
|
Utils::SetTransform(*iconText, {}, 0, 6);
|
||||||
|
}
|
||||||
|
|
||||||
switch (side)
|
switch (side)
|
||||||
{
|
{
|
||||||
case Side::Right:
|
case Side::Right:
|
||||||
|
@ -801,14 +838,22 @@ namespace Bar
|
||||||
{
|
{
|
||||||
auto powerBoxExpand = Widget::Create<Box>();
|
auto powerBoxExpand = Widget::Create<Box>();
|
||||||
powerBoxExpand->SetClass("power-box-expand");
|
powerBoxExpand->SetClass("power-box-expand");
|
||||||
|
if (!RotatedIcons())
|
||||||
|
{
|
||||||
powerBoxExpand->SetSpacing({8, true});
|
powerBoxExpand->SetSpacing({8, true});
|
||||||
powerBoxExpand->SetOrientation(Utils::GetOrientation());
|
|
||||||
Utils::SetTransform(*powerBoxExpand, {-1, true, Alignment::Fill, 0, 6});
|
Utils::SetTransform(*powerBoxExpand, {-1, true, Alignment::Fill, 0, 6});
|
||||||
|
}
|
||||||
|
powerBoxExpand->SetOrientation(Utils::GetOrientation());
|
||||||
{
|
{
|
||||||
auto exitButton = Widget::Create<Button>();
|
auto exitButton = Widget::Create<Button>();
|
||||||
exitButton->SetClass("exit-button");
|
exitButton->SetClass("exit-button");
|
||||||
exitButton->SetText("");
|
exitButton->SetText("");
|
||||||
exitButton->SetAngle(Utils::GetAngle());
|
exitButton->SetAngle(Utils::GetAngle());
|
||||||
|
if (RotatedIcons())
|
||||||
|
{
|
||||||
|
// Align in center
|
||||||
|
Utils::SetTransform(*exitButton, Transform{}, 0, 2);
|
||||||
|
}
|
||||||
exitButton->OnClick(
|
exitButton->OnClick(
|
||||||
[setActivate](Button& but)
|
[setActivate](Button& but)
|
||||||
{
|
{
|
||||||
|
@ -827,6 +872,11 @@ namespace Bar
|
||||||
lockButton->SetClass("sleep-button");
|
lockButton->SetClass("sleep-button");
|
||||||
lockButton->SetText("");
|
lockButton->SetText("");
|
||||||
lockButton->SetAngle(Utils::GetAngle());
|
lockButton->SetAngle(Utils::GetAngle());
|
||||||
|
if (RotatedIcons())
|
||||||
|
{
|
||||||
|
// Align in center
|
||||||
|
Utils::SetTransform(*lockButton, Transform{}, 0, 2);
|
||||||
|
}
|
||||||
lockButton->OnClick(
|
lockButton->OnClick(
|
||||||
[setActivate](Button& but)
|
[setActivate](Button& but)
|
||||||
{
|
{
|
||||||
|
@ -845,6 +895,11 @@ namespace Bar
|
||||||
sleepButton->SetClass("sleep-button");
|
sleepButton->SetClass("sleep-button");
|
||||||
sleepButton->SetText("");
|
sleepButton->SetText("");
|
||||||
sleepButton->SetAngle(Utils::GetAngle());
|
sleepButton->SetAngle(Utils::GetAngle());
|
||||||
|
if (RotatedIcons())
|
||||||
|
{
|
||||||
|
// Align in center
|
||||||
|
Utils::SetTransform(*sleepButton, Transform{}, 0, 2);
|
||||||
|
}
|
||||||
sleepButton->OnClick(
|
sleepButton->OnClick(
|
||||||
[setActivate](Button& but)
|
[setActivate](Button& but)
|
||||||
{
|
{
|
||||||
|
@ -863,7 +918,17 @@ namespace Bar
|
||||||
rebootButton->SetClass("reboot-button");
|
rebootButton->SetClass("reboot-button");
|
||||||
rebootButton->SetText("");
|
rebootButton->SetText("");
|
||||||
rebootButton->SetAngle(Utils::GetAngle());
|
rebootButton->SetAngle(Utils::GetAngle());
|
||||||
Utils::SetTransform(*rebootButton, {-1, true, Alignment::Fill, 0, 6});
|
|
||||||
|
if (!RotatedIcons())
|
||||||
|
{
|
||||||
|
Utils::SetTransform(*rebootButton, {-1, false, Alignment::Fill, 0, 6});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Align in center
|
||||||
|
Utils::SetTransform(*rebootButton, Transform{}, 0, 2);
|
||||||
|
}
|
||||||
|
|
||||||
rebootButton->OnClick(
|
rebootButton->OnClick(
|
||||||
[setActivate](Button& but)
|
[setActivate](Button& but)
|
||||||
{
|
{
|
||||||
|
@ -891,7 +956,9 @@ namespace Bar
|
||||||
powerButton->SetClass("power-button");
|
powerButton->SetClass("power-button");
|
||||||
powerButton->SetText(" ");
|
powerButton->SetText(" ");
|
||||||
powerButton->SetAngle(Utils::GetAngle());
|
powerButton->SetAngle(Utils::GetAngle());
|
||||||
Utils::SetTransform(*powerButton, {24, false, Alignment::Fill});
|
|
||||||
|
Utils::SetTransform(*powerButton, {24, false, Alignment::Fill}, RotatedIcons() ? 10 : 0, 0);
|
||||||
|
|
||||||
powerButton->OnClick(
|
powerButton->OnClick(
|
||||||
[setActivate](Button& but)
|
[setActivate](Button& but)
|
||||||
{
|
{
|
||||||
|
|
|
@ -252,6 +252,7 @@ void Config::Load()
|
||||||
AddConfigVar("UseHyprlandIPC", config.useHyprlandIPC, lineView, foundProperty);
|
AddConfigVar("UseHyprlandIPC", config.useHyprlandIPC, lineView, foundProperty);
|
||||||
AddConfigVar("EnableSNI", config.enableSNI, lineView, foundProperty);
|
AddConfigVar("EnableSNI", config.enableSNI, lineView, foundProperty);
|
||||||
AddConfigVar("SensorTooltips", config.sensorTooltips, lineView, foundProperty);
|
AddConfigVar("SensorTooltips", config.sensorTooltips, lineView, foundProperty);
|
||||||
|
AddConfigVar("IconsAlwaysUp", config.iconsAlwaysUp, lineView, foundProperty);
|
||||||
|
|
||||||
AddConfigVar("MinUploadBytes", config.minUploadBytes, lineView, foundProperty);
|
AddConfigVar("MinUploadBytes", config.minUploadBytes, lineView, foundProperty);
|
||||||
AddConfigVar("MaxUploadBytes", config.maxUploadBytes, lineView, foundProperty);
|
AddConfigVar("MaxUploadBytes", config.maxUploadBytes, lineView, foundProperty);
|
||||||
|
|
|
@ -39,6 +39,7 @@ public:
|
||||||
bool useHyprlandIPC = true; // Use Hyprland IPC instead of ext_workspaces protocol (Less buggy, but also less performant)
|
bool useHyprlandIPC = true; // Use Hyprland IPC instead of ext_workspaces protocol (Less buggy, but also less performant)
|
||||||
bool enableSNI = true; // Enable tray icon
|
bool enableSNI = true; // Enable tray icon
|
||||||
bool sensorTooltips = false; // Use tooltips instead of sliders for the sensors
|
bool sensorTooltips = false; // Use tooltips instead of sliders for the sensors
|
||||||
|
bool iconsAlwaysUp = false; // Force icons to always point upwards in sidebar mode
|
||||||
|
|
||||||
// Controls for color progression of the network widget
|
// Controls for color progression of the network widget
|
||||||
uint32_t minUploadBytes = 0; // Bottom limit of the network widgets upload. Everything below it is considered "under"
|
uint32_t minUploadBytes = 0; // Bottom limit of the network widgets upload. Everything below it is considered "under"
|
||||||
|
|
|
@ -438,6 +438,7 @@ namespace SNI
|
||||||
return a.name < b.name;
|
return a.name < b.name;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
bool rotatedIcons = (Config::Get().location == 'L' || Config::Get().location == 'R') && Config::Get().iconsAlwaysUp;
|
||||||
for (auto& item : items)
|
for (auto& item : items)
|
||||||
{
|
{
|
||||||
if (item.iconData)
|
if (item.iconData)
|
||||||
|
@ -494,7 +495,7 @@ namespace SNI
|
||||||
texture->AddPaddingTop(padding);
|
texture->AddPaddingTop(padding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Utils::SetTransform(*texture, {size, true, Alignment::Fill}, {size, true, Alignment::Fill});
|
Utils::SetTransform(*texture, {size, true, Alignment::Fill}, {size, true, Alignment::Fill, 0, rotatedIcons ? 6 : 0});
|
||||||
texture->SetBuf(item.w, item.h, item.iconData);
|
texture->SetBuf(item.w, item.h, item.iconData);
|
||||||
texture->SetTooltip(item.tooltip);
|
texture->SetTooltip(item.tooltip);
|
||||||
texture->SetAngle(Utils::GetAngle() == 270 ? 90 : 0);
|
texture->SetAngle(Utils::GetAngle() == 270 ? 90 : 0);
|
||||||
|
|
|
@ -392,6 +392,11 @@ namespace Utils
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void SetTransform(Widget& widget, const Transform& primary, int secondaryMarginBefore, int secondaryMarginAfter)
|
||||||
|
{
|
||||||
|
SetTransform(widget, primary, {-1, false, Alignment::Fill, secondaryMarginBefore, secondaryMarginAfter});
|
||||||
|
}
|
||||||
|
|
||||||
inline Orientation GetOrientation()
|
inline Orientation GetOrientation()
|
||||||
{
|
{
|
||||||
switch (Config::Get().location)
|
switch (Config::Get().location)
|
||||||
|
@ -406,7 +411,7 @@ namespace Utils
|
||||||
|
|
||||||
inline double GetAngle()
|
inline double GetAngle()
|
||||||
{
|
{
|
||||||
if (Config::Get().location == 'T' || Config::Get().location == 'B')
|
if (Config::Get().location == 'T' || Config::Get().location == 'B' || Config::Get().iconsAlwaysUp)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue