diff --git a/LibGUI/GElapsedTimer.cpp b/LibGUI/GElapsedTimer.cpp index d0b6f51022..e5ebe38dce 100644 --- a/LibGUI/GElapsedTimer.cpp +++ b/LibGUI/GElapsedTimer.cpp @@ -1,8 +1,10 @@ #include +#include #include void GElapsedTimer::start() { + m_valid = true; gettimeofday(&m_start_time, nullptr); } @@ -18,6 +20,7 @@ inline void timersub(const struct timeval* a, const struct timeval* b, struct ti int GElapsedTimer::elapsed() const { + ASSERT(is_valid()); struct timeval now; gettimeofday(&now, nullptr); struct timeval diff; diff --git a/LibGUI/GElapsedTimer.h b/LibGUI/GElapsedTimer.h index 434f2050b0..ec43bb0b2a 100644 --- a/LibGUI/GElapsedTimer.h +++ b/LibGUI/GElapsedTimer.h @@ -6,9 +6,11 @@ class GElapsedTimer { public: GElapsedTimer() { } + bool is_valid() const { return m_valid; } void start(); int elapsed() const; private: + bool m_valid { false }; struct timeval m_start_time { 0, 0 }; }; diff --git a/LibGUI/GWidget.cpp b/LibGUI/GWidget.cpp index d67d6b00ad..553dfa6cd8 100644 --- a/LibGUI/GWidget.cpp +++ b/LibGUI/GWidget.cpp @@ -67,9 +67,7 @@ void GWidget::event(GEvent& event) case GEvent::MouseMove: return mousemove_event(static_cast(event)); case GEvent::MouseDown: - if (accepts_focus()) - set_focus(true); - return mousedown_event(static_cast(event)); + return handle_mousedown_event(static_cast(event)); case GEvent::MouseUp: return handle_mouseup_event(static_cast(event)); case GEvent::Enter: @@ -154,6 +152,7 @@ void GWidget::handle_mouseup_event(GMouseEvent& event) // It's a click.. but is it a doubleclick? // FIXME: This needs improvement. int elapsed_since_last_click = m_click_clock.elapsed(); + dbgprintf("Click clock elapsed: %d\n", m_click_clock.elapsed()); if (elapsed_since_last_click < 250) { doubleclick_event(event); } else { @@ -161,6 +160,15 @@ void GWidget::handle_mouseup_event(GMouseEvent& event) } } +void GWidget::handle_mousedown_event(GMouseEvent& event) +{ + if (accepts_focus()) + set_focus(true); + if (!m_click_clock.is_valid()) + m_click_clock.start(); + mousedown_event(event); +} + void GWidget::click_event(GMouseEvent&) { } diff --git a/LibGUI/GWidget.h b/LibGUI/GWidget.h index a8bf7b2ff9..99b16857a4 100644 --- a/LibGUI/GWidget.h +++ b/LibGUI/GWidget.h @@ -147,6 +147,7 @@ private: void handle_paint_event(GPaintEvent&); void handle_resize_event(GResizeEvent&); + void handle_mousedown_event(GMouseEvent&); void handle_mouseup_event(GMouseEvent&); void do_layout();