Skip to content

Commit

Permalink
Add support for new devices attached after kloak starts (adapted from v…
Browse files Browse the repository at this point in the history
  • Loading branch information
ArrayBolt3 committed Sep 23, 2024
1 parent 7f9bc1b commit 0d91a09
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions debian/kloak.install
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ kloak usr/sbin/

etc/*
usr/*
lib/*
23 changes: 23 additions & 0 deletions lib/udev/rules.d/95-kloak.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
SUBSYSTEM!="input", GOTO="end"


# do not run kloak on devices created by kloak
KERNEL=="event*", ATTRS{name}=="kloak*", GOTO="end"

# new keyboard or mouse attached, start kloak@event[0-9].service
KERNEL=="event*", ACTION=="add", ENV{ID_INPUT_KEYBOARD}=="1", RUN+="/usr/bin/systemctl restart kloak.service"
KERNEL=="event*", ACTION=="add", ENV{ID_INPUT_KEYBOARD}=="1", GOTO="end"

KERNEL=="event*", ACTION=="add", ENV{ID_INPUT_MOUSE}=="1", RUN+="/usr/bin/systemctl restart kloak.service"
KERNEL=="event*", ACTION=="add", ENV{ID_INPUT_MOUSE}=="1", GOTO="end"


# keyboard or mouse removed, stop the service
KERNEL=="event*", ACTION=="remove", ENV{ID_INPUT_KEYBOARD}=="1", RUN+="/usr/bin/systemctl restart kloak.service"
KERNEL=="event*", ACTION=="remove", ENV{ID_INPUT_KEYBOARD}=="1", GOTO="end"

KERNEL=="event*", ACTION=="remove", ENV{ID_INPUT_MOUSE}=="1", RUN+="/usr/bin/systemctl restart kloak.service"
KERNEL=="event*", ACTION=="remove", ENV{ID_INPUT_MOUSE}=="1", GOTO="end"


LABEL="end"
3 changes: 3 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,15 @@ void init_inputs() {
}

void init_outputs() {
const char *name = "kloak output device";
for (int i = 0; i < device_count; i++) {
int err = libevdev_new_from_fd(input_fds[i], &output_devs[i]);

if (err != 0)
panic("Could not create evdev for input device: %s", named_inputs[i]);

libevdev_set_name(output_devs[i], name);

err = libevdev_uinput_create_from_device(output_devs[i], LIBEVDEV_UINPUT_OPEN_MANAGED, &uidevs[i]);

if (err != 0)
Expand Down

0 comments on commit 0d91a09

Please sign in to comment.