how can i catch right mouse click on a component? ...
# compose-desktop
z
how can i catch right mouse click on a component? i can do onClick() but how do i get the right click?
a
Copy code
Modifier.onClick(
    matcher = PointerMatcher.mouse(PointerButton.Secondary)
) {
                    
}
k
This is not a correct logic for macOS (and probably some Linux flavors as well), as that OS allows you to Ctrl+Left Click to bring up the popup menu. You can dive a bit deeper into AWT with
awaitPointerEventScope { awaitPointerEvent() }.awtEventOrNull
and then check
awtEvent?.isPopupTrigger == true
a
We have
Modifier.contextMenuOpenDetector
, but right now it only detects right-clicks. We should add ctrl-click on macOS to it probably.
z
thanks. good info this
Oh, it turns out we already report ctrl-click as “secondary mouse button click” on Mac OS X. So you can already use
Modifier.contextMenuOpenDetector
and it will work.
and my PR seems unnecessary