Merge branch 'aggregate_uinput' into 'master'
buffyboard: send EV_KEY and EV_SYN simultaneously See merge request postmarketOS/buffybox!74
This commit is contained in:
commit
6167953ca1
1 changed files with 23 additions and 26 deletions
|
|
@ -24,7 +24,20 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int fd = -1;
|
static int fd = -1;
|
||||||
struct input_event event;
|
static struct input_event events[2] = {
|
||||||
|
{ .time.tv_sec = 0,
|
||||||
|
.time.tv_usec = 0,
|
||||||
|
.type = EV_KEY,
|
||||||
|
.code = 0,
|
||||||
|
.value = 0
|
||||||
|
},
|
||||||
|
{ .time.tv_sec = 0,
|
||||||
|
.time.tv_usec = 0,
|
||||||
|
.type = EV_SYN,
|
||||||
|
.code = SYN_REPORT,
|
||||||
|
.value = 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -32,44 +45,30 @@ struct input_event event;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emit an event on the device.
|
* Emit a key event on the device.
|
||||||
* @param type event type
|
|
||||||
* @param code event code
|
* @param code event code
|
||||||
* @param value event value
|
* @param value event value
|
||||||
* @return true if emitting the event was succesful, false otherwise
|
* @return true if emitting the event was succesful, false otherwise
|
||||||
*/
|
*/
|
||||||
static bool uinput_device_emit(int type, int code, int value);
|
static bool emit_key(int code, int value);
|
||||||
|
|
||||||
/**
|
|
||||||
* Emit a synchronisation event on the device
|
|
||||||
* @return true if emitting the event was succesful, false otherwise
|
|
||||||
*/
|
|
||||||
static bool uinput_device_synchronise();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static functions
|
* Static functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static bool uinput_device_emit(int type, int code, int value) {
|
static bool emit_key(int code, int value) {
|
||||||
event.type = type;
|
events[0].code = code;
|
||||||
event.code = code;
|
events[0].value = value;
|
||||||
event.value = value;
|
|
||||||
event.input_event_sec = 0;
|
|
||||||
event.input_event_usec = 0;
|
|
||||||
|
|
||||||
if (write(fd, &event, sizeof(event)) != sizeof(event)) {
|
if (write(fd, events, sizeof(events)) != sizeof(events)) {
|
||||||
perror("Could not emit event");
|
bbx_log(BBX_LOG_LEVEL_WARNING, "Could not emit events");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool uinput_device_synchronise() {
|
|
||||||
return uinput_device_emit(EV_SYN, SYN_REPORT, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public functions
|
* Public functions
|
||||||
|
|
@ -110,15 +109,13 @@ bool bb_uinput_device_init(const int * const keycodes, int num_keycodes) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&event, 0, sizeof(event));
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bb_uinput_device_emit_key_down(int keycode) {
|
bool bb_uinput_device_emit_key_down(int keycode) {
|
||||||
return uinput_device_emit(EV_KEY, keycode, 1) && uinput_device_synchronise();
|
return emit_key(keycode, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bb_uinput_device_emit_key_up(int keycode) {
|
bool bb_uinput_device_emit_key_up(int keycode) {
|
||||||
return uinput_device_emit(EV_KEY, keycode, 0) && uinput_device_synchronise();
|
return emit_key(keycode, 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue