author | František Kučera <franta-hg@frantovo.cz> |
Fri, 02 Apr 2021 18:34:52 +0200 | |
branch | v_0 |
changeset 9 | 08c913c9662f |
parent 8 | 6f5616572273 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* Relational pipes |
|
3 |
* Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 |
* |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation, version 3 of the License. |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
*/ |
|
17 |
#pragma once |
|
18 |
||
19 |
#include <memory> |
|
20 |
#include <string> |
|
21 |
#include <vector> |
|
22 |
#include <iostream> |
|
23 |
#include <sstream> |
|
24 |
#include <locale> |
|
25 |
#include <stdexcept> |
|
26 |
||
2 | 27 |
#include <X11/extensions/XTest.h> |
28 |
||
1 | 29 |
#include <relpipe/common/type/typedefs.h> |
0 | 30 |
#include <relpipe/reader/TypeId.h> |
31 |
#include <relpipe/reader/handlers/RelationalReaderStringHandler.h> |
|
32 |
#include <relpipe/reader/handlers/AttributeMetadata.h> |
|
33 |
||
34 |
#include "Configuration.h" |
|
35 |
||
36 |
namespace relpipe { |
|
37 |
namespace out { |
|
38 |
namespace x11 { |
|
39 |
||
1 | 40 |
class X11Handler : public relpipe::reader::handlers::RelationalReaderStringHandler { |
0 | 41 |
private: |
2 | 42 |
|
9
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
43 |
enum class RelationType { |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
44 |
UNSUPPORTED, |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
45 |
DEVICES, |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
46 |
EVENTS, |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
47 |
}; |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
48 |
|
2 | 49 |
class Display { |
50 |
public: |
|
51 |
::Display* display = nullptr; |
|
52 |
// TODO: more OOP |
|
53 |
||
54 |
virtual ~Display() { |
|
55 |
if (display) XCloseDisplay(display); |
|
56 |
} |
|
57 |
}; |
|
58 |
||
3
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
59 |
class Event { |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
60 |
public: |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
61 |
|
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
62 |
enum class Type { |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
63 |
KEY, |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
64 |
BUTTON, |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
65 |
MOTION, |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
66 |
UNKNOWN |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
67 |
}; |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
68 |
|
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
69 |
enum class State { |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
70 |
PRESSED, |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
71 |
RELEASED, |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
72 |
UNKNOWN |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
73 |
}; |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
74 |
|
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
75 |
Type type = Type::UNKNOWN; |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
76 |
State state = State::UNKNOWN; |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
77 |
int key = -1; |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
78 |
int button = -1; |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
79 |
unsigned long screen = 0; |
4
e5baa07d6e60
use CurrentTime (0) as default delay
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
80 |
unsigned long delay = CurrentTime; |
3
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
81 |
int x = -1; |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
82 |
int y = -1; |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
83 |
} currentEvent; |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
84 |
|
9
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
85 |
class Device { |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
86 |
public: |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
87 |
relpipe::common::type::Integer id = -1; |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
88 |
relpipe::common::type::StringX name; |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
89 |
relpipe::common::type::StringX type; |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
90 |
} currentDevice; |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
91 |
|
2 | 92 |
Display display; |
0 | 93 |
Configuration& configuration; |
9
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
94 |
RelationType relationType = RelationType::UNSUPPORTED; |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
95 |
relpipe::common::type::StringX relationName; |
3
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
96 |
std::vector<relpipe::reader::handlers::AttributeMetadata> attributes; |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
97 |
relpipe::common::type::Integer attributeIndex = 0; |
0 | 98 |
public: |
99 |
||
3
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
100 |
X11Handler(Configuration& configuration) : configuration(configuration) { |
2 | 101 |
display.display = XOpenDisplay(nullptr); |
0 | 102 |
} |
103 |
||
1 | 104 |
void startRelation(relpipe::common::type::StringX name, std::vector<relpipe::reader::handlers::AttributeMetadata> attributes) override { |
9
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
105 |
this->attributes = attributes; |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
106 |
this->relationName = name; |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
107 |
|
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
108 |
if (relationName == L"x11_input_device") { |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
109 |
this->relationType = RelationType::DEVICES; |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
110 |
} else if (relationName == L"x11_input_event") { |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
111 |
this->relationType = RelationType::EVENTS; |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
112 |
if (display.display == nullptr) throw std::invalid_argument("Unable to open display. Please check the $DISPLAY variable."); |
0 | 113 |
} else { |
9
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
114 |
this->relationType = RelationType::UNSUPPORTED; |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
115 |
std::wcerr << L"Unsupported relation: " << relationName << std::endl; |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
116 |
// TODO: throw exception? |
0 | 117 |
} |
118 |
} |
|
119 |
||
1 | 120 |
void attribute(const relpipe::common::type::StringX& value) override { |
9
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
121 |
if (relationType == RelationType::DEVICES) attributeOfDevice(value); |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
122 |
else if (relationType == RelationType::EVENTS) attributeOfEvent(value); |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
123 |
else attributeOfUnsupported(value); |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
124 |
} |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
125 |
|
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
126 |
private: |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
127 |
|
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
128 |
void attributeOfDevice(const relpipe::common::type::StringX& value) { |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
129 |
if (attributes[attributeIndex].getAttributeName() == L"id") currentDevice.id = stol(value); |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
130 |
else if (attributes[attributeIndex].getAttributeName() == L"name") currentDevice.name = value; |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
131 |
else if (attributes[attributeIndex].getAttributeName() == L"type") currentDevice.type = value; |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
132 |
// else: ignore other attributes |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
133 |
|
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
134 |
attributeIndex++; |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
135 |
|
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
136 |
if (attributeIndex % attributes.size() == 0) { |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
137 |
if (configuration.debug) std::wcerr << L"Device: id = „" << currentDevice.id << L"“ name = „" << currentDevice.name << L"“ type = „" << currentDevice.type << L"“" << std::endl; |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
138 |
attributeIndex = 0; |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
139 |
currentEvent = Event(); |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
140 |
} |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
141 |
} |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
142 |
|
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
143 |
void attributeOfUnsupported(const relpipe::common::type::StringX& value) { |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
144 |
if (configuration.debug) std::wcerr << L"Unsupported relation „" << relationName << L"“ has attribute „" << value << L"“" << std::endl; |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
145 |
} |
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
146 |
|
08c913c9662f
debug print of devices + ignore unsupported relations
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
147 |
void attributeOfEvent(const relpipe::common::type::StringX& value) { |
8 | 148 |
// TODO: strictly expect correct data types (integers)? |
149 |
// TODO: shorter codes (k/b/m, p/r) instead of names or both? |
|
3
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
150 |
if (attributes[attributeIndex].getAttributeName() == L"device") { |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
151 |
// TODO: maybe add some filtering based on device ID |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
152 |
} else if (attributes[attributeIndex].getAttributeName() == L"type") { |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
153 |
if (value == L"key") currentEvent.type = Event::Type::KEY; |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
154 |
else if (value == L"button") currentEvent.type = Event::Type::BUTTON; |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
155 |
else if (value == L"motion") currentEvent.type = Event::Type::MOTION; |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
156 |
else currentEvent.type == Event::Type::UNKNOWN; // TODO: throw exception or print warning? |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
157 |
} else if (attributes[attributeIndex].getAttributeName() == L"state") { |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
158 |
if (value == L"pressed") currentEvent.state = Event::State::PRESSED; |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
159 |
else if (value == L"released") currentEvent.state = Event::State::RELEASED; |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
160 |
else currentEvent.state == Event::State::UNKNOWN; // TODO: throw exception or print warning? |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
161 |
} else if (attributes[attributeIndex].getAttributeName() == L"button") { |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
162 |
currentEvent.button = stol(value); |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
163 |
} else if (attributes[attributeIndex].getAttributeName() == L"key") { |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
164 |
currentEvent.key = stol(value); |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
165 |
} else if (attributes[attributeIndex].getAttributeName() == L"delay") { |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
166 |
currentEvent.delay = stoul(value); |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
167 |
} else if (attributes[attributeIndex].getAttributeName() == L"screen") { |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
168 |
currentEvent.screen = stol(value); |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
169 |
} else if (attributes[attributeIndex].getAttributeName() == L"x") { |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
170 |
currentEvent.x = stol(value); |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
171 |
} else if (attributes[attributeIndex].getAttributeName() == L"y") { |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
172 |
currentEvent.y = stol(value); |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
173 |
} else { |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
174 |
// ignore other attributes |
0 | 175 |
} |
176 |
||
3
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
177 |
attributeIndex++; |
6
3407386d1f60
do XFlush() after each record in order to immediately process events and avoid buffering/delays/lagging
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
178 |
|
5
dbf093b8b9ac
add boolean options: --debug and --dry-run
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
179 |
bool debug = configuration.debug; |
dbf093b8b9ac
add boolean options: --debug and --dry-run
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
180 |
bool run = !configuration.dryRun; |
3
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
181 |
|
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
182 |
if (attributeIndex % attributes.size() == 0) { |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
183 |
if (currentEvent.type == Event::Type::KEY) { |
7
93d9c4fce585
better debug output formatting: XML
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
184 |
if (debug) std::wcerr << L"<key x=\"" << currentEvent.x << L"\" y=\"" << currentEvent.y << L"\" code=\"" << currentEvent.key << L"\" state=\"" << (currentEvent.state == Event::State::PRESSED ? L"pressed" : L"released") << L"\"/>" << std::endl; |
5
dbf093b8b9ac
add boolean options: --debug and --dry-run
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
185 |
if (run) XTestFakeKeyEvent(display.display, currentEvent.key, currentEvent.state == Event::State::PRESSED, currentEvent.delay); |
3
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
186 |
} else if (currentEvent.type == Event::Type::BUTTON) { |
7
93d9c4fce585
better debug output formatting: XML
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
187 |
if (debug) std::wcerr << L"<button x=\"" << currentEvent.x << L"\" y=\"" << currentEvent.y << L"\" code=\"" << currentEvent.button << L"\" state=\"" << (currentEvent.state == Event::State::PRESSED ? L"pressed" : L"released") << L"\"/>" << std::endl; |
5
dbf093b8b9ac
add boolean options: --debug and --dry-run
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
188 |
if (run) XTestFakeButtonEvent(display.display, currentEvent.button, currentEvent.state == Event::State::PRESSED, currentEvent.delay); |
3
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
189 |
} else if (currentEvent.type == Event::Type::MOTION) { |
7
93d9c4fce585
better debug output formatting: XML
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
190 |
if (debug) std::wcerr << L"<motion x=\"" << currentEvent.x << L"\" y=\"" << currentEvent.y << L"\"/>" << std::endl; |
5
dbf093b8b9ac
add boolean options: --debug and --dry-run
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
191 |
if (run) XTestFakeMotionEvent(display.display, currentEvent.screen, currentEvent.x, currentEvent.y, currentEvent.delay); |
3
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
192 |
} else { |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
193 |
std::wcerr << L"Unsupported event" << std::endl; |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
194 |
} |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
195 |
|
6
3407386d1f60
do XFlush() after each record in order to immediately process events and avoid buffering/delays/lagging
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
196 |
XFlush(display.display); |
3
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
197 |
attributeIndex = 0; |
2c4e533e9e33
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
198 |
currentEvent = Event(); |
0 | 199 |
} |
200 |
} |
|
201 |
||
202 |
void endOfPipe() { |
|
203 |
} |
|
204 |
||
205 |
}; |
|
206 |
||
207 |
} |
|
208 |
} |
|
209 |
} |