From a95debf3c2d997ebfbfae3957ddf4a040c925c17 Mon Sep 17 00:00:00 2001 From: scorpion-26 Date: Wed, 19 Jul 2023 01:07:32 +0200 Subject: [PATCH] Add a "Location" config. Partially implements https://github.com/scorpion-26/gBar/issues/20 --- css/style.css | 24 +------- css/style.scss | 29 ++-------- data/config | 5 ++ src/Bar.cpp | 153 +++++++++++++++++++++++++++++++++++++++++-------- src/Config.cpp | 2 + src/Config.h | 2 + 6 files changed, 146 insertions(+), 69 deletions(-) diff --git a/css/style.css b/css/style.css index 3a2bb03..7ba9d42 100644 --- a/css/style.css +++ b/css/style.css @@ -13,7 +13,6 @@ } .right { - margin-right: 10px; border-radius: 16px; } @@ -23,7 +22,6 @@ .reboot-button { font-size: 28px; - margin-right: 6px; color: #6272a4; } @@ -42,10 +40,6 @@ color: #ff5555; } -.power-box-expand { - margin-right: 6px; -} - .system-confirm { color: #50fa7b; } @@ -55,7 +49,6 @@ trough { border-width: 1px; border-style: none; background-color: #44475a; - margin-top: 2px; min-width: 4px; min-height: 4px; } @@ -74,13 +67,13 @@ highlight { border-radius: 3px; border-width: 1px; border-style: none; + min-width: 6px; min-height: 6px; } .audio-icon { font-size: 24px; color: #ffb86c; - margin-right: 12px; } .audio-volume trough { @@ -96,7 +89,6 @@ highlight { .mic-icon { font-size: 24px; color: #bd93f9; - margin-right: 0px; } .mic-volume trough { @@ -110,34 +102,29 @@ highlight { } .package-outofdate { + margin: -5px -5px -5px -5px; font-size: 24px; - margin-right: -5px; - margin-left: -5px; color: #ff5555; } .bt-num { font-size: 16px; color: #1793D1; - margin-left: -6px; } .bt-label-on { font-size: 20px; color: #1793D1; - margin-right: 6px; } .bt-label-off { font-size: 24px; color: #1793D1; - margin-right: 6px; } .bt-label-connected { font-size: 28px; color: #1793D1; - margin-right: 6px; } .disk-util-progress { @@ -148,7 +135,6 @@ highlight { .disk-data-text { color: #bd93f9; - margin-right: 6px; font-size: 16px; } @@ -159,7 +145,6 @@ highlight { .vram-data-text { color: #ffb86c; - margin-right: 6px; font-size: 16px; } @@ -170,7 +155,6 @@ highlight { .ram-data-text { color: #f1fa8c; - margin-right: 6px; font-size: 16px; } @@ -181,7 +165,6 @@ highlight { .gpu-data-text { color: #8be9fd; - margin-right: 6px; font-size: 16px; } @@ -193,7 +176,6 @@ highlight { .cpu-data-text { color: #50fa7b; - margin-right: 6px; font-size: 16px; } @@ -205,13 +187,11 @@ highlight { .battery-data-text { color: #ff79c6; - margin-right: 6px; font-size: 16px; } .network-data-text { color: #50fa7b; - margin-right: 6px; font-size: 16px; } diff --git a/css/style.scss b/css/style.scss index 16ddfd1..fa6a9c5 100644 --- a/css/style.scss +++ b/css/style.scss @@ -38,7 +38,6 @@ $textsize: 16px; } .right { - margin-right: 10px; border-radius: 16px; } @@ -48,27 +47,22 @@ $textsize: 16px; .reboot-button { font-size: 28px; - //margin: -6px 6px -6px 0px; - margin-right: 6px; color: $darkblue; } .sleep-button { font-size: 28px; - //margin: -6px 0px -6px 0px; color: $darkblue; } .exit-button { font-size: 28px; - //margin: -6px 0px -6px 0px; color: $darkblue; } .power-button { font-size: 28px; - //margin: -16px -24px -16px 0px; color: $red; } @@ -77,7 +71,6 @@ $textsize: 16px; } .power-box-expand { - margin-right: 6px; } .system-confirm { @@ -90,7 +83,7 @@ trough { border-width: 1px; border-style: none; background-color: $inactive; - margin-top: 2px; + // margin-top: 2px; min-width: 4px; min-height: 4px; } @@ -110,13 +103,15 @@ highlight { border-radius: 3px; border-width: 1px; border-style: none; + // For vertical we need width, for horizontal we need height + // Both can coexist though + min-width: 6px; min-height: 6px; } .audio-icon { font-size: 24px; color: $orange; - margin-right: 12px; } .audio-volume { @@ -136,7 +131,7 @@ highlight { .mic-icon { font-size: 24px; color: $purple; - margin-right: 0px; + // margin-right: 0px; } .mic-volume { @@ -154,31 +149,26 @@ highlight { } .package-outofdate { + margin: -5px -5px -5px -5px; font-size: 24px; - margin-right: -5px; - margin-left: -5px; color: $red; } .bt-num { font-size: $textsize; color: $btblue; - margin-left: -6px; } .bt-label-on { font-size: 20px; color: $btblue; - margin-right: 6px; } .bt-label-off { font-size: 24px; color: $btblue; - margin-right: 6px; } .bt-label-connected { font-size: 28px; color: $btblue; - margin-right: 6px; } .disk-util-progress { @@ -188,7 +178,6 @@ highlight { } .disk-data-text { color: $purple; - margin-right: 6px; font-size: $textsize; } @@ -198,7 +187,6 @@ highlight { } .vram-data-text { color: $orange; - margin-right: 6px; font-size: $textsize; } @@ -208,7 +196,6 @@ highlight { } .ram-data-text { color: $yellow; - margin-right: 6px; font-size: $textsize; } @@ -218,7 +205,6 @@ highlight { } .gpu-data-text { color: $cyan; - margin-right: 6px; font-size: $textsize; } @@ -229,7 +215,6 @@ highlight { } .cpu-data-text { color: $green; - margin-right: 6px; font-size: $textsize; } @@ -240,13 +225,11 @@ highlight { } .battery-data-text { color: $pink; - margin-right: 6px; font-size: $textsize; } .network-data-text { color: $green; - margin-right: 6px; font-size: $textsize; } diff --git a/data/config b/data/config index 2ff3253..f2a3a2f 100644 --- a/data/config +++ b/data/config @@ -39,6 +39,11 @@ WorkspaceScrollInvert: false # since the protocol is not as feature complete as Hyprland IPC. UseHyprlandIPC: false +# The location of the bar +# Needs to be capitalized!! +# Values are: L (Left), R (Right), T (Top), B (bottom) +Location: T + # Forces the time to be centered. # This can cause the right issue 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 194ef32..5ffdc1e 100644 --- a/src/Bar.cpp +++ b/src/Bar.cpp @@ -4,6 +4,7 @@ #include "Common.h" #include "Config.h" #include "SNI.h" +#include #include namespace Bar @@ -268,16 +269,74 @@ namespace Bar #endif } + inline void SetTransform(Widget& widget, const Transform& primary, const Transform& secondary = {}) + { + if (Config::Get().location == 'T' || Config::Get().location == 'B') + { + widget.SetHorizontalTransform(primary); + widget.SetVerticalTransform(secondary); + } + else if (Config::Get().location == 'R' || Config::Get().location == 'L') + { + widget.SetVerticalTransform(primary); + widget.SetHorizontalTransform(secondary); + } + } + + inline TransitionType GetTransitionType() + { + switch (Config::Get().location) + { + case 'T': + case 'B': return TransitionType::SlideLeft; + case 'L': + case 'R': return TransitionType::SlideUp; + default: LOG("Invalid location char \"" << Config::Get().location << "\"!") return TransitionType::SlideLeft; + } + } + + inline Orientation GetOrientation() + { + switch (Config::Get().location) + { + case 'T': + case 'B': return Orientation::Horizontal; + case 'L': + case 'R': return Orientation::Vertical; + default: LOG("Invalid location char \"" << Config::Get().location << "\"!") return Orientation::Horizontal; + } + } + + inline double GetAngle() + { + if (Config::Get().location == 'T' || Config::Get().location == 'B') + { + return 0; + } + else if (Config::Get().location == 'L') + { + return 270; // 90 is buggy (Clipped text) + } + else if (Config::Get().location == 'R') + { + return 270; + } + + LOG("Invalid location char \"" << Config::Get().location << "\"!"); + return 0; + } + void WidgetSensor(Widget& parent, TimerCallback&& callback, const std::string& sensorClass, const std::string& textClass, Text*& textPtr) { auto eventBox = Widget::Create(); { auto box = Widget::Create(); box->SetSpacing({0, false}); - box->SetHorizontalTransform({-1, true, Alignment::Right}); + SetTransform(*box, {-1, true, Alignment::Right}); + box->SetOrientation(GetOrientation()); { auto revealer = Widget::Create(); - revealer->SetTransition({TransitionType::SlideLeft, 500}); + revealer->SetTransition({GetTransitionType(), 500}); // Add event to eventbox for the revealer to open eventBox->SetHoverFn( [textRevealer = revealer.get()](EventBox&, bool hovered) @@ -287,14 +346,25 @@ namespace Bar { auto text = Widget::Create(); text->SetClass(textClass); + text->SetAngle(GetAngle()); + SetTransform(*text, {-1, true, Alignment::Fill, 0, 6}); textPtr = text.get(); revealer->AddChild(std::move(text)); } auto sensor = Widget::Create(); sensor->SetClass(sensorClass); + double angle = -90; + switch (Config::Get().location) + { + case 'T': + case 'B': angle = -90; break; + case 'L': + case 'R': angle = 0; break; + } + sensor->SetStyle({angle}); sensor->AddTimer(std::move(callback), DynCtx::updateTime); - sensor->SetHorizontalTransform({24, true, Alignment::Fill}); + SetTransform(*sensor, {24, true, Alignment::Fill}); box->AddChild(std::move(revealer)); box->AddChild(std::move(sensor)); @@ -316,8 +386,8 @@ namespace Bar auto widgetAudioSlider = [](Widget& parent, AudioType type) { auto slider = Widget::Create(); - slider->SetOrientation(Orientation::Horizontal); - slider->SetHorizontalTransform({100, true, Alignment::Fill}); + slider->SetOrientation(GetOrientation()); + SetTransform(*slider, {100, true, Alignment::Fill}); slider->SetInverted(true); switch (type) { @@ -342,9 +412,11 @@ namespace Bar { auto box = Widget::Create(); box->SetSpacing({8, false}); - box->SetHorizontalTransform({-1, true, Alignment::Right}); + SetTransform(*box, {-1, true, Alignment::Right}); + box->SetOrientation(GetOrientation()); { auto icon = Widget::Create(); + icon->SetAngle(GetAngle()); switch (type) { case AudioType::Input: @@ -355,6 +427,7 @@ namespace Bar case AudioType::Output: icon->SetClass("audio-icon"); icon->SetText("󰕾 "); + SetTransform(*icon, {-1, true, Alignment::Fill, 0, 6}); DynCtx::audioIcon = icon.get(); break; } @@ -363,7 +436,7 @@ namespace Bar { EventBox& eventBox = (EventBox&)parent; auto revealer = Widget::Create(); - revealer->SetTransition({TransitionType::SlideLeft, 500}); + revealer->SetTransition({GetTransitionType(), 500}); // Add event to eventbox for the revealer to open eventBox.SetHoverFn( [slideRevealer = revealer.get()](EventBox&, bool hovered) @@ -419,6 +492,7 @@ namespace Bar text->SetText(""); text->SetVisible(false); text->SetClass("package-empty"); + text->SetAngle(GetAngle()); text->AddTimer(DynCtx::UpdatePackages, 1000 * Config::Get().checkUpdateInterval, TimerDispatchBehaviour::ImmediateDispatch); parent.AddChild(std::move(text)); } @@ -428,13 +502,17 @@ namespace Bar { auto box = Widget::Create(); box->SetSpacing({0, false}); + box->SetOrientation(GetOrientation()); { auto devText = Widget::Create(); + devText->SetAngle(GetAngle()); DynCtx::btDevText = devText.get(); devText->SetClass("bt-num"); auto iconText = Widget::Create