app: [macOS] add support for ActionMove

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-06-24 21:41:56 +02:00
parent 8457df2d1f
commit c5e07ba01f
2 changed files with 26 additions and 5 deletions
+25 -4
View File
@@ -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)
+1 -1
View File
@@ -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 <CALayerDelegate,NSTextInputClient>