SDL: add multitouch support#1599
Conversation
Partially inspired by the Android implementation. After I added it, I suddenly realized we could've had fake multitouch on desktop for years. There's a right button on the mouse, after all. A possible alternative would be to simply fake right mouse button as being to fingers at once, as opposed to having to truly press left and right at the same time.
…ase it needs to be reverted
|
Untested, but nothing jumps out at a quick glance ;). |
|
Rest assured I'd have noticed if anything didn't work. ;-) @ptrm Have you been able to try the Apple touchpad? I noticed you left a thumbs up :-P |
|
I tested macOS 13.3.1 myself. It seems to be fine. |
Includes: * Fix build on Mac OS X 13.3+ (missing ifr_netmask) (koreader/koreader-base#1596) * Add C declarations needed for zmq http server (koreader/koreader-base#1595) * SDL: add multitouch support (koreader/koreader-base#1599)
Includes: * Fix build on Mac OS X 13.3+ (missing ifr_netmask) (koreader/koreader-base#1596) * Add C declarations needed for zmq http server (koreader/koreader-base#1595) * SDL: add multitouch support (koreader/koreader-base#1599)
| local x = is_finger and event.tfinger.x * S.w or event.button.x | ||
| local y = is_finger and event.tfinger.y * S.h or event.button.y | ||
| setPointerDownState(slot, true) | ||
| genTouchDownEvent(event, slot, x, y) |
There was a problem hiding this comment.
This may be called for !is_finger, while it will access event.tfinger.fingerId, I'm not sure what it points to in the SDL magic union in those cases ;).
There was a problem hiding this comment.
Oh right, a minor oversight for the mouse, though it doesn't really matter in practice.
There was a problem hiding this comment.
The most obvious would probably be:
diff --git a/ffi/SDL2_0.lua b/ffi/SDL2_0.lua
index 4823dcac..ee5a767d 100644
--- a/ffi/SDL2_0.lua
+++ b/ffi/SDL2_0.lua
@@ -235,8 +235,9 @@ local function getFingerSlot(event)
end
local function genTouchDownEvent(event, slot, x, y)
+ local is_finger = event.type == SDL.SDL_FINGERDOWN
genEmuEvent(C.EV_ABS, C.ABS_MT_SLOT, slot)
- genEmuEvent(C.EV_ABS, C.ABS_MT_TRACKING_ID, tonumber(event.tfinger.fingerId))
+ genEmuEvent(C.EV_ABS, C.ABS_MT_TRACKING_ID, is_finger and tonumber(event.tfinger.fingerId) or slot)
genEmuEvent(C.EV_ABS, C.ABS_MT_POSITION_X, x)
genEmuEvent(C.EV_ABS, C.ABS_MT_POSITION_Y, y)
genEmuEvent(C.EV_SYN, C.SYN_REPORT, 0)I prefer tracking id not to be constantly 0 and 1 'cause if nothing else it's clearer to read. 😅
Sorry, that was meant as a quick sign of queueing it ;) will try it today, I don't have a touchpad on my mac mini though, so it'll be just mouse. |
|
Additional tests are welcome, but I did test the touchpad on a Macbook Air M1 already. It didn't seem to generate finger events. Looking again that used to be the behavior at some point in the past (and clearly it was back ca. 2014 when that code was written), but it looks like more recent SDL has made it configurable: Going back a little further, it was four years ago that the touchpad behavior was changed for Mac, see libsdl-org/SDL@e841b06 and a little further back libsdl-org/SDL@d9a2eff So I think we might want to set |
…rted trackpads macOS only for now, in SDL itself. Follow-up to <koreader#1599>.
SDL supports multitouch since koreader/koreader-base#1599
SDL supports multitouch since koreader/koreader-base#1599
Includes: * Fix build on Mac OS X 13.3+ (missing ifr_netmask) (koreader/koreader-base#1596) * Add C declarations needed for zmq http server (koreader/koreader-base#1595) * SDL: add multitouch support (koreader/koreader-base#1599)
SDL supports multitouch since koreader/koreader-base#1599
Partially inspired by the Android implementation.
After I added it, I suddenly realized we could've had fake multitouch on desktop for years. There's a right button on the mouse, after all. A possible alternative would be to simply fake right mouse button as being two fingers at once, as opposed to having to truly press left and right at the same time.
This change is