diff --git a/app/os_macos.go b/app/os_macos.go index b4d026d0..164cbe34 100644 --- a/app/os_macos.go +++ b/app/os_macos.go @@ -118,6 +118,11 @@ static void setWindowStandardButtonHidden(CFTypeRef windowRef, NSWindowButton bt [window standardWindowButton:btn].hidden = (BOOL)hide; } +static void performWindowDragWithEvent(CFTypeRef windowRef, CFTypeRef evt) { + NSWindow *window = (__bridge NSWindow *)windowRef; + [window performWindowDragWithEvent:(__bridge NSEvent*)evt]; +} + static void closeWindow(CFTypeRef windowRef) { NSWindow* window = (__bridge NSWindow *)windowRef; [window performClose:nil]; @@ -227,8 +232,9 @@ type window struct { displayLink *displayLink // redraw is a single entry channel for making sure only one // display link redraw request is in flight. - redraw chan struct{} - cursor pointer.Cursor + redraw chan struct{} + cursor pointer.Cursor + lastPress C.CFTypeRef scale float32 config Config @@ -409,6 +415,12 @@ func (w *window) Perform(acts system.Action) { C.setScreenFrame(w.window, C.CGFloat(x), C.CGFloat(y), C.CGFloat(sz.X), C.CGFloat(sz.Y)) case system.ActionRaise: C.raiseWindow(w.window) + case system.ActionMove: + if w.lastPress != 0 { + C.performWindowDragWithEvent(w.window, w.lastPress) + C.CFRelease(w.lastPress) + w.lastPress = 0 + } } }) if acts&system.ActionClose != 0 { @@ -488,7 +500,8 @@ func gio_onText(view, cstr C.CFTypeRef) { } //export gio_onMouse -func gio_onMouse(view C.CFTypeRef, cdir C.int, cbtns C.NSUInteger, x, y, dx, dy C.CGFloat, ti C.double, mods C.NSUInteger) { +func gio_onMouse(view, evt C.CFTypeRef, cdir C.int, cbtns C.NSUInteger, x, y, dx, dy C.CGFloat, ti C.double, mods C.NSUInteger) { + w := mustView(view) var typ pointer.Type switch cdir { case C.MOUSE_MOVE: @@ -497,6 +510,11 @@ func gio_onMouse(view C.CFTypeRef, cdir C.int, cbtns C.NSUInteger, x, y, dx, dy typ = pointer.Release case C.MOUSE_DOWN: typ = pointer.Press + if w.lastPress != 0 { + C.CFRelease(w.lastPress) + w.lastPress = 0 + } + w.lastPress = C.CFRetain(evt) case C.MOUSE_SCROLL: typ = pointer.Scroll default: @@ -513,7 +531,6 @@ func gio_onMouse(view C.CFTypeRef, cdir C.int, cbtns C.NSUInteger, x, y, dx, dy btns |= pointer.ButtonTertiary } t := time.Duration(float64(ti)*float64(time.Second) + .5) - w := mustView(view) xf, yf := float32(x)*w.scale, float32(y)*w.scale dxf, dyf := float32(dx)*w.scale, float32(dy)*w.scale w.w.Event(pointer.Event{ @@ -753,6 +770,10 @@ func gio_onClose(view C.CFTypeRef) { w.w.Event(ViewEvent{}) deleteView(view) w.w.Event(system.DestroyEvent{}) + if w.lastPress != 0 { + C.CFRelease(w.lastPress) + w.lastPress = 0 + } w.displayLink.Close() C.CFRelease(w.view) C.CFRelease(w.window) diff --git a/app/os_macos.m b/app/os_macos.m index 5fe2d99d..3eb8127d 100644 --- a/app/os_macos.m +++ b/app/os_macos.m @@ -61,7 +61,7 @@ static void handleMouse(NSView *view, NSEvent *event, int typ, CGFloat dx, CGFlo } // Origin is in the lower left corner. Convert to upper left. CGFloat height = view.bounds.size.height; - gio_onMouse((__bridge CFTypeRef)view, typ, [NSEvent pressedMouseButtons], p.x, height - p.y, dx, dy, [event timestamp], [event modifierFlags]); + gio_onMouse((__bridge CFTypeRef)view, (__bridge CFTypeRef)event, typ, [NSEvent pressedMouseButtons], p.x, height - p.y, dx, dy, [event timestamp], [event modifierFlags]); } @interface GioView : NSView