From 35a6670868be9530da19fa87f2f47d2e63269079 Mon Sep 17 00:00:00 2001 From: scorpion-26 <58082714+scorpion-26@users.noreply.github.com> Date: Wed, 22 Feb 2023 17:20:30 +0100 Subject: [PATCH] Fix issue with audio slider Due to the fact, that we needed to manually propagate hover events from the slider, two hover events are sent when coming from the side of the slider. This we need to await BOTH close events until we can call the leave function. --- src/Widget.cpp | 12 ++++++++++-- src/Widget.h | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Widget.cpp b/src/Widget.cpp index 9eceb21..0009b49 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -204,15 +204,23 @@ void EventBox::Create() auto enter = [](GtkWidget*, GdkEventCrossing*, gpointer data) -> gboolean { EventBox* box = (EventBox*)data; - if (box->m_HoverFn) + if (box->m_HoverFn && box->m_DiffHoverEvents <= 0) + { box->m_HoverFn(*box, true); + box->m_DiffHoverEvents = 0; + } + box->m_DiffHoverEvents++; return false; }; auto leave = [](GtkWidget*, GdkEventCrossing*, void* data) -> gboolean { EventBox* box = (EventBox*)data; - if (box->m_HoverFn) + box->m_DiffHoverEvents--; + if (box->m_HoverFn && box->m_DiffHoverEvents <= 0) + { box->m_HoverFn(*box, false); + box->m_DiffHoverEvents = 0; + } return false; }; // I am so done with the GTK docs. The docs clearly say GdkEventScroll and not GdkEventScroll*, but GdkEventScroll* is passed diff --git a/src/Widget.h b/src/Widget.h index b09c8d4..03b1094 100644 --- a/src/Widget.h +++ b/src/Widget.h @@ -205,6 +205,9 @@ public: virtual void Create() override; private: + // If two hover events are sent, it needs also two close events for a close. + // Somehow not doing that causes an issue. + int32_t m_DiffHoverEvents = 0; std::function m_HoverFn; std::function m_ScrollFn; };