mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 17:05:07 +00:00
LibGUI: Track double-clicking per individual mouse button.
Clicking two separate buttons in quick succession shouldn't be interpreted as a double click.
This commit is contained in:
parent
d4a8e2930e
commit
ba2e97aa52
2 changed files with 26 additions and 12 deletions
|
@ -155,24 +155,37 @@ void GWidget::handle_resize_event(GResizeEvent& event)
|
||||||
return resize_event(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)
|
void GWidget::handle_mouseup_event(GMouseEvent& event)
|
||||||
{
|
{
|
||||||
mouseup_event(event);
|
mouseup_event(event);
|
||||||
|
|
||||||
if (!rect().contains(event.position()))
|
if (!rect().contains(event.position()))
|
||||||
return;
|
return;
|
||||||
|
auto& clock = click_clock(event.button());
|
||||||
// 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.
|
||||||
if (m_click_clock.is_valid()) {
|
if (!clock.is_valid()) {
|
||||||
int elapsed_since_last_click = m_click_clock.elapsed();
|
clock.start();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int elapsed_since_last_click = clock.elapsed();
|
||||||
|
clock.start();
|
||||||
#if 0
|
#if 0
|
||||||
dbgprintf("Click clock elapsed: %d\n", m_click_clock.elapsed());
|
dbgprintf("Click clock elapsed: %d\n", elapsed_since_last_click);
|
||||||
#endif
|
#endif
|
||||||
if (elapsed_since_last_click < 250) {
|
if (elapsed_since_last_click < 250) {
|
||||||
doubleclick_event(event);
|
doubleclick_event(event);
|
||||||
} else {
|
|
||||||
m_click_clock.start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,9 +193,6 @@ void GWidget::handle_mousedown_event(GMouseEvent& event)
|
||||||
{
|
{
|
||||||
if (accepts_focus())
|
if (accepts_focus())
|
||||||
set_focus(true);
|
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);
|
mousedown_event(event);
|
||||||
if (event.button() == GMouseButton::Right) {
|
if (event.button() == GMouseButton::Right) {
|
||||||
GContextMenuEvent c_event(event.position(), screen_relative_rect().location().translated(event.position()));
|
GContextMenuEvent c_event(event.position(), screen_relative_rect().location().translated(event.position()));
|
||||||
|
|
|
@ -191,6 +191,8 @@ private:
|
||||||
void handle_leave_event(CEvent&);
|
void handle_leave_event(CEvent&);
|
||||||
void do_layout();
|
void do_layout();
|
||||||
|
|
||||||
|
CElapsedTimer& click_clock(GMouseButton);
|
||||||
|
|
||||||
GWindow* m_window { nullptr };
|
GWindow* m_window { nullptr };
|
||||||
OwnPtr<GLayout> m_layout;
|
OwnPtr<GLayout> m_layout;
|
||||||
|
|
||||||
|
@ -210,7 +212,9 @@ private:
|
||||||
bool m_enabled { true };
|
bool m_enabled { true };
|
||||||
bool m_layout_dirty { false };
|
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;
|
HashMap<GShortcut, GAction*> m_local_shortcut_actions;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue