Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux Hotkeys needs sudo to work #581

Closed
ThomasT75 opened this issue Oct 10, 2022 · 5 comments · Fixed by #592
Closed

Linux Hotkeys needs sudo to work #581

ThomasT75 opened this issue Oct 10, 2022 · 5 comments · Fixed by #592
Labels
bug There is a bug. hotkey This is about the hotkey implementation. needs further discussion It is unclear how to progress without making further decisions. priority: high This is a high priority issue.

Comments

@ThomasT75
Copy link

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

@CryZe CryZe added bug There is a bug. suitable for contributions The issue is suitable those who are contributing to livesplit-core. priority: high This is a high priority issue. hotkey This is about the hotkey implementation. labels Oct 10, 2022
@CryZe
Copy link
Collaborator

CryZe commented Oct 10, 2022

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.

@CryZe CryZe added needs further discussion It is unclear how to progress without making further decisions. and removed suitable for contributions The issue is suitable those who are contributing to livesplit-core. labels Oct 10, 2022
@ThomasT75
Copy link
Author

> 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

@CryZe
Copy link
Collaborator

CryZe commented Oct 10, 2022

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.

@Hurricane996
Copy link
Contributor

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.

@ThomasT75
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug There is a bug. hotkey This is about the hotkey implementation. needs further discussion It is unclear how to progress without making further decisions. priority: high This is a high priority issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants