Linux-Magic-Trackpad-2-Driver icon indicating copy to clipboard operation
Linux-Magic-Trackpad-2-Driver copied to clipboard

Quirky fix to Magic Mouse 2 driver not loading when reconnecting

Open RicardoEPRodrigues opened this issue 5 years ago • 14 comments

This fix is based on the work of 0xABAD, but I changed his method of detecting the mouse by searching for the Product ID and not depend on the unit codes.

RicardoEPRodrigues avatar Feb 03 '20 22:02 RicardoEPRodrigues

hello @RicardoEPRodrigues and thx for your effort to solve this problem.

I have applied your changes and the mouse has stopped working. It's connected but does not move.

I tried removing the files and reinstalling but still not moving in when I run install.sh

Running in ubuntu 18.04 with kernel 5.3.0-28-generic Blueman-manager 2.0.5

any suggestions?

thx

n0ni0 avatar Feb 18 '20 18:02 n0ni0

Hey @n0ni0, can you check if the logs have anything relating to udev or bluetooth?

If the mouse stopped working then part of the script is running. We have to find out if any error came up and what that error is. Can you check if the /opt/magic-mouse-fix/hid-magicmouse.ko file exists?

To revert the changes you can simply delete the udev rule file (sudo rm /etc/udev/rules.d/10-magicmouse.rules) and reboot. Have you tried rebooting after installing the driver?

RicardoEPRodrigues avatar Feb 18 '20 18:02 RicardoEPRodrigues

I found a log file when connect device in local/share/xorg/Xorg.0.log:

91.663] (**) Antonio Jiménez Mouse: Applying InputClass "libinput pointer catchall"
91.663] (II) Using input driver 'libinput' for 'Antonio Jiménez Mouse'
91.697] (EE) systemd-logind: failed to take device /dev/input/event16: No such device
91.697] (**) Antonio Jiménez Mouse: always reports core events
91.697] (**) Option "Device" "/dev/input/event16"
91.697] (**) Option "_source" "server/udev"
91.697] (EE) client bug: Invalid path /dev/input/event16
91.697] (EE) libinput: Antonio Jiménez Mouse: Failed to create a device for /dev/input/event16
91.697] (EE) PreInit returned 2 for "Antonio Jiménez Mouse"
91.697] (II) UnloadModule: "libinput"
91.851] (II) config/udev: Adding input device (unnamed) (/dev/input/mouse2)
91.851] (II) No input driver specified, ignoring this device.
91.851] (II) This device may have been added with another device file.

The file /opt/magic-mouse-fix/hid-magicmouse.ko exist

After restart the problem persist.

n0ni0 avatar Feb 18 '20 19:02 n0ni0

I currently don't have the time to look into what the issue is.

If you can please do some testing. First off delete the udev rule file (sudo rm /etc/udev/rules.d/10-magicmouse.rules) and restart udev (udevadm control -R), this will disable the script from being loaded when you connect the mouse. Check if the mouse works again without scroll.

After that you can try running the script yourself with sudo and see if the new driver is loaded: sudo /opt/magic-mouse-fix/magic-mouse-2-add.sh. Is the mouse moving? Is the scroll working?

Explore a bit of what the script does. These are its contents:

#!/bin/sh

reload() {
    modprobe -r hid_magicmouse
    insmod /opt/magic-mouse-fix/hid-magicmouse.ko \
           scroll_acceleration=1 \
           scroll_speed=25 \
           middle_click_3finger=1
}

reload &

As you can see it removes any magic mouse driver (hid_magicmouse) and adds our driver with some tweaks. Try removing the tweaks and see what you get.

I'll try to help more when I have time.

RicardoEPRodrigues avatar Feb 19 '20 10:02 RicardoEPRodrigues

  • Deleting the udev file and restarting udev, the mouse continue working with scroll, when restart scroll not work.

  • Running sudo /opt/magic-mouse-fix/magic-mouse-2-add.sh the mouse works with scroll without any problems, but after restart computer scroll not work.

  • Launching ./install.sh continue with the same problems of move and scroll.

I will try to investigate more, thx again.

n0ni0 avatar Feb 19 '20 14:02 n0ni0

@n0ni0 I updated my branch, can you test it out?

Apparently the UDEV rule will always try to run at least 3 times (loading and unloading the driver each time). I tried to limit the number of repetitions, but could only lower it to 3. To solve this I modified the script to check if others were running. So now I believe it will always run only one time!

You can use a new smaller script sudo ./install-fix.sh that will try to only run what is needed.

RicardoEPRodrigues avatar May 24 '20 00:05 RicardoEPRodrigues

Hello @RicardoEPRodrigues, using install-fix.sh works like a charm.

Thanks

n0ni0 avatar May 25 '20 21:05 n0ni0

@RicardoEPRodrigues

This is working for me to allow scrolling each time my mouse connects (thanks!), but the middle-click seems to have stopped working. It had been working fine with the @rohitpid version. Any idea what might be going on or how to fix this?

jaybeaton avatar Jun 12 '20 16:06 jaybeaton

@jaybeaton Great to know it is working!

On theory, the middle-click is on by default and should work. You can tweak the settings in the magic-mouse-2-add.sh. After tweaking the values you need to run sudo ./install-fix.sh

Unfortunately, I haven't tested it myself.

RicardoEPRodrigues avatar Jun 14 '20 19:06 RicardoEPRodrigues

So it looks like I have a similar issue. On any reboot I have to I have to reapply the Troubleshooting fix to get my MM2 to scroll. In the aforementioned posts you talk about some install-fix.sh script. But where is it? Or is there another solution? Thanks!

cavaughankirov avatar Jul 13 '20 17:07 cavaughankirov

@cavaughankirov this is a pull request with some changes. If you wanna try them out you have to download the changes in my repo: https://github.com/RicardoEPRodrigues/Linux-Magic-Trackpad-2-Driver

Just run install.sh and it should fix your issues. Let me know if it works for you!

RicardoEPRodrigues avatar Jul 20 '20 20:07 RicardoEPRodrigues

well, there's something wrong with the script and I wish I new coding better to try and figure it out. I moved the script to the scripts dir. But when running it it seems to reproduce the scripts dir. Here's the output: `` ~/Apps/MMouse/Linux-Magic-Trackpad-2-Driver/scripts$ sudo ./install.sh +++ dirname ./install.sh ++ cd . ++ pwd

  • DIR=/home/me/Apps/MMouse/Linux-Magic-Trackpad-2-Driver/scripts
  • OPT=/opt/magic-mouse-fix
  • UDEV=/etc/udev/rules.d
  • chmod u+x /home/me/Apps/MMouse/Linux-Magic-Trackpad-2-Driver/scripts/scripts/install.sh
  • /home/me/Apps/MMouse/Linux-Magic-Trackpad-2-Driver/scripts/scripts/install.sh +++ dirname /home/me/Apps/MMouse/Linux-Magic-Trackpad-2-Driver/scripts/scripts/install.sh ++ cd /home/me/Apps/MMouse/Linux-Magic-Trackpad-2-Driver/scripts/scripts ++ pwd
  • DIR=/home/me/Apps/MMouse/Linux-Magic-Trackpad-2-Driver/scripts/scripts
  • OPT=/opt/magic-mouse-fix
  • UDEV=/etc/udev/rules.d
  • chmod u+x /home/me/Apps/MMouse/Linux-Magic-Trackpad-2-Driver/scripts/scripts/scripts/install.sh chmod: cannot access '/home/me/Apps/MMouse/Linux-Magic-Trackpad-2-Driver/scripts/scripts/scripts/install.sh': No such file or directory

cavaughankirov avatar Jul 20 '20 22:07 cavaughankirov

@cavaughankirov you don't need to move the script anywhere. Just use my repo without modification and in the base directory run sudo ./install.sh.

RicardoEPRodrigues avatar Jul 21 '20 08:07 RicardoEPRodrigues

This fix works great for my magic mouse 2 on Linux Mint (Ubuntu 20.04) kernel 5.4.0-67-generic. I was having trouble with getting the rohitpid/magicmouse2 driver to work (I don't think it was even installing/loading) so i ran the remove script and tried this PR instead.

The install went smooth as butter and the scroll is now working perfectly - thank you :+1: :smile:

sirjoshua avatar Mar 26 '21 09:03 sirjoshua