Greatly reduce clipping when CenterTime is set

Giving each main box element (left, center, right) caused the window to
resize and clip out of the monitor when
e.g. the right part was larger than the 1/3 of the window.

Now we have a size for the center widget and try to manually center a box with
that size by setting the left widget's size accordingly. This allows the
right widget to have more room, so it can go right up to the center widget without issues.
This commit is contained in:
scorpion-26 2023-06-10 23:44:28 +02:00
parent a34ffd8334
commit 1f56e6ba15
4 changed files with 42 additions and 10 deletions

View file

@ -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

View file

@ -657,7 +657,7 @@ namespace Bar
void WidgetWorkspaces(Widget& parent)
{
auto margin = Widget::Create<Box>();
margin->SetHorizontalTransform({12, true, Alignment::Left});
margin->SetHorizontalTransform({12, false, Alignment::Left});
parent.AddChild(std::move(margin));
auto eventBox = Widget::Create<EventBox>();
eventBox->SetScrollFn(DynCtx::ScrollWorkspaces);
@ -691,12 +691,26 @@ namespace Bar
monitorID = monitor;
auto mainWidget = Widget::Create<Box>();
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<Box>();
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<Text>();
time->SetHorizontalTransform({-1, true, Alignment::Center});
time->SetClass("time-text");
time->SetText("Uninitialized");
time->AddTimer<Text>(DynCtx::UpdateTime, 1000);
auto center = Widget::Create<Box>();
center->SetHorizontalTransform({(int)Config::Get().timeSpace, false, Alignment::Left});
{
auto time = Widget::Create<Text>();
time->SetHorizontalTransform({-1, true, Alignment::Center});
time->SetClass("time-text");
time->SetText("Uninitialized");
time->AddTimer<Text>(DynCtx::UpdateTime, 1000);
center->AddChild(std::move(time));
}
auto right = Widget::Create<Box>();
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);

View file

@ -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);

View file

@ -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<std::string, uint32_t> sniIconSizes;
std::unordered_map<std::string, int32_t> sniPaddingTop;