diff --git a/data/config b/data/config index acc3c9c..55ab8c0 100644 --- a/data/config +++ b/data/config @@ -7,6 +7,18 @@ # - After the ':' # - After the value +# The following three options control the ordering of the widgets. +# Reordering can cause slight margin inconsistencies, +# so it is recommend to only make minor adjustments to the default layout. +# Adding the same widget multiple times to the layout is *not* supported and will cause issues. + +# Widgets to show on the left side +WidgetsLeft: [Workspaces] +# Widgets to center +WidgetsCenter: [Time] +# Widgets to display on the right side +WidgetsRight: [Tray, Packages, Audio, Bluetooth, Network, Disk, VRAM, GPU, RAM, CPU, Battery, Power] + # The CPU sensor to use CPUThermalZone: /sys/devices/pci0000:00/0000:00:18.3/hwmon/hwmon2/temp1_input diff --git a/src/Bar.cpp b/src/Bar.cpp index 4a08004..986f561 100644 --- a/src/Bar.cpp +++ b/src/Bar.cpp @@ -358,19 +358,47 @@ namespace Bar #endif } - void WidgetSensor(Widget& parent, TimerCallback&& callback, const std::string& sensorClass, const std::string& textClass, Text*& textPtr) + 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) { auto eventBox = Widget::Create(); + Utils::SetTransform(*eventBox, {-1, false, SideToAlignment(side)}); { auto box = Widget::Create(); box->SetSpacing({0, false}); - Utils::SetTransform(*box, {-1, true, Alignment::Right}); box->SetOrientation(Utils::GetOrientation()); { + auto revealer = Widget::Create(); if (!Config::Get().sensorTooltips) { - auto revealer = Widget::Create(); - revealer->SetTransition({Utils::GetTransitionType(), 500}); + revealer->SetTransition({Utils::GetTransitionType(SideToDefaultTransition(side)), 500}); // Add event to eventbox for the revealer to open eventBox->SetHoverFn( [textRevealer = revealer.get()](EventBox&, bool hovered) @@ -381,11 +409,13 @@ namespace Bar auto text = Widget::Create(); text->SetClass(textClass); text->SetAngle(Utils::GetAngle()); - Utils::SetTransform(*text, {-1, true, Alignment::Fill, 0, 6}); + // Since we don't know, on which side the text is, add padding to both sides. + // This creates double padding on the side opposite to the sensor. + // TODO: Remove that padding. + Utils::SetTransform(*text, {-1, true, Alignment::Fill, 6, 6}); textPtr = text.get(); revealer->AddChild(std::move(text)); } - box->AddChild(std::move(revealer)); } auto sensor = Widget::Create(); @@ -402,7 +432,25 @@ namespace Bar sensor->AddTimer(std::move(callback), DynCtx::updateTime); Utils::SetTransform(*sensor, {24, true, Alignment::Fill}); - box->AddChild(std::move(sensor)); + switch (side) + { + case Side::Right: + case Side::Center: + { + if (!Config::Get().sensorTooltips) + box->AddChild(std::move(revealer)); + box->AddChild(std::move(sensor)); + break; + } + case Side::Left: + { + // Invert + box->AddChild(std::move(sensor)); + if (!Config::Get().sensorTooltips) + box->AddChild(std::move(revealer)); + break; + } + } } eventBox->AddChild(std::move(box)); } @@ -411,7 +459,7 @@ namespace Bar } // Handles in and out - void WidgetAudio(Widget& parent) + void WidgetAudio(Widget& parent, Side side) { enum class AudioType { @@ -477,11 +525,11 @@ namespace Bar } }; - auto widgetAudioBody = [&widgetAudioVolume](Widget& parent, AudioType type) + auto widgetAudioBody = [&widgetAudioVolume, side](Widget& parent, AudioType type) { auto box = Widget::Create(); box->SetSpacing({8, false}); - Utils::SetTransform(*box, {-1, true, Alignment::Right}); + Utils::SetTransform(*box, {-1, false, SideToAlignment(side)}); box->SetOrientation(Utils::GetOrientation()); { auto icon = Widget::Create(); @@ -505,7 +553,7 @@ namespace Bar { EventBox& eventBox = (EventBox&)parent; auto revealer = Widget::Create(); - revealer->SetTransition({Utils::GetTransitionType(), 500}); + revealer->SetTransition({Utils::GetTransitionType(SideToDefaultTransition(side)), 500}); // Add event to eventbox for the revealer to open eventBox.SetHoverFn( [slideRevealer = revealer.get()](EventBox&, bool hovered) @@ -555,7 +603,7 @@ namespace Bar parent.AddTimer(DynCtx::UpdateAudio, DynCtx::updateTimeFast); } - void WidgetPackages(Widget& parent) + void WidgetPackages(Widget& parent, Side) { auto text = Widget::Create(); text->SetText(""); @@ -567,16 +615,19 @@ namespace Bar } #ifdef WITH_BLUEZ - void WidgetBluetooth(Widget& parent) + void WidgetBluetooth(Widget& parent, Side side) { auto box = Widget::Create(); box->SetSpacing({0, false}); box->SetOrientation(Utils::GetOrientation()); + Utils::SetTransform(*box, {-1, false, SideToAlignment(side)}); { auto devText = Widget::Create(); devText->SetAngle(Utils::GetAngle()); DynCtx::btDevText = devText.get(); devText->SetClass("bt-num"); + if (side == Side::Left) + Utils::SetTransform(*devText, {-1, true, Alignment::Fill, 6, 0}); auto iconText = Widget::Create