kde-lockscreen-suspend-display/evdev/evdev.c

34 lines
799 B
C

#include "evdev.h"
int block_until_keypress(const char* keyboardPath) {
int keyboardFd = open(keyboardPath, O_RDONLY);
if (keyboardFd < 0) {
return keyboardFd;
}
int eventSize = sizeof(struct input_event);
int bytesRead = 0;
struct input_event events[NUM_EVENTS];
int readEvents = 1;
while(readEvents) {
bytesRead = read(keyboardFd, events, eventSize * NUM_EVENTS);
if (bytesRead < 0) {
return bytesRead;
}
for(int i = 0; i < (bytesRead / eventSize); ++i) {
struct input_event event = events[i];
if(event.type == EV_KEY) {
if(event.value == 1) {
readEvents = 0;
}
}
}
}
close(keyboardFd);
return 0;
}