Skip to content

Commit 9fc9be7

Browse files
committed
[X11] Fix double click events not handled when using graphic tablets
Tested with 2 different Wacom tablets.
1 parent cbcb4f1 commit 9fc9be7

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

os/x11/window.cpp

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,12 +1035,37 @@ void WindowX11::getX11FrameExtents()
10351035
}
10361036
}
10371037

1038+
bool WindowX11::isDoubleClickEvent(const Event& event) const
1039+
{
1040+
const gfx::Point currentPos = event.position();
1041+
return (m_doubleClickButton == event.button() &&
1042+
base::current_tick() - m_doubleClickTick < LAF_X11_DOUBLE_CLICK_TIMEOUT &&
1043+
std::abs(currentPos.x - m_doubleClickStartPos.x) < kDoubleClickThreshold &&
1044+
std::abs(currentPos.y - m_doubleClickStartPos.y) < kDoubleClickThreshold);
1045+
}
1046+
1047+
void WindowX11::handleXInputDoubleClickEvent(int button, Event& ev)
1048+
{
1049+
if (ev.type() == Event::MouseDown && !is_mouse_wheel_button(button)) {
1050+
if (isDoubleClickEvent(ev)) {
1051+
ev.setType(Event::MouseDoubleClick);
1052+
m_doubleClickButton = Event::NoneButton;
1053+
}
1054+
else {
1055+
m_doubleClickButton = ev.button();
1056+
m_doubleClickTick = base::current_tick();
1057+
m_doubleClickStartPos = ev.position();
1058+
}
1059+
}
1060+
}
1061+
10381062
void WindowX11::processX11Event(XEvent& event)
10391063
{
10401064
auto* xinput = X11::instance()->xinput();
10411065
if (xinput->handleExtensionEvent(event)) {
10421066
Event ev;
10431067
xinput->convertExtensionEvent(event, ev, m_scale, g_lastXInputEventTime);
1068+
handleXInputDoubleClickEvent(event.xbutton.button, ev);
10441069
queueEvent(ev);
10451070
return;
10461071
}
@@ -1184,6 +1209,9 @@ void WindowX11::processX11Event(XEvent& event)
11841209
break;
11851210

11861211
Event ev;
1212+
ev.setModifiers(get_modifiers_from_x(event.xbutton.state));
1213+
ev.setPosition(gfx::Point(event.xbutton.x / m_scale, event.xbutton.y / m_scale));
1214+
11871215
if (is_mouse_wheel_button(event.xbutton.button)) {
11881216
if (event.type == ButtonPress) {
11891217
ev.setType(Event::MouseWheel);
@@ -1204,10 +1232,7 @@ void WindowX11::processX11Event(XEvent& event)
12041232
if (event.type == ButtonPress) {
12051233
gfx::Point currentPos(event.xbutton.x / m_scale, event.xbutton.y / m_scale);
12061234

1207-
if (m_doubleClickButton == button &&
1208-
base::current_tick() - m_doubleClickTick < LAF_X11_DOUBLE_CLICK_TIMEOUT &&
1209-
std::abs(currentPos.x - m_doubleClickStartPos.x) < kDoubleClickThreshold &&
1210-
std::abs(currentPos.y - m_doubleClickStartPos.y) < kDoubleClickThreshold) {
1235+
if (isDoubleClickEvent(ev)) {
12111236
ev.setType(Event::MouseDoubleClick);
12121237
m_doubleClickButton = Event::NoneButton;
12131238
}
@@ -1218,8 +1243,6 @@ void WindowX11::processX11Event(XEvent& event)
12181243
}
12191244
}
12201245
}
1221-
ev.setModifiers(get_modifiers_from_x(event.xbutton.state));
1222-
ev.setPosition(gfx::Point(event.xbutton.x / m_scale, event.xbutton.y / m_scale));
12231246

12241247
queueEvent(ev);
12251248
break;

os/x11/window.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ class WindowX11 : public Window {
103103
bool setX11Cursor(::Cursor xcursor);
104104
bool requestX11FrameExtents();
105105
void getX11FrameExtents();
106+
107+
bool isDoubleClickEvent(const Event& event) const;
108+
void handleXInputDoubleClickEvent(int button, Event& ev);
109+
106110
static void addWindow(WindowX11* window);
107111
static void removeWindow(WindowX11* window);
108112

0 commit comments

Comments
 (0)