1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:28:12 +00:00

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.
This commit is contained in:
RasmusNylander 2021-12-16 14:17:39 +01:00 committed by Andreas Kling
parent 35afd32a51
commit 64684cbd5d
2 changed files with 14 additions and 7 deletions

View file

@ -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);
}