`combinedClickable` and `mouseClickable` are mutua...
# compose-desktop
d
combinedClickable
and
mouseClickable
are mutually exclusive, but have non-overlapping functionality. Is there a built-in way to handle both double-clicks and right-clicks on an item?
I have a grid row (think Excel) where I want to show a context menu on right-click, but toggle some other thing if the user double-clicks (using the primary mouse button).
combinedClickable
lets me add a double-click handler, and
mouseClickable
lets me add a right-click handler, but I cannot use both at once. I'd like to avoid home-rolling a double-click detector, if possible...
k
One thing to remember - right click is not the same as show-context-menu. On macOS for example, context menu should also be shown on Ctrl+left click. There's also the difference between when the context menu should be shown (mouse press or mouse release) on Windows vs macOS
d
Good points! I hadn't thought about macOS because my support for it will be dubious (due to doing a lot of file io and not having a mac to test with).
Is there a standard Compose way of detecting when a context menu should be shown, then, since the keypresses are standardized?
and...I'm still left without an answer.
mouseClickable
doesn't have a double-click handler, which feels like an oversight or something unfinished.
I tried digging into it, but
PointerInputScope.detectTapWithContext
is
internal
, whereas
PointerInputScope.detectTapGestures
is
public
was hoping to be able to combine the two into a more flexible click handler
k
I created a function like this, that can do whatever you like.
Copy code
Modifier
    .pointerInput(Unit) {
        forEachGesture {
            awaitPointerEventScope {
                awaitFirstDown()
                do {
                    val event = awaitPointerEvent()
                    // detect mouse buttons and keyboard modifiers here:
                    // event.buttons.xxxx
                    // event.keyboard.Modifiers.xxxx
                    // event.***  :-D
                } while (event.changes.any { it.pressed })
            }
        }
    }
d
Thanks, I'll copy/paste from
PointerInputScope.detectTapGestures
to add double-click detection and hopefully this will be added to the easy-to-use APIs in the future.