From 136cff5765754a186a0c2858232d37a5249a3954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benoi=CC=82t=20LeBlanc?= Date: Fri, 13 Sep 2013 15:04:01 -0400 Subject: [PATCH 01/10] Property CMAKE_OSX_DEPLOYMENT_TARGET needs to be set on the cmake command-line, otherwise it generates a compilation error. --- CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 164e2f5a5..14c34f84c 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -237,10 +237,6 @@ if(APPLE) set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${FREERDP_IOS_EXTERNAL_SSL_PATH}) set_property(GLOBAL PROPERTY XCODE_ATTRIBUTE_SKIP_INSTALL YES) else() - if(NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET OR CMAKE_OSX_DEPLOYMENT_TARGET MATCHES "") - set(CMAKE_OSX_DEPLOYMENT_TARGET 10.6 CACHE STRING "OSX deployment target" FORCE) - endif() - if(NOT DEFINED CMAKE_OSX_ARCHITECTURES) set(CMAKE_OSX_ARCHITECTURES i386 x86_64) endif() 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 02/10] 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 From aca72114e248c6a26ceb45a7dd22c85777daa4dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benoi=CC=82t=20LeBlanc?= Date: Tue, 1 Oct 2013 14:30:06 -0400 Subject: [PATCH 03/10] Mouse events and region invalidate support for smart sizing. --- client/Mac/MRDPView.h | 9 +++-- client/Mac/MRDPView.m | 84 +++++++++++++++++++++++++++++------------- client/Mac/mf_client.h | 2 + client/Mac/mf_client.m | 19 ++++++++++ client/Mac/mfreerdp.h | 2 - 5 files changed, 85 insertions(+), 31 deletions(-) diff --git a/client/Mac/MRDPView.h b/client/Mac/MRDPView.h index 59cbf3b72..960efbff6 100755 --- a/client/Mac/MRDPView.h +++ b/client/Mac/MRDPView.h @@ -41,6 +41,7 @@ @interface MRDPView : NSView { + mfContext* mfc; NSBitmapImageRep* bmiRep; NSMutableArray* cursors; NSMutableArray* windows; @@ -52,10 +53,8 @@ rdpContext* context; CGContextRef bitmap_context; char* pixel_data; - int width; - int height; int argc; - char** argv; + char** argv; NSPoint savedDragLocation; BOOL firstCreateWindow; @@ -75,7 +74,7 @@ int kdrmeta; int kdcapslock; - BOOL initialized; + BOOL initialized; @public NSPasteboard* pasteboard_rd; /* for reading from clipboard */ @@ -87,6 +86,8 @@ - (int) rdpStart :(rdpContext*) rdp_context; - (void) setCursor: (NSCursor*) cursor; +- (void) setScrollOffset:(int)xOffset y:(int)yOffset; +- (void) sendMouseEvent:(UINT16) flags withX:(UINT16)x withY:(UINT16)y; - (void) onPasteboardTimerFired :(NSTimer *) timer; - (void) releaseResources; diff --git a/client/Mac/MRDPView.m b/client/Mac/MRDPView.m index dc06222ef..b70791b41 100644 --- a/client/Mac/MRDPView.m +++ b/client/Mac/MRDPView.m @@ -123,7 +123,6 @@ struct rgba_data - (int) rdpStart:(rdpContext*) rdp_context { - mfContext* mfc; rdpSettings* settings; EmbedWindowEventArgs e; @@ -274,8 +273,6 @@ DWORD mac_client_thread(void* param) if (!initialized) { // store our window dimensions - width = [self frame].size.width; - height = [self frame].size.height; titleBarHeight = 22; [[self window] becomeFirstResponder]; @@ -340,11 +337,10 @@ DWORD mac_client_thread(void* param) NSPoint loc = [event locationInWindow]; int x = (int) loc.x; int y = (int) loc.y; - - y = height - y; - - // send mouse motion event to RDP server - instance->input->MouseEvent(instance->input, PTR_FLAGS_MOVE, x, y); + + y = [self frame].size.height - y; + + mf_scale_mouse_event(context, instance->input, PTR_FLAGS_MOVE, x, y); } /** ********************************************************************* @@ -362,9 +358,9 @@ DWORD mac_client_thread(void* param) int x = (int) loc.x; int y = (int) loc.y; - y = height - y; + y = [self frame].size.height - y; - instance->input->MouseEvent(instance->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1, x, y); + mf_scale_mouse_event(context, instance->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1, x, y); } /** ********************************************************************* @@ -382,9 +378,9 @@ DWORD mac_client_thread(void* param) int x = (int) loc.x; int y = (int) loc.y; - y = height - y; + y = [self frame].size.height - y; - instance->input->MouseEvent(instance->input, PTR_FLAGS_BUTTON1, x, y); + mf_scale_mouse_event(context, instance->input, PTR_FLAGS_BUTTON1, x, y); } /** ********************************************************************* @@ -402,9 +398,9 @@ DWORD mac_client_thread(void* param) int x = (int) loc.x; int y = (int) loc.y; - y = height - y; + y = [self frame].size.height - y; - instance->input->MouseEvent(instance->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON2, x, y); + mf_scale_mouse_event(context, instance->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON2, x, y); } /** ********************************************************************* @@ -422,9 +418,9 @@ DWORD mac_client_thread(void* param) int x = (int) loc.x; int y = (int) loc.y; - y = height - y; + y = [self frame].size.height - y; - instance->input->MouseEvent(instance->input, PTR_FLAGS_BUTTON2, x, y); + mf_scale_mouse_event(context, instance->input, PTR_FLAGS_BUTTON2, x, y); } /** ********************************************************************* @@ -442,9 +438,9 @@ DWORD mac_client_thread(void* param) int x = (int) loc.x; int y = (int) loc.y; - y = height - y; + y = [self frame].size.height - y; - instance->input->MouseEvent(instance->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON3, x, y); + mf_scale_mouse_event(context, instance->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON3, x, y); } /** ********************************************************************* @@ -462,9 +458,9 @@ DWORD mac_client_thread(void* param) int x = (int) loc.x; int y = (int) loc.y; - y = height - y; + y = [self frame].size.height - y; - instance->input->MouseEvent(instance->input, PTR_FLAGS_BUTTON3, x, y); + mf_scale_mouse_event(context, instance->input, PTR_FLAGS_BUTTON3, x, y); } - (void) scrollWheel:(NSEvent *)event @@ -480,7 +476,7 @@ DWORD mac_client_thread(void* param) int x = (int) loc.x; int y = (int) loc.y; - y = height - y; + y = [self frame].size.height - y; flags = PTR_FLAGS_WHEEL; @@ -493,7 +489,7 @@ DWORD mac_client_thread(void* param) /* limit to maximum value in WheelRotationMask (9bit signed value) */ int step = MIN(MAX(-256, units), 255); - instance->input->MouseEvent(instance->input, flags | ((UINT16)step & WheelRotationMask), x, y); + mf_scale_mouse_event(context, instance->input, flags | ((UINT16)step & WheelRotationMask), x, y); units -= step; } } @@ -514,10 +510,10 @@ DWORD mac_client_thread(void* param) int x = (int) loc.x; int y = (int) loc.y; - y = height - y; + y = [self frame].size.height - y; // send mouse motion event to RDP server - instance->input->MouseEvent(instance->input, PTR_FLAGS_MOVE, x, y); + mf_scale_mouse_event(context, instance->input, PTR_FLAGS_MOVE, x, y); } /** ********************************************************************* @@ -754,6 +750,16 @@ DWORD mac_client_thread(void* param) } } +- (void) setScrollOffset:(int)xOffset y:(int)yOffset +{ + if (xOffset != mfc->xCurrentScroll || yOffset != mfc->yCurrentScroll) + { + NSLog(@"setScrollOffset h:%d v:%d", xOffset, yOffset); + mfc->yCurrentScroll = yOffset; + mfc->xCurrentScroll = xOffset; + } +} + /************************************************************************ * * * C functions * @@ -1093,6 +1099,13 @@ void mac_end_paint(rdpContext* context) mfContext* mfc = (mfContext*) context; MRDPView* view = (MRDPView*) mfc->view; + int ww, wh, dw, dh; + + ww = [view frame].size.width; + wh = [view frame].size.height; + dw = mfc->context.settings->DesktopWidth; + dh = mfc->context.settings->DesktopHeight; + if ((context == 0) || (context->gdi == 0)) return; @@ -1110,7 +1123,17 @@ 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; + + if (mfc->context.settings->SmartSizing && (ww != dw || wh != dh)) + { + drawRect.origin.y = drawRect.origin.y * wh / dh; + drawRect.size.height = drawRect.size.height * wh / dh; + drawRect.origin.x = drawRect.origin.x * ww / dw; + drawRect.size.width = drawRect.size.width * ww / dw; + } + windows_to_apple_cords(mfc->view, &drawRect); + [view setNeedsDisplayInRect:drawRect]; } @@ -1371,6 +1394,16 @@ void cliprdr_process_cb_format_list_event(freerdp* instance, RDP_CB_FORMAT_LIST_ } } +- (void) sendMouseEvent:(UINT16) flags withX:(UINT16)x withY:(UINT16)y +{ + y = instance->settings->DesktopHeight - y + mfc->yCurrentScroll; + + x = x + mfc->xCurrentScroll; + + // send mouse motion event to RDP server + mf_scale_mouse_event(context, instance->input, PTR_FLAGS_MOVE, x, y); +} + void process_cliprdr_event(freerdp* instance, wMessage* event) { if (event) @@ -1445,7 +1478,8 @@ void cliprdr_send_supported_format_list(freerdp* instance) void windows_to_apple_cords(MRDPView* view, NSRect* r) { - r->origin.y = view->height - (r->origin.y + r->size.height); + r->origin.y = [view frame].size.height - (r->origin.y + r->size.height); } + @end diff --git a/client/Mac/mf_client.h b/client/Mac/mf_client.h index 711c77b47..341fcacbc 100755 --- a/client/Mac/mf_client.h +++ b/client/Mac/mf_client.h @@ -28,6 +28,8 @@ extern "C" { #endif +FREERDP_API void mf_scale_mouse_event(void* context, rdpInput* input, UINT16 flags, UINT16 x, UINT16 y); + /** * Client Interface */ diff --git a/client/Mac/mf_client.m b/client/Mac/mf_client.m index 2ccddd625..502c5af9e 100755 --- a/client/Mac/mf_client.m +++ b/client/Mac/mf_client.m @@ -192,6 +192,25 @@ void freerdp_client_mouse_event(rdpContext* cfc, DWORD flags, int x, int y) input->MouseEvent(input, flags, x, y); } + +void mf_scale_mouse_event(void* context, rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) +{ + mfContext* mfc = (mfContext*) context; + MRDPView* view = (MRDPView*) mfc->view; + + int ww, wh, dw, dh; + + ww = [view frame].size.width; + wh = [view frame].size.height; + dw = mfc->context.settings->DesktopWidth; + dh = mfc->context.settings->DesktopHeight; + + if (!mfc->context.settings->SmartSizing || ((ww == dw) && (wh == dh))) + input->MouseEvent(input, flags, x + mfc->xCurrentScroll, y + mfc->yCurrentScroll); + else + input->MouseEvent(input, flags, x * dw / ww + mfc->xCurrentScroll, y * dh / wh + mfc->yCurrentScroll); +} + int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints) { pEntryPoints->Version = 1; diff --git a/client/Mac/mfreerdp.h b/client/Mac/mfreerdp.h index 52e7be122..6af864364 100644 --- a/client/Mac/mfreerdp.h +++ b/client/Mac/mfreerdp.h @@ -40,8 +40,6 @@ struct mf_context char window_title[64]; int client_x; int client_y; - int client_width; - int client_height; HANDLE keyboardThread; HANDLE stopEvent; From 27750e7022e584bc41aea26a61557f590f7ab7e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benoi=CC=82t=20LeBlanc?= Date: Tue, 1 Oct 2013 15:45:50 -0400 Subject: [PATCH 04/10] wf_event: missing parentesis --- client/Windows/wf_event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/Windows/wf_event.c b/client/Windows/wf_event.c index c243d35da..87a0ec17e 100644 --- a/client/Windows/wf_event.c +++ b/client/Windows/wf_event.c @@ -588,7 +588,7 @@ void wf_scale_mouse_event(wfContext* wfc, rdpInput* input, UINT16 flags, UINT16 dw = wfc->instance->settings->DesktopWidth; dh = wfc->instance->settings->DesktopHeight; - if (!wfc->instance->settings->SmartSizing || (ww == dw) && (wh == dh)) + if (!wfc->instance->settings->SmartSizing || ((ww == dw) && (wh == dh))) input->MouseEvent(input, flags, x + wfc->xCurrentScroll, y + wfc->yCurrentScroll); else input->MouseEvent(input, flags, x * dw / ww + wfc->xCurrentScroll, y * dh / wh + wfc->yCurrentScroll); From 78981418ce55013d69102109244a5dc9a298bbc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benoi=CC=82t=20LeBlanc?= Date: Wed, 2 Oct 2013 10:24:01 -0400 Subject: [PATCH 05/10] MacFreeRDP: Handling of mouse and region invalidation on scaling/scrolling --- client/Mac/MRDPView.h | 4 +--- client/Mac/MRDPView.m | 44 ++++++++++++++++-------------------------- client/Mac/mf_client.m | 26 ++++++++++++++++++++----- client/Mac/mfreerdp.h | 2 ++ 4 files changed, 41 insertions(+), 35 deletions(-) diff --git a/client/Mac/MRDPView.h b/client/Mac/MRDPView.h index 960efbff6..29964ff19 100755 --- a/client/Mac/MRDPView.h +++ b/client/Mac/MRDPView.h @@ -48,7 +48,6 @@ NSTimer* pasteboard_timer; NSCursor* currentCursor; NSRect prevWinPosition; - int titleBarHeight; freerdp* instance; rdpContext* context; CGContextRef bitmap_context; @@ -86,8 +85,7 @@ - (int) rdpStart :(rdpContext*) rdp_context; - (void) setCursor: (NSCursor*) cursor; -- (void) setScrollOffset:(int)xOffset y:(int)yOffset; -- (void) sendMouseEvent:(UINT16) flags withX:(UINT16)x withY:(UINT16)y; +- (void) setScrollOffset:(int)xOffset y:(int)yOffset w:(int)width h:(int)height; - (void) onPasteboardTimerFired :(NSTimer *) timer; - (void) releaseResources; diff --git a/client/Mac/MRDPView.m b/client/Mac/MRDPView.m index b70791b41..3c534f273 100644 --- a/client/Mac/MRDPView.m +++ b/client/Mac/MRDPView.m @@ -147,6 +147,8 @@ struct rgba_data instance->settings->DesktopHeight = screenFrame.size.height; } + mfc->client_height = instance->settings->DesktopHeight; + mfc->client_width = instance->settings->DesktopWidth; mfc->thread = CreateThread(NULL, 0, mac_client_thread, (void*) context, 0, &mfc->mainThreadId); @@ -272,12 +274,6 @@ DWORD mac_client_thread(void* param) { if (!initialized) { - // store our window dimensions - titleBarHeight = 22; - - [[self window] becomeFirstResponder]; - [[self window] setAcceptsMouseMovedEvents:YES]; - cursors = [[NSMutableArray alloc] initWithCapacity:10]; // setup a mouse tracking area @@ -750,14 +746,13 @@ DWORD mac_client_thread(void* param) } } -- (void) setScrollOffset:(int)xOffset y:(int)yOffset +- (void) setScrollOffset:(int)xOffset y:(int)yOffset w:(int)width h:(int)height { - if (xOffset != mfc->xCurrentScroll || yOffset != mfc->yCurrentScroll) - { - NSLog(@"setScrollOffset h:%d v:%d", xOffset, yOffset); - mfc->yCurrentScroll = yOffset; - mfc->xCurrentScroll = xOffset; - } + NSLog(@"setScrollOffset x:%d y:%d w:%d h:%d", xOffset, yOffset, width, height); + mfc->yCurrentScroll = yOffset; + mfc->xCurrentScroll = xOffset; + mfc->client_height = height; + mfc->client_width = width; } /************************************************************************ @@ -1101,8 +1096,8 @@ void mac_end_paint(rdpContext* context) int ww, wh, dw, dh; - ww = [view frame].size.width; - wh = [view frame].size.height; + ww = mfc->client_width; + wh = mfc->client_height; dw = mfc->context.settings->DesktopWidth; dh = mfc->context.settings->DesktopHeight; @@ -1124,6 +1119,10 @@ void mac_end_paint(rdpContext* context) drawRect.size.width = gdi->primary->hdc->hwnd->cinvalid[i].w + 1; drawRect.size.height = gdi->primary->hdc->hwnd->cinvalid[i].h + 1; + NSLog(@"drawRect x:%d y:%d w:%d h:%d", (int) drawRect.origin.x, (int) drawRect.origin.y, (int) drawRect.size.width, (int) drawRect.size.height); + + windows_to_apple_cords(mfc->view, &drawRect); + if (mfc->context.settings->SmartSizing && (ww != dw || wh != dh)) { drawRect.origin.y = drawRect.origin.y * wh / dh; @@ -1132,9 +1131,10 @@ void mac_end_paint(rdpContext* context) drawRect.size.width = drawRect.size.width * ww / dw; } - windows_to_apple_cords(mfc->view, &drawRect); + // Note: The xCurrentScroll and yCurrentScroll values do not need to be taken into account + // because the current frame is always at full size, since the scrolling is handled by the external container. - [view setNeedsDisplayInRect:drawRect]; + [view setNeedsDisplayInRect:drawRect]; } gdi->primary->hdc->hwnd->ninvalid = 0; @@ -1394,16 +1394,6 @@ void cliprdr_process_cb_format_list_event(freerdp* instance, RDP_CB_FORMAT_LIST_ } } -- (void) sendMouseEvent:(UINT16) flags withX:(UINT16)x withY:(UINT16)y -{ - y = instance->settings->DesktopHeight - y + mfc->yCurrentScroll; - - x = x + mfc->xCurrentScroll; - - // send mouse motion event to RDP server - mf_scale_mouse_event(context, instance->input, PTR_FLAGS_MOVE, x, y); -} - void process_cliprdr_event(freerdp* instance, wMessage* event) { if (event) diff --git a/client/Mac/mf_client.m b/client/Mac/mf_client.m index 502c5af9e..d37e7f2f6 100755 --- a/client/Mac/mf_client.m +++ b/client/Mac/mf_client.m @@ -196,19 +196,35 @@ void freerdp_client_mouse_event(rdpContext* cfc, DWORD flags, int x, int y) void mf_scale_mouse_event(void* context, rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { mfContext* mfc = (mfContext*) context; - MRDPView* view = (MRDPView*) mfc->view; int ww, wh, dw, dh; - ww = [view frame].size.width; - wh = [view frame].size.height; + ww = mfc->client_width; + wh = mfc->client_height; dw = mfc->context.settings->DesktopWidth; dh = mfc->context.settings->DesktopHeight; + NSLog(@"mouse event ww:%d wh:%d dw:%d dh:%d xScroll:%d yScroll:%d x1:%d y1:%d", + ww, wh, dw, dh, mfc->xCurrentScroll, mfc->yCurrentScroll, x, y); + if (!mfc->context.settings->SmartSizing || ((ww == dw) && (wh == dh))) - input->MouseEvent(input, flags, x + mfc->xCurrentScroll, y + mfc->yCurrentScroll); + { + y = y + mfc->yCurrentScroll; + + if (wh != dh) + { + y -= (dh - wh); + } + + NSLog(@"(scale off) -> input->MouseEvent(%d, %d)", x + mfc->xCurrentScroll, y); + input->MouseEvent(input, flags, x + mfc->xCurrentScroll, y); + } else - input->MouseEvent(input, flags, x * dw / ww + mfc->xCurrentScroll, y * dh / wh + mfc->yCurrentScroll); + { + y = y * dh / wh + mfc->yCurrentScroll; + NSLog(@"(scale on) -> input->MouseEvent(%d, %d)", x * dw / ww + mfc->xCurrentScroll, y); + input->MouseEvent(input, flags, x * dw / ww + mfc->xCurrentScroll, y); + } } int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints) diff --git a/client/Mac/mfreerdp.h b/client/Mac/mfreerdp.h index 6af864364..52e7be122 100644 --- a/client/Mac/mfreerdp.h +++ b/client/Mac/mfreerdp.h @@ -40,6 +40,8 @@ struct mf_context char window_title[64]; int client_x; int client_y; + int client_width; + int client_height; HANDLE keyboardThread; HANDLE stopEvent; From 766c1a18aa0f0a8242fdf1b903cbbf7437a5179e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benoi=CC=82t=20LeBlanc?= Date: Wed, 2 Oct 2013 10:51:48 -0400 Subject: [PATCH 06/10] MacFreeRDP: fixed invalid region coordinates conversion, cleanup traces --- client/Mac/MRDPView.m | 30 +++++++++++++++++------------- client/Mac/mf_client.m | 5 ----- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/client/Mac/MRDPView.m b/client/Mac/MRDPView.m index 3c534f273..4a02dbcb1 100644 --- a/client/Mac/MRDPView.m +++ b/client/Mac/MRDPView.m @@ -748,7 +748,6 @@ DWORD mac_client_thread(void* param) - (void) setScrollOffset:(int)xOffset y:(int)yOffset w:(int)width h:(int)height { - NSLog(@"setScrollOffset x:%d y:%d w:%d h:%d", xOffset, yOffset, width, height); mfc->yCurrentScroll = yOffset; mfc->xCurrentScroll = xOffset; mfc->client_height = height; @@ -1114,22 +1113,27 @@ void mac_end_paint(rdpContext* context) for (i = 0; i < gdi->primary->hdc->hwnd->ninvalid; i++) { - drawRect.origin.x = gdi->primary->hdc->hwnd->cinvalid[i].x - 1; - 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; - - NSLog(@"drawRect x:%d y:%d w:%d h:%d", (int) drawRect.origin.x, (int) drawRect.origin.y, (int) drawRect.size.width, (int) drawRect.size.height); - - windows_to_apple_cords(mfc->view, &drawRect); + drawRect.origin.x = gdi->primary->hdc->hwnd->cinvalid[i].x; + drawRect.origin.y = gdi->primary->hdc->hwnd->cinvalid[i].y; + drawRect.size.width = gdi->primary->hdc->hwnd->cinvalid[i].w; + drawRect.size.height = gdi->primary->hdc->hwnd->cinvalid[i].h; if (mfc->context.settings->SmartSizing && (ww != dw || wh != dh)) { - drawRect.origin.y = drawRect.origin.y * wh / dh; - drawRect.size.height = drawRect.size.height * wh / dh; - drawRect.origin.x = drawRect.origin.x * ww / dw; - drawRect.size.width = drawRect.size.width * ww / dw; + drawRect.origin.y = drawRect.origin.y * wh / dh - 1; + drawRect.size.height = drawRect.size.height * wh / dh + 1; + drawRect.origin.x = drawRect.origin.x * ww / dw - 1; + drawRect.size.width = drawRect.size.width * ww / dw + 1; } + else + { + drawRect.origin.y = drawRect.origin.y - 1; + drawRect.size.height = drawRect.size.height + 1; + drawRect.origin.x = drawRect.origin.x - 1; + drawRect.size.width = drawRect.size.width + 1; + } + + windows_to_apple_cords(mfc->view, &drawRect); // Note: The xCurrentScroll and yCurrentScroll values do not need to be taken into account // because the current frame is always at full size, since the scrolling is handled by the external container. diff --git a/client/Mac/mf_client.m b/client/Mac/mf_client.m index d37e7f2f6..2d75b3a7b 100755 --- a/client/Mac/mf_client.m +++ b/client/Mac/mf_client.m @@ -204,9 +204,6 @@ void mf_scale_mouse_event(void* context, rdpInput* input, UINT16 flags, UINT16 x dw = mfc->context.settings->DesktopWidth; dh = mfc->context.settings->DesktopHeight; - NSLog(@"mouse event ww:%d wh:%d dw:%d dh:%d xScroll:%d yScroll:%d x1:%d y1:%d", - ww, wh, dw, dh, mfc->xCurrentScroll, mfc->yCurrentScroll, x, y); - if (!mfc->context.settings->SmartSizing || ((ww == dw) && (wh == dh))) { y = y + mfc->yCurrentScroll; @@ -216,13 +213,11 @@ void mf_scale_mouse_event(void* context, rdpInput* input, UINT16 flags, UINT16 x y -= (dh - wh); } - NSLog(@"(scale off) -> input->MouseEvent(%d, %d)", x + mfc->xCurrentScroll, y); input->MouseEvent(input, flags, x + mfc->xCurrentScroll, y); } else { y = y * dh / wh + mfc->yCurrentScroll; - NSLog(@"(scale on) -> input->MouseEvent(%d, %d)", x * dw / ww + mfc->xCurrentScroll, y); input->MouseEvent(input, flags, x * dw / ww + mfc->xCurrentScroll, y); } } From fcb9ccd2157647bef68e604b69fd38cf614ebf36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20LeBlanc?= Date: Wed, 2 Oct 2013 14:33:10 -0400 Subject: [PATCH 07/10] Fixed decoration in embedded mode in Windows --- client/Windows/wf_interface.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/Windows/wf_interface.c b/client/Windows/wf_interface.c index 87abe188d..a8e8d1b8f 100644 --- a/client/Windows/wf_interface.c +++ b/client/Windows/wf_interface.c @@ -388,6 +388,9 @@ BOOL wf_post_connect(freerdp* instance) else _snwprintf(lpWindowName, ARRAYSIZE(lpWindowName), L"FreeRDP: %S:%d", settings->ServerHostname, settings->ServerPort); + if (settings->EmbeddedWindow) + settings->Decorations = FALSE; + if (!settings->Decorations) dwStyle = WS_CHILD | WS_BORDER; else From cf02d714b95eeefae18228b55fcde96b9c6d05fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20LeBlanc?= Date: Wed, 2 Oct 2013 14:33:46 -0400 Subject: [PATCH 08/10] fixed freerdp_set_param_string prototype to use const char* --- include/freerdp/settings.h | 2 +- libfreerdp/common/settings.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/freerdp/settings.h b/include/freerdp/settings.h index 02697579d..99b188acb 100644 --- a/include/freerdp/settings.h +++ b/include/freerdp/settings.h @@ -1333,7 +1333,7 @@ FREERDP_API UINT64 freerdp_get_param_uint64(rdpSettings* settings, int id); FREERDP_API int freerdp_set_param_uint64(rdpSettings* settings, int id, UINT64 param); FREERDP_API char* freerdp_get_param_string(rdpSettings* settings, int id); -FREERDP_API int freerdp_set_param_string(rdpSettings* settings, int id, char* param); +FREERDP_API int freerdp_set_param_string(rdpSettings* settings, int id, const char* param); FREERDP_API double freerdp_get_param_double(rdpSettings* settings, int id); FREERDP_API int freerdp_set_param_double(rdpSettings* settings, int id, double param); diff --git a/libfreerdp/common/settings.c b/libfreerdp/common/settings.c index ffcf1937f..0b667f640 100644 --- a/libfreerdp/common/settings.c +++ b/libfreerdp/common/settings.c @@ -2167,7 +2167,7 @@ char* freerdp_get_param_string(rdpSettings* settings, int id) return NULL; } -int freerdp_set_param_string(rdpSettings* settings, int id, char* param) +int freerdp_set_param_string(rdpSettings* settings, int id, const char* param) { ParamChangeEventArgs e; rdpContext* context = ((freerdp*) settings->instance)->context; From d274363b1a135845985951590fc7efba5ad9c116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20LeBlanc?= Date: Wed, 2 Oct 2013 14:34:10 -0400 Subject: [PATCH 09/10] Fixed client crash at close. Entry points were freed too soon. --- client/common/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/common/client.c b/client/common/client.c index 14456618c..d43375a10 100644 --- a/client/common/client.c +++ b/client/common/client.c @@ -70,8 +70,8 @@ void freerdp_client_context_free(rdpContext* context) { freerdp* instance = context->instance; - free(instance->pClientEntryPoints); freerdp_context_free(instance); + free(instance->pClientEntryPoints); freerdp_free(instance); } From 77c260da14dd1ed894b599c56247cf4c1d70070a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20LeBlanc?= Date: Thu, 3 Oct 2013 17:09:53 -0400 Subject: [PATCH 10/10] wf_interface: added function wf_set_window_size windows: triggering OnEmbedWindow event --- client/Windows/wf_interface.c | 11 ++++++++++- client/Windows/wf_interface.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/client/Windows/wf_interface.c b/client/Windows/wf_interface.c index a8e8d1b8f..9d09d30a5 100644 --- a/client/Windows/wf_interface.c +++ b/client/Windows/wf_interface.c @@ -49,6 +49,7 @@ #include #include #include +#include #include "wf_gdi.h" #include "wf_graphics.h" @@ -331,6 +332,7 @@ BOOL wf_post_connect(freerdp* instance) rdpContext* context; WCHAR lpWindowName[64]; rdpSettings* settings; + EmbedWindowEventArgs e; settings = instance->settings; context = instance->context; @@ -401,7 +403,7 @@ BOOL wf_post_connect(freerdp* instance) wfc->hwnd = CreateWindowEx((DWORD) NULL, wfc->wndClassName, lpWindowName, dwStyle, 0, 0, 0, 0, wfc->hWndParent, NULL, wfc->hInstance, NULL); - SetWindowLongPtr(wfc->hwnd, GWLP_USERDATA, (LONG_PTR) wfc); + SetWindowLongPtr(wfc->hwnd, GWLP_USERDATA, (LONG_PTR) wfc); } wf_resize_window(wfc); @@ -411,6 +413,11 @@ BOOL wf_post_connect(freerdp* instance) BitBlt(wfc->primary->hdc, 0, 0, wfc->width, wfc->height, NULL, 0, 0, BLACKNESS); wfc->drawing = wfc->primary; + EventArgsInit(&e, "wfreerdp"); + e.embed = FALSE; + e.handle = (void*) wfc->hwnd; + PubSub_OnEmbedWindow(context->pubSub, context, &e); + ShowWindow(wfc->hwnd, SW_SHOWNORMAL); UpdateWindow(wfc->hwnd); @@ -767,6 +774,8 @@ int freerdp_client_focus_out(wfContext* wfc) int freerdp_client_set_window_size(wfContext* wfc, int width, int height) { + fprintf(stderr, "freerdp_client_set_window_size %d, %d", width, height); + if ((width != wfc->client_width) || (height != wfc->client_height)) { PostThreadMessage(wfc->mainThreadId, WM_SIZE, SIZE_RESTORED, ((UINT) height << 16) | (UINT) width); diff --git a/client/Windows/wf_interface.h b/client/Windows/wf_interface.h index 028e1a853..de83a55e3 100644 --- a/client/Windows/wf_interface.h +++ b/client/Windows/wf_interface.h @@ -138,6 +138,8 @@ typedef struct wf_context wfContext; */ FREERDP_API int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints); +FREERDP_API int freerdp_client_set_window_size(wfContext* wfc, int width, int height); + #ifdef __cplusplus }