From 5350d8e7c61e4f4dc63d71c3d82cd165abd55e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Moreau?= Date: Thu, 5 Nov 2015 11:57:47 -0500 Subject: [PATCH] mfreerdp: fix dynamic desktop resize --- client/Mac/MRDPView.m | 14 ++++++++++ client/Mac/cli/AppDelegate.m | 53 +++++++++++++++++++++++------------- 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/client/Mac/MRDPView.m b/client/Mac/MRDPView.m index fb8f120ed..f2d3fc9dd 100644 --- a/client/Mac/MRDPView.m +++ b/client/Mac/MRDPView.m @@ -1267,6 +1267,7 @@ BOOL mac_end_paint(rdpContext* context) BOOL mac_desktop_resize(rdpContext* context) { + ResizeWindowEventArgs e; mfContext* mfc = (mfContext*) context; MRDPView* view = (MRDPView*) mfc->view; rdpSettings* settings = context->settings; @@ -1288,8 +1289,21 @@ BOOL mac_desktop_resize(rdpContext* context) return FALSE; view->bitmap_context = mac_create_bitmap_context(context); + if (!view->bitmap_context) return FALSE; + + mfc->client_width = mfc->width; + mfc->client_height = mfc->height; + + [view setFrameSize:NSMakeSize(mfc->width, mfc->height)]; + + EventArgsInit(&e, "mfreerdp"); + e.width = settings->DesktopWidth; + e.height = settings->DesktopHeight; + + PubSub_OnResizeWindow(context->pubSub, context, &e); + return TRUE; } diff --git a/client/Mac/cli/AppDelegate.m b/client/Mac/cli/AppDelegate.m index d1020beab..83061d3f3 100644 --- a/client/Mac/cli/AppDelegate.m +++ b/client/Mac/cli/AppDelegate.m @@ -13,9 +13,10 @@ #import 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); +void AppDelegate_EmbedWindowEventHandler(void* context, EmbedWindowEventArgs* e); +void AppDelegate_ResizeWindowEventHandler(void* context, ResizeWindowEventArgs* e); void mac_set_view_size(rdpContext* context, MRDPView* view); @implementation AppDelegate @@ -52,6 +53,7 @@ void mac_set_view_size(rdpContext* context, MRDPView* view); PubSub_SubscribeConnectionResult(context->pubSub, AppDelegate_ConnectionResultEventHandler); PubSub_SubscribeErrorInfo(context->pubSub, AppDelegate_ErrorInfoEventHandler); PubSub_SubscribeEmbedWindow(context->pubSub, AppDelegate_EmbedWindowEventHandler); + PubSub_SubscribeResizeWindow(context->pubSub, AppDelegate_ResizeWindowEventHandler); freerdp_client_start(context); } @@ -171,24 +173,6 @@ void mac_set_view_size(rdpContext* context, MRDPView* view); @end -void AppDelegate_EmbedWindowEventHandler(void* ctx, EmbedWindowEventArgs* e) -{ - rdpContext* context = (rdpContext*) ctx; - - if (_singleDelegate) - { - mfContext* mfc = (mfContext*) context; - _singleDelegate->mrdpView = mfc->view; - - if (_singleDelegate->window) - { - [[_singleDelegate->window contentView] addSubview:mfc->view]; - } - - mac_set_view_size(context, mfc->view); - } -} - /** ********************************************************************* * On connection error, display message and quit application ***********************************************************************/ @@ -232,6 +216,37 @@ void AppDelegate_ErrorInfoEventHandler(void* ctx, ErrorInfoEventArgs* e) } } +void AppDelegate_EmbedWindowEventHandler(void* ctx, EmbedWindowEventArgs* e) +{ + rdpContext* context = (rdpContext*) ctx; + + if (_singleDelegate) + { + mfContext* mfc = (mfContext*) context; + _singleDelegate->mrdpView = mfc->view; + + if (_singleDelegate->window) + { + [[_singleDelegate->window contentView] addSubview:mfc->view]; + } + + mac_set_view_size(context, mfc->view); + } +} + +void AppDelegate_ResizeWindowEventHandler(void* ctx, ResizeWindowEventArgs* e) +{ + rdpContext* context = (rdpContext*) ctx; + + fprintf(stderr, "ResizeWindowEventHandler: %d %d\n", e->width, e->height); + + if (_singleDelegate) + { + mfContext* mfc = (mfContext*) context; + mac_set_view_size(context, mfc->view); + } +} + void mac_set_view_size(rdpContext* context, MRDPView* view) { // set client area to specified dimensions