Skip to content

Commit

Permalink
macOS: fire EventWindowMove on resizes if position changes (closes #116)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed Aug 21, 2021
1 parent 877ff99 commit 801b314
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions macos/cc/WindowDelegate.mm
Expand Up @@ -16,12 +16,17 @@ - (WindowDelegate*)initWithWindow:(jwm::WindowMac*)initWindow {
}

- (void)windowDidMove:(NSNotification *)notification {
NSPoint pos = jwm::nsWindowPosition(fWindow->fNSWindow);
jwm::JNILocal<jobject> event(fWindow->fEnv, jwm::classes::EventWindowMove::make(fWindow->fEnv, pos.x, pos.y));
fWindow->dispatch(event.get());
NSPoint origin = fWindow->fNSWindow.frame.origin;
if (origin.x != fWindow->fLastPosition.x || origin.y != fWindow->fLastPosition.y) {
fWindow->fLastPosition = origin;
NSPoint pos = jwm::nsWindowPosition(fWindow->fNSWindow);
jwm::JNILocal<jobject> event(fWindow->fEnv, jwm::classes::EventWindowMove::make(fWindow->fEnv, pos.x, pos.y));
fWindow->dispatch(event.get());
}
}

- (void)windowDidResize:(NSNotification *)notification {
[self windowDidMove:notification];
const NSRect windowFrame = [fWindow->fNSWindow frame];
const NSRect contentFrame = [fWindow->fNSWindow.contentView frame];
CGFloat scale = fWindow->getScale();
Expand Down
1 change: 1 addition & 0 deletions macos/cc/WindowMac.hh
Expand Up @@ -17,6 +17,7 @@ namespace jwm {
void close();

NSWindow* fNSWindow = nullptr;
NSPoint fLastPosition = {0, 0};
CVDisplayLinkRef fDisplayLink = 0;
volatile bool fFrameRequested = false;
volatile bool fFrameScheduled = false;
Expand Down

0 comments on commit 801b314

Please sign in to comment.