From 64684cbd5dd242d62c912563b667ec6f890b6fae Mon Sep 17 00:00:00 2001 From: RasmusNylander <43042651+rasmusnylander@users.noreply.github.com> Date: Thu, 16 Dec 2021 14:17:39 +0100 Subject: KeyboardMapper: Fix discrepancy between cursor and button clickability KeyButton now only responds to clicks on the key-cap's face. This corresponds to when the cursor switches from the default arrow to a hand. --- Userland/Applications/KeyboardMapper/KeyButton.cpp | 19 ++++++++++++------- Userland/Applications/KeyboardMapper/KeyButton.h | 2 ++ 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'Userland/Applications/KeyboardMapper') diff --git a/Userland/Applications/KeyboardMapper/KeyButton.cpp b/Userland/Applications/KeyboardMapper/KeyButton.cpp index 712849897b..1700626baa 100644 --- a/Userland/Applications/KeyboardMapper/KeyButton.cpp +++ b/Userland/Applications/KeyboardMapper/KeyButton.cpp @@ -53,7 +53,7 @@ void KeyButton::paint_event(GUI::PaintEvent& event) void KeyButton::click(unsigned) { - if (on_click) + if (on_click && m_face_hovered) on_click(); } @@ -64,17 +64,22 @@ void KeyButton::mousemove_event(GUI::MouseEvent& event) Gfx::IntRect key_cap_face_rect = { rect().x() + 7, rect().y() + 4, rect().width() - 14, rect().height() - 14 }; - if (key_cap_face_rect.contains(event.position())) { - window()->set_cursor(Gfx::StandardCursor::Hand); - return; - } - window()->set_cursor(Gfx::StandardCursor::Arrow); + set_face_hovered(key_cap_face_rect.contains(event.position())); AbstractButton::mousemove_event(event); } void KeyButton::leave_event(Core::Event& event) { - window()->set_cursor(Gfx::StandardCursor::Arrow); + set_face_hovered(false); AbstractButton::leave_event(event); } + +void KeyButton::set_face_hovered(bool value) +{ + m_face_hovered = value; + if (m_face_hovered) + set_override_cursor(Gfx::StandardCursor::Hand); + else + set_override_cursor(Gfx::StandardCursor::None); +} diff --git a/Userland/Applications/KeyboardMapper/KeyButton.h b/Userland/Applications/KeyboardMapper/KeyButton.h index 38afde394a..31b03ffe9f 100644 --- a/Userland/Applications/KeyboardMapper/KeyButton.h +++ b/Userland/Applications/KeyboardMapper/KeyButton.h @@ -28,4 +28,6 @@ private: KeyButton() = default; bool m_pressed { false }; + bool m_face_hovered { false }; + void set_face_hovered(bool value); }; -- cgit v1.2.3