diff --git a/client/Mac/MRDPView.h b/client/Mac/MRDPView.h index 2cc67c2d4..cd4d06b03 100755 --- a/client/Mac/MRDPView.h +++ b/client/Mac/MRDPView.h @@ -78,6 +78,8 @@ int kdlmeta; int kdrmeta; int kdcapslock; + + BOOL initialized; @public NSPasteboard* pasteboard_rd; /* for reading from clipboard */ diff --git a/client/Mac/MRDPView.m b/client/Mac/MRDPView.m index 5b951c4d3..d4020679f 100644 --- a/client/Mac/MRDPView.m +++ b/client/Mac/MRDPView.m @@ -129,11 +129,12 @@ struct rgba_data rdpSettings* settings; EmbedWindowEventArgs e; + [self initializeView]; + context = rdp_context; mfc = (mfContext*) rdp_context; instance = context->instance; settings = context->settings; - mfc->view = self; EventArgsInit(&e, "mfreerdp"); e.embed = TRUE; @@ -185,7 +186,7 @@ struct rgba_data - (id)initWithFrame:(NSRect)frame { - self = [super initWithFrame:frame]; + self = [super initWithFrame:frame]; if (self) { @@ -203,22 +204,32 @@ struct rgba_data // won't be called if the view is created dynamically - (void) viewDidLoad { - // store our window dimensions - width = [self frame].size.width; - height = [self frame].size.height; - titleBarHeight = 22; - - [[self window] becomeFirstResponder]; - [[self window] setAcceptsMouseMovedEvents:YES]; - - cursors = [[NSMutableArray alloc] initWithCapacity:10]; + [self initializeView]; +} - // setup a mouse tracking area - NSTrackingArea * trackingArea = [[NSTrackingArea alloc] initWithRect:[self visibleRect] options:NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingCursorUpdate | NSTrackingEnabledDuringMouseDrag | NSTrackingActiveWhenFirstResponder owner:self userInfo:nil]; - - [self addTrackingArea:trackingArea]; - - mouseInClientArea = YES; +- (void) initializeView +{ + if (!initialized) + { + // store our window dimensions + width = [self frame].size.width; + height = [self frame].size.height; + titleBarHeight = 22; + + [[self window] becomeFirstResponder]; + [[self window] setAcceptsMouseMovedEvents:YES]; + + cursors = [[NSMutableArray alloc] initWithCapacity:10]; + + // setup a mouse tracking area + NSTrackingArea * trackingArea = [[NSTrackingArea alloc] initWithRect:[self visibleRect] options:NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingCursorUpdate | NSTrackingEnabledDuringMouseDrag | NSTrackingActiveWhenFirstResponder owner:self userInfo:nil]; + + [self addTrackingArea:trackingArea]; + + mouseInClientArea = YES; + + initialized = YES; + } } /** ********************************************************************* @@ -619,11 +630,6 @@ struct rgba_data if (run_loop_src_channels != 0) CFRunLoopRemoveSource(CFRunLoopGetCurrent(), run_loop_src_channels, kCFRunLoopDefaultMode); - - freerdp_client_stop(self->context); - - freerdp_client_context_free(self->context); - } /** ********************************************************************* diff --git a/client/Mac/mf_client.m b/client/Mac/mf_client.m index 20aa3ce01..7913a4ee9 100755 --- a/client/Mac/mf_client.m +++ b/client/Mac/mf_client.m @@ -25,6 +25,7 @@ #include #include #include +#import "MRDPView.h" /** * Client Interface @@ -46,6 +47,13 @@ int mfreerdp_client_start(rdpContext* context) MRDPView* view; mfContext* mfc = (mfContext*) context; + if (mfc->view == NULL) + { + // view not specified beforehand. Create view dynamically + mfc->view = [[MRDPView alloc] initWithFrame : NSMakeRect(0, 0, 300, 300)]; + mfc->view_ownership = TRUE; + } + view = (MRDPView*) mfc->view; [view rdpStart:context]; @@ -74,6 +82,13 @@ int mfreerdp_client_stop(rdpContext* context) mfc->disconnect = TRUE; } + if (mfc->view_ownership) + { + MRDPView* view = (MRDPView*) view; + [view releaseResources]; + [view release]; + } + return 0; } diff --git a/client/Mac/mfreerdp.h b/client/Mac/mfreerdp.h index 02b0272e2..ff3bd6176 100644 --- a/client/Mac/mfreerdp.h +++ b/client/Mac/mfreerdp.h @@ -28,6 +28,7 @@ struct mf_context DEFINE_RDP_CLIENT_COMMON(); void* view; + BOOL view_ownership; // TRUE indicates that the window was created and should be freed by the API. int width; int height;