summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2022-03-07 02:18:20 +0300
committerOxore <oxore@protonmail.com>2022-03-07 02:21:44 +0300
commitf8cf93243ccc2988b8911c11ff27db7e5aab0fbe (patch)
tree8f7952f1a77847e7b572437391914bbb61f521d8
parentfa64ad0cc74abfd00e6ad9c039796573d3624bb1 (diff)
Impl grabbing input device
-rw-r--r--main.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/main.c b/main.c
index d3623ff..7085a43 100644
--- a/main.c
+++ b/main.c
@@ -9,6 +9,9 @@
#include <signal.h>
#include <inttypes.h>
+// TODO Impl repeating key when right thumb-stick tilted enough in any way
+// TODO Impl switching between keyboard and regular mode by BTN_MODE (the PS key)
+
/* Analog Binarization Threshold */
#define ABT 64
/* Analog Binarization Hysteresis */
@@ -160,12 +163,21 @@ struct mapping g_mapping[MAPPINGS_NUM] = {
};
bool should_stop = false;
+int ifd = -1;
static void sigint_handler(int _value)
{
(void) _value;
should_stop = true;
printf("Received SIGINT, quitting...\n");
+ {
+ int ret = ioctl(ifd, EVIOCGRAB, (void *)0);
+ if (ret != 0) {
+ fprintf(stderr, "Ungrab failed: ");
+ perror("ioctl(ifd, EVIOCGRAB, 0)");
+ exit(1);
+ }
+ }
// Set default handler and re-issue the signal to unblock the read(3p) call
signal(SIGINT, SIG_DFL);
kill(0, SIGINT);
@@ -458,12 +470,20 @@ int main(int argc, char *argv[])
exit(1);
}
const char *input_path = argv[1];
- int ifd = open(input_path, O_RDONLY);
+ ifd = open(input_path, O_RDONLY);
if (ifd == -1) {
fprintf(stderr, "\"%s\": ", input_path);
perror("open");
exit(1);
}
+ {
+ int ret = ioctl(ifd, EVIOCGRAB, (void *)1);
+ if (ret != 0) {
+ fprintf(stderr, "Grab failed: ");
+ perror("ioctl(ifd, EVIOCGRAB, 1)");
+ exit(1);
+ }
+ }
int ofd = open("/dev/uinput", O_WRONLY);
if (ofd == -1) {
fprintf(stderr, "\"/dev/uinput\": ");