sezanzeb / input-remapper

🎮 ⌨ An easy to use tool to change the behaviour of your input devices.
GNU General Public License v3.0
3.74k stars 155 forks source link

Autloading after laptop lid close not working #820

Open SamuelBorn opened 9 months ago

SamuelBorn commented 9 months ago

** My report

I am using my MX Master 3s (bluetooth connected, not thunderbolt) on my Dell XPS 15 7590.

The autoload works fine if I connect to the mouse while the laptop is running.

But when I close the lid and reopen+unlock the laptop, the remaps do not work anymore.

Turning off and on again bluetooth fixes the problem, is annoying though.

System Information and logs

  1. input-remapper-control --version
    input-remapper 2.0.1  https://github.com/sezanzeb/input-remapper
    python-evdev 1.6.1
  2. which linux distro (ubuntu 20.04, manjaro, etc.) fedora 39
  3. which desktop environment (gnome, plasma, xfce4, etc.) gnome
  4. sudo ls -l /proc/1/exe to check if you are using systemd lrwxrwxrwx. 1 root root 0 Dec 12 15:42 /proc/1/exe -> /usr/lib/systemd/systemd
  5. cat ~/.config/input-remapper-2/config.json to see if the "autoload" config is written correctly
    {
    "version": "2.0.1",
    "autoload": {
        "Logitech MX Master 3S": "Remap Mouse To Switch Workspaces"
    }
    }
  6. systemctl status input-remapper -n 50 the service has to be running
    
    ● input-remapper.service - Service to inject keycodes without the GUI application
     Loaded: loaded (/usr/lib/systemd/system/input-remapper.service; enabled; preset: disabled)
    Drop-In: /usr/lib/systemd/system/service.d
             └─10-timeout-abort.conf
     Active: active (running) since Tue 2023-12-12 15:42:27 CET; 53min ago
    Main PID: 1005 (input-remapper-)
      Tasks: 6 (limit: 18693)
     Memory: 39.4M
        CPU: 1min 13.997s
     CGroup: /system.slice/input-remapper.service
             ├─ 1005 /usr/bin/python3 /usr/bin/input-remapper-service
             ├─ 1248 /usr/bin/python3 /usr/bin/input-remapper-service
             └─10132 /usr/bin/python3 /usr/bin/input-remapper-service

Dec 12 15:42:53 fedora-xps input-remapper-service[1005]: Autoloading for "Logitech MX Master 3S" Dec 12 15:42:53 fedora-xps input-remapper-service[1005]: Request to start injecting for "Logitech MX Master 3S" Dec 12 15:42:53 fedora-xps input-remapper-service[1005]: Loading preset from "/home/born/.config/input-remapper-2/presets/Logitech MX Master 3S/Remap Mouse To Switch Workspaces.json" Dec 12 15:42:53 fedora-xps input-remapper-service[3433]: Starting injecting the preset for "Logitech MX Master 3S" Dec 12 16:31:00 fedora-xps input-remapper-service[3433]: ERROR: fd broke, was the device unplugged? Dec 12 16:31:00 fedora-xps input-remapper-service[3433]: read loop for /dev/input/event17 stopped Dec 12 16:31:15 fedora-xps input-remapper-service[1005]: Request to autoload for "Logitech MX Master 3S" Dec 12 16:31:15 fedora-xps input-remapper-service[1005]: Found "Sleep Button", "AT Translated Set 2 keyboard", "SynPS/2 Synaptics TouchPad", "SYNA2393:00 06CB:7A13 Mouse", "Video Bus", "Intel HID events", "input-remapper keyboard", "input-remapper Logitech MX Master 3S forwarded", "Logitech MX Master 3S" Dec 12 16:31:15 fedora-xps input-remapper-service[1005]: Autoloading for "Logitech MX Master 3S" Dec 12 16:31:15 fedora-xps input-remapper-service[1005]: Request to start injecting for "Logitech MX Master 3S" Dec 12 16:31:15 fedora-xps input-remapper-service[1005]: Loading preset from "/home/born/.config/input-remapper-2/presets/Logitech MX Master 3S/Remap Mouse To Switch Workspaces.json" Dec 12 16:31:15 fedora-xps input-remapper-service[1005]: Stopping injecting keycodes for group "Logitech MX Master 3S" Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: Starting injecting the preset for "Logitech MX Master 3S" Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: Process Logitech MX Master 3S: Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: Traceback (most recent call last): Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: File "/usr/lib64/python3.12/site-packages/evdev/device.py", line 125, in init Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: fd = os.open(dev, os.O_RDWR | os.O_NONBLOCK) Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: FileNotFoundError: [Errno 2] No such file or directory: '/dev/input/event19' Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: During handling of the above exception, another exception occurred: Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: Traceback (most recent call last): Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: File "/usr/lib64/python3.12/multiprocessing/process.py", line 314, in _bootstrap Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: self.run() Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: File "/usr/lib/python3.12/site-packages/inputremapper/injection/injector.py", line 414, in run Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: forward_devices[device_hash] = self._create_forwarding_device(device) Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: File "/usr/lib/python3.12/site-packages/inputremapper/injection/injector.py", line 361, in _create_forwarding_device Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: forward_to = evdev.UInput( Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: ^^^^^^^^^^^^^ Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: File "/usr/lib64/python3.12/site-packages/evdev/uinput.py", line 155, in init Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: self.device = self._find_device() Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: ^^^^^^^^^^^^^^^^^^^ Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: File "/usr/lib64/python3.12/site-packages/evdev/uinput.py", line 282, in _find_device Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: d = device.InputDevice(path) Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: ^^^^^^^^^^^^^^^^^^^^^^^^ Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: File "/usr/lib64/python3.12/site-packages/evdev/device.py", line 127, in init Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: fd = os.open(dev, os.O_RDONLY | os.O_NONBLOCK) Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Dec 12 16:31:15 fedora-xps input-remapper-service[9955]: FileNotFoundError: [Errno 2] No such file or directory: '/dev/input/event19' Dec 12 16:31:25 fedora-xps input-remapper-service[1005]: Request to autoload for "Logitech MX Master 3S" Dec 12 16:31:25 fedora-xps input-remapper-service[1005]: Found "Sleep Button", "AT Translated Set 2 keyboard", "SynPS/2 Synaptics TouchPad", "SYNA2393:00 06CB:7A13 Mouse", "Video Bus", "Intel HID events", "input-remapper keyboard", "Logitech MX Master 3S" Dec 12 16:31:25 fedora-xps input-remapper-service[1005]: Autoloading for "Logitech MX Master 3S" Dec 12 16:31:25 fedora-xps input-remapper-service[1005]: Not autoloading the same preset "Remap Mouse To Switch Workspaces" again for group "Logitech MX Master 3S" Dec 12 16:31:46 fedora-xps input-remapper-service[1005]: Request to autoload for "Logitech MX Master 3S" Dec 12 16:31:46 fedora-xps input-remapper-service[1005]: Found "Sleep Button", "AT Translated Set 2 keyboard", "SynPS/2 Synaptics TouchPad", "SYNA2393:00 06CB:7A13 Mouse", "Video Bus", "Intel HID events", "input-remapper keyboard", "Logitech MX Master 3S" Dec 12 16:31:46 fedora-xps input-remapper-service[1005]: Autoloading for "Logitech MX Master 3S" Dec 12 16:31:46 fedora-xps input-remapper-service[1005]: Request to start injecting for "Logitech MX Master 3S" Dec 12 16:31:46 fedora-xps input-remapper-service[1005]: Loading preset from "/home/born/.config/input-remapper-2/presets/Logitech MX Master 3S/Remap Mouse To Switch Workspaces.json" Dec 12 16:31:46 fedora-xps input-remapper-service[1005]: Stopping injecting keycodes for group "Logitech MX Master 3S" Dec 12 16:31:46 fedora-xps input-remapper-service[10132]: Starting injecting the preset for "Logitech MX Master 3S"


**Testing the setup**

1. `input-remapper-control --command hello`

Connected to the service Daemon answered with "hello" Done


3. `sudo pkill -f input-remapper-service && sudo input-remapper-service -d & sleep 2 && input-remapper-control --command autoload`, are your keys mapped now?
`yes`
5. (while the previous command is still running) `sudo evtest` and search for a device suffixed by "mapped". Select it, does it report any events? Share the output.
`evtest not installed, sorry
`7. `sudo udevadm control --log-priority=debug && sudo udevadm control --reload-rules && journalctl -f | grep input-remapper`, now plug in the device that should autoload
rodrigoreyes79 commented 9 months ago

Same issue here using MX Master 3s on a Lenovo Flex but it tends to happen when the laptop is left unattended for a while. Not sure if it's related to the laptop going into some "sleep" state (don´t think so as I have configured it not to but the laptop's screen still goes dark) or the mouse going to sleep.

I can recover from the issue by executing the following command: systemctl restart input-remapper.service && input-remapper-control --command autoload

dmersiowsky commented 9 months ago

Same here with the MX Master 3 connected via Bluetooth. Service says:

input-remapper-service[17283]: ERROR: fd broke, was the device unplugged?
input-remapper-service[17283]: read loop for /dev/input/event13 stopped

Version:

input-remapper 2.0.0 9e04df79ca4dca77516a9864d740b9b2d4aef788 https://github.com/sezanzeb/input-remapper
python-evdev 1.4.0

Using Ubuntu 22.04 LTS.

SamuelBorn commented 8 months ago

I can recover from the issue by executing the following command: systemctl restart input-remapper.service && input-remapper-control --command autoload

For me just input-remapper-control --command autoload works too

christopherseaman commented 6 months ago

Adding a quote of my comment on a possibly related issue as it might help with yours.

This is definitely not the Right Way (tm) to do this, but it works for my use case with a single bluetooth device being remapped and input-remapper sometimes failing on reconnect. If you have multiple devices being remapped, this will cause an interruption whenever a device disconnects. Also, it's quite hacky as I didn't spend a lot of time learning the codebase ¯\_(ツ)_/¯

I updated inputremapper/injection/event_reader.py to send stop_all and autoload commands to the daemon upon device disconnect. Here's the diff with added lines identified with +'s, surrounding lines (without "+") are provided for context:

# Added lines for inputremapper/injection/event_reader.py

# ---------------- import daemon methods ----------------
from inputremapper.input_event import InputEvent
from inputremapper.logger import logger

+# Load daemon methods to send commands upon device disconnect
+import inputremapper.daemon as ir_daemon
+

class Context(Protocol):

# ---------------- send `stop_all` and `autoload` to daemon ----------------
                loop.remove_reader(self._source.fileno())
                logger.debug("read loop stopped")
+                # Connect to daemon and send "stop_all" and "autoload" commands
+                daemon = ir_daemon.Daemon.connect()
+                await daemon.send_stop_all()
+                await daemon.send_autoload()
                return

            events_ready.clear()

Modified event_reader.py attached, had to rename to event_reader.py.txt because GH restricts attachment file types.