From 05febe9d03cf3f9706e54fc3b7e2bae0717e9079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benoi=CC=82t=20LeBlanc?= Date: Fri, 27 Sep 2013 17:36:53 -0400 Subject: [PATCH] MacFreeRDP: Moved setViewSize logic out of the framework to the CLI app, because the content resizes the parent window, which interferes with other applications using the framework. --- client/Mac/MRDPView.h | 3 -- client/Mac/MRDPView.m | 52 ++++---------------------- client/Mac/cli/AppDelegate.m | 71 +++++++++++++++++++++++++++++++++++- client/Mac/mf_client.m | 1 - 4 files changed, 77 insertions(+), 50 deletions(-) diff --git a/client/Mac/MRDPView.h b/client/Mac/MRDPView.h index 289dae5ce..59cbf3b72 100755 --- a/client/Mac/MRDPView.h +++ b/client/Mac/MRDPView.h @@ -76,8 +76,6 @@ int kdcapslock; BOOL initialized; - - NSImageView* imageView; @public NSPasteboard* pasteboard_rd; /* for reading from clipboard */ @@ -92,7 +90,6 @@ - (void) onPasteboardTimerFired :(NSTimer *) timer; - (void) releaseResources; -- (void) setViewSize : (int) w : (int) h; @property (assign) int is_connected; diff --git a/client/Mac/MRDPView.m b/client/Mac/MRDPView.m index d12f2da3a..7650a0a2d 100644 --- a/client/Mac/MRDPView.m +++ b/client/Mac/MRDPView.m @@ -138,7 +138,6 @@ struct rgba_data e.embed = TRUE; e.handle = (void*) self; PubSub_OnEmbedWindow(context->pubSub, context, &e); - [self setViewSize :instance->settings->DesktopWidth :instance->settings->DesktopHeight]; mfc->thread = CreateThread(NULL, 0, mac_client_thread, (void*) context, 0, &mfc->mainThreadId); @@ -290,8 +289,6 @@ DWORD mac_client_thread(void* param) { self->currentCursor = cursor; [[self window] invalidateCursorRectsForView:self]; - - [imageView setImage:[currentCursor image]]; } @@ -703,19 +700,19 @@ DWORD mac_client_thread(void* param) return; if (self->bitmap_context) - { + { CGContextRef cgContext = [[NSGraphicsContext currentContext] graphicsPort]; CGImageRef cgImage = CGBitmapContextCreateImage(self->bitmap_context); - CGContextClipToRect(cgContext, CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)); - CGContextDrawImage(cgContext, CGRectMake(0, 0, [self bounds].size.width, [self bounds].size.height), cgImage); + CGContextClipToRect(cgContext, CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)); + CGContextDrawImage(cgContext, CGRectMake(0, 0, [self bounds].size.width, [self bounds].size.height), cgImage); - CGImageRelease(cgImage); - } + CGImageRelease(cgImage); + } else { // just clear the screen with black - [[NSColor redColor] set]; + [[NSColor blackColor] set]; NSRectFill([self bounds]); } } @@ -743,41 +740,6 @@ DWORD mac_client_thread(void* param) } } -- (void) setViewSize : (int) w : (int) h -{ - // store current dimensions - width = w; - height = h; - - // compute difference between window and client area - NSRect outerRect = [[self window] frame]; - NSRect innerRect = [self frame]; - - int widthDiff = outerRect.size.width - innerRect.size.width; - int heightDiff = outerRect.size.height - innerRect.size.height; - - // we are not in RemoteApp mode, disable resizing - outerRect.size.width = w + widthDiff; - outerRect.size.height = h + heightDiff; - [[self window] setMaxSize:outerRect.size]; - [[self window] setMinSize:outerRect.size]; - - @try - { - [[self window] setFrame:outerRect display:YES]; - } - @catch (NSException * e) { - NSLog(@"Exception: %@", e); - } - @finally { - } - - // set client area to specified dimensions - innerRect.size.width = w; - innerRect.size.height = h; - [self setFrame:innerRect]; -} - /************************************************************************ * * * C functions * @@ -1134,7 +1096,7 @@ void mac_end_paint(rdpContext* context) drawRect.origin.y = gdi->primary->hdc->hwnd->cinvalid[i].y - 1; drawRect.size.width = gdi->primary->hdc->hwnd->cinvalid[i].w + 1; drawRect.size.height = gdi->primary->hdc->hwnd->cinvalid[i].h + 1; - windows_to_apple_cords(mfc->view, &drawRect); + windows_to_apple_cords(mfc->view, &drawRect); [view setNeedsDisplayInRect:drawRect]; } diff --git a/client/Mac/cli/AppDelegate.m b/client/Mac/cli/AppDelegate.m index aec62be91..678a4c9f9 100644 --- a/client/Mac/cli/AppDelegate.m +++ b/client/Mac/cli/AppDelegate.m @@ -9,11 +9,14 @@ #import "AppDelegate.h" #import "MacFreeRDP/mfreerdp.h" #import "MacFreeRDP/mf_client.h" +#import "MacFreeRDP/MRDPView.h" static AppDelegate* _singleDelegate = nil; void AppDelegate_EmbedWindowEventHandler(void* context, EmbedWindowEventArgs* e); void AppDelegate_ConnectionResultEventHandler(void* context, ConnectionResultEventArgs* e); void AppDelegate_ErrorInfoEventHandler(void* ctx, ErrorInfoEventArgs* e); +int mac_client_start(rdpContext* context); +void mac_set_view_size(rdpContext* context, MRDPView* view); @implementation AppDelegate @@ -103,12 +106,24 @@ void AppDelegate_ErrorInfoEventHandler(void* ctx, ErrorInfoEventArgs* e); clientEntryPoints.Version = RDP_CLIENT_INTERFACE_VERSION; RdpClientEntry(&clientEntryPoints); + + clientEntryPoints.ClientStart = mac_client_start; context = freerdp_client_context_new(&clientEntryPoints); } - (void) ReleaseContext { + mfContext* mfc; + MRDPView* view; + + mfc = (mfContext*) context; + view = (MRDPView*) mfc->view; + + [view releaseResources]; + [view release]; + mfc->view = nil; + freerdp_client_context_free(context); context = nil; } @@ -156,6 +171,9 @@ void AppDelegate_EmbedWindowEventHandler(void* ctx, EmbedWindowEventArgs* e) { [[_singleDelegate->window contentView] addSubview:mfc->view]; } + + + mac_set_view_size(context, mfc->view); } } @@ -201,4 +219,55 @@ void AppDelegate_ErrorInfoEventHandler(void* ctx, ErrorInfoEventArgs* e) [_singleDelegate performSelectorOnMainThread:@selector(rdpConnectError:) withObject:message waitUntilDone:TRUE]; [message release]; } -} \ No newline at end of file +} + + +void mac_set_view_size(rdpContext* context, MRDPView* view) +{ + // compute difference between window and client area + NSRect outerRect = [[view window] frame]; + NSRect innerRect = [view frame]; + + int widthDiff = outerRect.size.width - innerRect.size.width; + int heightDiff = outerRect.size.height - innerRect.size.height; + + NSSize desktopSize; + desktopSize.width = context->settings->DesktopWidth; + desktopSize.height = context->settings->DesktopHeight; + + // we are not in RemoteApp mode, disable resizing + outerRect.size.width = desktopSize.width + widthDiff; + outerRect.size.height = desktopSize.height + heightDiff; + [[view window] setMaxSize:outerRect.size]; + [[view window] setMinSize:outerRect.size]; + + @try + { + [[view window] setFrame:outerRect display:YES]; + } + @catch (NSException * e) { + NSLog(@"Exception: %@", e); + } + @finally { + } + + // set client area to specified dimensions + innerRect.size.width = desktopSize.width; + innerRect.size.height = desktopSize.height; + [view setFrame:innerRect]; +} + +int mac_client_start(rdpContext* context) +{ + mfContext* mfc; + MRDPView* view; + + mfc = (mfContext*) context; + view = [[MRDPView alloc] initWithFrame : NSMakeRect(0, 0, context->settings->DesktopWidth, context->settings->DesktopHeight)]; + mfc->view = view; + + [view rdpStart:context]; + mac_set_view_size(context, view); + + return 0; +} diff --git a/client/Mac/mf_client.m b/client/Mac/mf_client.m index cf830d3c7..2ccddd625 100755 --- a/client/Mac/mf_client.m +++ b/client/Mac/mf_client.m @@ -25,7 +25,6 @@ #include #include #include -#import "MRDPView.h" /** * Client Interface