diff options
author | RasmusNylander <43042651+rasmusnylander@users.noreply.github.com> | 2021-12-16 14:17:39 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-06 17:54:03 +0100 |
commit | 64684cbd5dd242d62c912563b667ec6f890b6fae (patch) | |
tree | 69804e719e9419977feb554920d9fc6ad76d9412 /Userland/Applications/KeyboardMapper | |
parent | 35afd32a51c56e3c425f1f27f2cff5f45df7912d (diff) | |
download | serenity-64684cbd5dd242d62c912563b667ec6f890b6fae.zip |
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.
Diffstat (limited to 'Userland/Applications/KeyboardMapper')
-rw-r--r-- | Userland/Applications/KeyboardMapper/KeyButton.cpp | 19 | ||||
-rw-r--r-- | Userland/Applications/KeyboardMapper/KeyButton.h | 2 |
2 files changed, 14 insertions, 7 deletions
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); }; |