Update upstream source from tag 'upstream/0.1.1'
Update to upstream version '0.1.1'
with Debian dir 6059bc683cc059db6d8f6ae6a83940ae8d613b0d
Alexandre Viau
4 years ago
0 | before_script: | |
1 | - apt update | |
2 | - apt install -y build-essential cmake git rpm | |
3 | ||
4 | build:debian:9: | |
5 | stage: build | |
6 | image: debian:9 | |
7 | artifacts: | |
8 | untracked: true | |
9 | script: | |
10 | - mkdir build | |
11 | - cd build | |
12 | - cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS='-O1 -g' .. | |
13 | - make | |
14 | ||
15 | package:debian:9: | |
16 | stage: deploy | |
17 | dependencies: | |
18 | - build:debian:9 | |
19 | script: | |
20 | - cd build && make package | |
21 | artifacts: | |
22 | paths: | |
23 | - "build/*.deb" | |
24 | - "build/*.a" | |
25 | - "build/*.so.*.*.*" | |
26 | ||
27 | build:ubuntu:18.04: | |
28 | stage: build | |
29 | image: ubuntu:18.04 | |
30 | artifacts: | |
31 | untracked: true | |
32 | script: | |
33 | - mkdir build | |
34 | - cd build | |
35 | - cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS='-O1 -g' .. | |
36 | - make | |
37 | ||
38 | package:ubuntu:18.04: | |
39 | stage: deploy | |
40 | dependencies: | |
41 | - build:ubuntu:18.04 | |
42 | script: | |
43 | - cd build && make package | |
44 | artifacts: | |
45 | paths: | |
46 | - "build/*.deb" | |
47 | - "build/*.a" | |
48 | - "build/*.so.*.*.*" | |
49 | ||
50 | build:ubuntu:19.04: | |
51 | stage: build | |
52 | image: ubuntu:19.04 | |
53 | artifacts: | |
54 | untracked: true | |
55 | script: | |
56 | - mkdir build | |
57 | - cd build | |
58 | - cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS='-O1 -g' .. | |
59 | - make | |
60 | ||
61 | package:ubuntu:19.04: | |
62 | stage: deploy | |
63 | dependencies: | |
64 | - build:ubuntu:19.04 | |
65 | script: | |
66 | - cd build && make package | |
67 | artifacts: | |
68 | paths: | |
69 | - "build/*.deb" | |
70 | - "build/*.a" | |
71 | - "build/*.so.*.*.*"⏎ |
0 | cmake_minimum_required(VERSION 3.8) | |
0 | cmake_minimum_required(VERSION 3.0) | |
1 | 1 | project(libevdevPlus) |
2 | 2 | |
3 | 3 | set(CMAKE_CXX_STANDARD 11) |
4 | set(PROJECT_VERSION "0.1.0") | |
4 | set(PROJECT_VERSION "0.1.1") | |
5 | 5 | set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) |
6 | 6 | set(CPACK_PACKAGE_VERSION_MAJOR "0") |
7 | 7 | set(CPACK_PACKAGE_VERSION_MINOR "1") |
8 | set(CPACK_PACKAGE_VERSION_PATCH "0") | |
8 | set(CPACK_PACKAGE_VERSION_PATCH "1") | |
9 | 9 | set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "An easy-to-use C++ event device library") |
10 | 10 | set(CPACK_PACKAGE_CONTACT "Yuki Workshop <https://github.com/YukiWorkshop>") |
11 | 11 | set(CMAKE_PROJECT_HOMEPAGE_URL "https://github.com/YukiWorkshop/libevdevPlus") |
34 | 34 | add_executable(evdevPlus_test test.cpp) |
35 | 35 | target_link_libraries(evdevPlus_test evdevPlus) |
36 | 36 | |
37 | configure_file(evdevPlus.pc.in evdevPlus.pc @ONLY) | |
37 | 38 | install(TARGETS evdevPlus |
38 | 39 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
39 | 40 | |
40 | 41 | install(TARGETS evdevPlus_Static |
41 | 42 | DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
42 | 43 | |
43 | install(FILES evdevPlus.hpp InputEvent.hpp CommonIncludes.hpp DESTINATION include/evdevPlus/)⏎ | |
44 | install(FILES evdevPlus.hpp InputEvent.hpp CommonIncludes.hpp DESTINATION include/evdevPlus/) | |
45 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/evdevPlus.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/) |
15 | 15 | #include "CommonIncludes.hpp" |
16 | 16 | |
17 | 17 | namespace evdevPlus { |
18 | class InputEvent { | |
19 | public: | |
20 | input_event event{}; | |
18 | class InputEvent { | |
19 | public: | |
20 | input_event event{}; | |
21 | 21 | |
22 | timeval &Time = event.time; | |
23 | uint16_t &Type = event.type; | |
24 | uint16_t &Code = event.code; | |
25 | int32_t &Value = event.value; | |
22 | timeval &Time = event.time; | |
23 | uint16_t &Type = event.type; | |
24 | uint16_t &Code = event.code; | |
25 | int32_t &Value = event.value; | |
26 | 26 | |
27 | InputEvent() = default; | |
27 | InputEvent() = default; | |
28 | 28 | |
29 | InputEvent(input_event *__event) { | |
30 | memcpy(&event, __event, sizeof(input_event)); | |
31 | } | |
29 | InputEvent(input_event *__event) { | |
30 | memcpy(&event, __event, sizeof(input_event)); | |
31 | } | |
32 | 32 | |
33 | InputEvent(uint16_t type, uint16_t code, uint16_t value, timeval *time = NULL) { | |
34 | Type = type; | |
35 | Code = code; | |
36 | Value = value; | |
33 | InputEvent(uint16_t type, uint16_t code, uint16_t value, timeval *time = NULL) { | |
34 | Type = type; | |
35 | Code = code; | |
36 | Value = value; | |
37 | 37 | |
38 | if (time) | |
39 | memcpy(&event.time, time, sizeof(timeval)); | |
40 | } | |
38 | if (time) | |
39 | memcpy(&event.time, time, sizeof(timeval)); | |
40 | } | |
41 | 41 | |
42 | friend void swap(InputEvent &first, InputEvent &second) { | |
43 | using std::swap; | |
42 | friend void swap(InputEvent &first, InputEvent &second) { | |
43 | using std::swap; | |
44 | 44 | |
45 | swap(first.event, second.event); | |
46 | } | |
45 | swap(first.event, second.event); | |
46 | } | |
47 | 47 | |
48 | InputEvent(InputEvent &&other) noexcept : InputEvent() { | |
49 | swap(*this, other); | |
50 | } | |
48 | InputEvent(InputEvent &&other) noexcept : InputEvent() { | |
49 | swap(*this, other); | |
50 | } | |
51 | 51 | |
52 | InputEvent& operator= (InputEvent other) { | |
53 | swap(*this, other); | |
54 | return *this; | |
55 | } | |
52 | InputEvent& operator= (InputEvent other) { | |
53 | swap(*this, other); | |
54 | return *this; | |
55 | } | |
56 | 56 | |
57 | InputEvent(const InputEvent &other) { | |
58 | memcpy(&event, &(other.event), sizeof(input_event)); | |
59 | } | |
57 | InputEvent(const InputEvent &other) { | |
58 | memcpy(&event, &(other.event), sizeof(input_event)); | |
59 | } | |
60 | 60 | |
61 | }; | |
61 | }; | |
62 | 62 | |
63 | 63 | } |
64 | 64 | #endif //LIBEVDEVPLUS_INPUTEVENT_HPP |
0 | 0 | # libevdevPlus |
1 | 1 | |
2 | [![pipeline status](https://gitlab.com/ReimuNotMoe/libevdevPlus/badges/master/pipeline.svg)](https://gitlab.com/ReimuNotMoe/libevdevPlus/pipelines) | |
3 | ||
4 | ## Releases | |
5 | - [Ubuntu 18.04](https://gitlab.com/ReimuNotMoe/libevdevPlus/-/jobs/artifacts/master/browse/build?job=package:ubuntu:18.04) | |
6 | - [Ubuntu 19.04](https://gitlab.com/ReimuNotMoe/libevdevPlus/-/jobs/artifacts/master/browse/build?job=package:ubuntu:19.04) | |
7 | - [Debian 9](https://gitlab.com/ReimuNotMoe/libevdevPlus/-/jobs/artifacts/master/browse/build?job=package:debian:9)⏎ |
11 | 11 | |
12 | 12 | #include "evdevPlus.hpp" |
13 | 13 | |
14 | const std::unordered_map<std::string, int> evdevPlus::Table_FunctionKeys = { | |
14 | const std::unordered_map<std::string, int> evdevPlus::Table_ModifierKeys = { | |
15 | 15 | {"ALT", KEY_LEFTALT}, {"ALT_L", KEY_LEFTALT}, {"ALT_R", KEY_RIGHTALT}, |
16 | 16 | {"SHIFT", KEY_LEFTSHIFT}, {"SHIFT_L", KEY_LEFTSHIFT}, {"SHIFT_R", KEY_RIGHTSHIFT}, |
17 | 17 | {"CTRL", KEY_LEFTCTRL}, {"CTRL_L", KEY_LEFTCTRL}, {"CTRL_R", KEY_RIGHTCTRL}, |
18 | {"META", KEY_LEFTMETA}, {"META_L", KEY_LEFTMETA}, {"META_R", KEY_RIGHTMETA}, | |
18 | {"SUPER", KEY_LEFTMETA}, {"SUPER_L", KEY_LEFTMETA}, {"SUPER_R", KEY_RIGHTMETA}, | |
19 | {"META", KEY_LEFTMETA}, {"META_L", KEY_LEFTMETA}, {"META_R", KEY_RIGHTMETA} | |
20 | }; | |
21 | ||
22 | const std::unordered_map<std::string, int> evdevPlus::Table_FunctionKeys = { | |
23 | {"UP", KEY_UP}, {"DOWN", KEY_DOWN}, {"LEFT", KEY_LEFT}, {"RIGHT", KEY_RIGHT}, | |
19 | 24 | {"TAB", KEY_TAB}, {"CAPSLOCK", KEY_CAPSLOCK}, {"NUMLOCK", KEY_NUMLOCK}, {"SCROLLLOCK", KEY_SCROLLLOCK}, {"ESC", KEY_ESC}, {"ENTER", KEY_ENTER}, {"BACKSPACE", KEY_BACKSPACE}, {"DELETE", KEY_DELETE}, |
20 | 25 | {"INSERT", KEY_INSERT}, {"HOME", KEY_HOME}, {"END", KEY_END}, {"PAGEUP", KEY_PAGEUP}, {"PAGEDOWN", KEY_PAGEDOWN}, {"SYSRQ", KEY_SYSRQ}, {"PAUSE", KEY_PAUSE}, |
21 | 26 | {"F1", KEY_F1}, {"F2", KEY_F2}, {"F3", KEY_F3}, {"F4", KEY_F4}, {"F5", KEY_F5}, {"F6", KEY_F6}, {"F7", KEY_F7}, {"F8", KEY_F8}, {"F9", KEY_F9}, {"F10", KEY_F10}, {"F11", KEY_F11}, {"F12", KEY_F12} |
153 | 158 | {"KEY_CAMERA_RIGHT", KEY_CAMERA_RIGHT}, {"KEY_ATTENDANT_ON", KEY_ATTENDANT_ON}, |
154 | 159 | {"KEY_ATTENDANT_OFF", KEY_ATTENDANT_OFF}, {"KEY_ATTENDANT_TOGGLE", KEY_ATTENDANT_TOGGLE}, |
155 | 160 | {"KEY_LIGHTS_TOGGLE", KEY_LIGHTS_TOGGLE}, {"KEY_ALS_TOGGLE", KEY_ALS_TOGGLE}, |
156 | {"KEY_ROTATE_LOCK_TOGGLE", KEY_ROTATE_LOCK_TOGGLE}, {"KEY_BUTTONCONFIG", KEY_BUTTONCONFIG}, | |
161 | ||
157 | 162 | {"KEY_TASKMANAGER", KEY_TASKMANAGER}, {"KEY_JOURNAL", KEY_JOURNAL}, {"KEY_CONTROLPANEL", KEY_CONTROLPANEL}, |
158 | 163 | {"KEY_APPSELECT", KEY_APPSELECT}, {"KEY_SCREENSAVER", KEY_SCREENSAVER}, {"KEY_VOICECOMMAND", KEY_VOICECOMMAND}, |
159 | {"KEY_ASSISTANT", KEY_ASSISTANT}, {"KEY_BRIGHTNESS_MIN", KEY_BRIGHTNESS_MIN}, | |
164 | {"KEY_BRIGHTNESS_MIN", KEY_BRIGHTNESS_MIN}, | |
160 | 165 | {"KEY_BRIGHTNESS_MAX", KEY_BRIGHTNESS_MAX}, {"KEY_KBDINPUTASSIST_PREV", KEY_KBDINPUTASSIST_PREV}, |
161 | 166 | {"KEY_KBDINPUTASSIST_NEXT", KEY_KBDINPUTASSIST_NEXT}, |
162 | 167 | {"KEY_KBDINPUTASSIST_PREVGROUP", KEY_KBDINPUTASSIST_PREVGROUP}, |
169 | 174 | {"KEY_3D_MODE", KEY_3D_MODE}, {"KEY_NEXT_FAVORITE", KEY_NEXT_FAVORITE}, {"KEY_STOP_RECORD", KEY_STOP_RECORD}, |
170 | 175 | {"KEY_PAUSE_RECORD", KEY_PAUSE_RECORD}, {"KEY_VOD", KEY_VOD}, {"KEY_UNMUTE", KEY_UNMUTE}, |
171 | 176 | {"KEY_FASTREVERSE", KEY_FASTREVERSE}, {"KEY_SLOWREVERSE", KEY_SLOWREVERSE}, {"KEY_DATA", KEY_DATA}, |
172 | {"KEY_ONSCREEN_KEYBOARD", KEY_ONSCREEN_KEYBOARD}, {"KEY_MIN_INTERESTING", KEY_MIN_INTERESTING}, | |
177 | ||
178 | {"KEY_MIN_INTERESTING", KEY_MIN_INTERESTING}, | |
173 | 179 | {"BTN_MISC", BTN_MISC}, {"BTN_0", BTN_0}, {"BTN_1", BTN_1}, {"BTN_2", BTN_2}, {"BTN_3", BTN_3}, |
174 | 180 | {"BTN_4", BTN_4}, {"BTN_5", BTN_5}, {"BTN_6", BTN_6}, {"BTN_7", BTN_7}, {"BTN_8", BTN_8}, {"BTN_9", BTN_9}, |
175 | 181 | {"BTN_MOUSE", BTN_MOUSE}, {"BTN_LEFT", BTN_LEFT}, {"BTN_RIGHT", BTN_RIGHT}, {"BTN_MIDDLE", BTN_MIDDLE}, |
186 | 192 | {"BTN_TOOL_BRUSH", BTN_TOOL_BRUSH}, {"BTN_TOOL_PENCIL", BTN_TOOL_PENCIL}, |
187 | 193 | {"BTN_TOOL_AIRBRUSH", BTN_TOOL_AIRBRUSH}, {"BTN_TOOL_FINGER", BTN_TOOL_FINGER}, |
188 | 194 | {"BTN_TOOL_MOUSE", BTN_TOOL_MOUSE}, {"BTN_TOOL_LENS", BTN_TOOL_LENS}, {"BTN_TOOL_QUINTTAP", BTN_TOOL_QUINTTAP}, |
189 | {"BTN_STYLUS3", BTN_STYLUS3}, {"BTN_TOUCH", BTN_TOUCH}, {"BTN_STYLUS", BTN_STYLUS}, | |
195 | {"BTN_TOUCH", BTN_TOUCH}, {"BTN_STYLUS", BTN_STYLUS}, | |
190 | 196 | {"BTN_STYLUS2", BTN_STYLUS2}, {"BTN_TOOL_DOUBLETAP", BTN_TOOL_DOUBLETAP}, |
191 | 197 | {"BTN_TOOL_TRIPLETAP", BTN_TOOL_TRIPLETAP}, {"BTN_TOOL_QUADTAP", BTN_TOOL_QUADTAP}, {"BTN_WHEEL", BTN_WHEEL}, |
192 | 198 | {"BTN_GEAR_DOWN", BTN_GEAR_DOWN}, {"BTN_GEAR_UP", BTN_GEAR_UP}, {"BTN_DPAD_UP", BTN_DPAD_UP}, |
17 | 17 | |
18 | 18 | namespace evdevPlus { |
19 | 19 | |
20 | extern const std::unordered_map<std::string, int> Table_FunctionKeys; | |
21 | extern const std::unordered_map<char, int> Table_LowerKeys; | |
22 | extern const std::unordered_map<char, int> Table_UpperKeys; | |
23 | extern const std::unordered_map<std::string, int> Table_KeyCodes; | |
20 | extern const std::unordered_map<std::string, int> Table_FunctionKeys; | |
21 | extern const std::unordered_map<std::string, int> Table_ModifierKeys; | |
22 | extern const std::unordered_map<char, int> Table_LowerKeys; | |
23 | extern const std::unordered_map<char, int> Table_UpperKeys; | |
24 | extern const std::unordered_map<std::string, int> Table_KeyCodes; | |
24 | 25 | |
25 | 26 | |
26 | class EventDeviceID { | |
27 | public: | |
28 | input_id inputId{}; | |
27 | class EventDeviceID { | |
28 | public: | |
29 | input_id inputId{}; | |
29 | 30 | |
30 | uint16_t &BusType = inputId.bustype; | |
31 | uint16_t &Vendor = inputId.vendor; | |
32 | uint16_t &Product = inputId.product; | |
33 | uint16_t &Version = inputId.version; | |
31 | uint16_t &BusType = inputId.bustype; | |
32 | uint16_t &Vendor = inputId.vendor; | |
33 | uint16_t &Product = inputId.product; | |
34 | uint16_t &Version = inputId.version; | |
34 | 35 | |
35 | EventDeviceID() = default; | |
36 | EventDeviceID(uint16_t bus_type, uint16_t vid, uint16_t pid, uint16_t version) { | |
37 | BusType = bus_type; | |
38 | Vendor = vid; | |
39 | Product = pid; | |
40 | Version = version; | |
41 | } | |
36 | EventDeviceID() = default; | |
37 | EventDeviceID(uint16_t bus_type, uint16_t vid, uint16_t pid, uint16_t version) { | |
38 | BusType = bus_type; | |
39 | Vendor = vid; | |
40 | Product = pid; | |
41 | Version = version; | |
42 | } | |
42 | 43 | |
43 | friend void swap(EventDeviceID &first, EventDeviceID &second) { | |
44 | using std::swap; | |
44 | friend void swap(EventDeviceID &first, EventDeviceID &second) { | |
45 | using std::swap; | |
45 | 46 | |
46 | swap(first.inputId, second.inputId); | |
47 | } | |
47 | swap(first.inputId, second.inputId); | |
48 | } | |
48 | 49 | |
49 | EventDeviceID(EventDeviceID &&other) noexcept : EventDeviceID() { | |
50 | swap(*this, other); | |
51 | } | |
50 | EventDeviceID(EventDeviceID &&other) noexcept : EventDeviceID() { | |
51 | swap(*this, other); | |
52 | } | |
52 | 53 | |
53 | EventDeviceID& operator= (EventDeviceID other) { | |
54 | swap(*this, other); | |
55 | return *this; | |
56 | } | |
54 | EventDeviceID& operator= (EventDeviceID other) { | |
55 | swap(*this, other); | |
56 | return *this; | |
57 | } | |
57 | 58 | |
58 | EventDeviceID(const EventDeviceID &other) { | |
59 | memcpy(&inputId, &(other.inputId), sizeof(uinput_setup)); | |
60 | } | |
59 | EventDeviceID(const EventDeviceID &other) { | |
60 | memcpy(&inputId, &(other.inputId), sizeof(uinput_setup)); | |
61 | } | |
61 | 62 | |
62 | }; | |
63 | }; | |
63 | 64 | |
64 | 65 | |
65 | class EventDevice { | |
66 | public: | |
67 | int FD = -1; | |
68 | std::string Path; | |
66 | class EventDevice { | |
67 | public: | |
68 | int FD = -1; | |
69 | std::string Path; | |
69 | 70 | |
70 | int DriverVersion = -1; | |
71 | EventDeviceID DeviceID; | |
72 | std::string DeviceName; | |
73 | std::set<int> EventTypes; | |
71 | int DriverVersion = -1; | |
72 | EventDeviceID DeviceID; | |
73 | std::string DeviceName; | |
74 | std::set<int> EventTypes; | |
74 | 75 | |
75 | EventDevice() = default; | |
76 | EventDevice(const std::string &path, int open_flags = O_RDONLY) { | |
77 | Open(path, open_flags); | |
78 | } | |
79 | EventDevice(int fd) { | |
80 | Open(fd); | |
81 | } | |
82 | ~EventDevice() { | |
83 | Close(); | |
84 | } | |
76 | EventDevice() = default; | |
77 | EventDevice(const std::string &path, int open_flags = O_RDONLY) { | |
78 | Open(path, open_flags); | |
79 | } | |
80 | EventDevice(int fd) { | |
81 | Open(fd); | |
82 | } | |
83 | ~EventDevice() { | |
84 | Close(); | |
85 | } | |
85 | 86 | |
86 | void Open(const std::string &path, int open_flags = O_RDONLY); | |
87 | void Open(int fd); | |
88 | void Close(); | |
87 | void Open(const std::string &path, int open_flags = O_RDONLY); | |
88 | void Open(int fd); | |
89 | void Close(); | |
89 | 90 | |
90 | void Init(); | |
91 | void Init(); | |
91 | 92 | |
92 | void Grab(); | |
93 | void Ungrab(); | |
93 | void Grab(); | |
94 | void Ungrab(); | |
94 | 95 | |
95 | InputEvent Read(); | |
96 | InputEvent Read(); | |
96 | 97 | |
97 | static bool IsValidDevice(int fd); | |
98 | bool IsValidDevice(); | |
98 | static bool IsValidDevice(int fd); | |
99 | bool IsValidDevice(); | |
99 | 100 | |
100 | 101 | |
101 | bool const operator== (const EventDevice &o) const { | |
102 | return (Path == o.Path) && (FD == o.FD); | |
103 | } | |
102 | bool const operator== (const EventDevice &o) const { | |
103 | return (Path == o.Path) && (FD == o.FD); | |
104 | } | |
104 | 105 | |
105 | }; | |
106 | }; | |
106 | 107 | } |
107 | 108 | |
108 | 109 |