I have been trying to find clues on getting pinch ...
# compose-desktop
s
I have been trying to find clues on getting pinch zoom to work on Compose Desktop using a Mac trackpad. I've tried searching the chat archives and found some clues, but most are old. The closest I came is this thread where some of the posts seem to hint that it might work out of the box with a
Modifier.transformable()
with a recent enough JDK (for example using code like this) but I have not been able to get it working. Has anyone else, or maybe knows if this is even supposed to work yet, or if there are any alternative ways of detecting trackpad pinch zoom?
đź‘€ 3
n
Indeed I was the original thread poster but still have not found an answer...
Okay I fucking got it! It was a rabbit hole… So basically the macos trackpad events are in package com.apple.eawt.event. There you have GestureListener that also has MagnificationListener. And that’s what you need. What you will need is in your root window, add the following code:
Copy code
GestureUtilities.addGestureListenerTo(window.rootPane, object : MagnificationListener,
        GestureListener {
        override fun magnify(e: MagnificationEvent?) {
            println("magnify") // your stuff 
        }

    })
But this will not compile because apparently oracle removed that since java 9. Check here and here. Then you add those argument to your javac (check screenshot how to do it in intellij) But that’s not enough because apparently there are some compilation errors. You just add
@file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE")
It worked for me and now I am receiving events. I don’t know how it behaves on Window/Linux trackpads
s
Thanks @Nuru Nabiyev, I appreciate it - very useful summary! So now you receive what looks like reasonable values then from
getMagnification()
on
MagnificationEvent
then?
n
Yes exactly @soderbjorn
i
Dear compose desktop team, please look into my solution in replies above. I was able to find the missing MacOS trackpad gestures, would be nice to incorporate those (along with Windows/Linux) to Modifier.transform . Let me know if something is needed
This solution can't be implemented in Compose itself, we can't use any private API to avoid backward compatibility issues. The only solution might be using native API.