OSX: fix cursor visibility for sharing service

This commit is contained in:
2019-03-11 19:38:56 +01:00
parent 5bef9c7286
commit de376d0a56
2 changed files with 43 additions and 5 deletions

View File

@@ -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<NSString*>*)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

View File

@@ -18,6 +18,7 @@
bool gl_ready;
bool cursor_visible;
bool cursor_inside;
bool cursor_ignore;
NSTrackingArea* trackingArea;
@public NSString* file2open;
}