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

Tabs double opening on 12.5.1 #31

Closed rosslynnie closed 2 years ago

rosslynnie commented 2 years ago

Have noticed sometimes middle click makes the tab open twice (while opening a separate tab as the middle click intended, it will register as a another click and open the link in the current tab/page as well). It's not always, but frequent enough. Have not noticed any specific patterns for replication, but it happens maybe 3 out of 5 middle clicks. I'm upgraded to 12.5.1 but the problem was there before. M1 Macbook Pro 14inch. Any idea why?

aaronkollasch commented 2 years ago

What gesture are you using for middle click? Or is it middle click with a mouse?

rosslynnie commented 2 years ago

What gesture are you using for middle click? Or is it middle click with a mouse?

I'm using one rest one tap to the right (two finger gesture). Many thanks for looking into it!

Update: have also tried three finger tap for middle click, problem persists. 1 in 3 taps/clicks or so will open the link in current page, as well as new tab.

aaronkollasch commented 2 years ago

I was able to replicate the one-fix-one-tap issue. However, three-finger tap seems more elusive. What browser are you using? I've been using three-finger tap as "Open in new tab" in Firefox for a while, and haven't seen this issue. I have seen inadvertent clicks with using one-fix one-tap to switch tabs, though those clicks usually don't do anything since my mouse doesn't rest on a link when switching tabs.

This has to do with a race condition (similar to the one identified here) between two separate macOS APIs. Because the gesture is also interpreted by the OS as a click, we need to suppress a click that occurs at the same time as a gesture is performed. However, if the click arrives before we can detect that multiple fingers are down, we don't know to suppress it. It's a tricky problem to solve without introducing lag to all mouse clicks.

You can see which clicks are suppressed by switching logging mode to Debug in the About section of the preferences, then opening ~/Library/Logs/com.jitouch.Jitouch.log in Console, or running less +F ~/Library/Logs/com.jitouch.Jitouch.log in Terminal. A message like Did not suppress Mouse1 with 1 fingers 100.000000 means that LeftMouseDown was not suppressed as only one finger was detected, whereas Suppressed Mouse1 with 2 fingers 0.016066 means LeftMouseDown was suppressed as two fingers were detected with a distance of 0.016.

rosslynnie commented 2 years ago

You can see which clicks are suppressed by switching logging mode to Debug in the About section of the preferences, then opening ~/Library/Logs/com.jitouch.Jitouch.log in Console, or running less +F ~/Library/Logs/com.jitouch.Jitouch.log in Terminal. A message like Did not suppress Mouse1 with 1 fingers 100.000000 means that LeftMouseDown was not suppressed as only one finger was detected, whereas Suppressed Mouse1 with 2 fingers 0.016066 means LeftMouseDown was suppressed as two fingers were detected with a distance of 0.016.

Yep you are absolutely correct, in the debug logs I can see the difference - when middle clicks are executed correctly it shows suppressed clicks whereas opening in the current page does not show the same message. Although I have to say from the period I was looking at the logs, it was acting up quite badly so only very few times did the supressed clicks happen. Most of the time it doesn't suppress at all and links just open in the current page (and sometimes open twice in two different tabs, as some links are designated to be opened in new tabs anyway). Does this mean it simply can't be fixed? :(

aaronkollasch commented 2 years ago

I had an idea to try adding a small delay to mouse clicks, and if two+ fingers are detected within that delay, then suppress the click. Ideally an imperceptible delay would be enough to suppress most errors of this type. The last time I tried this, it didn't work well, even with a massive delay, but I think I may not have been doing it entirely correctly. Other than that, I don't think there's a way to fix it without changing the underlying system.

aaronkollasch commented 2 years ago

Beta now released at https://github.com/aaronkollasch/jitouch/releases/tag/v2.82-beta.2. Let me know if it works.

rosslynnie commented 2 years ago

Beta now released at https://github.com/aaronkollasch/jitouch/releases/tag/v2.82-beta.2. Let me know if it works.

Have been using this for a day and it seems to have fixed the problem! Thank you so much, and will report back if there are anything else. Cheers!

aaronkollasch commented 2 years ago

Glad to hear it!