1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 13:15:07 +00:00

Move double click events from LibGUI to the window server

This commit is contained in:
Robin Burchell 2019-05-15 22:17:09 +02:00 committed by Andreas Kling
parent 3cba2a8a78
commit a4b0dfff43
10 changed files with 92 additions and 43 deletions

View file

@ -84,6 +84,8 @@ void GWidget::event(CEvent& event)
return mousemove_event(static_cast<GMouseEvent&>(event));
case GEvent::MouseDown:
return handle_mousedown_event(static_cast<GMouseEvent&>(event));
case GEvent::MouseDoubleClick:
return handle_mousedoubleclick_event(static_cast<GMouseEvent&>(event));
case GEvent::MouseUp:
return handle_mouseup_event(static_cast<GMouseEvent&>(event));
case GEvent::MouseWheel:
@ -157,38 +159,9 @@ void GWidget::handle_resize_event(GResizeEvent& event)
return resize_event(event);
}
CElapsedTimer& GWidget::click_clock(GMouseButton button)
{
switch (button) {
case GMouseButton::Left: return m_left_click_clock;
case GMouseButton::Right: return m_right_click_clock;
case GMouseButton::Middle: return m_middle_click_clock;
default:
ASSERT_NOT_REACHED();
}
}
void GWidget::handle_mouseup_event(GMouseEvent& event)
{
mouseup_event(event);
if (!rect().contains(event.position()))
return;
auto& clock = click_clock(event.button());
// It's a click.. but is it a doubleclick?
// FIXME: This needs improvement.
if (!clock.is_valid()) {
clock.start();
return;
}
int elapsed_since_last_click = clock.elapsed();
clock.start();
#if 0
dbgprintf("Click clock elapsed: %d\n", elapsed_since_last_click);
#endif
if (elapsed_since_last_click < 250) {
doubleclick_event(event);
}
}
void GWidget::handle_mousedown_event(GMouseEvent& event)
@ -202,6 +175,11 @@ void GWidget::handle_mousedown_event(GMouseEvent& event)
}
}
void GWidget::handle_mousedoubleclick_event(GMouseEvent& event)
{
doubleclick_event(event);
}
void GWidget::handle_enter_event(CEvent& event)
{
if (has_tooltip())