Skip to content

Commit fe67fef

Browse files
author
Robin Müller
committed
Send first hard-coded keys
- send CTRL+ALT+UP for 3 fingers down - send CTRL+ALT+DOWN for 3 fingers up
1 parent 09141d7 commit fe67fef

File tree

5 files changed

+62
-24
lines changed

5 files changed

+62
-24
lines changed

src/gesture_detection.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <linux/input.h>
3333

3434
#include "gesture_detection.h"
35-
#include "input_event_array.h"
3635

3736
typedef struct point {
3837
int x;
@@ -170,7 +169,7 @@ static int32_t get_axix_threshold(int fd, int axis, uint8_t percentage) {
170169
return (absinfo.maximum - absinfo.minimum) * percentage / 100;
171170
}
172171

173-
void process_events(int fd, configuration_t config) {
172+
void process_events(int fd, configuration_t config, void (*callback)(input_event_array_t*)) {
174173
struct input_event ev[64];
175174
int i, rd;
176175
uint8_t finger_count;
@@ -210,13 +209,7 @@ void process_events(int fd, configuration_t config) {
210209
break;
211210
case EV_SYN: {
212211
input_event_array_t *input_events = process_syn_event(ev[i], config, gesture_start, mt_slots.points, thresholds, &finger_count);
213-
int i;
214-
for (i = 0; i < input_events->length; i++) {
215-
printf("%s%d", i > 0 ? " + " : "", input_events->data[i].code);
216-
}
217-
if (input_events->length) {
218-
printf("\n");
219-
}
212+
callback(input_events);
220213
free(input_events);
221214
}
222215
break;

src/gesture_detection.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
#define GESTURE_DETECTION_H_
2727

2828
#include "configuraion.h"
29+
#include "input_event_array.h"
2930

30-
void process_events(int fd, configuration_t config);
31+
void process_events(int fd, configuration_t config, void (*callback)(input_event_array_t*));
3132

3233
#endif // GESTURE_DETECTION_H_

src/gestures_device.c

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
#include <stdlib.h>
2828
#include <string.h>
2929
#include <unistd.h>
30+
#include <stdint.h>
3031

3132
#include <linux/input.h>
3233
#include <linux/uinput.h>
3334

3435
#include "common.h"
3536
#include "gestures_device.h"
3637

37-
int init_uinput(int_array_t keys) {
38+
int init_uinput(int_array_t *keys) {
3839
int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
3940
if(fd < 0) {
4041
die("error: open");
@@ -51,8 +52,8 @@ int init_uinput(int_array_t keys) {
5152
ioctl(fd, UI_SET_KEYBIT, BTN_MIDDLE);
5253

5354
int i;
54-
for (i = 0; i < keys.length; i++) {
55-
ioctl(fd, UI_SET_KEYBIT, keys.data[i]);
55+
for (i = 0; i < keys->length; i++) {
56+
ioctl(fd, UI_SET_KEYBIT, keys->data[i]);
5657
}
5758

5859
struct uinput_user_dev uidev;
@@ -111,3 +112,35 @@ void send_key(int fd, int key) {
111112
die("error: write");
112113
}
113114
}
115+
116+
void send_events(int fd, input_event_array_t *input_events) {
117+
struct input_event syn_ev;
118+
uint8_t i;
119+
if (input_events->length > 0) {
120+
for (i = 0; i < input_events->length; i++) {
121+
input_events->data[i].value = 1;
122+
if (write(fd, &input_events->data[i], sizeof(struct input_event)) < 0) {
123+
die("error: write");
124+
}
125+
}
126+
127+
memset(&syn_ev, 0, sizeof(struct input_event));
128+
syn_ev.type = EV_SYN;
129+
syn_ev.code = SYN_REPORT;
130+
syn_ev.value = 0;
131+
if (write(fd, &syn_ev, sizeof(struct input_event)) < 0) {
132+
die("error: write");
133+
}
134+
135+
for (i = 0; i < input_events->length; i++) {
136+
input_events->data[i].value = 0;
137+
if (write(fd, &input_events->data[i], sizeof(struct input_event)) < 0) {
138+
die("error: write");
139+
}
140+
}
141+
142+
if (write(fd, &syn_ev, sizeof(struct input_event)) < 0) {
143+
die("error: write");
144+
}
145+
}
146+
}

src/gestures_device.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
#define GESTURES_DEVICE_H_
2727

2828
#include "int_array.h"
29+
#include "input_event_array.h"
2930

30-
int init_uinput(int_array_t keys);
31+
int init_uinput(int_array_t *keys);
3132
int destroy_uinput(int fd);
3233
void send_key(int fd, int key);
34+
void send_events(int fd, input_event_array_t *input_events);
3335

3436
#endif // GESTURES_DEVICE_H_

src/main.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,21 @@
3535
#include "gestures_device.h"
3636
#include "gesture_detection.h"
3737

38+
int uinput_fd;
39+
40+
static void execute_events(input_event_array_t *input_events) {
41+
send_events(uinput_fd, input_events);
42+
}
3843

3944
int main(int argc, char *argv[]) {
40-
int_array_t *keys = new_int_array(1);
41-
keys->data[0] = KEY_D;
42-
int uinput_fd = init_uinput(*keys);
45+
int_array_t *keys = new_int_array(4);
46+
keys->data[0] = KEY_LEFTCTRL;
47+
keys->data[1] = KEY_LEFTALT;
48+
keys->data[2] = KEY_UP;
49+
keys->data[3] = KEY_DOWN;
50+
uinput_fd = init_uinput(keys);
4351
free(keys);
4452

45-
// sleep(1);
46-
// send_key(uinput_fd, KEY_D);
47-
destroy_uinput(uinput_fd);
48-
4953
if (argc > 1) {
5054
int fd = open(argv[1], O_RDONLY);
5155
if (fd < 0) {
@@ -55,10 +59,15 @@ int main(int argc, char *argv[]) {
5559
clean_config(&config);
5660
config.horz_threshold_percentage = 15;
5761
config.vert_threshold_percentage = 15;
58-
config.swipe_keys[3][0].keys[0] = KEY_D;
59-
config.swipe_keys[3][0].keys[1] = KEY_A;
60-
process_events(fd, config);
62+
config.swipe_keys[3][UP].keys[0] = KEY_LEFTCTRL;
63+
config.swipe_keys[3][UP].keys[1] = KEY_LEFTALT;
64+
config.swipe_keys[3][UP].keys[2] = KEY_DOWN;
65+
config.swipe_keys[3][DOWN].keys[0] = KEY_LEFTCTRL;
66+
config.swipe_keys[3][DOWN].keys[1] = KEY_LEFTALT;
67+
config.swipe_keys[3][DOWN].keys[2] = KEY_UP;
68+
process_events(fd, config, &execute_events);
6169
close(fd);
6270
}
71+
destroy_uinput(uinput_fd);
6372
return 0;
6473
}

0 commit comments

Comments
 (0)