From d96aae32ef2965331699919d0b9e7f4d965ebd21 Mon Sep 17 00:00:00 2001 From: Mart G Date: Thu, 29 Apr 2021 00:43:30 +0200 Subject: [PATCH] LibGUI: Fix issue where buttons with a menu sometimes stayed depressed When a Button has a menu, the AbstractButton behaviour will now not be used in the mousemove_event. This was already the case for mousedown_event. Why only sometimes? Normally the presence of the menu prevents mousemove_events from being delivered to the button. But the menu doesn't spawn immediately. So sometimes mousemove events got through to the AbstractButton after the menu was told to spawn but before it appeared. This caused the m_being_pressed field of AbstractButton to be set to true. But there was never a mouseup_event because the menu got those instead. --- Userland/Libraries/LibGUI/Button.cpp | 8 ++++++++ Userland/Libraries/LibGUI/Button.h | 1 + 2 files changed, 9 insertions(+) diff --git a/Userland/Libraries/LibGUI/Button.cpp b/Userland/Libraries/LibGUI/Button.cpp index 7394efecfd6..6d4346f9766 100644 --- a/Userland/Libraries/LibGUI/Button.cpp +++ b/Userland/Libraries/LibGUI/Button.cpp @@ -174,4 +174,12 @@ void Button::mousedown_event(MouseEvent& event) AbstractButton::mousedown_event(event); } +void Button::mousemove_event(MouseEvent& event) +{ + if (m_menu) { + return; + } + AbstractButton::mousemove_event(event); +} + } diff --git a/Userland/Libraries/LibGUI/Button.h b/Userland/Libraries/LibGUI/Button.h index 13f73cfc4e6..eedb99604c1 100644 --- a/Userland/Libraries/LibGUI/Button.h +++ b/Userland/Libraries/LibGUI/Button.h @@ -50,6 +50,7 @@ public: protected: explicit Button(String text = {}); virtual void mousedown_event(MouseEvent&) override; + virtual void mousemove_event(MouseEvent&) override; virtual void paint_event(PaintEvent&) override; private: