diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-26 14:15:11 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-26 14:15:11 +0200 |
commit | ba2e97aa52ab18a2e66b83bbf177bc1a864564d2 (patch) | |
tree | e0b50bfb0091723170982faac40d299cd930dcfb /LibGUI | |
parent | d4a8e2930e1c276715c133bda05fbee45bd2c8a6 (diff) | |
download | serenity-ba2e97aa52ab18a2e66b83bbf177bc1a864564d2.zip |
LibGUI: Track double-clicking per individual mouse button.
Clicking two separate buttons in quick succession shouldn't be interpreted
as a double click.
Diffstat (limited to 'LibGUI')
-rw-r--r-- | LibGUI/GWidget.cpp | 32 | ||||
-rw-r--r-- | LibGUI/GWidget.h | 6 |
2 files changed, 26 insertions, 12 deletions
diff --git a/LibGUI/GWidget.cpp b/LibGUI/GWidget.cpp index fe95a9de1a..4b4cc35a52 100644 --- a/LibGUI/GWidget.cpp +++ b/LibGUI/GWidget.cpp @@ -155,24 +155,37 @@ 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 (m_click_clock.is_valid()) { - int elapsed_since_last_click = m_click_clock.elapsed(); + if (!clock.is_valid()) { + clock.start(); + return; + } + int elapsed_since_last_click = clock.elapsed(); + clock.start(); #if 0 - dbgprintf("Click clock elapsed: %d\n", m_click_clock.elapsed()); + dbgprintf("Click clock elapsed: %d\n", elapsed_since_last_click); #endif - if (elapsed_since_last_click < 250) { - doubleclick_event(event); - } else { - m_click_clock.start(); - } + if (elapsed_since_last_click < 250) { + doubleclick_event(event); } } @@ -180,9 +193,6 @@ void GWidget::handle_mousedown_event(GMouseEvent& event) { if (accepts_focus()) set_focus(true); - // FIXME: Maybe the click clock should be per-button. - if (!m_click_clock.is_valid()) - m_click_clock.start(); mousedown_event(event); if (event.button() == GMouseButton::Right) { GContextMenuEvent c_event(event.position(), screen_relative_rect().location().translated(event.position())); diff --git a/LibGUI/GWidget.h b/LibGUI/GWidget.h index eebf6e0a17..1cb7104fa1 100644 --- a/LibGUI/GWidget.h +++ b/LibGUI/GWidget.h @@ -191,6 +191,8 @@ private: void handle_leave_event(CEvent&); void do_layout(); + CElapsedTimer& click_clock(GMouseButton); + GWindow* m_window { nullptr }; OwnPtr<GLayout> m_layout; @@ -210,7 +212,9 @@ private: bool m_enabled { true }; bool m_layout_dirty { false }; - CElapsedTimer m_click_clock; + CElapsedTimer m_left_click_clock; + CElapsedTimer m_right_click_clock; + CElapsedTimer m_middle_click_clock; HashMap<GShortcut, GAction*> m_local_shortcut_actions; }; |