Initial checkin master
authorJames Bunton <jamesbunton@delx.net.au>
Sat, 9 May 2020 01:25:02 +0000 (11:25 +1000)
committerJames Bunton <jamesbunton@delx.net.au>
Sat, 9 May 2020 01:53:21 +0000 (11:53 +1000)
.gitignore [new file with mode: 0644]
Makefile [new file with mode: 0644]
README.md [new file with mode: 0644]
mouse-wiggle.c [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..6e18fac
--- /dev/null
@@ -0,0 +1,2 @@
+mouse-wiggle
+*.o
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..6d1096b
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,8 @@
+CFLAGS += -Wall -Wextra `pkg-config --cflags libevdev`
+LDLIBS += `pkg-config --libs libevdev`
+
+mouse-wiggle: mouse-wiggle.o
+
+.PHONY: clean
+clean:
+       rm -f mouse-wiggle *.o
diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..102a5c7
--- /dev/null
+++ b/README.md
@@ -0,0 +1,5 @@
+# mouse-wiggle
+
+Wiggles the mouse on Linux using `/dev/uinput`.
+
+In some applications this will cause the mouse to appear. In others it will make it disappear.
diff --git a/mouse-wiggle.c b/mouse-wiggle.c
new file mode 100644 (file)
index 0000000..de5c543
--- /dev/null
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <libevdev/libevdev-uinput.h>
+
+int main() {
+    int err = 0;
+
+    struct libevdev *dev = libevdev_new();
+    libevdev_set_name(dev, "mouse-wiggle");
+    libevdev_enable_event_type(dev, EV_REL);
+    libevdev_enable_event_code(dev, EV_REL, REL_X, NULL);
+    libevdev_enable_event_code(dev, EV_REL, REL_Y, NULL);
+    libevdev_enable_event_type(dev, EV_KEY);
+    libevdev_enable_event_code(dev, EV_KEY, BTN_LEFT, NULL);
+    libevdev_enable_event_code(dev, EV_KEY, BTN_MIDDLE, NULL);
+    libevdev_enable_event_code(dev, EV_KEY, BTN_RIGHT, NULL);
+
+    struct libevdev_uinput *uidev;
+    err = libevdev_uinput_create_from_device(
+        dev,
+        LIBEVDEV_UINPUT_OPEN_MANAGED,
+        &uidev
+        );
+    if (err != 0) goto err;
+
+    sleep(1);
+
+    err = libevdev_uinput_write_event(uidev, EV_REL, REL_X, 1);
+    if (err != 0) goto err;
+    libevdev_uinput_write_event(uidev, EV_SYN, SYN_REPORT, 0);
+    if (err != 0) goto err;
+
+    sleep(1);
+
+    err = libevdev_uinput_write_event(uidev, EV_REL, REL_X, -1);
+    if (err != 0) goto err;
+    libevdev_uinput_write_event(uidev, EV_SYN, SYN_REPORT, 0);
+    if (err != 0) goto err;
+
+err:
+    if (err != 0) {
+        fprintf(stderr, "uinput error!\n");
+        return err;
+    }
+    libevdev_uinput_destroy(uidev);
+    return 0;
+}