Skip to content

Commit

Permalink
Fixed a case where [event.modifiersEx] does not provide info about th…
Browse files Browse the repository at this point in the history
…e pressed mouse button (AWT). (#181)

- Fixed a case where [event.modifiersEx] does not provide info about the pressed mouse button when using touchpad on MacOS 12 (AWT).

Test: manual.
  • Loading branch information
Rsedaikin committed Feb 8, 2022
1 parent 8ff912c commit ef944ae
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,25 @@ private fun ComposeScene.onMouseWheelEvent(
)
}


@OptIn(ExperimentalComposeUiApi::class)
private val MouseEvent.buttons get() = PointerButtons(
isPrimaryPressed = (modifiersEx and MouseEvent.BUTTON1_DOWN_MASK) != 0 && !isMacOsCtrlClick,
isSecondaryPressed = (modifiersEx and MouseEvent.BUTTON3_DOWN_MASK) != 0 || isMacOsCtrlClick,
isTertiaryPressed = (modifiersEx and MouseEvent.BUTTON2_DOWN_MASK) != 0,
isBackPressed = (modifiersEx and MouseEvent.getMaskForButton(4)) != 0,
isForwardPressed = (modifiersEx and MouseEvent.getMaskForButton(5)) != 0,
// We should check [event.button] because of case where [event.modifiersEx] does not provide
// info about the pressed mouse button when using touchpad on MacOS 12 (AWT only).
// When the [Tap to click] feature is activated on Mac OS 12, half of all clicks are not
// handled because [event.modifiersEx] may not provide info about the pressed mouse button.
isPrimaryPressed = ((modifiersEx and MouseEvent.BUTTON1_DOWN_MASK) != 0
|| (id == MouseEvent.MOUSE_PRESSED && button == MouseEvent.BUTTON1))
&& !isMacOsCtrlClick,
isSecondaryPressed = (modifiersEx and MouseEvent.BUTTON3_DOWN_MASK) != 0
|| (id == MouseEvent.MOUSE_PRESSED && button == MouseEvent.BUTTON3)
|| isMacOsCtrlClick,
isTertiaryPressed = (modifiersEx and MouseEvent.BUTTON2_DOWN_MASK) != 0
|| (id == MouseEvent.MOUSE_PRESSED && button == MouseEvent.BUTTON2),
isBackPressed = (modifiersEx and MouseEvent.getMaskForButton(4)) != 0
|| (id == MouseEvent.MOUSE_PRESSED && button == 4),
isForwardPressed = (modifiersEx and MouseEvent.getMaskForButton(5)) != 0
|| (id == MouseEvent.MOUSE_PRESSED && button == 5),
)

@OptIn(ExperimentalComposeUiApi::class)
Expand Down

0 comments on commit ef944ae

Please sign in to comment.