-
Notifications
You must be signed in to change notification settings - Fork 2
/
mouse_linux.cpp
59 lines (50 loc) · 1.13 KB
/
mouse_linux.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 "mouse.h"
#include "uinput_ifc.h"
#include <QMutex>
#include <QMessageBox>
struct mouseLocalData{
mouseLocalData(): fd(-1){};
int fd;
QMutex mutex;
};
mouseClass::mouseClass(){
data = new mouseLocalData();
}
mouseClass::~mouseClass(){
close_uinput(data->fd);
data->fd = -1;
delete data;
}
bool mouseClass::init()
{
char *fileName;
bool permProblem = false;
data->fd = open_uinput(&fileName, &permProblem);
if(data->fd == -1){
QMessageBox::critical(NULL, QString::fromUtf8("Error Creating Virtual Mouse"),
QString::fromUtf8("There was a problem accessing the file \"%1\"\n\
Please check that you have the right to write to it.").arg(QString::fromUtf8(fileName)));
return false;
}
return create_device(data->fd);
}
bool mouseClass::move(int dx, int dy)
{
if(data->fd == -1){
return false;
}
data->mutex.lock();
movem(data->fd, dx,dy);
data->mutex.unlock();
return true;
}
bool mouseClass::click(buttons_t buttons, struct timeval ts)
{
if(data->fd == -1){
return false;
}
data->mutex.lock();
clickm(data->fd, buttons, ts);
data->mutex.unlock();
return true;
}