Add option to disable the manual flyin animation

Instead of sidetracking the compositor which leads to issues on
Hyprland, let the compositor do the animations instead.

Fixes https://github.com/scorpion-26/gBar/issues/96
This commit is contained in:
scorpion-26 2024-10-13 23:37:41 +02:00
parent b1e2c2ed26
commit 2f3f973f7c
6 changed files with 31 additions and 8 deletions

View file

@ -150,6 +150,11 @@ AudioScrollSpeed: 5
# Display numbers instead of a slider for the two audio widgets. Doesn't affect the audio flyin
AudioNumbers: false
# Manually perform the flyin animation for the audio widget. Enabling this can cause some graphical issues (Damage tracking issues after the flyin disappers) on Hyprland.
# So it is recommended to disable this on Hyprland and configure the flyin animation there:
# layerrule = animation slide, gbar-audio
ManualFlyinAnimation: false
# Command that is run to check if there are out-of-date packages.
# The script should return *ONLY* a number. If it doesn't output a number, updates are no longer checked.
# Default value is applicable for Arch Linux. (See data/update.sh for a human-readable version)

View file

@ -78,14 +78,19 @@ namespace AudioFlyin
}
msOpen++;
auto marginFunction = [](int32_t x) -> int32_t
if (Config::Get().manualFlyinAnimation)
{
// A inverted, cutoff 'V' shape
// Fly in -> hover -> fly out
double steepness = (double)height / (double)transitionTime;
return (int32_t)std::min(-std::abs((double)x - (double)curCloseTime / 2) * steepness + (double)curCloseTime / 2, (double)height);
};
win->SetMargin(Anchor::Bottom, marginFunction(msOpen));
auto marginFunction = [](int32_t x) -> int32_t
{
// A inverted, cutoff 'V' shape
// Fly in -> hover -> fly out
double steepness = (double)height / (double)transitionTime;
return (int32_t)std::min(-std::abs((double)x - (double)curCloseTime / 2) * steepness + (double)curCloseTime / 2, (double)height);
};
win->SetMargin(Anchor::Bottom, marginFunction(msOpen));
}
if (msOpen >= curCloseTime)
{
win->Close();
@ -151,9 +156,16 @@ namespace AudioFlyin
mainWidget->AddChild(std::move(padding));
// We want the audio flyin on top of fullscreen windows
window.SetLayerNamespace("gbar-audio");
window.SetLayer(Layer::Overlay);
window.SetExclusive(false);
window.SetAnchor(Anchor::Bottom);
window.SetMainWidget(std::move(mainWidget));
if (!Config::Get().manualFlyinAnimation)
{
// Do the margin here, so we don't need to update it every frame
window.SetMargin(Anchor::Bottom, DynCtx::height);
}
}
}

View file

@ -289,6 +289,7 @@ void Config::Load(const std::string& overrideConfigLocation)
AddConfigVar("AudioInput", config.audioInput, lineView, foundProperty);
AddConfigVar("AudioRevealer", config.audioRevealer, lineView, foundProperty);
AddConfigVar("AudioNumbers", config.audioNumbers, lineView, foundProperty);
AddConfigVar("ManualFlyinAnimation", config.manualFlyinAnimation, lineView, foundProperty);
AddConfigVar("NetworkWidget", config.networkWidget, lineView, foundProperty);
AddConfigVar("WorkspaceScrollOnMonitor", config.workspaceScrollOnMonitor, lineView, foundProperty);
AddConfigVar("WorkspaceScrollInvert", config.workspaceScrollInvert, lineView, foundProperty);

View file

@ -59,7 +59,8 @@ public:
bool centerWidgets = true; // Force the center widgets to be in the center.
bool audioRevealer = false;
bool audioInput = false;
bool audioNumbers = false; // Affects both audio sliders
bool audioNumbers = false; // Affects both audio sliders
bool manualFlyinAnimation = false; // Do the flyin animation via margin updating
bool networkWidget = true;
bool workspaceScrollOnMonitor = true; // Scroll through workspaces on monitor instead of all
bool workspaceScrollInvert = false; // Up = +1, instead of Up = -1

View file

@ -140,6 +140,8 @@ void Window::Create()
case Layer::Overlay: gtk_layer_set_layer(m_Window, GTK_LAYER_SHELL_LAYER_OVERLAY); break;
}
gtk_layer_set_namespace(m_Window, m_LayerNamespace.c_str());
if (m_Exclusive)
gtk_layer_auto_exclusive_zone_enable(m_Window);

View file

@ -37,6 +37,7 @@ public:
void SetMargin(Anchor anchor, int32_t margin);
void SetExclusive(bool exclusive) { m_Exclusive = exclusive; }
void SetLayer(Layer layer) { m_Layer = layer; }
void SetLayerNamespace(const std::string& layerNamespace) { m_LayerNamespace = layerNamespace; }
void SetMainWidget(std::unique_ptr<Widget>&& mainWidget);
@ -69,6 +70,7 @@ private:
std::array<std::pair<Anchor, int32_t>, 4> m_Margin;
bool m_Exclusive = true;
Layer m_Layer = Layer::Top;
std::string m_LayerNamespace = "gbar";
// The monitor we are currently on.
std::string m_MonitorName;