Skip to content

Commit

Permalink
fix(maxOS): modify event's mouse location in drag_window (#743)
Browse files Browse the repository at this point in the history
  • Loading branch information
pewsheen authored Jun 1, 2023
1 parent dc951ae commit 8132901
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changes/drag-window-cursor-position.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": patch
---

On macOS, fix the unexpected shifting of the window when dragging after closing the share dialog.
32 changes: 28 additions & 4 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ use crate::{
use cocoa::{
appkit::{
self, CGFloat, NSApp, NSApplication, NSApplicationPresentationOptions, NSColor, NSEvent,
NSRequestUserAttentionType, NSScreen, NSView, NSWindow, NSWindowButton,
NSWindowCollectionBehavior, NSWindowOrderingMode, NSWindowStyleMask,
NSEventModifierFlags, NSEventSubtype, NSEventType, NSRequestUserAttentionType, NSScreen,
NSView, NSWindow, NSWindowButton, NSWindowCollectionBehavior, NSWindowOrderingMode,
NSWindowStyleMask,
},
base::{id, nil},
foundation::{
NSArray, NSAutoreleasePool, NSDictionary, NSPoint, NSRect, NSSize, NSString, NSUInteger,
NSArray, NSAutoreleasePool, NSDictionary, NSInteger, NSPoint, NSRect, NSSize, NSString,
NSTimeInterval, NSUInteger,
},
};
use core_graphics::display::{CGDisplay, CGDisplayMode};
Expand Down Expand Up @@ -839,7 +841,29 @@ impl UnownedWindow {
#[inline]
pub fn drag_window(&self) -> Result<(), ExternalError> {
unsafe {
let event: id = msg_send![NSApp(), currentEvent];
let mut event: id = msg_send![NSApp(), currentEvent];

let event_type: NSUInteger = msg_send![event, type];
if event_type == 0x15 {
let mouse_location: NSPoint = msg_send![class!(NSEvent), mouseLocation];
let event_modifier_flags: NSEventModifierFlags = msg_send![event, modifierFlags];
let event_timestamp: NSTimeInterval = msg_send![event, timestamp];
let event_window_number: NSInteger = msg_send![event, windowNumber];

event = msg_send![
class!(NSEvent),
mouseEventWithType: NSEventType::NSLeftMouseDown
location: mouse_location
modifierFlags: event_modifier_flags
timestamp: event_timestamp
windowNumber: event_window_number
context: nil
eventNumber: NSEventSubtype::NSWindowExposedEventType
clickCount: 1
pressure: 1.0
];
}

let _: () = msg_send![*self.ns_window, performWindowDragWithEvent: event];
}

Expand Down

0 comments on commit 8132901

Please sign in to comment.