JitouchApp / Jitouch

A multi-touch extension for MacBook, Magic Mouse, and Magic Trackpad
GNU General Public License v3.0
391 stars 28 forks source link

Gestures stop working after reconnecting the magic mouse #40

Closed katzelad closed 1 year ago

katzelad commented 1 year ago

After disconnecting and reconnecting the magic mouse its gestures stop working for me, and I have to restart the app to get them to work again. I use MacOS Monterey on a 2019 16" MBP. Thanks for maintaining this great app!

aaronkollasch commented 1 year ago

Related to #28

I will get to this eventually – Jitouch has code to detect newly connected devices already so it needs some investigation. For the moment I use Shortcuts.app to create a "Reload Jitouch" shortcut that just runs killall -HUP Jitouch, which tells Jitouch to reload the device list.

aaronkollasch commented 1 year ago

Hey, I've made a pull request that should fix this issue. I don't have a Magic Mouse to test, but it should work for the Magic Mouse as well as the Trackpad. Try out the debug build below and let me know how it goes.

Install-Jitouch.zip (updated 2022-11-13)

katzelad commented 1 year ago

Works great, thanks!

katzelad commented 1 year ago

@aaronkollasch The middle click gesture (with 2 fingers) still doesn't work after reconnection (other gestures work).

aaronkollasch commented 1 year ago

Thanks for reporting.

The function turnOffMagicMouse() gets called when the mouse is disconnected, which sets middleClickFlag to 0: https://github.com/aaronkollasch/jitouch/blob/833c26f72e07141ac8de407dfbd91f096766b2f3/jitouch/Jitouch/Gesture.m#L226-L233

but middleClickFlag should be quickly overwritten the next time the magicMouseCallback is run, by gestureMagicMouseMiddleClick(): https://github.com/aaronkollasch/jitouch/blob/833c26f72e07141ac8de407dfbd91f096766b2f3/jitouch/Jitouch/Gesture.m#L2615-L2619

Since all the other gestures are working, I'm not sure why this one isn't. Can you set the logging mode to debug (in the "About" section of the preferences), try a few different gestures, and check the logs at ~/Library/Logs/com.jitouch.Jitouch.log? Perhaps the middle click gesture is being replaced by another gesture?

Also, if you see messages like Suppressed MouseDown in the debug logs when you try to perform the 2-finger middle-click, that could show that the trackpadCallback is unexpectedly being run for the magic mouse and is suppressing left clicks with two fingers down.

katzelad commented 1 year ago

@aaronkollasch Not really sure this has to do with reconnection. The problem is with all click gestures (middle click and 3 finger click). Nothing is printed to the log. Other gestures work and are written to the log in DEBUG mode. I do get the following message on reconnection despite Jitouch being enabled in the accessibility settings:

Received kCGEventTapDisabledByTimeout; attempting to recreate CGEventTap. Allow Jitouch in System Preferences -> Privacy -> Accessibility.

aaronkollasch commented 1 year ago

Ok, can you try removing Jitouch from the accessibility settings, then run killall Jitouch, then re-add Jitouch when prompted? The accessibility settings can sometimes show Jitouch as enabled when it really points to a different location, so it's easiest to just remove the permission and re-enable.

Other than that, I'm not sure why Jitouch would receive a kCGEventTapDisabledByTimeout on reconnection. Can you try disabling magic mouse character recognition? Just a thought from looking at the code.

katzelad commented 1 year ago

Readding Jitouch in the accessibility settings doesn't solve the problem - the click gestures work again but stop working some time after reconnection. It is definitely because of CGEventTap, I get "Could not create CGEventTap" in the log right before the click gestures stop working. This always happens a few minutes after reconnection (immediately after the gestures still work). Character recognition is disabled.

aaronkollasch commented 1 year ago

Which version of Jitouch are you running? Can you send the logs from where you start Jitouch to reconnection to observing the issue?

katzelad commented 1 year ago

v2.82.1-beta.1, the problem also affects the trackpad (no clicks-based gestures). The log from initialization to the problem starting (18:28:40) to the gesture attempt in the end (doesn't show up in the logs). com.jitouch.Jitouch.log

aaronkollasch commented 1 year ago

That's strange, I'm not sure why the EventTap is timing out, but Jitouch should be attempting to recreate it.

I wonder if perhaps something in this block is hanging, perhaps a call to mouseRecognizer(): https://github.com/aaronkollasch/jitouch/blob/299af2b382e103ba3abd673883ffe6c056cf55b8/jitouch/Jitouch/Gesture.m#L3074-L3141

katzelad commented 1 year ago

@aaronkollasch It looks like 2.82.1 fixed it, thanks! Another small problem I encounter occasionally - sometimes the magic mouse left click stops working until I perform a left click on the trackpad.

2023-01-11 10:59:42.853 Jitouch[13225:4794400] Suppressed MouseDown with 2 fingers d=0.285989 t=0.020944

After clicking the trackpad, MouseDown is no longer suppressed.

aaronkollasch commented 1 year ago

Great, I'm glad to hear it! That means the fix was probably this commit: d5715569eb921ea652f317dc1fedad690b4d87c0

Could you open a separate issue for that problem, and I'll close this issue. Thanks!