From 11459be7250882eb3328215ec4b200b68dc82077 Mon Sep 17 00:00:00 2001
From: Stefan Huber <shuber@sthu.org>
Date: Sun, 17 Dec 2023 20:25:55 +0100
Subject: [PATCH] udev: Add xprofile-udevinput-monitor

---
 udev/input/install.sh                         | 10 ++++++++++
 udev/input/xprofile-udevinput                 |  7 +++++++
 udev/input/xprofile-udevinput-monitor         | 10 ++++++++++
 udev/input/xprofile-udevinput-monitor.service | 12 ++++++++++++
 4 files changed, 39 insertions(+)
 create mode 100644 udev/input/install.sh
 create mode 100755 udev/input/xprofile-udevinput
 create mode 100755 udev/input/xprofile-udevinput-monitor
 create mode 100644 udev/input/xprofile-udevinput-monitor.service

diff --git a/udev/input/install.sh b/udev/input/install.sh
new file mode 100644
index 0000000..59b4c22
--- /dev/null
+++ b/udev/input/install.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+cp ./xprofile-udevinput ~/.xprofile-udevinput
+echo "You may source ~/.xprofile-udevinput in your ~/.xinitrc or so"
+
+cp ./xprofile-udevinput-monitor ~/.local/bin/
+cp ./xprofile-udevinput-monitor.service ~/.config/systemd/user/
+systemctl --user daemon-reload
+
+echo "You may call systemctl --user enable xprofile-udevinput-monitor.service"
diff --git a/udev/input/xprofile-udevinput b/udev/input/xprofile-udevinput
new file mode 100755
index 0000000..9664326
--- /dev/null
+++ b/udev/input/xprofile-udevinput
@@ -0,0 +1,7 @@
+#!bin/sh
+# Load this script whenever a USB keyboard is attached
+
+xset r rate 200 60
+
+# Barrier needs this on client and server side
+setxkbmap -device `xinput list --id-only "Virtual core XTEST keyboard"` de
diff --git a/udev/input/xprofile-udevinput-monitor b/udev/input/xprofile-udevinput-monitor
new file mode 100755
index 0000000..e48d1ac
--- /dev/null
+++ b/udev/input/xprofile-udevinput-monitor
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+set -e
+
+# For each add-event of input subsystem by udev call ~/.xprofile-keyboard
+udevadm monitor -u -s input | grep --line-buffered add | while read line; do
+	echo ">> $line";
+	sh ~/.xprofile-udevinput
+done
+
diff --git a/udev/input/xprofile-udevinput-monitor.service b/udev/input/xprofile-udevinput-monitor.service
new file mode 100644
index 0000000..09725fb
--- /dev/null
+++ b/udev/input/xprofile-udevinput-monitor.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=xprofile-udevinput-monitor daemon
+After=multi-user.target
+
+[Service]
+Environment=DISPLAY=:0
+ExecStart=%h/.local/bin/xprofile-udevinput-monitor
+Restart=always
+RestartSec=10min
+
+[Install]
+WantedBy=default.target
-- 
2.39.5