diff --git a/data/config b/data/config index af9dbfb..2ff3253 100644 --- a/data/config +++ b/data/config @@ -40,9 +40,18 @@ WorkspaceScrollInvert: false UseHyprlandIPC: false # Forces the time to be centered. -# This can cause issues, if there is not enough space on screen (e.g. when opening the text) +# 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. +# So try to decrease "TimeSpace" first, before setting this configuration to false. CenterTime: true +# How much space should be reserved for the time widget. Setting this too high can cause the right widget to clip outside. +# Therefore try to set it as low as possible if you experience clipping. +# Although keep in mind, that a value that is too low can cause the widget to be be off-center, +# which can also cause clipping. +# If you can't find an optimal value, consider setting 'CenterTime' to false +TimeSpace: 300 + # Set datetime style # DateTimeStyle: %a %D - %H:%M:%S %Z diff --git a/src/Bar.cpp b/src/Bar.cpp index 1afd241..194ef32 100644 --- a/src/Bar.cpp +++ b/src/Bar.cpp @@ -657,7 +657,7 @@ namespace Bar void WidgetWorkspaces(Widget& parent) { auto margin = Widget::Create(); - margin->SetHorizontalTransform({12, true, Alignment::Left}); + margin->SetHorizontalTransform({12, false, Alignment::Left}); parent.AddChild(std::move(margin)); auto eventBox = Widget::Create(); eventBox->SetScrollFn(DynCtx::ScrollWorkspaces); @@ -691,12 +691,26 @@ namespace Bar monitorID = monitor; auto mainWidget = Widget::Create(); - mainWidget->SetSpacing({0, Config::Get().centerTime}); + mainWidget->SetSpacing({0, false}); mainWidget->SetClass("bar"); { + // Calculate how much space we need have for the left widget. + // The center widget will come directly after that. + // This ensures that the center widget is centered. + int windowCenter = window.GetWidth() / 2; + int endLeftWidgets = windowCenter - Config::Get().timeSpace / 2; + + if (!Config::Get().centerTime) + { + // Don't care if time is centered or not. + endLeftWidgets = -1; + } + auto left = Widget::Create(); left->SetSpacing({0, false}); - left->SetHorizontalTransform({-1, true, Alignment::Left}); + // For centerTime the width of the left widget handles the centering. + // For not centerTime we want to set it as much right as possible. So let this expand as much as possible. + left->SetHorizontalTransform({endLeftWidgets, !Config::Get().centerTime, Alignment::Left}); #ifdef WITH_WORKSPACES if (RuntimeConfig::Get().hasWorkspaces) { @@ -704,11 +718,16 @@ namespace Bar } #endif - auto time = Widget::Create(); - time->SetHorizontalTransform({-1, true, Alignment::Center}); - time->SetClass("time-text"); - time->SetText("Uninitialized"); - time->AddTimer(DynCtx::UpdateTime, 1000); + auto center = Widget::Create(); + center->SetHorizontalTransform({(int)Config::Get().timeSpace, false, Alignment::Left}); + { + auto time = Widget::Create(); + time->SetHorizontalTransform({-1, true, Alignment::Center}); + time->SetClass("time-text"); + time->SetText("Uninitialized"); + time->AddTimer(DynCtx::UpdateTime, 1000); + center->AddChild(std::move(time)); + } auto right = Widget::Create(); right->SetClass("right"); @@ -736,7 +755,7 @@ namespace Bar } mainWidget->AddChild(std::move(left)); - mainWidget->AddChild(std::move(time)); + mainWidget->AddChild(std::move(center)); mainWidget->AddChild(std::move(right)); } window.SetAnchor(Anchor::Left | Anchor::Right | Anchor::Top); diff --git a/src/Config.cpp b/src/Config.cpp index 03bf7c8..7c4fe44 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -189,6 +189,8 @@ void Config::Load() AddConfigVar("CheckUpdateInterval", config.checkUpdateInterval, lineView, foundProperty); + AddConfigVar("TimeSpace", config.timeSpace, lineView, foundProperty); + AddConfigVar("AudioScrollSpeed", config.audioScrollSpeed, lineView, foundProperty); AddConfigVar("AudioMinVolume", config.audioMinVolume, lineView, foundProperty); diff --git a/src/Config.h b/src/Config.h index db1bd34..67c8cf9 100644 --- a/src/Config.h +++ b/src/Config.h @@ -40,6 +40,8 @@ public: uint32_t checkUpdateInterval = 5 * 60; // Interval to run the "checkPackagesCommand". In seconds + uint32_t timeSpace = 300; // How much time should be reserved for the time widget. + // SNIIconSize: ["Title String"], ["Size"] std::unordered_map sniIconSizes; std::unordered_map sniPaddingTop;