-
Notifications
You must be signed in to change notification settings - Fork 1
/
cursorpostionmonitor.cpp
57 lines (44 loc) · 1.2 KB
/
cursorpostionmonitor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "cursorpostionmonitor.h"
#include "common.h"
#include <QDebug>
CursorPostionMonitor::CursorPostionMonitor(QObject *parent) : QObject(parent)
{
}
void CursorPostionMonitor::startMonitor()
{
Display *dpy = XOpenDisplay(NULL);
int xi_opcode, event, error;
if (!dpy) {
qDebug() << "Failed to open display.";
Q_EMIT failed();
return;
}
if (!XQueryExtension(dpy, "XInputExtension", &xi_opcode, &event, &error)) {
qDebug() << "X Input extension not available.";
Q_EMIT failed();
return;
}
if (!has_xi2(dpy)) {
Q_EMIT failed();
return;
}
/* select for XI2 events */
select_events(dpy, DefaultRootWindow(dpy));
XEvent ev;
while(1) {
XGenericEventCookie *cookie = &ev.xcookie;
XNextEvent(dpy, &ev);
if (cookie->type != GenericEvent ||
cookie->extension != xi_opcode ||
!XGetEventData(dpy, cookie)) {
continue;
}
switch (cookie->evtype) {
case XI_RawMotion:
qDebug() << QCursor::pos();
Q_EMIT cursorMoved(QCursor::pos());
break;
}
XFreeEventData(dpy, cookie);
}
}