https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
z

Zoff

11/21/2023, 9:31 AM
how can i catch right mouse click on a component? i can do onClick() but how do i get the right click?
a

Alexander Maryanovsky

11/21/2023, 10:34 AM
Copy code
Modifier.onClick(
    matcher = PointerMatcher.mouse(PointerButton.Secondary)
) {
                    
}
k

Kirill Grouchnikov

11/21/2023, 2:03 PM
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

Alexander Maryanovsky

11/21/2023, 2:07 PM
We have
Modifier.contextMenuOpenDetector
, but right now it only detects right-clicks. We should add ctrl-click on macOS to it probably.
z

Zoff

11/21/2023, 2:12 PM
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
4 Views