From de376d0a564303409a51b07f871c69b4ad81d055 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Mon, 11 Mar 2019 19:38:56 +0100 Subject: [PATCH] OSX: fix cursor visibility for sharing service --- PanoPainter-OSX/main.cpp | 47 +++++++++++++++++++++++++++++++++++----- PanoPainter-OSX/main.h | 1 + 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/PanoPainter-OSX/main.cpp b/PanoPainter-OSX/main.cpp index 4a71cf7..22c7522 100644 --- a/PanoPainter-OSX/main.cpp +++ b/PanoPainter-OSX/main.cpp @@ -50,7 +50,7 @@ std::mutex task_mutex; if (cursor_visible == visible) return; cursor_visible = visible; - if (cursor_inside) + if (cursor_inside && !cursor_ignore) visible ? [NSCursor unhide] : [NSCursor hide]; } - (std::string)pick_file:(NSArray*)types @@ -63,7 +63,15 @@ std::mutex task_mutex; //NSArray* fileTypes = [NSArray arrayWithObjects:@"png", @"PNG", @"jpg", @"JPG", @"jpeg", nil]; [panel setAllowedFileTypes:types]; + [self removeTrackingArea:trackingArea]; + if (!cursor_visible) + [NSCursor unhide]; + NSInteger clicked = [panel runModal]; + + [self addTrackingArea:trackingArea]; + if (!cursor_visible) + [NSCursor hide]; std::string ret; if (clicked == NSFileHandlingPanelOKButton) @@ -83,8 +91,16 @@ std::mutex task_mutex; [panel setCanChooseDirectories:YES]; [panel setAllowsMultipleSelection:NO]; // yes if more than one dir is allowed + [self removeTrackingArea:trackingArea]; + if (!cursor_visible) + [NSCursor unhide]; + NSInteger clicked = [panel runModal]; + [self addTrackingArea:trackingArea]; + if (!cursor_visible) + [NSCursor hide]; + std::string ret; if (clicked == NSFileHandlingPanelOKButton) { @@ -100,6 +116,12 @@ std::mutex task_mutex; { NSURL *url = [NSURL fileURLWithPath:file_path]; NSArray *objectsToShare = @[url]; + + [self removeTrackingArea:trackingArea]; + cursor_ignore = true; + if (!cursor_visible) + [NSCursor unhide]; + [airdrop_service performWithItems:objectsToShare]; } - (NSWindow *)sharingService:(NSSharingService *)sharingService sourceWindowForShareItems:(NSArray *)items sharingContentScope:(NSSharingContentScope *)sharingContentScope @@ -110,6 +132,23 @@ std::mutex task_mutex; { return self; } +-(void)sharingService:(NSSharingService *)sharingService willShareItems:(NSArray *)items +{ +} +- (void)sharingService:(NSSharingService *)sharingService didFailToShareItems:(NSArray *)items error:(NSError *)error +{ + [self addTrackingArea:trackingArea]; + cursor_ignore = false; + if (!cursor_visible) + [NSCursor hide]; +} +- (void)sharingService:(NSSharingService *)sharingService didShareItems:(NSArray *)items +{ + [self addTrackingArea:trackingArea]; + cursor_ignore = false; + if (!cursor_visible) + [NSCursor hide]; +} - (instancetype)initWithFrame:(NSRect)frameRect { airdrop_service = [NSSharingService sharingServiceNamed:NSSharingServiceNameSendViaAirDrop]; @@ -117,6 +156,7 @@ std::mutex task_mutex; gl_ready = false; cursor_visible = CGCursorIsVisible(); cursor_inside = false; + cursor_ignore = false; NSOpenGLPixelFormatAttribute attrs[] = { NSOpenGLPFADoubleBuffer, @@ -135,10 +175,7 @@ std::mutex task_mutex; [self setPixelFormat:pf]; [self setOpenGLContext:context]; - trackingArea = [[NSTrackingArea alloc] initWithRect:frameRect - options: (NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveInKeyWindow ) - owner:self userInfo:nil]; - [self addTrackingArea:trackingArea]; + [self updateTrackingAreas]; return self; } - (void)prepareOpenGL diff --git a/PanoPainter-OSX/main.h b/PanoPainter-OSX/main.h index fe90c85..ebc9c1a 100644 --- a/PanoPainter-OSX/main.h +++ b/PanoPainter-OSX/main.h @@ -18,6 +18,7 @@ bool gl_ready; bool cursor_visible; bool cursor_inside; + bool cursor_ignore; NSTrackingArea* trackingArea; @public NSString* file2open; }