Skip to content

Commit

Permalink
dispatch EventTrackpadTouch* events
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunlebron committed Nov 29, 2022
1 parent 2bce8f6 commit ecdcdfd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
67 changes: 54 additions & 13 deletions macos/cc/JWMMainView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,55 @@ void onMouseButton(jwm::WindowMac* window, NSEvent* event, NSUInteger* lastPress
*lastPressedButtons = after;
}

void onTrackpadTouchStart(jwm::WindowMac* window, NSEvent* event) {
NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil];
for (NSTouch *touch in touches) {
const NSSize size = [touch deviceSize];
const NSPoint pos = [touch normalizedPosition];
jwm::JNILocal<jobject> eventObj(window->fEnv, jwm::classes::EventTrackpadTouchStart::make(
window->fEnv,
(jint)touch.identity.hash,
pos.x,
pos.y,
size.width,
size.height));
window->dispatch(eventObj.get());
}
}

void onTrackpadTouchMove(jwm::WindowMac* window, NSEvent* event) {
NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseMoved inView:nil];
for (NSTouch *touch in touches) {
const NSPoint pos = [touch normalizedPosition];
jwm::JNILocal<jobject> eventObj(window->fEnv, jwm::classes::EventTrackpadTouchMove::make(
window->fEnv,
(jint)touch.identity.hash,
pos.x,
pos.y));
window->dispatch(eventObj.get());
}
}

void onTrackpadTouchCancel(jwm::WindowMac* window, NSEvent* event) {
NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseCancelled inView:nil];
for (NSTouch *touch in touches) {
jwm::JNILocal<jobject> eventObj(window->fEnv, jwm::classes::EventTrackpadTouchCancel::make(
window->fEnv,
(jint)touch.identity.hash));
window->dispatch(eventObj.get());
}
}

void onTrackpadTouchEnd(jwm::WindowMac* window, NSEvent* event) {
NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseEnded inView:nil];
for (NSTouch *touch in touches) {
jwm::JNILocal<jobject> eventObj(window->fEnv, jwm::classes::EventTrackpadTouchEnd::make(
window->fEnv,
(jint)touch.identity.hash));
window->dispatch(eventObj.get());
}
}

void logTouch(NSTouch* touch) {
const NSSize size = [touch deviceSize];
const NSPoint pos = [touch normalizedPosition];
Expand Down Expand Up @@ -309,30 +358,22 @@ - (BOOL)acceptsTouchEvents {
}

- (void)touchesBeganWithEvent:(NSEvent *)event {
// FIXME: Mouse events originating outside the view are still tracked if the window is in focus.
// NOTE: Mouse events originating outside the view are still tracked if the window is in focus.
// But touch events here are only triggered if the cursor originates inside the view.
// Is this related to fTrackingArea?
NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseTouching inView:nil];
for (NSTouch *touch in touches) {
jwm::logTouch(touch);
}
onTrackpadTouchStart(fWindow, event);
}

- (void)touchesMovedWithEvent:(NSEvent *)event {
NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseTouching inView:nil];
for (NSTouch *touch in touches) {
jwm::logTouch(touch);
}
onTrackpadTouchMove(fWindow, event);
}

- (void)touchesEndedWithEvent:(NSEvent *)event {
NSSet *touches = [event touchesMatchingPhase:NSTouchPhaseTouching inView:nil];
for (NSTouch *touch in touches) {
jwm::logTouch(touch);
}
onTrackpadTouchEnd(fWindow, event);
}

- (void)touchesCancelledWithEvent:(NSEvent *)event {
onTrackpadTouchCancel(fWindow, event);
}

- (void)updateTrackingAreas {
Expand Down
4 changes: 4 additions & 0 deletions shared/cc/impl/Library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,10 @@ extern "C" JNIEXPORT void JNICALL Java_io_github_humbleui_jwm_impl_Library__1nAf
jwm::classes::EventMouseButton::onLoad(env);
jwm::classes::EventMouseMove::onLoad(env);
jwm::classes::EventMouseScroll::onLoad(env);
jwm::classes::EventTrackpadTouchStart::onLoad(env);
jwm::classes::EventTrackpadTouchMove::onLoad(env);
jwm::classes::EventTrackpadTouchCancel::onLoad(env);
jwm::classes::EventTrackpadTouchEnd::onLoad(env);
jwm::classes::EventTextInput::onLoad(env);
jwm::classes::EventTextInputMarked::onLoad(env);
jwm::classes::EventWindowCloseRequest::onLoad(env);
Expand Down
2 changes: 1 addition & 1 deletion shared/java/EventMouseMove.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ public boolean isButtonDown(MouseButton button) {
public boolean isModifierDown(KeyModifier modifier) {
return (_modifiers & modifier._mask) != 0;
}
}
}

0 comments on commit ecdcdfd

Please sign in to comment.