From 2f3f973f7cb1265f10fde558b78db87f1fea9a4a Mon Sep 17 00:00:00 2001 From: scorpion-26 Date: Sun, 13 Oct 2024 23:37:41 +0200 Subject: [PATCH] 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 --- data/config | 5 +++++ src/AudioFlyin.cpp | 26 +++++++++++++++++++------- src/Config.cpp | 1 + src/Config.h | 3 ++- src/Window.cpp | 2 ++ src/Window.h | 2 ++ 6 files changed, 31 insertions(+), 8 deletions(-) diff --git a/data/config b/data/config index 130ce82..23648d4 100644 --- a/data/config +++ b/data/config @@ -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) diff --git a/src/AudioFlyin.cpp b/src/AudioFlyin.cpp index 0d314ef..20dc338 100644 --- a/src/AudioFlyin.cpp +++ b/src/AudioFlyin.cpp @@ -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); + } } } diff --git a/src/Config.cpp b/src/Config.cpp index e5e15f8..80af797 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -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); diff --git a/src/Config.h b/src/Config.h index b8f3276..381cb3e 100644 --- a/src/Config.h +++ b/src/Config.h @@ -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 diff --git a/src/Window.cpp b/src/Window.cpp index 65d7f8d..a234653 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -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); diff --git a/src/Window.h b/src/Window.h index f9bf5e8..d48257c 100644 --- a/src/Window.h +++ b/src/Window.h @@ -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&& mainWidget); @@ -69,6 +70,7 @@ private: std::array, 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;