mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:18:11 +00:00
LibGUI: Fix broken doubleclick detection due to uninitialized GElapsedTimer.
This commit is contained in:
parent
ee4d7c18c8
commit
c9b0d87927
4 changed files with 17 additions and 3 deletions
|
@ -1,8 +1,10 @@
|
||||||
#include <LibGUI/GElapsedTimer.h>
|
#include <LibGUI/GElapsedTimer.h>
|
||||||
|
#include <AK/Assertions.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
void GElapsedTimer::start()
|
void GElapsedTimer::start()
|
||||||
{
|
{
|
||||||
|
m_valid = true;
|
||||||
gettimeofday(&m_start_time, nullptr);
|
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
|
int GElapsedTimer::elapsed() const
|
||||||
{
|
{
|
||||||
|
ASSERT(is_valid());
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
gettimeofday(&now, nullptr);
|
gettimeofday(&now, nullptr);
|
||||||
struct timeval diff;
|
struct timeval diff;
|
||||||
|
|
|
@ -6,9 +6,11 @@ class GElapsedTimer {
|
||||||
public:
|
public:
|
||||||
GElapsedTimer() { }
|
GElapsedTimer() { }
|
||||||
|
|
||||||
|
bool is_valid() const { return m_valid; }
|
||||||
void start();
|
void start();
|
||||||
int elapsed() const;
|
int elapsed() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool m_valid { false };
|
||||||
struct timeval m_start_time { 0, 0 };
|
struct timeval m_start_time { 0, 0 };
|
||||||
};
|
};
|
||||||
|
|
|
@ -67,9 +67,7 @@ void GWidget::event(GEvent& event)
|
||||||
case GEvent::MouseMove:
|
case GEvent::MouseMove:
|
||||||
return mousemove_event(static_cast<GMouseEvent&>(event));
|
return mousemove_event(static_cast<GMouseEvent&>(event));
|
||||||
case GEvent::MouseDown:
|
case GEvent::MouseDown:
|
||||||
if (accepts_focus())
|
return handle_mousedown_event(static_cast<GMouseEvent&>(event));
|
||||||
set_focus(true);
|
|
||||||
return mousedown_event(static_cast<GMouseEvent&>(event));
|
|
||||||
case GEvent::MouseUp:
|
case GEvent::MouseUp:
|
||||||
return handle_mouseup_event(static_cast<GMouseEvent&>(event));
|
return handle_mouseup_event(static_cast<GMouseEvent&>(event));
|
||||||
case GEvent::Enter:
|
case GEvent::Enter:
|
||||||
|
@ -154,6 +152,7 @@ void GWidget::handle_mouseup_event(GMouseEvent& event)
|
||||||
// It's a click.. but is it a doubleclick?
|
// It's a click.. but is it a doubleclick?
|
||||||
// FIXME: This needs improvement.
|
// FIXME: This needs improvement.
|
||||||
int elapsed_since_last_click = m_click_clock.elapsed();
|
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) {
|
if (elapsed_since_last_click < 250) {
|
||||||
doubleclick_event(event);
|
doubleclick_event(event);
|
||||||
} else {
|
} 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&)
|
void GWidget::click_event(GMouseEvent&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,6 +147,7 @@ private:
|
||||||
|
|
||||||
void handle_paint_event(GPaintEvent&);
|
void handle_paint_event(GPaintEvent&);
|
||||||
void handle_resize_event(GResizeEvent&);
|
void handle_resize_event(GResizeEvent&);
|
||||||
|
void handle_mousedown_event(GMouseEvent&);
|
||||||
void handle_mouseup_event(GMouseEvent&);
|
void handle_mouseup_event(GMouseEvent&);
|
||||||
void do_layout();
|
void do_layout();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue