LiveSplit / livesplit-core

livesplit-core is a library that provides a lot of functionality for creating a speedrun timer.

Home Page:https://livesplit.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Linux Hotkeys needs sudo to work

ThomasT75 opened this issue · comments

Issue description
Not using sudo It won't print "num1" with, or without focus
Using sudo It will print "num1" with, or without focus
I tested both master, and latest release

Minimal reproducible example:

fn main() {
    let hk_hook = livesplit_core::hotkey::Hook::new().unwrap();
    hk_hook.register(livesplit_core::hotkey::KeyCode::Numpad1, || {
        println!("num1")
    }).unwrap();
    loop{}
}

System Info:
Distro: Arch
Kernel: 5.19.13-zen1-1-zen (64-bit)

livesplit-core versions:
401b70f
0.12.0

You don't need to run it as root, but the user needs to be in the correct group. On my system this group seems to be called input. Can you run ls -lhA /dev/input and groups and paste the results? Overall we may need to bring back X11 support, but I'm not sure yet, maybe more manually managed systems such as Arch require to manually set up that group, as this seems to be already be the case with most other distros.

> ls -lhA /dev/input
total 0
drwxr-xr-x  2 root root     200 out 10 14:10 by-id
drwxr-xr-x  2 root root     240 out 10 14:10 by-path
crw-rw----  1 root input 13, 64 out 10 14:10 event0
crw-rw----  1 root input 13, 65 out 10 14:10 event1
crw-rw----  1 root input 13, 74 out 10 14:10 event10
crw-rw----  1 root input 13, 75 out 10 14:10 event11
crw-rw----  1 root input 13, 76 out 10 14:10 event12
crw-rw----  1 root input 13, 77 out 10 14:10 event13
crw-rw----  1 root input 13, 78 out 10 14:10 event14
crw-rw----  1 root input 13, 79 out 10 14:10 event15
crw-rw----  1 root input 13, 80 out 10 14:10 event16
crw-rw----  1 root input 13, 81 out 10 14:10 event17
crw-rw----  1 root input 13, 82 out 10 14:10 event18
crw-rw----  1 root input 13, 83 out 10 14:10 event19
crw-rw----  1 root input 13, 66 out 10 14:10 event2
crw-rw----  1 root input 13, 84 out 10 14:10 event20
crw-rw----  1 root input 13, 85 out 10 14:10 event21
crw-rw----  1 root input 13, 67 out 10 14:10 event3
crw-rw----  1 root input 13, 68 out 10 14:10 event4
crw-rw----+ 1 root input 13, 69 out 10 14:10 event5
crw-rw----  1 root input 13, 70 out 10 14:10 event6
crw-rw----  1 root input 13, 71 out 10 14:10 event7
crw-rw----  1 root input 13, 72 out 10 14:10 event8
crw-rw----  1 root input 13, 73 out 10 14:10 event9
crw-rw-r--+ 1 root input 13,  0 out 10 14:10 js0
crw-rw----  1 root input 13, 63 out 10 14:10 mice
crw-rw----  1 root input 13, 32 out 10 14:10 mouse0
> groups
sambashare wheel thomast75

Ah yeah. So it definitely seems like adding yourself to the input group would fix the problem. However it does seem like not being part of that group could be seen as a security feature so applications can't just read what you input in other applications... so it's unclear to me so far if the solution is to just add yourself to the group or adding a fallback to X11 and exclusively grabbing keys.

In other programs where input group access is needed, the solution is usually to have the program be setuid to a custom user whose only permission is the input group.

My problem with the input group solution is that if i were to send this program to a friend or upload it to GitHub the install could involve running: sudo gpasswd -a $USER input, and the uninstall would do the opposite, but only if another program didn't try to add the same $USER to input group, and I don't know how it would detect that.
The setuid solution is the same problem as above, but more complicated.

The current hotkey code works for Gamepads without input group.

IMO a solution that uses X11 and another solution that uses Wayland (when support is added for global hotkeys) would be a good solution and keep the current code for Gamepads.