diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-02-11 11:06:41 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-02-11 11:06:41 +0100 |
commit | e6de6c4f451f5d62b18afe877d92a3e0d21a5ce6 (patch) | |
tree | 5c665d9818b99849e91b5284207c8c0f506b0381 /WindowServer | |
parent | 6dd1a1f26d8ca59090962270e71844087d2c8c91 (diff) | |
download | serenity-e6de6c4f451f5d62b18afe877d92a3e0d21a5ce6.zip |
WindowServer: Don't keep menu items in hovered state after the cursor leaves.
Diffstat (limited to 'WindowServer')
-rw-r--r-- | WindowServer/WSMenu.cpp | 11 | ||||
-rw-r--r-- | WindowServer/WSMenu.h | 3 | ||||
-rw-r--r-- | WindowServer/WSWindowManager.cpp | 4 |
3 files changed, 16 insertions, 2 deletions
diff --git a/WindowServer/WSMenu.cpp b/WindowServer/WSMenu.cpp index 505c4f35ab..0369e9bebf 100644 --- a/WindowServer/WSMenu.cpp +++ b/WindowServer/WSMenu.cpp @@ -114,12 +114,19 @@ void WSMenu::on_window_message(WSMessage& message) if (!m_hovered_item) return; did_activate(*m_hovered_item); - m_hovered_item = nullptr; - redraw(); + clear_hovered_item(); return; } } +void WSMenu::clear_hovered_item() +{ + if (!m_hovered_item) + return; + m_hovered_item = nullptr; + redraw(); +} + void WSMenu::did_activate(WSMenuItem& item) { if (on_item_activation) diff --git a/WindowServer/WSMenu.h b/WindowServer/WSMenu.h index dc7adb4592..bc42eba5d3 100644 --- a/WindowServer/WSMenu.h +++ b/WindowServer/WSMenu.h @@ -57,6 +57,9 @@ public: WSMenuItem* item_at(const Point&); void redraw(); + const WSMenuItem* hovered_item() const { return m_hovered_item; } + void clear_hovered_item(); + Function<void(WSMenuItem&)> on_item_activation; private: diff --git a/WindowServer/WSWindowManager.cpp b/WindowServer/WSWindowManager.cpp index 1ea94c30d8..cfba1fdda2 100644 --- a/WindowServer/WSWindowManager.cpp +++ b/WindowServer/WSWindowManager.cpp @@ -485,6 +485,10 @@ void WSWindowManager::process_mouse_event(WSMouseEvent& event) return; } + if (m_current_menu && m_current_menu->hovered_item() && !m_current_menu->menu_window()->rect().contains(event.position())) { + m_current_menu->clear_hovered_item(); + } + // FIXME: Figure out an automatic menu dismissal logic that feels right. #if 0 if (m_current_menu && event.type() == WSMouseEvent::MouseUp && event.button() == MouseButton::Left) |