From 56b65b8449a14f30b4109c7b529cf431ad5253ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 22 Oct 2021 15:15:52 +0200 Subject: [PATCH] Use Xlib code to find a keyboard instead of relying on user config --- cmd/after-lock/after-lock.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/after-lock/after-lock.go b/cmd/after-lock/after-lock.go index 94f8e62..d7cfbe5 100644 --- a/cmd/after-lock/after-lock.go +++ b/cmd/after-lock/after-lock.go @@ -1,12 +1,14 @@ package main import ( + "errors" "kdelsd/afterlock" "kdelsd/config" "kdelsd/lockfile" "kdelsd/xdg/display" "kdelsd/xdg/keypressdetector" "kdelsd/xdg/lockscreen" + "kdelsd/xdg/xinput_devnodes" "log" "os" "os/signal" @@ -18,7 +20,6 @@ import ( type afterLockConfig struct { INITIAL_DELAY int LOOP_DELAY int - DEV_NODE string LOCK_PATH string LOG_PATH string PRINT_STACKTRACES bool @@ -99,11 +100,19 @@ func initCleanup(lock *lockfile.Lockfile, logfile *os.File) { } func buildAfterlock() *afterlock.AfterLock { - al := afterlock.New(configuration.DEV_NODE) + al := afterlock.New(getKeyboardDevNode()) al.InitialDelay = uint(configuration.INITIAL_DELAY) al.LoopDelay = uint(configuration.LOOP_DELAY) al.Display = display.Xset{} al.LockScreen = lockscreen.XDG{} al.KeypressDetector = keypressdetector.Evdev{} return al -} \ No newline at end of file +} + +func getKeyboardDevNode() string { + devNode := xinput_devnodes.FindKeyboardDevNode() + if devNode == "" { + panic(errors.New("unable to find keyboard device node")) + } + return devNode +}