jbensmann / mouseless

A replacement for the mouse in Linux
MIT License
170 stars 16 forks source link

Can't run mouseless: "Device or resource busy" #1

Closed ahfornitani closed 1 year ago

ahfornitani commented 2 years ago

Hi! First of all, thanks for your new program! I've been using (and proselytizing about) xmouseless for a while now, and am very happy with it. :)

At the same time, I've been wanting to switch to Wayland on KDE — since you announced on xmouless's issue list that you'd make a replacement that runs on Wayland, I've been enthusiastically waiting for it.

However, I wasn't able to run it. Apparently, my system blocks the device from being used:

ls /dev/input/by-id/*kbd* ; ls /dev/input/by-path/*kbd* gives me:

/dev/input/by-id/usb-413c_Dell_KB216_Wired_Keyboard-event-kbd
/dev/input/by-path/pci-0000:0a:00.3-usb-0:4:1.0-event-kbd

which is linked/mapped to event3 (i.e. /dev/input/event3)

Either sudo lsof /dev/input/by-id/usb-413c_Dell_KB216_Wired_Keyboard-event-kbd or sudo lsof /dev/input/event3 gives me something like:

COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
systemd     1 root  105u   CHR  13,67      0t0  611 /dev/input/by-id/../event3
systemd-l 531 root   18u   CHR  13,67      0t0  611 /dev/input/by-id/../event3
systemd-l 531 root   28u   CHR  13,67      0t0  611 /dev/input/by-id/../event3
kwin_wayl 863  aug   32u   CHR  13,67      0t0  611 /dev/input/by-id/../event3

(the truncated commands should be kwin_wayland and systemd-logind, I think) If I had to guess — but I don't really know about any of this — kwin_wayland would be the "culprit"? EDIT: got the same problem on X11. So I've edited the issue title to not include "Wayland".

sudo lsof /dev/input/by-id/usb-413c_Dell_KB216_Wired_Keyboard-event-kbd
COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
systemd-l  531 root   18u   CHR  13,67      0t0  611 /dev/input/by-id/../event3
Xorg      5695 root   36u   CHR  13,67      0t0  611 /dev/input/by-id/../event3

Here's the full output of mouseless with the --debug flag:

sudo mouseless --debug --config ~/.config/mouseless/config.yaml
[sudo] password for aug: 
DEBU[0000] Available keyboard devices:                  
DEBU[0000] /dev/input/by-path/pci-0000:0a:00.3-usb-0:4:1.0-event-kbd Dell KB216 Wired Keyboard usb-0000:0a:00.3-4/input0 
DEBU[0000] /dev/input/by-id/usb-413c_Dell_KB216_Wired_Keyboard-event-kbd Dell KB216 Wired Keyboard usb-0000:0a:00.3-4/input0 
DEBU[0000] Using config file: /home/aug/.config/mouseless/config.yaml 
DEBU[0000] config: {Devices:[/dev/input/by-id/usb-413c_Dell_KB216_Wired_Keyboard-event-kbd] StartCommand:setxkbmap en BaseMouseSpeed:750 BaseScrollSpeed:20 Layers:[0xc0000be2e0 0xc0000be3a0 0xc0000be5a0]} 
DEBU[0000] Switching to initial layer initial           
DEBU[0000] Executing start command: setxkbmap en        
DEBU[0000] opening the keyboard device /dev/input/by-path/pci-0000:0a:00.3-usb-0:4:1.0-event-kbd 
DEBU[0000] InputDevice /dev/input/by-path/pci-0000:0a:00.3-usb-0:4:1.0-event-kbd (fd 12)
  name Dell KB216 Wired Keyboard
  phys usb-0000:0a:00.3-4/input0
  bus 0x0003, vendor 0x413c, product 0x2113, version 0x0111
  events EV_SYN 0, EV_KEY 1, EV_MSC 4, EV_LED 17 
DEBU[0000] Device name: Dell KB216 Wired Keyboard       
DEBU[0000] Evdev protocol version: 65537                
DEBU[0000] Device info: bus 0x0003, vendor 0x413c, product 0x2113, version 0x0111 
DEBU[0000] opening the keyboard device /dev/input/by-id/usb-413c_Dell_KB216_Wired_Keyboard-event-kbd 
DEBU[0000] Failed to open /dev/input/by-id/usb-413c_Dell_KB216_Wired_Keyboard-event-kbd: device or resource busy 
ERRO[0000] Execution of start command failed: exit status 5 

My ~/.config/mouseless/config.yaml is the same as https://github.com/jbensmann/mouseless#configuration , except for the device line, of course:

line 1 devices:
line 2 # change this to a keyboard device
line 3 - "/dev/input/by-id/usb-413c_Dell_KB216_Wired_Keyboard-event-kbd"
line 4 # - "/dev/input/event3"
line 5 # - "/dev/input/by-path/pci-0000:0a:00.3-usb-0:4:1.0-event-kbd"
line 6 # this is executed when mouseless starts
line 7 startCommand: "setxkbmap en"

I tried switching between lines 3, 4 and 5 just in case, but the debug output is always the same:

DEBU[0000] Failed to open /dev/input/by-id/usb-413c_Dell_KB216_Wired_Keyboard-event-kbd: device or resource busy 
ERRO[0000] Execution of start command failed: exit status 5 

Finally, I also tried running without root privileges, but the debug message is the same as with sudo. My user is aug, so the file is /etc/udev/rules.d/99-aug.rules, with only this as content:

KERNEL=="uinput", GROUP="aug", MODE:="0660"    
KERNEL=="event*", GROUP="aug", NAME="input/%k", MODE="660"  

Please let me know if this is useful information, or the right place to send it. Thanks!

jbensmann commented 2 years ago

Hi, first thanks for creating the detailed issue, this is absolutely the right place to ask and it always helps a lot to get feedback from users.

I think the output of lsof is fine, it looks similar for me (running X11), the processes listed there are reading from the device but probably do not have exclusive access which mouseless is trying to gain.

The reason mouseless existed, at least in the case where you posted the log, is that it could not execute the start command:

DEBU[0000] Executing start command: setxkbmap en
...
ERRO[0000] Execution of start command failed: exit status 5

The start command is specified in the config file, so you could try to simply remove it. What setxkbmap en does is set the keyboard layout to en, but this is probably not necessary and also only works in X11 (I have it in my config because I want to switch to a different layout than the default one when mouseless starts. I should probably remove that from the config example, or at least document what that does :)

The reason that it says it could open the device (at least in the run from the logs) is that it seems like you gave 2 different devices for the same keyboard:

DEBU[0000] opening the keyboard device /dev/input/by-path/pci-0000:0a:00.3-usb-0:4:1.0-event-kbd
...
DEBU[0000] opening the keyboard device /dev/input/by-id/usb-413c_Dell_KB216_Wired_Keyboard-event-kbd 
DEBU[0000] Failed to open /dev/input/by-id/usb-413c_Dell_KB216_Wired_Keyboard-event-kbd: device or resource busy

But it looks like it could successfully open the first one, and the second one fails because it cannot be grabbed twice. I am sure you also tried running with only one device and in these cases the start command was the problem.

So could you try it without a start command and report back if it works?

Btw, I have to admit I have not tried running mouseless in Wayland yet, but see no reason that it should not work (except when some other application is exclusively grabbing the device), and other applications that work similar to mouseless run in Wayland too. So it would also be nice if you can confirm that it works :)

ahfornitani commented 2 years ago

Oh, that worked! Thanks! :) The program does not crash anymore (exit status 5).

However, these persist, even if I don't press anything else:

DEBU[0005] opening the keyboard device /dev/input/by-id/usb-413c_Dell_KB216_Wired_Keyboard-event-kbd 
DEBU[0005] Failed to open /dev/input/by-id/usb-413c_Dell_KB216_Wired_Keyboard-event-kbd: device or resource busy 

The beginning of my ~/.config/mouseless/config.yaml is now:

devices:    
# change this to a keyboard device    
- "/dev/input/by-id/usb-413c_Dell_KB216_Wired_Keyboard-event-kbd"    
# this is executed when mouseless starts    
# startCommand: "setxkbmap en"    
# the default speed for mouse movement    
baseMouseSpeed: 750.0    
# the default speed for scrolling    
baseScrollSpeed: 20.0    
layers:    
# the first layer is active at start    
- name: initial    
  bindings:    # etc…

I've also recorded the steps I'm trying in this short video (35 s):

asciicast

The --debug output appears to be exactly the same under Wayland.

Seems to me that at this point it might be something related to my system? Could other keyboard settings (e.g., using fcitx) get in the way? I had fcitx active on my system until yesterday, then I thought it'd be interfering with mouseless and removed it for the moment being — but there could be “leftovers”. Any ideas?

Thanks!

jbensmann commented 2 years ago

Sorry for the late response, after searching what program might grab device, I finally found the solution by looking at your recording again, where I saw in the logs that it tried to open two devices although you only specified one in the config file. I remembered that I was experimenting with auto detection of the devices, and it seems that I accidentally built the 0.1.1 release from that branch, so it tries to open all devices it can find.

But in this case the program should work nonetheless, since it looks like it could successfully open one device, and it also switches to the mouse layer when you pressed tab. While you are holding tab, the mouse bindings should be available (but you can also fix the layer by pressing space).

I updated the 0.1.1 release with a built from the right branch, so that should work now without any problems opening a device. I should really automate this, sorry for the inconvenience :)

ahfornitani commented 1 year ago

I can confirm: it works now! :) Tested on X11 and Wayland on KDE (Plasma 5.25.2, kernel 5.18.10-arch1-1)

I might open another GH issue regarding some differences in the way I used xmouseless, which I wasn't able to replicate in mouseless, but I'll try to adapt to the way things are now, instead. But for this current issue, I believe no other comment is needed, and it can be marked as “Closed”.

Thank you very much!

jbensmann commented 1 year ago

Great, feel free to open another issue, maybe there is a way to achieve what you want.