|
| 1 | +// Copyright 2013 Dustin Bensing |
| 2 | + |
| 3 | +// This file is part of XInputSimulator. |
| 4 | + |
| 5 | +// XInputSimulator is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU Lesser Public License as published by |
| 7 | +// the Free Software Foundation, either version 3 of the License, or |
| 8 | +// any later version. |
| 9 | + |
| 10 | +// XInputSimulator is distributed in the hope that it will be useful, |
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +// GNU Lesser Public License for more details. |
| 14 | + |
| 15 | +// You should have received a copy of the GNU Lesser Public License |
| 16 | +// along with XInputSimulator. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
1 | 18 | #include "xinputsimulatorimpllinux.h"
|
2 | 19 | #include "notimplementedexception.h"
|
3 | 20 | #include <iostream>
|
4 | 21 |
|
5 | 22 | XInputSimulatorImplLinux::XInputSimulatorImplLinux()
|
6 | 23 | {
|
| 24 | + if((display = XOpenDisplay(NULL)) == NULL) { |
| 25 | + std::cout << "can not access display server!" << std::endl; |
| 26 | + return; |
| 27 | + } |
| 28 | + |
| 29 | + root = DefaultRootWindow(display); |
7 | 30 | }
|
8 | 31 |
|
9 | 32 | void XInputSimulatorImplLinux::mouseMoveTo(int x, int y)
|
10 | 33 | {
|
11 | 34 | std::cout << "move the mouse!\n";
|
| 35 | + |
| 36 | + if(!display){ |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + XWarpPointer(display, None, root, 0, 0, 0, 0, x, y); |
| 41 | + XFlush(display); |
12 | 42 | }
|
13 | 43 |
|
14 | 44 | void XInputSimulatorImplLinux::mouseMoveRelative(int x, int y)
|
15 | 45 | {
|
16 |
| - throw NotImplementedException(); |
17 |
| -} |
18 |
| - |
19 |
| -// Copyright 2013 Dustin Bensing |
| 46 | + //throw NotImplementedException(); |
20 | 47 |
|
21 |
| -// This file is part of XInputSimulator. |
| 48 | + if(!display){ |
| 49 | + return; |
| 50 | + } |
22 | 51 |
|
23 |
| -// XInputSimulator is free software: you can redistribute it and/or modify |
24 |
| -// it under the terms of the GNU Lesser Public License as published by |
25 |
| -// the Free Software Foundation, either version 3 of the License, or |
26 |
| -// any later version. |
27 |
| - |
28 |
| -// XInputSimulator is distributed in the hope that it will be useful, |
29 |
| -// but WITHOUT ANY WARRANTY; without even the implied warranty of |
30 |
| -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
31 |
| -// GNU Lesser Public License for more details. |
32 |
| - |
33 |
| -// You should have received a copy of the GNU Lesser Public License |
34 |
| -// along with XInputSimulator. If not, see <http://www.gnu.org/licenses/>. |
| 52 | + XWarpPointer(display, None, None, 0, 0, 0, 0, x, y); |
| 53 | + XFlush(display); |
| 54 | +} |
35 | 55 |
|
36 | 56 | void XInputSimulatorImplLinux::mouseDown(int button)
|
37 | 57 | {
|
|
0 commit comments