From 6c8f57238ae47c0b28e183b1470f874ee608cd94 Mon Sep 17 00:00:00 2001 From: scorpion-26 Date: Wed, 1 Nov 2023 00:34:33 +0100 Subject: [PATCH] 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 --- data/config | 4 ++ src/Bar.cpp | 137 ++++++++++++++++++++++++++++++++++++------------- src/Config.cpp | 1 + src/Config.h | 1 + src/SNI.cpp | 3 +- src/Widget.h | 7 ++- 6 files changed, 116 insertions(+), 37 deletions(-) diff --git a/data/config b/data/config index 222e6a1..d0fc0c2 100644 --- a/data/config +++ b/data/config @@ -69,6 +69,10 @@ UseHyprlandIPC: true # Values are: L (Left), R (Right), T (Top), B (bottom) 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. # 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. diff --git a/src/Bar.cpp b/src/Bar.cpp index a5ff239..78f04fb 100644 --- a/src/Bar.cpp +++ b/src/Bar.cpp @@ -9,6 +9,38 @@ 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; namespace DynCtx @@ -184,10 +216,18 @@ namespace Bar std::string ico = System::BTTypeToIcon(dev); tooltip += dev.name + " & "; btDev += ico; + + if (RotatedIcons()) + { + btDev += "\n"; + } } // Delete last delim if (tooltip.size()) tooltip.erase(tooltip.end() - 3, tooltip.end()); + if (btDev.size() && btDev.back() == '\n') + btDev.erase(btDev.end() - 1); + btDevText->SetTooltip(tooltip); btDevText->SetText(std::move(btDev)); } @@ -373,33 +413,6 @@ namespace Bar #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&& callback, const std::string& sensorClass, const std::string& textClass, Text*& textPtr, Side side) { @@ -441,7 +454,7 @@ namespace Bar case 'T': case 'B': angle = -90; break; case 'L': - case 'R': angle = 0; break; + case 'R': angle = RotatedIcons() ? -90 : 0; break; } sensor->SetStyle({angle}); sensor->AddTimer(std::move(callback), DynCtx::updateTime); @@ -559,7 +572,8 @@ namespace Bar case AudioType::Output: icon->SetClass("audio-icon"); icon->SetText("󰕾 "); - Utils::SetTransform(*icon, {-1, true, Alignment::Fill, 0, 6}); + if (!RotatedIcons()) + Utils::SetTransform(*icon, {-1, true, Alignment::Fill, 0, 6}); DynCtx::audioIcon = icon.get(); break; } @@ -626,6 +640,13 @@ namespace Bar text->SetClass("package-empty"); text->SetAngle(Utils::GetAngle()); text->AddTimer(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)); } @@ -641,15 +662,31 @@ namespace Bar devText->SetAngle(Utils::GetAngle()); DynCtx::btDevText = devText.get(); devText->SetClass("bt-num"); - if (side == Side::Left) + if (side == Side::Left && !RotatedIcons()) + { Utils::SetTransform(*devText, {-1, true, Alignment::Fill, 6, 0}); + } + else if(RotatedIcons()) + { + Utils::SetTransform(*devText, {}, 6, 0); + } auto iconText = Widget::Create