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

Quirky fix to Magic Mouse 2 driver not loading when reconnecting #1

Open
wants to merge 36 commits into
base: magicmouse2
Choose a base branch
from

Conversation

RicardoEPRodrigues
Copy link

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.

This fix is based on the work of [0xABAD](https://github.com/0xABAD/magic-mouse-2), but I changed his method of detecting the mouse by searching for the Product ID and not depend on the unit codes.
README now has information on the new script and on how the fixes work.
When an USB with that product ID is detected then a input driver is loaded. I think this is the correct interpretation.
Previously the rule used the USB ID of the computer and not the mouse.
@n0ni0
Copy link

n0ni0 commented Feb 18, 2020

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

@RicardoEPRodrigues
Copy link
Author

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?

@n0ni0
Copy link

n0ni0 commented Feb 18, 2020

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.

@RicardoEPRodrigues
Copy link
Author

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.

@n0ni0
Copy link

n0ni0 commented Feb 19, 2020

  • 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.

Also added a smaller install script that does not install dkms and does not install the bluetooth fix.
@RicardoEPRodrigues
Copy link
Author

@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.

Added a delay after removing the previous driver and before adding the new one
@n0ni0
Copy link

n0ni0 commented May 25, 2020

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

Thanks

@jaybeaton
Copy link

@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?

@RicardoEPRodrigues
Copy link
Author

RicardoEPRodrigues commented Jun 14, 2020

@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.

@cavaughankirov
Copy link

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!

@RicardoEPRodrigues
Copy link
Author

@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!

@cavaughankirov
Copy link

cavaughankirov commented Jul 20, 2020

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

@RicardoEPRodrigues
Copy link
Author

@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 and others added 7 commits July 21, 2020 20:07
for newer systems bluetooth restart now is done with systemctl.

It also adds a small check to detect root. If not it asks to run it as sudo.
This adds a 1/5 of a second delay from the registration of a drag event
to actually starting to scroll. The result is a slight decrease in
sensitivity when dragging a finger on the Magic Mouse to start a scroll.
The actual scrolling is the same as before, there is a just a small
delay at the beginning of the stroke which helps to eliminate accidental
scrolls when just resting the finger lightly on the mouse surface.
This update simplifies the code. Please run `remove.sh` before updating the driver to ensure a smooth transition.

Removed unnecessary files from repo.

Changes were made to install, the main loading script to make use of modprobe more accurately.

The parameters for hid-magicmouse were moved to /etc/modprobe.d/hid-magicmouse.conf . This allows the unloading and loading of the module with predefined parameters.

A `remove.sh` script was added to uninstall the driver. NOTE: It does not remove the bluetooth fix.

Changed DKMS version to reflect the driver name.
Also add parameter definition to conf file.
@sirjoshua
Copy link

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 👍 😄

RicardoEPRodrigues and others added 8 commits June 7, 2021 18:48
This fix removes the need for external files to load the driver. It turns out the driver already loaded itself, but without a delay it would fail. This is now fixed.

Based on the work seen here johnchen902/linux@cb700d0
This update brings a feature that allows you to stop scrolling if the mouse is moving. It is still very rough, but it works.
Add reload driver instructions to README file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants