mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-22 11:12:49 +00:00
SNI: Allow bar rotation
Texture was also rewritten, so it doesn't need the SNIPaddingTop hack as much anymore
This commit is contained in:
parent
6e8e7f3f9e
commit
f78758c4ee
4 changed files with 134 additions and 120 deletions
155
src/Bar.cpp
155
src/Bar.cpp
|
@ -269,74 +269,17 @@ namespace Bar
|
||||||
#endif
|
#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<Sensor>&& callback, const std::string& sensorClass, const std::string& textClass, Text*& textPtr)
|
void WidgetSensor(Widget& parent, TimerCallback<Sensor>&& callback, const std::string& sensorClass, const std::string& textClass, Text*& textPtr)
|
||||||
{
|
{
|
||||||
auto eventBox = Widget::Create<EventBox>();
|
auto eventBox = Widget::Create<EventBox>();
|
||||||
{
|
{
|
||||||
auto box = Widget::Create<Box>();
|
auto box = Widget::Create<Box>();
|
||||||
box->SetSpacing({0, false});
|
box->SetSpacing({0, false});
|
||||||
SetTransform(*box, {-1, true, Alignment::Right});
|
Utils::SetTransform(*box, {-1, true, Alignment::Right});
|
||||||
box->SetOrientation(GetOrientation());
|
box->SetOrientation(Utils::GetOrientation());
|
||||||
{
|
{
|
||||||
auto revealer = Widget::Create<Revealer>();
|
auto revealer = Widget::Create<Revealer>();
|
||||||
revealer->SetTransition({GetTransitionType(), 500});
|
revealer->SetTransition({Utils::GetTransitionType(), 500});
|
||||||
// Add event to eventbox for the revealer to open
|
// Add event to eventbox for the revealer to open
|
||||||
eventBox->SetHoverFn(
|
eventBox->SetHoverFn(
|
||||||
[textRevealer = revealer.get()](EventBox&, bool hovered)
|
[textRevealer = revealer.get()](EventBox&, bool hovered)
|
||||||
|
@ -346,8 +289,8 @@ namespace Bar
|
||||||
{
|
{
|
||||||
auto text = Widget::Create<Text>();
|
auto text = Widget::Create<Text>();
|
||||||
text->SetClass(textClass);
|
text->SetClass(textClass);
|
||||||
text->SetAngle(GetAngle());
|
text->SetAngle(Utils::GetAngle());
|
||||||
SetTransform(*text, {-1, true, Alignment::Fill, 0, 6});
|
Utils::SetTransform(*text, {-1, true, Alignment::Fill, 0, 6});
|
||||||
textPtr = text.get();
|
textPtr = text.get();
|
||||||
revealer->AddChild(std::move(text));
|
revealer->AddChild(std::move(text));
|
||||||
}
|
}
|
||||||
|
@ -364,7 +307,7 @@ namespace Bar
|
||||||
}
|
}
|
||||||
sensor->SetStyle({angle});
|
sensor->SetStyle({angle});
|
||||||
sensor->AddTimer<Sensor>(std::move(callback), DynCtx::updateTime);
|
sensor->AddTimer<Sensor>(std::move(callback), DynCtx::updateTime);
|
||||||
SetTransform(*sensor, {24, true, Alignment::Fill});
|
Utils::SetTransform(*sensor, {24, true, Alignment::Fill});
|
||||||
|
|
||||||
box->AddChild(std::move(revealer));
|
box->AddChild(std::move(revealer));
|
||||||
box->AddChild(std::move(sensor));
|
box->AddChild(std::move(sensor));
|
||||||
|
@ -386,8 +329,8 @@ namespace Bar
|
||||||
auto widgetAudioSlider = [](Widget& parent, AudioType type)
|
auto widgetAudioSlider = [](Widget& parent, AudioType type)
|
||||||
{
|
{
|
||||||
auto slider = Widget::Create<Slider>();
|
auto slider = Widget::Create<Slider>();
|
||||||
slider->SetOrientation(GetOrientation());
|
slider->SetOrientation(Utils::GetOrientation());
|
||||||
SetTransform(*slider, {100, true, Alignment::Fill});
|
Utils::SetTransform(*slider, {100, true, Alignment::Fill});
|
||||||
slider->SetInverted(true);
|
slider->SetInverted(true);
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
|
@ -412,11 +355,11 @@ namespace Bar
|
||||||
{
|
{
|
||||||
auto box = Widget::Create<Box>();
|
auto box = Widget::Create<Box>();
|
||||||
box->SetSpacing({8, false});
|
box->SetSpacing({8, false});
|
||||||
SetTransform(*box, {-1, true, Alignment::Right});
|
Utils::SetTransform(*box, {-1, true, Alignment::Right});
|
||||||
box->SetOrientation(GetOrientation());
|
box->SetOrientation(Utils::GetOrientation());
|
||||||
{
|
{
|
||||||
auto icon = Widget::Create<Text>();
|
auto icon = Widget::Create<Text>();
|
||||||
icon->SetAngle(GetAngle());
|
icon->SetAngle(Utils::GetAngle());
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case AudioType::Input:
|
case AudioType::Input:
|
||||||
|
@ -427,7 +370,7 @@ namespace Bar
|
||||||
case AudioType::Output:
|
case AudioType::Output:
|
||||||
icon->SetClass("audio-icon");
|
icon->SetClass("audio-icon");
|
||||||
icon->SetText(" ");
|
icon->SetText(" ");
|
||||||
SetTransform(*icon, {-1, true, Alignment::Fill, 0, 6});
|
Utils::SetTransform(*icon, {-1, true, Alignment::Fill, 0, 6});
|
||||||
DynCtx::audioIcon = icon.get();
|
DynCtx::audioIcon = icon.get();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -436,7 +379,7 @@ namespace Bar
|
||||||
{
|
{
|
||||||
EventBox& eventBox = (EventBox&)parent;
|
EventBox& eventBox = (EventBox&)parent;
|
||||||
auto revealer = Widget::Create<Revealer>();
|
auto revealer = Widget::Create<Revealer>();
|
||||||
revealer->SetTransition({GetTransitionType(), 500});
|
revealer->SetTransition({Utils::GetTransitionType(), 500});
|
||||||
// Add event to eventbox for the revealer to open
|
// Add event to eventbox for the revealer to open
|
||||||
eventBox.SetHoverFn(
|
eventBox.SetHoverFn(
|
||||||
[slideRevealer = revealer.get()](EventBox&, bool hovered)
|
[slideRevealer = revealer.get()](EventBox&, bool hovered)
|
||||||
|
@ -492,7 +435,7 @@ namespace Bar
|
||||||
text->SetText("");
|
text->SetText("");
|
||||||
text->SetVisible(false);
|
text->SetVisible(false);
|
||||||
text->SetClass("package-empty");
|
text->SetClass("package-empty");
|
||||||
text->SetAngle(GetAngle());
|
text->SetAngle(Utils::GetAngle());
|
||||||
text->AddTimer<Text>(DynCtx::UpdatePackages, 1000 * Config::Get().checkUpdateInterval, TimerDispatchBehaviour::ImmediateDispatch);
|
text->AddTimer<Text>(DynCtx::UpdatePackages, 1000 * Config::Get().checkUpdateInterval, TimerDispatchBehaviour::ImmediateDispatch);
|
||||||
parent.AddChild(std::move(text));
|
parent.AddChild(std::move(text));
|
||||||
}
|
}
|
||||||
|
@ -502,17 +445,17 @@ namespace Bar
|
||||||
{
|
{
|
||||||
auto box = Widget::Create<Box>();
|
auto box = Widget::Create<Box>();
|
||||||
box->SetSpacing({0, false});
|
box->SetSpacing({0, false});
|
||||||
box->SetOrientation(GetOrientation());
|
box->SetOrientation(Utils::GetOrientation());
|
||||||
{
|
{
|
||||||
auto devText = Widget::Create<Text>();
|
auto devText = Widget::Create<Text>();
|
||||||
devText->SetAngle(GetAngle());
|
devText->SetAngle(Utils::GetAngle());
|
||||||
DynCtx::btDevText = devText.get();
|
DynCtx::btDevText = devText.get();
|
||||||
devText->SetClass("bt-num");
|
devText->SetClass("bt-num");
|
||||||
|
|
||||||
auto iconText = Widget::Create<Button>();
|
auto iconText = Widget::Create<Button>();
|
||||||
iconText->OnClick(DynCtx::OnBTClick);
|
iconText->OnClick(DynCtx::OnBTClick);
|
||||||
iconText->SetAngle(GetAngle());
|
iconText->SetAngle(Utils::GetAngle());
|
||||||
SetTransform(*iconText, {-1, true, Alignment::Fill, 0, 6});
|
Utils::SetTransform(*iconText, {-1, true, Alignment::Fill, 0, 6});
|
||||||
DynCtx::btIconText = iconText.get();
|
DynCtx::btIconText = iconText.get();
|
||||||
|
|
||||||
box->AddChild(std::move(devText));
|
box->AddChild(std::move(devText));
|
||||||
|
@ -530,11 +473,11 @@ namespace Bar
|
||||||
{
|
{
|
||||||
auto box = Widget::Create<Box>();
|
auto box = Widget::Create<Box>();
|
||||||
box->SetSpacing({0, false});
|
box->SetSpacing({0, false});
|
||||||
SetTransform(*box, {-1, true, Alignment::Right});
|
Utils::SetTransform(*box, {-1, true, Alignment::Right});
|
||||||
box->SetOrientation(GetOrientation());
|
box->SetOrientation(Utils::GetOrientation());
|
||||||
{
|
{
|
||||||
auto revealer = Widget::Create<Revealer>();
|
auto revealer = Widget::Create<Revealer>();
|
||||||
revealer->SetTransition({GetTransitionType(), 500});
|
revealer->SetTransition({Utils::GetTransitionType(), 500});
|
||||||
// Add event to eventbox for the revealer to open
|
// Add event to eventbox for the revealer to open
|
||||||
eventBox->SetHoverFn(
|
eventBox->SetHoverFn(
|
||||||
[textRevealer = revealer.get()](EventBox&, bool hovered)
|
[textRevealer = revealer.get()](EventBox&, bool hovered)
|
||||||
|
@ -544,8 +487,8 @@ namespace Bar
|
||||||
{
|
{
|
||||||
auto text = Widget::Create<Text>();
|
auto text = Widget::Create<Text>();
|
||||||
text->SetClass("network-data-text");
|
text->SetClass("network-data-text");
|
||||||
text->SetAngle(GetAngle());
|
text->SetAngle(Utils::GetAngle());
|
||||||
SetTransform(*text, {-1, true, Alignment::Fill, 0, 6});
|
Utils::SetTransform(*text, {-1, true, Alignment::Fill, 0, 6});
|
||||||
DynCtx::networkText = text.get();
|
DynCtx::networkText = text.get();
|
||||||
revealer->AddChild(std::move(text));
|
revealer->AddChild(std::move(text));
|
||||||
}
|
}
|
||||||
|
@ -553,9 +496,9 @@ namespace Bar
|
||||||
auto sensor = Widget::Create<NetworkSensor>();
|
auto sensor = Widget::Create<NetworkSensor>();
|
||||||
sensor->SetLimitUp({(double)Config::Get().minUploadBytes, (double)Config::Get().maxUploadBytes});
|
sensor->SetLimitUp({(double)Config::Get().minUploadBytes, (double)Config::Get().maxUploadBytes});
|
||||||
sensor->SetLimitDown({(double)Config::Get().minDownloadBytes, (double)Config::Get().maxDownloadBytes});
|
sensor->SetLimitDown({(double)Config::Get().minDownloadBytes, (double)Config::Get().maxDownloadBytes});
|
||||||
sensor->SetAngle(GetAngle());
|
sensor->SetAngle(Utils::GetAngle());
|
||||||
sensor->AddTimer<NetworkSensor>(DynCtx::UpdateNetwork, DynCtx::updateTime);
|
sensor->AddTimer<NetworkSensor>(DynCtx::UpdateNetwork, DynCtx::updateTime);
|
||||||
SetTransform(*sensor, {24, true, Alignment::Fill});
|
Utils::SetTransform(*sensor, {24, true, Alignment::Fill});
|
||||||
|
|
||||||
box->AddChild(std::move(revealer));
|
box->AddChild(std::move(revealer));
|
||||||
box->AddChild(std::move(sensor));
|
box->AddChild(std::move(sensor));
|
||||||
|
@ -620,24 +563,24 @@ namespace Bar
|
||||||
{
|
{
|
||||||
auto powerBox = Widget::Create<Box>();
|
auto powerBox = Widget::Create<Box>();
|
||||||
powerBox->SetClass("power-box");
|
powerBox->SetClass("power-box");
|
||||||
SetTransform(*powerBox, {-1, false, Alignment::Right});
|
Utils::SetTransform(*powerBox, {-1, false, Alignment::Right});
|
||||||
powerBox->SetSpacing({0, false});
|
powerBox->SetSpacing({0, false});
|
||||||
powerBox->SetOrientation(GetOrientation());
|
powerBox->SetOrientation(Utils::GetOrientation());
|
||||||
{
|
{
|
||||||
auto revealer = Widget::Create<Revealer>();
|
auto revealer = Widget::Create<Revealer>();
|
||||||
DynCtx::powerBoxRevealer = revealer.get();
|
DynCtx::powerBoxRevealer = revealer.get();
|
||||||
revealer->SetTransition({GetTransitionType(), 500});
|
revealer->SetTransition({Utils::GetTransitionType(), 500});
|
||||||
{
|
{
|
||||||
auto powerBoxExpand = Widget::Create<Box>();
|
auto powerBoxExpand = Widget::Create<Box>();
|
||||||
powerBoxExpand->SetClass("power-box-expand");
|
powerBoxExpand->SetClass("power-box-expand");
|
||||||
powerBoxExpand->SetSpacing({8, true});
|
powerBoxExpand->SetSpacing({8, true});
|
||||||
powerBoxExpand->SetOrientation(GetOrientation());
|
powerBoxExpand->SetOrientation(Utils::GetOrientation());
|
||||||
SetTransform(*powerBoxExpand, {-1, true, Alignment::Fill, 0, 6});
|
Utils::SetTransform(*powerBoxExpand, {-1, true, Alignment::Fill, 0, 6});
|
||||||
{
|
{
|
||||||
auto exitButton = Widget::Create<Button>();
|
auto exitButton = Widget::Create<Button>();
|
||||||
exitButton->SetClass("exit-button");
|
exitButton->SetClass("exit-button");
|
||||||
exitButton->SetText("");
|
exitButton->SetText("");
|
||||||
exitButton->SetAngle(GetAngle());
|
exitButton->SetAngle(Utils::GetAngle());
|
||||||
exitButton->OnClick(
|
exitButton->OnClick(
|
||||||
[setActivate](Button& but)
|
[setActivate](Button& but)
|
||||||
{
|
{
|
||||||
|
@ -655,7 +598,7 @@ namespace Bar
|
||||||
auto lockButton = Widget::Create<Button>();
|
auto lockButton = Widget::Create<Button>();
|
||||||
lockButton->SetClass("sleep-button");
|
lockButton->SetClass("sleep-button");
|
||||||
lockButton->SetText("");
|
lockButton->SetText("");
|
||||||
lockButton->SetAngle(GetAngle());
|
lockButton->SetAngle(Utils::GetAngle());
|
||||||
lockButton->OnClick(
|
lockButton->OnClick(
|
||||||
[setActivate](Button& but)
|
[setActivate](Button& but)
|
||||||
{
|
{
|
||||||
|
@ -673,7 +616,7 @@ namespace Bar
|
||||||
auto sleepButton = Widget::Create<Button>();
|
auto sleepButton = Widget::Create<Button>();
|
||||||
sleepButton->SetClass("sleep-button");
|
sleepButton->SetClass("sleep-button");
|
||||||
sleepButton->SetText("");
|
sleepButton->SetText("");
|
||||||
sleepButton->SetAngle(GetAngle());
|
sleepButton->SetAngle(Utils::GetAngle());
|
||||||
sleepButton->OnClick(
|
sleepButton->OnClick(
|
||||||
[setActivate](Button& but)
|
[setActivate](Button& but)
|
||||||
{
|
{
|
||||||
|
@ -691,8 +634,8 @@ namespace Bar
|
||||||
auto rebootButton = Widget::Create<Button>();
|
auto rebootButton = Widget::Create<Button>();
|
||||||
rebootButton->SetClass("reboot-button");
|
rebootButton->SetClass("reboot-button");
|
||||||
rebootButton->SetText("");
|
rebootButton->SetText("");
|
||||||
rebootButton->SetAngle(GetAngle());
|
rebootButton->SetAngle(Utils::GetAngle());
|
||||||
SetTransform(*rebootButton, {-1, true, Alignment::Fill, 0, 6});
|
Utils::SetTransform(*rebootButton, {-1, true, Alignment::Fill, 0, 6});
|
||||||
rebootButton->OnClick(
|
rebootButton->OnClick(
|
||||||
[setActivate](Button& but)
|
[setActivate](Button& but)
|
||||||
{
|
{
|
||||||
|
@ -719,8 +662,8 @@ namespace Bar
|
||||||
auto powerButton = Widget::Create<Button>();
|
auto powerButton = Widget::Create<Button>();
|
||||||
powerButton->SetClass("power-button");
|
powerButton->SetClass("power-button");
|
||||||
powerButton->SetText(" ");
|
powerButton->SetText(" ");
|
||||||
powerButton->SetAngle(GetAngle());
|
powerButton->SetAngle(Utils::GetAngle());
|
||||||
SetTransform(*powerButton, {24, true, Alignment::Fill});
|
Utils::SetTransform(*powerButton, {24, true, Alignment::Fill});
|
||||||
powerButton->OnClick(
|
powerButton->OnClick(
|
||||||
[setActivate](Button& but)
|
[setActivate](Button& but)
|
||||||
{
|
{
|
||||||
|
@ -752,13 +695,13 @@ namespace Bar
|
||||||
{
|
{
|
||||||
auto box = Widget::Create<Box>();
|
auto box = Widget::Create<Box>();
|
||||||
box->SetSpacing({8, true});
|
box->SetSpacing({8, true});
|
||||||
box->SetOrientation(GetOrientation());
|
box->SetOrientation(Utils::GetOrientation());
|
||||||
SetTransform(*box, {-1, true, Alignment::Left, 12, 0});
|
Utils::SetTransform(*box, {-1, true, Alignment::Left, 12, 0});
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < DynCtx::workspaces.size(); i++)
|
for (size_t i = 0; i < DynCtx::workspaces.size(); i++)
|
||||||
{
|
{
|
||||||
auto workspace = Widget::Create<Button>();
|
auto workspace = Widget::Create<Button>();
|
||||||
SetTransform(*workspace, {8, false, Alignment::Fill});
|
Utils::SetTransform(*workspace, {8, false, Alignment::Fill});
|
||||||
workspace->OnClick(
|
workspace->OnClick(
|
||||||
[i](Button&)
|
[i](Button&)
|
||||||
{
|
{
|
||||||
|
@ -780,7 +723,7 @@ namespace Bar
|
||||||
monitorID = monitor;
|
monitorID = monitor;
|
||||||
|
|
||||||
auto mainWidget = Widget::Create<Box>();
|
auto mainWidget = Widget::Create<Box>();
|
||||||
mainWidget->SetOrientation(GetOrientation());
|
mainWidget->SetOrientation(Utils::GetOrientation());
|
||||||
mainWidget->SetSpacing({0, false});
|
mainWidget->SetSpacing({0, false});
|
||||||
mainWidget->SetClass("bar");
|
mainWidget->SetClass("bar");
|
||||||
{
|
{
|
||||||
|
@ -799,10 +742,10 @@ namespace Bar
|
||||||
|
|
||||||
auto left = Widget::Create<Box>();
|
auto left = Widget::Create<Box>();
|
||||||
left->SetSpacing({0, false});
|
left->SetSpacing({0, false});
|
||||||
left->SetOrientation(GetOrientation());
|
left->SetOrientation(Utils::GetOrientation());
|
||||||
// For centerTime the width of the left widget handles the centering.
|
// 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.
|
// For not centerTime we want to set it as much right as possible. So let this expand as much as possible.
|
||||||
SetTransform(*left, {endLeftWidgets, !Config::Get().centerTime, Alignment::Left});
|
Utils::SetTransform(*left, {endLeftWidgets, !Config::Get().centerTime, Alignment::Left});
|
||||||
#ifdef WITH_WORKSPACES
|
#ifdef WITH_WORKSPACES
|
||||||
if (RuntimeConfig::Get().hasWorkspaces)
|
if (RuntimeConfig::Get().hasWorkspaces)
|
||||||
{
|
{
|
||||||
|
@ -811,12 +754,12 @@ namespace Bar
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto center = Widget::Create<Box>();
|
auto center = Widget::Create<Box>();
|
||||||
center->SetOrientation(GetOrientation());
|
center->SetOrientation(Utils::GetOrientation());
|
||||||
SetTransform(*center, {(int)Config::Get().timeSpace, false, Alignment::Left});
|
Utils::SetTransform(*center, {(int)Config::Get().timeSpace, false, Alignment::Left});
|
||||||
{
|
{
|
||||||
auto time = Widget::Create<Text>();
|
auto time = Widget::Create<Text>();
|
||||||
SetTransform(*time, {-1, true, Alignment::Center});
|
Utils::SetTransform(*time, {-1, true, Alignment::Center});
|
||||||
time->SetAngle(GetAngle());
|
time->SetAngle(Utils::GetAngle());
|
||||||
time->SetClass("time-text");
|
time->SetClass("time-text");
|
||||||
time->SetText("Uninitialized");
|
time->SetText("Uninitialized");
|
||||||
time->AddTimer<Text>(DynCtx::UpdateTime, 1000);
|
time->AddTimer<Text>(DynCtx::UpdateTime, 1000);
|
||||||
|
@ -826,8 +769,8 @@ namespace Bar
|
||||||
auto right = Widget::Create<Box>();
|
auto right = Widget::Create<Box>();
|
||||||
right->SetClass("right");
|
right->SetClass("right");
|
||||||
right->SetSpacing({8, false});
|
right->SetSpacing({8, false});
|
||||||
right->SetOrientation(GetOrientation());
|
right->SetOrientation(Utils::GetOrientation());
|
||||||
SetTransform(*right, {-1, true, Alignment::Right, 0, 10});
|
Utils::SetTransform(*right, {-1, true, Alignment::Right, 0, 10});
|
||||||
{
|
{
|
||||||
#ifdef WITH_SNI
|
#ifdef WITH_SNI
|
||||||
SNI::WidgetSNI(*right);
|
SNI::WidgetSNI(*right);
|
||||||
|
|
13
src/SNI.cpp
13
src/SNI.cpp
|
@ -306,6 +306,8 @@ namespace SNI
|
||||||
|
|
||||||
auto container = Widget::Create<Box>();
|
auto container = Widget::Create<Box>();
|
||||||
container->SetSpacing({4, false});
|
container->SetSpacing({4, false});
|
||||||
|
container->SetOrientation(Utils::GetOrientation());
|
||||||
|
Utils::SetTransform(*container, {-1, true, Alignment::Fill, 0, 8});
|
||||||
iconBox = container.get();
|
iconBox = container.get();
|
||||||
for (auto& item : items)
|
for (auto& item : items)
|
||||||
{
|
{
|
||||||
|
@ -337,16 +339,17 @@ namespace SNI
|
||||||
LOG("SNI: Add " << item.name << " to widget");
|
LOG("SNI: Add " << item.name << " to widget");
|
||||||
auto texture = Widget::Create<Texture>();
|
auto texture = Widget::Create<Texture>();
|
||||||
bool wasExplicitOverride = false;
|
bool wasExplicitOverride = false;
|
||||||
for (auto& [filter, size] : Config::Get().sniIconSizes)
|
int size = 24;
|
||||||
|
for (auto& [filter, iconSize] : Config::Get().sniIconSizes)
|
||||||
{
|
{
|
||||||
if (item.tooltip.find(filter) != std::string::npos)
|
if (item.tooltip.find(filter) != std::string::npos)
|
||||||
{
|
{
|
||||||
wasExplicitOverride = true;
|
wasExplicitOverride = true;
|
||||||
texture->ForceHeight(size);
|
size = iconSize;
|
||||||
}
|
}
|
||||||
else if (filter == "*" && !wasExplicitOverride)
|
else if (filter == "*" && !wasExplicitOverride)
|
||||||
{
|
{
|
||||||
texture->ForceHeight(size);
|
size = iconSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wasExplicitOverride = false;
|
wasExplicitOverride = false;
|
||||||
|
@ -354,7 +357,6 @@ namespace SNI
|
||||||
{
|
{
|
||||||
if (item.tooltip.find(filter) != std::string::npos)
|
if (item.tooltip.find(filter) != std::string::npos)
|
||||||
{
|
{
|
||||||
LOG("Padding " << padding);
|
|
||||||
wasExplicitOverride = true;
|
wasExplicitOverride = true;
|
||||||
texture->AddPaddingTop(padding);
|
texture->AddPaddingTop(padding);
|
||||||
}
|
}
|
||||||
|
@ -363,9 +365,10 @@ namespace SNI
|
||||||
texture->AddPaddingTop(padding);
|
texture->AddPaddingTop(padding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
texture->SetHorizontalTransform({0, true, Alignment::Fill});
|
Utils::SetTransform(*texture, {size, true, Alignment::Fill}, {size, true, Alignment::Fill});
|
||||||
texture->SetBuf(item.w, item.h, item.iconData);
|
texture->SetBuf(item.w, item.h, item.iconData);
|
||||||
texture->SetTooltip(item.tooltip);
|
texture->SetTooltip(item.tooltip);
|
||||||
|
texture->SetAngle(Utils::GetAngle() - 180.0);
|
||||||
|
|
||||||
eventBox->AddChild(std::move(texture));
|
eventBox->AddChild(std::move(texture));
|
||||||
iconBox->AddChild(std::move(eventBox));
|
iconBox->AddChild(std::move(eventBox));
|
||||||
|
|
|
@ -527,17 +527,21 @@ void Texture::SetBuf(size_t width, size_t height, uint8_t* buf)
|
||||||
|
|
||||||
void Texture::Draw(cairo_t* cr)
|
void Texture::Draw(cairo_t* cr)
|
||||||
{
|
{
|
||||||
GtkAllocation dim;
|
Quad q = GetQuad();
|
||||||
gtk_widget_get_allocation(m_Widget, &dim);
|
|
||||||
|
|
||||||
double height = m_ForcedHeight != 0 ? m_ForcedHeight : dim.height;
|
// TODO: Non-quad sizes
|
||||||
double scale = (double)height / (double)m_Height;
|
double scaleX = q.size / m_Width;
|
||||||
double width = (double)m_Width * scale;
|
double scaleY = q.size / m_Height;
|
||||||
|
|
||||||
gtk_widget_set_size_request(m_Widget, width + 2, height);
|
// Rotate around center of Quad
|
||||||
cairo_scale(cr, scale, scale);
|
cairo_rectangle(cr, q.x, q.y + m_Padding, q.size, q.size);
|
||||||
cairo_rectangle(cr, (dim.width - width) / 2.0, m_Padding + (dim.height - height) / 2.0, m_Width, m_Height);
|
|
||||||
gdk_cairo_set_source_pixbuf(cr, m_Pixbuf, (dim.width - width) / 2.0, m_Padding + (dim.height - height) / 2.0);
|
cairo_translate(cr, q.x + q.size / 2, q.y + m_Padding + q.size / 2);
|
||||||
|
cairo_rotate(cr, m_Angle * M_PI / 180.0);
|
||||||
|
cairo_translate(cr, -(q.x + q.size / 2), -(q.y + m_Padding + q.size / 2));
|
||||||
|
cairo_scale(cr, scaleX, scaleY);
|
||||||
|
|
||||||
|
gdk_cairo_set_source_pixbuf(cr, m_Pixbuf, q.x, (q.y + m_Padding) * (1.f / scaleY));
|
||||||
cairo_fill(cr);
|
cairo_fill(cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
64
src/Widget.h
64
src/Widget.h
|
@ -1,4 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "Config.h"
|
||||||
|
#include "Log.h"
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -287,6 +289,7 @@ public:
|
||||||
|
|
||||||
void ForceHeight(size_t height) { m_ForcedHeight = height; };
|
void ForceHeight(size_t height) { m_ForcedHeight = height; };
|
||||||
void AddPaddingTop(int32_t topPadding) { m_Padding = topPadding; };
|
void AddPaddingTop(int32_t topPadding) { m_Padding = topPadding; };
|
||||||
|
void SetAngle(double angle) { m_Angle = angle; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Draw(cairo_t* cr) override;
|
void Draw(cairo_t* cr) override;
|
||||||
|
@ -294,6 +297,7 @@ private:
|
||||||
size_t m_Width;
|
size_t m_Width;
|
||||||
size_t m_Height;
|
size_t m_Height;
|
||||||
size_t m_ForcedHeight = 0;
|
size_t m_ForcedHeight = 0;
|
||||||
|
double m_Angle;
|
||||||
int32_t m_Padding = 0;
|
int32_t m_Padding = 0;
|
||||||
GBytes* m_Bytes;
|
GBytes* m_Bytes;
|
||||||
GdkPixbuf* m_Pixbuf;
|
GdkPixbuf* m_Pixbuf;
|
||||||
|
@ -370,3 +374,63 @@ private:
|
||||||
double m_ScrollSpeed = 5. / 100.; // 5%
|
double m_ScrollSpeed = 5. / 100.; // 5%
|
||||||
std::function<void(Slider&, double)> m_OnValueChange;
|
std::function<void(Slider&, double)> m_OnValueChange;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace Utils
|
||||||
|
{
|
||||||
|
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 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue