From 7641710f604e019d21b19258b592c7c08dfa41de Mon Sep 17 00:00:00 2001 From: akallabeth Date: Wed, 19 Jan 2022 09:27:39 +0100 Subject: [PATCH] Use a client/common context component * Allows moving common client code from specific client to a generic client/common implementation --- client/Android/android_freerdp.c | 34 ++++----- client/Android/android_freerdp.h | 2 +- client/Mac/MRDPView.m | 40 ++++++++--- client/Mac/cli/AppDelegate.m | 21 ++++-- client/Mac/mf_client.m | 24 +++++-- client/Mac/mfreerdp.h | 3 +- client/Sample/tf_channels.c | 6 +- client/Sample/tf_freerdp.h | 2 +- client/Wayland/wlf_channels.c | 26 ++++--- client/Wayland/wlf_cliprdr.c | 8 ++- client/Wayland/wlf_disp.c | 64 ++++++++++++----- client/Wayland/wlfreerdp.c | 14 ++-- client/Wayland/wlfreerdp.h | 2 +- client/Windows/wf_channels.c | 34 ++++++--- client/Windows/wf_client.c | 48 +++++++------ client/Windows/wf_client.h | 3 +- client/Windows/wf_event.c | 47 ++++++++----- client/Windows/wf_floatbar.c | 2 +- client/Windows/wf_gdi.c | 22 +++--- client/Windows/wf_graphics.c | 2 +- client/Windows/wf_rail.c | 2 +- client/X11/xf_channels.c | 17 ++--- client/X11/xf_client.c | 117 ++++++++++++++++++++++++------- client/X11/xf_cliprdr.c | 8 ++- client/X11/xf_disp.c | 72 +++++++++++++------ client/X11/xf_event.c | 86 +++++++++++++++++------ client/X11/xf_floatbar.c | 4 +- client/X11/xf_gdi.c | 23 ++++-- client/X11/xf_gfx.c | 43 ++++++++++-- client/X11/xf_graphics.c | 7 +- client/X11/xf_input.c | 23 ++++-- client/X11/xf_keyboard.c | 49 +++++++++---- client/X11/xf_monitor.c | 12 +++- client/X11/xf_rail.c | 34 +++++++-- client/X11/xf_video.c | 12 +++- client/X11/xf_window.c | 58 ++++++++++----- client/X11/xfreerdp.h | 3 +- include/freerdp/client.h | 4 +- server/shadow/Win/win_rdp.c | 2 +- server/shadow/Win/win_rdp.h | 3 +- server/shadow/Win/win_shadow.c | 10 ++- 41 files changed, 696 insertions(+), 297 deletions(-) diff --git a/client/Android/android_freerdp.c b/client/Android/android_freerdp.c index fc6113a66..ed8812d00 100644 --- a/client/Android/android_freerdp.c +++ b/client/Android/android_freerdp.c @@ -71,19 +71,20 @@ static void android_OnChannelConnectedEventHandler(void* context, } afc = (androidContext*)context; - settings = afc->rdpCtx.settings; + settings = afc->common.context.settings; if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0) { if (settings->SoftwareGdi) { - gdi_graphics_pipeline_init(afc->rdpCtx.gdi, (RdpgfxClientContext*)e->pInterface); - } - else - { - WLog_WARN(TAG, "GFX without software GDI requested. " - " This is not supported, add /gdi:sw"); + gdi_graphics_pipeline_init(afc->common.context.gdi, + (RdpgfxClientContext*)e->pInterface); } + else + { + WLog_WARN(TAG, "GFX without software GDI requested. " + " This is not supported, add /gdi:sw"); + } } else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0) { @@ -104,19 +105,20 @@ static void android_OnChannelDisconnectedEventHandler(void* context, } afc = (androidContext*)context; - settings = afc->rdpCtx.settings; + settings = afc->common.context.settings; if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0) { if (settings->SoftwareGdi) { - gdi_graphics_pipeline_uninit(afc->rdpCtx.gdi, (RdpgfxClientContext*)e->pInterface); - } - else - { - WLog_WARN(TAG, "GFX without software GDI requested. " - " This is not supported, add /gdi:sw"); + gdi_graphics_pipeline_uninit(afc->common.context.gdi, + (RdpgfxClientContext*)e->pInterface); } + else + { + WLog_WARN(TAG, "GFX without software GDI requested. " + " This is not supported, add /gdi:sw"); + } } else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0) { @@ -153,7 +155,7 @@ static BOOL android_end_paint(rdpContext* context) if (!gdi || !gdi->primary || !gdi->primary->hdc) return FALSE; - hwnd = ctx->rdpCtx.gdi->primary->hdc->hwnd; + hwnd = ctx->common.context.gdi->primary->hdc->hwnd; if (!hwnd) return FALSE; @@ -528,7 +530,7 @@ static int android_freerdp_run(freerdp* instance) count += tmp; status = WaitForMultipleObjects(count, handles, FALSE, INFINITE); - if ((status == WAIT_FAILED)) + if (status == WAIT_FAILED) { WLog_ERR(TAG, "WaitForMultipleObjects failed with %" PRIu32 " [%08lX]", status, GetLastError()); diff --git a/client/Android/android_freerdp.h b/client/Android/android_freerdp.h index aad308b20..9f5157a0b 100644 --- a/client/Android/android_freerdp.h +++ b/client/Android/android_freerdp.h @@ -23,7 +23,7 @@ typedef struct { - rdpContext rdpCtx; + rdpClientContext common; ANDROID_EVENT_QUEUE* event_queue; HANDLE thread; diff --git a/client/Mac/MRDPView.m b/client/Mac/MRDPView.m index fda7b80a8..87fab0318 100644 --- a/client/Mac/MRDPView.m +++ b/client/Mac/MRDPView.m @@ -98,7 +98,7 @@ static DWORD WINAPI mac_client_thread(void *param); mfc->client_height = instance->settings->DesktopHeight; mfc->client_width = instance->settings->DesktopWidth; - if (!(mfc->thread = + if (!(mfc->common.thread = CreateThread(NULL, 0, mac_client_thread, (void *)context, 0, &mfc->mainThreadId))) { WLog_ERR(TAG, "failed to create client thread"); @@ -142,7 +142,7 @@ DWORD WINAPI mac_client_thread(void *param) { int status; DWORD rc; - HANDLE events[16]; + HANDLE events[16] = { 0 }; HANDLE inputEvent; HANDLE inputThread = NULL; DWORD nCount; @@ -807,6 +807,8 @@ DWORD fixKeyCode(DWORD keyCode, unichar keyChar, enum APPLE_KEYBOARD_TYPE type) - (void)setScrollOffset:(int)xOffset y:(int)yOffset w:(int)width h:(int)height { + WINPR_ASSERT(mfc); + mfc->yCurrentScroll = yOffset; mfc->xCurrentScroll = xOffset; mfc->client_height = height; @@ -815,8 +817,14 @@ DWORD fixKeyCode(DWORD keyCode, unichar keyChar, enum APPLE_KEYBOARD_TYPE type) static void mac_OnChannelConnectedEventHandler(void *context, const ChannelConnectedEventArgs *e) { + rdpSettings *settings; mfContext *mfc = (mfContext *)context; - rdpSettings *settings = mfc->context.settings; + + WINPR_ASSERT(mfc); + WINPR_ASSERT(e); + + settings = mfc->common.context.settings; + WINPR_ASSERT(settings); if (strcmp(e->name, RDPEI_DVC_CHANNEL_NAME) == 0) { @@ -824,7 +832,8 @@ static void mac_OnChannelConnectedEventHandler(void *context, const ChannelConne else if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0) { if (settings->SoftwareGdi) - gdi_graphics_pipeline_init(mfc->context.gdi, (RdpgfxClientContext *)e->pInterface); + gdi_graphics_pipeline_init(mfc->common.context.gdi, + (RdpgfxClientContext *)e->pInterface); } else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0) { @@ -838,8 +847,14 @@ static void mac_OnChannelConnectedEventHandler(void *context, const ChannelConne static void mac_OnChannelDisconnectedEventHandler(void *context, const ChannelDisconnectedEventArgs *e) { + rdpSettings *settings; mfContext *mfc = (mfContext *)context; - rdpSettings *settings = mfc->context.settings; + + WINPR_ASSERT(mfc); + WINPR_ASSERT(e); + + settings = mfc->common.context.settings; + WINPR_ASSERT(settings); if (strcmp(e->name, RDPEI_DVC_CHANNEL_NAME) == 0) { @@ -847,7 +862,8 @@ static void mac_OnChannelDisconnectedEventHandler(void *context, else if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0) { if (settings->SoftwareGdi) - gdi_graphics_pipeline_uninit(mfc->context.gdi, (RdpgfxClientContext *)e->pInterface); + gdi_graphics_pipeline_uninit(mfc->common.context.gdi, + (RdpgfxClientContext *)e->pInterface); } else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0) { @@ -861,10 +877,16 @@ static void mac_OnChannelDisconnectedEventHandler(void *context, BOOL mac_pre_connect(freerdp *instance) { rdpSettings *settings; + + WINPR_ASSERT(instance); + WINPR_ASSERT(instance->update); + instance->update->BeginPaint = mac_begin_paint; instance->update->EndPaint = mac_end_paint; instance->update->DesktopResize = mac_desktop_resize; + settings = instance->settings; + WINPR_ASSERT(settings); if (!settings->ServerHostname) { @@ -1284,8 +1306,8 @@ BOOL mac_end_paint(rdpContext *context) ww = mfc->client_width; wh = mfc->client_height; - dw = mfc->context.settings->DesktopWidth; - dh = mfc->context.settings->DesktopHeight; + dw = mfc->common.context.settings->DesktopWidth; + dh = mfc->common.context.settings->DesktopHeight; if ((!context) || (!context->gdi)) return FALSE; @@ -1299,7 +1321,7 @@ BOOL mac_end_paint(rdpContext *context) newDrawRect.size.width = invalid->w; newDrawRect.size.height = invalid->h; - if (mfc->context.settings->SmartSizing && (ww != dw || wh != dh)) + if (mfc->common.context.settings->SmartSizing && (ww != dw || wh != dh)) { newDrawRect.origin.y = newDrawRect.origin.y * wh / dh - 1; newDrawRect.size.height = newDrawRect.size.height * wh / dh + 1; diff --git a/client/Mac/cli/AppDelegate.m b/client/Mac/cli/AppDelegate.m index a4904542f..a9625975f 100644 --- a/client/Mac/cli/AppDelegate.m +++ b/client/Mac/cli/AppDelegate.m @@ -10,6 +10,8 @@ #import "MacFreeRDP/mfreerdp.h" #import "MacFreeRDP/mf_client.h" #import "MacFreeRDP/MRDPView.h" + +#import #import static AppDelegate *_singleDelegate = nil; @@ -38,17 +40,22 @@ void mac_set_view_size(rdpContext *context, MRDPView *view); [self CreateContext]; status = [self ParseCommandLineArguments]; mfc = (mfContext *)context; + WINPR_ASSERT(mfc); + mfc->view = (void *)mrdpView; if (status == 0) { NSScreen *screen = [[NSScreen screens] objectAtIndex:0]; NSRect screenFrame = [screen frame]; + rdpSettings *settings = context->settings; - if (context->instance->settings->Fullscreen) + WINPR_ASSERT(settings); + + if (settings->Fullscreen) { - context->instance->settings->DesktopWidth = screenFrame.size.width; - context->instance->settings->DesktopHeight = screenFrame.size.height; + settings->DesktopWidth = screenFrame.size.width; + settings->DesktopHeight = screenFrame.size.height; } PubSub_SubscribeConnectionResult(context->pubSub, AppDelegate_ConnectionResultEventHandler); @@ -58,17 +65,17 @@ void mac_set_view_size(rdpContext *context, MRDPView *view); freerdp_client_start(context); NSString *winTitle; - if (mfc->context.settings->WindowTitle && mfc->context.settings->WindowTitle[0]) + if (settings->WindowTitle && settings->WindowTitle[0]) { - winTitle = [[NSString alloc] initWithCString:mfc->context.settings->WindowTitle]; + winTitle = [[NSString alloc] initWithCString:settings->WindowTitle]; } else { winTitle = [[NSString alloc] initWithFormat:@"%@:%u", - [NSString stringWithCString:mfc->context.settings->ServerHostname + [NSString stringWithCString:settings->ServerHostname encoding:NSUTF8StringEncoding], - mfc -> context.settings->ServerPort]; + settings -> ServerPort]; } [window setTitle:winTitle]; diff --git a/client/Mac/mf_client.m b/client/Mac/mf_client.m index 5d140e7a9..43a4dfd97 100644 --- a/client/Mac/mf_client.m +++ b/client/Mac/mf_client.m @@ -22,6 +22,9 @@ #endif #include "mfreerdp.h" + +#include + #include #include #include @@ -65,12 +68,12 @@ static int mfreerdp_client_stop(rdpContext *context) mfContext *mfc = (mfContext *)context; freerdp_abort_connect(context->instance); - if (mfc->thread) + if (mfc->common.thread) { SetEvent(mfc->stopEvent); - WaitForSingleObject(mfc->thread, INFINITE); - CloseHandle(mfc->thread); - mfc->thread = NULL; + WaitForSingleObject(mfc->common.thread, INFINITE); + CloseHandle(mfc->common.thread); + mfc->common.thread = NULL; } if (mfc->view_ownership) @@ -88,7 +91,12 @@ static BOOL mfreerdp_client_new(freerdp *instance, rdpContext *context) { mfContext *mfc; rdpSettings *settings; + + WINPR_ASSERT(instance); + mfc = (mfContext *)instance->context; + WINPR_ASSERT(mfc); + mfc->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); context->instance->PreConnect = mac_pre_connect; context->instance->PostConnect = mac_post_connect; @@ -121,10 +129,10 @@ static void mf_scale_mouse_coordinates(mfContext *mfc, UINT16 *px, UINT16 *py) UINT16 y = *py; UINT32 ww = mfc->client_width; UINT32 wh = mfc->client_height; - UINT32 dw = mfc->context.settings->DesktopWidth; - UINT32 dh = mfc->context.settings->DesktopHeight; + UINT32 dw = mfc->common.context.settings->DesktopWidth; + UINT32 dh = mfc->common.context.settings->DesktopHeight; - if (!mfc->context.settings->SmartSizing || ((ww == dw) && (wh == dh))) + if (!mfc->common.context.settings->SmartSizing || ((ww == dw) && (wh == dh))) { y = y + mfc->yCurrentScroll; x = x + mfc->xCurrentScroll; @@ -205,6 +213,8 @@ void mf_press_mouse_button(void *context, rdpInput *input, int button, int x, in int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS *pEntryPoints) { + WINPR_ASSERT(pEntryPoints); + pEntryPoints->Version = 1; pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1); pEntryPoints->GlobalInit = mfreerdp_client_global_init; diff --git a/client/Mac/mfreerdp.h b/client/Mac/mfreerdp.h index a5721689e..857e6fe1c 100644 --- a/client/Mac/mfreerdp.h +++ b/client/Mac/mfreerdp.h @@ -29,8 +29,7 @@ typedef struct { - rdpContext context; - DEFINE_RDP_CLIENT_COMMON(); + rdpClientContext common; void* view; BOOL view_ownership; diff --git a/client/Sample/tf_channels.c b/client/Sample/tf_channels.c index 53a145273..ea9e691cd 100644 --- a/client/Sample/tf_channels.c +++ b/client/Sample/tf_channels.c @@ -79,6 +79,7 @@ void tf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEven WINPR_ASSERT(tf); WINPR_ASSERT(e); + if (strcmp(e->name, RDPEI_DVC_CHANNEL_NAME) == 0) { tf->rdpei = (RdpeiClientContext*)e->pInterface; @@ -86,7 +87,7 @@ void tf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEven else if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0) { RdpgfxClientContext* gfx = (RdpgfxClientContext*)e->pInterface; - gdi_graphics_pipeline_init(tf->context.gdi, gfx); + gdi_graphics_pipeline_init(tf->common.context.gdi, gfx); } else if (strcmp(e->name, RAIL_SVC_CHANNEL_NAME) == 0) { @@ -109,13 +110,14 @@ void tf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnect WINPR_ASSERT(tf); WINPR_ASSERT(e); + if (strcmp(e->name, RDPEI_DVC_CHANNEL_NAME) == 0) { tf->rdpei = NULL; } else if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0) { - gdi_graphics_pipeline_uninit(tf->context.gdi, (RdpgfxClientContext*)e->pInterface); + gdi_graphics_pipeline_uninit(tf->common.context.gdi, (RdpgfxClientContext*)e->pInterface); } else if (strcmp(e->name, RAIL_SVC_CHANNEL_NAME) == 0) { diff --git a/client/Sample/tf_freerdp.h b/client/Sample/tf_freerdp.h index 585d0b25b..41c79299f 100644 --- a/client/Sample/tf_freerdp.h +++ b/client/Sample/tf_freerdp.h @@ -30,7 +30,7 @@ typedef struct { - rdpContext context; + rdpClientContext common; /* Channels */ RdpeiClientContext* rdpei; diff --git a/client/Wayland/wlf_channels.c b/client/Wayland/wlf_channels.c index a0b86565e..6fa2b6a2b 100644 --- a/client/Wayland/wlf_channels.c +++ b/client/Wayland/wlf_channels.c @@ -64,7 +64,9 @@ wlf_encomsp_participant_created(EncomspClientContext* context, return ERROR_INVALID_PARAMETER; wlf = (wlfContext*)context->custom; - settings = wlf->context.settings; + WINPR_ASSERT(wlf); + + settings = wlf->common.context.settings; if (!settings) return ERROR_INVALID_PARAMETER; @@ -103,13 +105,16 @@ void wlf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEve { wlfContext* wlf = (wlfContext*)context; + WINPR_ASSERT(wlf); + WINPR_ASSERT(e); + if (strcmp(e->name, RDPEI_DVC_CHANNEL_NAME) == 0) { wlf->rdpei = (RdpeiClientContext*)e->pInterface; } else if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0) { - gdi_graphics_pipeline_init(wlf->context.gdi, (RdpgfxClientContext*)e->pInterface); + gdi_graphics_pipeline_init(wlf->common.context.gdi, (RdpgfxClientContext*)e->pInterface); } else if (strcmp(e->name, RAIL_SVC_CHANNEL_NAME) == 0) { @@ -128,15 +133,15 @@ void wlf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEve } else if (strcmp(e->name, GEOMETRY_DVC_CHANNEL_NAME) == 0) { - gdi_video_geometry_init(wlf->context.gdi, (GeometryClientContext*)e->pInterface); + gdi_video_geometry_init(wlf->common.context.gdi, (GeometryClientContext*)e->pInterface); } else if (strcmp(e->name, VIDEO_CONTROL_DVC_CHANNEL_NAME) == 0) { - gdi_video_control_init(wlf->context.gdi, (VideoClientContext*)e->pInterface); + gdi_video_control_init(wlf->common.context.gdi, (VideoClientContext*)e->pInterface); } else if (strcmp(e->name, VIDEO_DATA_DVC_CHANNEL_NAME) == 0) { - gdi_video_data_init(wlf->context.gdi, (VideoClientContext*)e->pInterface); + gdi_video_data_init(wlf->common.context.gdi, (VideoClientContext*)e->pInterface); } } @@ -144,13 +149,16 @@ void wlf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnec { wlfContext* wlf = (wlfContext*)context; + WINPR_ASSERT(wlf); + WINPR_ASSERT(e); + if (strcmp(e->name, RDPEI_DVC_CHANNEL_NAME) == 0) { wlf->rdpei = NULL; } else if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0) { - gdi_graphics_pipeline_uninit(wlf->context.gdi, (RdpgfxClientContext*)e->pInterface); + gdi_graphics_pipeline_uninit(wlf->common.context.gdi, (RdpgfxClientContext*)e->pInterface); } else if (strcmp(e->name, RAIL_SVC_CHANNEL_NAME) == 0) { @@ -169,14 +177,14 @@ void wlf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnec } else if (strcmp(e->name, GEOMETRY_DVC_CHANNEL_NAME) == 0) { - gdi_video_geometry_uninit(wlf->context.gdi, (GeometryClientContext*)e->pInterface); + gdi_video_geometry_uninit(wlf->common.context.gdi, (GeometryClientContext*)e->pInterface); } else if (strcmp(e->name, VIDEO_CONTROL_DVC_CHANNEL_NAME) == 0) { - gdi_video_control_uninit(wlf->context.gdi, (VideoClientContext*)e->pInterface); + gdi_video_control_uninit(wlf->common.context.gdi, (VideoClientContext*)e->pInterface); } else if (strcmp(e->name, VIDEO_DATA_DVC_CHANNEL_NAME) == 0) { - gdi_video_data_uninit(wlf->context.gdi, (VideoClientContext*)e->pInterface); + gdi_video_data_uninit(wlf->common.context.gdi, (VideoClientContext*)e->pInterface); } } diff --git a/client/Wayland/wlf_cliprdr.c b/client/Wayland/wlf_cliprdr.c index 51185897c..dea865d5b 100644 --- a/client/Wayland/wlf_cliprdr.c +++ b/client/Wayland/wlf_cliprdr.c @@ -889,14 +889,18 @@ static UINT wlf_cliprdr_clipboard_file_range_failure(wClipboardDelegate* delegat wfClipboard* wlf_clipboard_new(wlfContext* wfc) { rdpChannels* channels; - wfClipboard* clipboard = (wfClipboard*)calloc(1, sizeof(wfClipboard)); + wfClipboard* clipboard; + + WINPR_ASSERT(wfc); + + clipboard = (wfClipboard*)calloc(1, sizeof(wfClipboard)); if (!clipboard) goto fail; InitializeCriticalSection(&clipboard->lock); clipboard->wfc = wfc; - channels = wfc->context.channels; + channels = wfc->common.context.channels; clipboard->log = WLog_Get(TAG); clipboard->channels = channels; clipboard->system = ClipboardCreate(); diff --git a/client/Wayland/wlf_disp.c b/client/Wayland/wlf_disp.c index 0228c1125..b0e33cde2 100644 --- a/client/Wayland/wlf_disp.c +++ b/client/Wayland/wlf_disp.c @@ -48,7 +48,13 @@ static UINT wlf_disp_sendLayout(DispClientContext* disp, const rdpMonitor* monit static BOOL wlf_disp_settings_changed(wlfDispContext* wlfDisp) { - rdpSettings* settings = wlfDisp->wlc->context.settings; + rdpSettings* settings; + + WINPR_ASSERT(wlfDisp); + WINPR_ASSERT(wlfDisp->wlc); + + settings = wlfDisp->wlc->common.context.settings; + WINPR_ASSERT(settings); if (wlfDisp->lastSentWidth != wlfDisp->targetWidth) return TRUE; @@ -73,7 +79,14 @@ static BOOL wlf_disp_settings_changed(wlfDispContext* wlfDisp) static BOOL wlf_update_last_sent(wlfDispContext* wlfDisp) { - rdpSettings* settings = wlfDisp->wlc->context.settings; + rdpSettings* settings; + + WINPR_ASSERT(wlfDisp); + WINPR_ASSERT(wlfDisp->wlc); + + settings = wlfDisp->wlc->common.context.settings; + WINPR_ASSERT(settings); + wlfDisp->lastSentWidth = wlfDisp->targetWidth; wlfDisp->lastSentHeight = wlfDisp->targetHeight; wlfDisp->lastSentDesktopOrientation = settings->DesktopOrientation; @@ -93,7 +106,7 @@ static BOOL wlf_disp_sendResize(wlfDispContext* wlfDisp) return FALSE; wlc = wlfDisp->wlc; - settings = wlc->context.settings; + settings = wlc->common.context.settings; if (!settings) return FALSE; @@ -157,12 +170,12 @@ static BOOL wlf_disp_check_context(void* context, wlfContext** ppwlc, wlfDispCon if (!(wlc->disp)) return FALSE; - if (!wlc->context.settings) + if (!wlc->common.context.settings) return FALSE; *ppwlc = wlc; *ppwlfDisp = wlc->disp; - *ppSettings = wlc->context.settings; + *ppSettings = wlc->common.context.settings; return TRUE; } @@ -226,21 +239,25 @@ static void wlf_disp_OnTimer(void* context, const TimerEventArgs* e) wlfDispContext* wlf_disp_new(wlfContext* wlc) { wlfDispContext* ret; + wPubSub* pubSub; + rdpSettings* settings; - if (!wlc || !wlc->context.settings || !wlc->context.pubSub) + if (!wlc || !wlc->common.context.settings || !wlc->common.context.pubSub) return NULL; + settings = wlc->common.context.settings; + pubSub = wlc->common.context.pubSub; ret = calloc(1, sizeof(wlfDispContext)); if (!ret) return NULL; ret->wlc = wlc; - ret->lastSentWidth = ret->targetWidth = wlc->context.settings->DesktopWidth; - ret->lastSentHeight = ret->targetHeight = wlc->context.settings->DesktopHeight; - PubSub_SubscribeActivated(wlc->context.pubSub, wlf_disp_OnActivated); - PubSub_SubscribeGraphicsReset(wlc->context.pubSub, wlf_disp_OnGraphicsReset); - PubSub_SubscribeTimer(wlc->context.pubSub, wlf_disp_OnTimer); + ret->lastSentWidth = ret->targetWidth = settings->DesktopWidth; + ret->lastSentHeight = ret->targetHeight = settings->DesktopHeight; + PubSub_SubscribeActivated(pubSub, wlf_disp_OnActivated); + PubSub_SubscribeGraphicsReset(pubSub, wlf_disp_OnGraphicsReset); + PubSub_SubscribeTimer(pubSub, wlf_disp_OnTimer); return ret; } @@ -251,9 +268,10 @@ void wlf_disp_free(wlfDispContext* disp) if (disp->wlc) { - PubSub_UnsubscribeActivated(disp->wlc->context.pubSub, wlf_disp_OnActivated); - PubSub_UnsubscribeGraphicsReset(disp->wlc->context.pubSub, wlf_disp_OnGraphicsReset); - PubSub_UnsubscribeTimer(disp->wlc->context.pubSub, wlf_disp_OnTimer); + wPubSub* pubSub = disp->wlc->common.context.pubSub; + PubSub_UnsubscribeActivated(pubSub, wlf_disp_OnActivated); + PubSub_UnsubscribeGraphicsReset(pubSub, wlf_disp_OnGraphicsReset); + PubSub_UnsubscribeTimer(pubSub, wlf_disp_OnTimer); } free(disp); @@ -275,7 +293,7 @@ UINT wlf_disp_sendLayout(DispClientContext* disp, const rdpMonitor* monitors, si WINPR_ASSERT(wlfDisp); WINPR_ASSERT(wlfDisp->wlc); - settings = wlfDisp->wlc->context.settings; + settings = wlfDisp->wlc->common.context.settings; WINPR_ASSERT(settings); layouts = calloc(nmonitors, sizeof(DISPLAY_CONTROL_MONITOR_LAYOUT)); @@ -347,8 +365,18 @@ static UINT wlf_DisplayControlCaps(DispClientContext* disp, UINT32 maxNumMonitor UINT32 maxMonitorAreaFactorA, UINT32 maxMonitorAreaFactorB) { /* we're called only if dynamic resolution update is activated */ - wlfDispContext* wlfDisp = (wlfDispContext*)disp->custom; - rdpSettings* settings = wlfDisp->wlc->context.settings; + wlfDispContext* wlfDisp; + rdpSettings* settings; + + WINPR_ASSERT(disp); + + wlfDisp = (wlfDispContext*)disp->custom; + WINPR_ASSERT(wlfDisp); + WINPR_ASSERT(wlfDisp->wlc); + + settings = wlfDisp->wlc->common.context.settings; + WINPR_ASSERT(settings); + WLog_DBG(TAG, "DisplayControlCapsPdu: MaxNumMonitors: %" PRIu32 " MaxMonitorAreaFactorA: %" PRIu32 " MaxMonitorAreaFactorB: %" PRIu32 "", @@ -369,7 +397,7 @@ BOOL wlf_disp_init(wlfDispContext* wlfDisp, DispClientContext* disp) if (!wlfDisp || !wlfDisp->wlc || !disp) return FALSE; - settings = wlfDisp->wlc->context.settings; + settings = wlfDisp->wlc->common.context.settings; if (!settings) return FALSE; diff --git a/client/Wayland/wlfreerdp.c b/client/Wayland/wlfreerdp.c index d76d13988..a7c017f95 100644 --- a/client/Wayland/wlfreerdp.c +++ b/client/Wayland/wlfreerdp.c @@ -74,7 +74,7 @@ static BOOL wl_update_buffer(wlfContext* context_w, INT32 ix, INT32 iy, INT32 iw if (!data || (rc != UWAC_SUCCESS)) goto fail; - gdi = context_w->context.gdi; + gdi = context_w->common.context.gdi; if (!gdi) goto fail; @@ -93,13 +93,13 @@ static BOOL wl_update_buffer(wlfContext* context_w, INT32 ix, INT32 iy, INT32 iw if (!wlf_copy_image(gdi->primary_buffer, gdi->stride, gdi->width, gdi->height, data, stride, geometry.width, geometry.height, &area, - context_w->context.settings->SmartSizing)) + context_w->common.context.settings->SmartSizing)) goto fail; - if (!wlf_scale_coordinates(&context_w->context, &x, &y, FALSE)) + if (!wlf_scale_coordinates(&context_w->common.context, &x, &y, FALSE)) goto fail; - if (!wlf_scale_coordinates(&context_w->context, &w, &h, FALSE)) + if (!wlf_scale_coordinates(&context_w->common.context, &w, &h, FALSE)) goto fail; if (UwacWindowAddDamage(context_w->window, x, y, w, h) != UWAC_SUCCESS) @@ -147,10 +147,10 @@ static BOOL wl_refresh_display(wlfContext* context) { rdpGdi* gdi; - if (!context || !context->context.gdi) + if (!context || !context->common.context.gdi) return FALSE; - gdi = context->context.gdi; + gdi = context->common.context.gdi; return wl_update_buffer(context, 0, 0, gdi->width, gdi->height); } @@ -553,7 +553,7 @@ static int wlfreerdp_run(freerdp* instance) if ((status != WAIT_TIMEOUT) && (status == WAIT_OBJECT_0)) { timerEvent.now = GetTickCount64(); - PubSub_OnTimer(context->context.pubSub, context, &timerEvent); + PubSub_OnTimer(context->common.context.pubSub, context, &timerEvent); } } diff --git a/client/Wayland/wlfreerdp.h b/client/Wayland/wlfreerdp.h index b46d7516a..e4e456aec 100644 --- a/client/Wayland/wlfreerdp.h +++ b/client/Wayland/wlfreerdp.h @@ -43,7 +43,7 @@ typedef struct typedef struct { - rdpContext context; + rdpClientContext common; UwacDisplay* display; HANDLE displayHandle; diff --git a/client/Windows/wf_channels.c b/client/Windows/wf_channels.c index b83d92a90..d1dd1648c 100644 --- a/client/Windows/wf_channels.c +++ b/client/Windows/wf_channels.c @@ -20,6 +20,8 @@ #include "config.h" #endif +#include + #include "wf_channels.h" #include "wf_rail.h" @@ -34,7 +36,13 @@ void wf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e) { wfContext* wfc = (wfContext*)context; - rdpSettings* settings = wfc->context.settings; + rdpSettings* settings; + + WINPR_ASSERT(wfc); + WINPR_ASSERT(e); + + settings = wfc->common.context.settings; + WINPR_ASSERT(settings); if (strcmp(e->name, RDPEI_DVC_CHANNEL_NAME) == 0) { @@ -45,7 +53,7 @@ void wf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEven WLog_WARN(TAG, "Channel " RDPGFX_DVC_CHANNEL_NAME " does not support hardware acceleration, using fallback."); - gdi_graphics_pipeline_init(wfc->context.gdi, (RdpgfxClientContext*)e->pInterface); + gdi_graphics_pipeline_init(wfc->common.context.gdi, (RdpgfxClientContext*)e->pInterface); } else if (strcmp(e->name, RAIL_SVC_CHANNEL_NAME) == 0) { @@ -64,29 +72,35 @@ void wf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEven } else if (strcmp(e->name, GEOMETRY_DVC_CHANNEL_NAME) == 0) { - gdi_video_geometry_init(wfc->context.gdi, (GeometryClientContext*)e->pInterface); + gdi_video_geometry_init(wfc->common.context.gdi, (GeometryClientContext*)e->pInterface); } else if (strcmp(e->name, VIDEO_CONTROL_DVC_CHANNEL_NAME) == 0) { - gdi_video_control_init(wfc->context.gdi, (VideoClientContext*)e->pInterface); + gdi_video_control_init(wfc->common.context.gdi, (VideoClientContext*)e->pInterface); } else if (strcmp(e->name, VIDEO_DATA_DVC_CHANNEL_NAME) == 0) { - gdi_video_data_init(wfc->context.gdi, (VideoClientContext*)e->pInterface); + gdi_video_data_init(wfc->common.context.gdi, (VideoClientContext*)e->pInterface); } } void wf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e) { wfContext* wfc = (wfContext*)context; - rdpSettings* settings = wfc->context.settings; + rdpSettings* settings; + + WINPR_ASSERT(wfc); + WINPR_ASSERT(e); + + settings = wfc->common.context.settings; + WINPR_ASSERT(settings); if (strcmp(e->name, RDPEI_DVC_CHANNEL_NAME) == 0) { } else if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0) { - gdi_graphics_pipeline_uninit(wfc->context.gdi, (RdpgfxClientContext*)e->pInterface); + gdi_graphics_pipeline_uninit(wfc->common.context.gdi, (RdpgfxClientContext*)e->pInterface); } else if (strcmp(e->name, RAIL_SVC_CHANNEL_NAME) == 0) { @@ -105,14 +119,14 @@ void wf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnect } else if (strcmp(e->name, GEOMETRY_DVC_CHANNEL_NAME) == 0) { - gdi_video_geometry_uninit(wfc->context.gdi, (GeometryClientContext*)e->pInterface); + gdi_video_geometry_uninit(wfc->common.context.gdi, (GeometryClientContext*)e->pInterface); } else if (strcmp(e->name, VIDEO_CONTROL_DVC_CHANNEL_NAME) == 0) { - gdi_video_control_uninit(wfc->context.gdi, (VideoClientContext*)e->pInterface); + gdi_video_control_uninit(wfc->common.context.gdi, (VideoClientContext*)e->pInterface); } else if (strcmp(e->name, VIDEO_DATA_DVC_CHANNEL_NAME) == 0) { - gdi_video_data_uninit(wfc->context.gdi, (VideoClientContext*)e->pInterface); + gdi_video_data_uninit(wfc->common.context.gdi, (VideoClientContext*)e->pInterface); } } diff --git a/client/Windows/wf_client.c b/client/Windows/wf_client.c index 10691f706..7be01a66b 100644 --- a/client/Windows/wf_client.c +++ b/client/Windows/wf_client.c @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -295,7 +296,7 @@ static void wf_add_system_menu(wfContext* wfc) return; } - if (wfc->context.settings->DynamicResolutionUpdate) + if (wfc->common.context.settings->DynamicResolutionUpdate) { return; } @@ -311,7 +312,7 @@ static void wf_add_system_menu(wfContext* wfc) item_info.dwItemData = (ULONG_PTR)wfc; InsertMenuItem(hMenu, 6, TRUE, &item_info); - if (wfc->context.settings->SmartSizing) + if (wfc->common.context.settings->SmartSizing) { CheckMenuItem(hMenu, SYSCOMMAND_ID_SMARTSIZING, MF_CHECKED); } @@ -488,9 +489,9 @@ static BOOL wf_authenticate_raw(freerdp* instance, const char* title, char** use if (!(*UserName && *Password)) { - if (!wfc->isConsole && wfc->context.settings->CredentialsFromStdin) + if (!wfc->isConsole && wfc->common.context.settings->CredentialsFromStdin) WLog_ERR(TAG, "Flag for stdin read present but stdin is redirected; using GUI"); - if (wfc->isConsole && wfc->context.settings->CredentialsFromStdin) + if (wfc->isConsole && wfc->common.context.settings->CredentialsFromStdin) status = CredUICmdLinePromptForCredentialsA( title, NULL, 0, UserName, CREDUI_MAX_USERNAME_LENGTH + 1, Password, CREDUI_MAX_PASSWORD_LENGTH + 1, &fSave, dwFlags); @@ -1181,13 +1182,19 @@ int freerdp_client_set_window_size(wfContext* wfc, int width, int height) void wf_size_scrollbars(wfContext* wfc, UINT32 client_width, UINT32 client_height) { + const rdpSettings* settings; + WINPR_ASSERT(wfc); + + settings = wfc->common.context.settings; + WINPR_ASSERT(settings); + if (wfc->disablewindowtracking) return; // prevent infinite message loop wfc->disablewindowtracking = TRUE; - if (wfc->context.settings->SmartSizing || wfc->context.settings->DynamicResolutionUpdate) + if (settings->SmartSizing || settings->DynamicResolutionUpdate) { wfc->xCurrentScroll = 0; wfc->yCurrentScroll = 0; @@ -1207,24 +1214,22 @@ void wf_size_scrollbars(wfContext* wfc, UINT32 client_width, UINT32 client_heigh BOOL horiz = wfc->xScrollVisible; BOOL vert = wfc->yScrollVisible; - if (!horiz && client_width < wfc->context.settings->DesktopWidth) + if (!horiz && client_width < settings->DesktopWidth) { horiz = TRUE; } else if (horiz && - client_width >= - wfc->context.settings->DesktopWidth /* - GetSystemMetrics(SM_CXVSCROLL)*/) + client_width >= settings->DesktopWidth /* - GetSystemMetrics(SM_CXVSCROLL)*/) { horiz = FALSE; } - if (!vert && client_height < wfc->context.settings->DesktopHeight) + if (!vert && client_height < settings->DesktopHeight) { vert = TRUE; } else if (vert && - client_height >= - wfc->context.settings->DesktopHeight /* - GetSystemMetrics(SM_CYHSCROLL)*/) + client_height >= settings->DesktopHeight /* - GetSystemMetrics(SM_CYHSCROLL)*/) { vert = FALSE; } @@ -1259,12 +1264,12 @@ void wf_size_scrollbars(wfContext* wfc, UINT32 client_width, UINT32 client_heigh // The horizontal scrolling range is defined by // (bitmap_width) - (client_width). The current horizontal // scroll value remains within the horizontal scrolling range. - wfc->xMaxScroll = MAX(wfc->context.settings->DesktopWidth - client_width, 0); + wfc->xMaxScroll = MAX(settings->DesktopWidth - client_width, 0); wfc->xCurrentScroll = MIN(wfc->xCurrentScroll, wfc->xMaxScroll); si.cbSize = sizeof(si); si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; si.nMin = wfc->xMinScroll; - si.nMax = wfc->context.settings->DesktopWidth; + si.nMax = settings->DesktopWidth; si.nPage = client_width; si.nPos = wfc->xCurrentScroll; SetScrollInfo(wfc->hwnd, SB_HORZ, &si, TRUE); @@ -1275,12 +1280,12 @@ void wf_size_scrollbars(wfContext* wfc, UINT32 client_width, UINT32 client_heigh // The vertical scrolling range is defined by // (bitmap_height) - (client_height). The current vertical // scroll value remains within the vertical scrolling range. - wfc->yMaxScroll = MAX(wfc->context.settings->DesktopHeight - client_height, 0); + wfc->yMaxScroll = MAX(settings->DesktopHeight - client_height, 0); wfc->yCurrentScroll = MIN(wfc->yCurrentScroll, wfc->yMaxScroll); si.cbSize = sizeof(si); si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; si.nMin = wfc->yMinScroll; - si.nMax = wfc->context.settings->DesktopHeight; + si.nMax = settings->DesktopHeight; si.nPage = client_height; si.nPos = wfc->yCurrentScroll; SetScrollInfo(wfc->hwnd, SB_VERT, &si, TRUE); @@ -1396,9 +1401,10 @@ static int wfreerdp_client_start(rdpContext* context) if (!wfc->keyboardThread) return -1; - wfc->thread = CreateThread(NULL, 0, wf_client_thread, (void*)instance, 0, &wfc->mainThreadId); + wfc->common.thread = + CreateThread(NULL, 0, wf_client_thread, (void*)instance, 0, &wfc->mainThreadId); - if (!wfc->thread) + if (!wfc->common.thread) return -1; return 0; @@ -1408,12 +1414,12 @@ static int wfreerdp_client_stop(rdpContext* context) { wfContext* wfc = (wfContext*)context; - if (wfc->thread) + if (wfc->common.thread) { PostThreadMessage(wfc->mainThreadId, WM_QUIT, 0, 0); - WaitForSingleObject(wfc->thread, INFINITE); - CloseHandle(wfc->thread); - wfc->thread = NULL; + WaitForSingleObject(wfc->common.thread, INFINITE); + CloseHandle(wfc->common.thread); + wfc->common.thread = NULL; wfc->mainThreadId = 0; } diff --git a/client/Windows/wf_client.h b/client/Windows/wf_client.h index 49f9c1a0b..d78cb4426 100644 --- a/client/Windows/wf_client.h +++ b/client/Windows/wf_client.h @@ -74,8 +74,7 @@ extern "C" struct wf_context { - rdpContext context; - DEFINE_RDP_CLIENT_COMMON(); + rdpClientContext common; int offset_x; int offset_y; diff --git a/client/Windows/wf_event.c b/client/Windows/wf_event.c index 55286542c..28ff4ffd6 100644 --- a/client/Windows/wf_event.c +++ b/client/Windows/wf_event.c @@ -25,6 +25,7 @@ #include +#include #include #include @@ -88,7 +89,7 @@ LRESULT CALLBACK wf_ll_kbd_proc(int nCode, WPARAM wParam, LPARAM lParam) if (!wfc || !p) return 1; - input = wfc->context.input; + input = wfc->common.context.input; rdp_scancode = MAKE_RDP_SCANCODE((BYTE)p->scanCode, p->flags & LLKHF_EXTENDED); DEBUG_KBD("keydown %d scanCode 0x%08lX flags 0x%08lX vkCode 0x%08lX", (wParam == WM_KEYDOWN), p->scanCode, p->flags, p->vkCode); @@ -167,7 +168,7 @@ void wf_event_focus_in(wfContext* wfc) rdpInput* input; POINT pt; RECT rc; - input = wfc->context.input; + input = wfc->common.context.input; syncFlags = 0; if (GetKeyState(VK_NUMLOCK)) @@ -198,8 +199,13 @@ static BOOL wf_event_process_WM_MOUSEWHEEL(wfContext* wfc, HWND hWnd, UINT Msg, int delta; UINT16 flags = 0; rdpInput* input; + + WINPR_ASSERT(wfc); + + input = wfc->common.context.input; + WINPR_ASSERT(input); + DefWindowProc(hWnd, Msg, wParam, lParam); - input = wfc->context.input; delta = ((signed short)HIWORD(wParam)); /* GET_WHEEL_DELTA_WPARAM(wParam); */ if (horizontal) @@ -220,7 +226,7 @@ static BOOL wf_event_process_WM_MOUSEWHEEL(wfContext* wfc, HWND hWnd, UINT Msg, static void wf_sizing(wfContext* wfc, WPARAM wParam, LPARAM lParam) { - rdpSettings* settings = wfc->context.settings; + rdpSettings* settings = wfc->common.context.settings; // Holding the CTRL key down while resizing the window will force the desktop aspect ratio. LPRECT rect; @@ -262,7 +268,7 @@ static void wf_send_resize(wfContext* wfc) RECT windowRect; int targetWidth = wfc->client_width; int targetHeight = wfc->client_height; - rdpSettings* settings = wfc->context.settings; + rdpSettings* settings = wfc->common.context.settings; if (settings->DynamicResolutionUpdate && wfc->disp != NULL) { @@ -319,8 +325,8 @@ LRESULT CALLBACK wf_event_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam if (wfc != NULL) { - rdpInput* input = wfc->context.input; - rdpSettings* settings = wfc->context.settings; + rdpInput* input = wfc->common.context.input; + rdpSettings* settings = wfc->common.context.settings; switch (Msg) { @@ -336,8 +342,8 @@ LRESULT CALLBACK wf_event_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam break; case WM_GETMINMAXINFO: - if (wfc->context.settings->SmartSizing || - wfc->context.settings->DynamicResolutionUpdate) + if (wfc->common.context.settings->SmartSizing || + wfc->common.context.settings->DynamicResolutionUpdate) { processed = FALSE; } @@ -640,10 +646,11 @@ LRESULT CALLBACK wf_event_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam if (wParam == SYSCOMMAND_ID_SMARTSIZING) { HMENU hMenu = GetSystemMenu(wfc->hwnd, FALSE); - freerdp_settings_set_bool(wfc->context.settings, FreeRDP_SmartSizing, - !wfc->context.settings->SmartSizing); + freerdp_settings_set_bool(wfc->common.context.settings, FreeRDP_SmartSizing, + !wfc->common.context.settings->SmartSizing); CheckMenuItem(hMenu, SYSCOMMAND_ID_SMARTSIZING, - wfc->context.settings->SmartSizing ? MF_CHECKED : MF_UNCHECKED); + wfc->common.context.settings->SmartSizing ? MF_CHECKED + : MF_UNCHECKED); } else { @@ -678,7 +685,7 @@ LRESULT CALLBACK wf_event_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam g_flipping_in = TRUE; g_focus_hWnd = hWnd; - freerdp_set_focus(wfc->context.instance); + freerdp_set_focus(wfc->common.context.instance); break; case WM_KILLFOCUS: @@ -727,7 +734,10 @@ BOOL wf_scale_blt(wfContext* wfc, HDC hdc, int x, int y, int w, int h, HDC hdcSr { rdpSettings* settings; UINT32 ww, wh, dw, dh; - settings = wfc->context.settings; + WINPR_ASSERT(wfc); + + settings = wfc->common.context.settings; + WINPR_ASSERT(settings); if (!wfc->client_width) wfc->client_width = settings->DesktopWidth; @@ -746,7 +756,7 @@ BOOL wf_scale_blt(wfContext* wfc, HDC hdc, int x, int y, int w, int h, HDC hdcSr if (!wh) wh = dh; - if (wfc->fullscreen || !wfc->context.settings->SmartSizing || (ww == dw && wh == dh)) + if (wfc->fullscreen || !settings->SmartSizing || (ww == dw && wh == dh)) { return BitBlt(hdc, x, y, w, h, wfc->primary->hdc, x1, y1, SRCCOPY); } @@ -763,13 +773,12 @@ BOOL wf_scale_blt(wfContext* wfc, HDC hdc, int x, int y, int w, int h, HDC hdcSr static BOOL wf_scale_mouse_pos(wfContext* wfc, UINT16* x, UINT16* y) { int ww, wh, dw, dh; - rdpContext* context; rdpSettings* settings; if (!wfc || !x || !y) return FALSE; - settings = wfc->context.settings; + settings = wfc->common.context.settings; if (!settings) return FALSE; @@ -812,7 +821,7 @@ static BOOL wf_scale_mouse_event(wfContext* wfc, rdpInput* input, UINT16 flags, eventArgs.flags = flags; eventArgs.x = x; eventArgs.y = y; - PubSub_OnMouseEvent(wfc->context.pubSub, &wfc->context, &eventArgs); + PubSub_OnMouseEvent(wfc->common.context.pubSub, &wfc->common.context, &eventArgs); return TRUE; } @@ -837,7 +846,7 @@ static BOOL wf_scale_mouse_event_ex(wfContext* wfc, rdpInput* input, UINT16 flag eventArgs.flags = flags; eventArgs.x = x; eventArgs.y = y; - PubSub_OnMouseEventEx(wfc->context.pubSub, &wfc->context, &eventArgs); + PubSub_OnMouseEventEx(wfc->common.context.pubSub, &wfc->common.context, &eventArgs); return TRUE; } #endif diff --git a/client/Windows/wf_floatbar.c b/client/Windows/wf_floatbar.c index da19f0228..653253f6a 100644 --- a/client/Windows/wf_floatbar.c +++ b/client/Windows/wf_floatbar.c @@ -699,7 +699,7 @@ wfFloatBar* wf_floatbar_new(wfContext* wfc, HINSTANCE window, DWORD flags) if (!update_locked_state(floatbar)) goto fail; - if (!wf_floatbar_toggle_fullscreen(floatbar, wfc->context.settings->Fullscreen)) + if (!wf_floatbar_toggle_fullscreen(floatbar, wfc->common.context.settings->Fullscreen)) goto fail; return floatbar; diff --git a/client/Windows/wf_gdi.c b/client/Windows/wf_gdi.c index 060233755..55a92a11d 100644 --- a/client/Windows/wf_gdi.c +++ b/client/Windows/wf_gdi.c @@ -71,8 +71,8 @@ static BOOL wf_decode_color(wfContext* wfc, const UINT32 srcColor, COLORREF* col if (!wfc) return FALSE; - gdi = wfc->context.gdi; - settings = wfc->context.settings; + gdi = wfc->common.context.gdi; + settings = wfc->common.context.settings; if (!gdi || !settings) return FALSE; @@ -216,10 +216,10 @@ static BOOL wf_scale_rect(wfContext* wfc, RECT* source) UINT32 ww, wh, dw, dh; rdpSettings* settings; - if (!wfc || !source || !wfc->context.settings) + if (!wfc || !source || !wfc->common.context.settings) return FALSE; - settings = wfc->context.settings; + settings = wfc->common.context.settings; if (!settings) return FALSE; @@ -242,7 +242,7 @@ static BOOL wf_scale_rect(wfContext* wfc, RECT* source) if (!wh) wh = dh; - if (wfc->context.settings->SmartSizing && (ww != dw || wh != dh)) + if (wfc->common.context.settings->SmartSizing && (ww != dw || wh != dh)) { source->bottom = source->bottom * wh / dh + 20; source->top = source->top * wh / dh - 20; @@ -260,7 +260,7 @@ static BOOL wf_scale_rect(wfContext* wfc, RECT* source) void wf_invalidate_region(wfContext* wfc, UINT32 x, UINT32 y, UINT32 width, UINT32 height) { RECT rect; - rdpGdi* gdi = wfc->context.gdi; + rdpGdi* gdi = wfc->common.context.gdi; wfc->update_rect.left = x + wfc->offset_x; wfc->update_rect.top = y + wfc->offset_y; wfc->update_rect.right = wfc->update_rect.left + width; @@ -278,11 +278,11 @@ void wf_invalidate_region(wfContext* wfc, UINT32 x, UINT32 y, UINT32 width, UINT void wf_update_offset(wfContext* wfc) { rdpSettings* settings; - settings = wfc->context.settings; + settings = wfc->common.context.settings; if (wfc->fullscreen) { - if (wfc->context.settings->UseMultimon) + if (wfc->common.context.settings->UseMultimon) { int x = GetSystemMetrics(SM_XVIRTUALSCREEN); int y = GetSystemMetrics(SM_YVIRTUALSCREEN); @@ -321,11 +321,11 @@ void wf_update_offset(wfContext* wfc) void wf_resize_window(wfContext* wfc) { rdpSettings* settings; - settings = wfc->context.settings; + settings = wfc->common.context.settings; if (wfc->fullscreen) { - if (wfc->context.settings->UseMultimon) + if (wfc->common.context.settings->UseMultimon) { int x = GetSystemMetrics(SM_XVIRTUALSCREEN); int y = GetSystemMetrics(SM_YVIRTUALSCREEN); @@ -341,7 +341,7 @@ void wf_resize_window(wfContext* wfc) GetSystemMetrics(SM_CYSCREEN), SWP_FRAMECHANGED); } } - else if (!wfc->context.settings->Decorations) + else if (!wfc->common.context.settings->Decorations) { SetWindowLongPtr(wfc->hwnd, GWL_STYLE, WS_CHILD); diff --git a/client/Windows/wf_graphics.c b/client/Windows/wf_graphics.c index 1c1520f4b..55286c885 100644 --- a/client/Windows/wf_graphics.c +++ b/client/Windows/wf_graphics.c @@ -58,7 +58,7 @@ HBITMAP wf_create_dib(wfContext* wfc, UINT32 width, UINT32 height, UINT32 srcFor if (data) freerdp_image_copy(cdata, dstFormat, 0, 0, 0, width, height, data, srcFormat, 0, 0, 0, - &wfc->context.gdi->palette, FREERDP_FLIP_NONE); + &wfc->common.context.gdi->palette, FREERDP_FLIP_NONE); if (pdata) *pdata = cdata; diff --git a/client/Windows/wf_rail.c b/client/Windows/wf_rail.c index 5f2a279c5..28386fec0 100644 --- a/client/Windows/wf_rail.c +++ b/client/Windows/wf_rail.c @@ -878,7 +878,7 @@ static UINT wf_rail_server_start_cmd(RailClientContext* context) RAIL_SYSPARAM_ORDER sysparam = { 0 }; RAIL_CLIENT_STATUS_ORDER clientStatus = { 0 }; wfContext* wfc = (wfContext*)context->custom; - rdpSettings* settings = wfc->context.settings; + rdpSettings* settings = wfc->common.context.settings; clientStatus.flags = TS_RAIL_CLIENTSTATUS_ALLOWLOCALMOVESIZE; if (settings->AutoReconnectionEnabled) diff --git a/client/X11/xf_channels.c b/client/X11/xf_channels.c index b17266636..c46ff3a88 100644 --- a/client/X11/xf_channels.c +++ b/client/X11/xf_channels.c @@ -21,6 +21,7 @@ #include "config.h" #endif +#include #include #include "xf_channels.h" @@ -45,7 +46,7 @@ void xf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEven WINPR_ASSERT(e); WINPR_ASSERT(e->name); - settings = xfc->context.settings; + settings = xfc->common.context.settings; WINPR_ASSERT(settings); if (strcmp(e->name, RDPEI_DVC_CHANNEL_NAME) == 0) @@ -80,18 +81,18 @@ void xf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEven } else if (strcmp(e->name, GEOMETRY_DVC_CHANNEL_NAME) == 0) { - gdi_video_geometry_init(xfc->context.gdi, (GeometryClientContext*)e->pInterface); + gdi_video_geometry_init(xfc->common.context.gdi, (GeometryClientContext*)e->pInterface); } else if (strcmp(e->name, VIDEO_CONTROL_DVC_CHANNEL_NAME) == 0) { if (settings->SoftwareGdi) - gdi_video_control_init(xfc->context.gdi, (VideoClientContext*)e->pInterface); + gdi_video_control_init(xfc->common.context.gdi, (VideoClientContext*)e->pInterface); else xf_video_control_init(xfc, (VideoClientContext*)e->pInterface); } else if (strcmp(e->name, VIDEO_DATA_DVC_CHANNEL_NAME) == 0) { - gdi_video_data_init(xfc->context.gdi, (VideoClientContext*)e->pInterface); + gdi_video_data_init(xfc->common.context.gdi, (VideoClientContext*)e->pInterface); } } @@ -104,7 +105,7 @@ void xf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnect WINPR_ASSERT(e); WINPR_ASSERT(e->name); - settings = xfc->context.settings; + settings = xfc->common.context.settings; WINPR_ASSERT(settings); if (strcmp(e->name, RDPEI_DVC_CHANNEL_NAME) == 0) @@ -139,17 +140,17 @@ void xf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnect } else if (strcmp(e->name, GEOMETRY_DVC_CHANNEL_NAME) == 0) { - gdi_video_geometry_uninit(xfc->context.gdi, (GeometryClientContext*)e->pInterface); + gdi_video_geometry_uninit(xfc->common.context.gdi, (GeometryClientContext*)e->pInterface); } else if (strcmp(e->name, VIDEO_CONTROL_DVC_CHANNEL_NAME) == 0) { if (settings->SoftwareGdi) - gdi_video_control_uninit(xfc->context.gdi, (VideoClientContext*)e->pInterface); + gdi_video_control_uninit(xfc->common.context.gdi, (VideoClientContext*)e->pInterface); else xf_video_control_uninit(xfc, (VideoClientContext*)e->pInterface); } else if (strcmp(e->name, VIDEO_DATA_DVC_CHANNEL_NAME) == 0) { - gdi_video_data_uninit(xfc->context.gdi, (VideoClientContext*)e->pInterface); + gdi_video_data_uninit(xfc->common.context.gdi, (VideoClientContext*)e->pInterface); } } diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index 5d169ac5f..313cca28e 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -83,6 +83,7 @@ #include #include +#include #include #include #include @@ -130,7 +131,11 @@ static void xf_draw_screen_scaled(xfContext* xfc, int x, int y, int w, int h) int x2; int y2; const char* filter; - rdpSettings* settings = xfc->context.settings; + rdpSettings* settings; + WINPR_ASSERT(xfc); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); if (xfc->scaledWidth <= 0 || xfc->scaledHeight <= 0) { @@ -212,7 +217,12 @@ static void xf_draw_screen_scaled(xfContext* xfc, int x, int y, int w, int h) BOOL xf_picture_transform_required(xfContext* xfc) { - rdpSettings* settings = xfc->context.settings; + rdpSettings* settings; + + WINPR_ASSERT(xfc); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); if ((xfc->offset_x != 0) || (xfc->offset_y != 0) || (xfc->scaledWidth != (INT64)settings->DesktopWidth) || @@ -256,7 +266,11 @@ static BOOL xf_desktop_resize(rdpContext* context) { rdpSettings* settings; xfContext* xfc = (xfContext*)context; + + WINPR_ASSERT(xfc); + settings = context->settings; + WINPR_ASSERT(settings); if (xfc->primary) { @@ -273,7 +287,7 @@ static BOOL xf_desktop_resize(rdpContext* context) #ifdef WITH_XRENDER - if (!xfc->context.settings->SmartSizing) + if (!settings->SmartSizing) { xfc->scaledWidth = settings->DesktopWidth; xfc->scaledHeight = settings->DesktopHeight; @@ -289,7 +303,7 @@ static BOOL xf_desktop_resize(rdpContext* context) { #ifdef WITH_XRENDER - if (!xfc->context.settings->SmartSizing) + if (!settings->SmartSizing) #endif { /* Update the saved width and height values the window will be @@ -414,7 +428,10 @@ static BOOL xf_hw_end_paint(rdpContext* context) UINT32 w, h; xfContext* xfc = (xfContext*)context; - if (xfc->context.gdi->suppressOutput) + WINPR_ASSERT(xfc); + WINPR_ASSERT(xfc->common.context.gdi); + + if (xfc->common.context.gdi->suppressOutput) return TRUE; if (!xfc->remote_app) @@ -479,10 +496,19 @@ static BOOL xf_hw_end_paint(rdpContext* context) static BOOL xf_hw_desktop_resize(rdpContext* context) { - rdpGdi* gdi = context->gdi; + rdpGdi* gdi; xfContext* xfc = (xfContext*)context; - rdpSettings* settings = context->settings; + rdpSettings* settings; BOOL ret = FALSE; + + WINPR_ASSERT(xfc); + + gdi = context->gdi; + WINPR_ASSERT(gdi); + + settings = context->settings; + WINPR_ASSERT(settings); + xf_lock_x11(xfc); if (!gdi_resize(gdi, settings->DesktopWidth, settings->DesktopHeight)) @@ -557,14 +583,19 @@ static char* xf_window_get_title(rdpSettings* settings) BOOL xf_create_window(xfContext* xfc) { XGCValues gcv; - XEvent xevent; + XEvent xevent = { 0 }; int width, height; char* windowTitle; rdpGdi* gdi; rdpSettings* settings; - settings = xfc->context.settings; - gdi = xfc->context.gdi; - ZeroMemory(&xevent, sizeof(xevent)); + + WINPR_ASSERT(xfc); + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); + + gdi = xfc->common.context.gdi; + WINPR_ASSERT(gdi); + width = settings->DesktopWidth; height = settings->DesktopHeight; @@ -651,7 +682,9 @@ BOOL xf_create_window(xfContext* xfc) if (!xfc->image) { - rdpGdi* cgdi = xfc->context.gdi; + rdpGdi* cgdi = xfc->common.context.gdi; + WINPR_ASSERT(cgdi); + xfc->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, (char*)cgdi->primary_buffer, settings->DesktopWidth, settings->DesktopHeight, xfc->scanline_pad, cgdi->stride); @@ -782,7 +815,9 @@ xf_encomsp_participant_created(EncomspClientContext* context, return ERROR_INVALID_PARAMETER; xfc = context->custom; - settings = xfc->context.settings; + WINPR_ASSERT(xfc); + + settings = xfc->common.context.settings; if (!settings) return ERROR_INVALID_PARAMETER; @@ -1108,6 +1143,10 @@ static void xf_button_map_init(xfContext* xfc) /* logical mouse button which is used for each physical mouse */ /* button (indexed from zero). This is the default map. */ unsigned char x11_map[112] = { 0 }; + + WINPR_ASSERT(xfc); + WINPR_ASSERT(xfc->common.context.settings); + x11_map[0] = Button1; x11_map[1] = Button2; x11_map[2] = Button3; @@ -1121,7 +1160,7 @@ static void xf_button_map_init(xfContext* xfc) x11_map[111] = 112; /* query system for actual remapping */ - if (xfc->context.settings->UnmapButtons) + if (xfc->common.context.settings->UnmapButtons) { xf_get_x11_button_map(xfc, x11_map); } @@ -1394,8 +1433,18 @@ static DWORD WINAPI xf_input_thread(LPVOID arg) HANDLE events[3]; wMessage msg; wMessageQueue* queue; + rdpSettings* settings; freerdp* instance = (freerdp*)arg; - xfContext* xfc = (xfContext*)instance->context; + xfContext* xfc; + + WINPR_ASSERT(instance); + + xfc = (xfContext*)instance->context; + WINPR_ASSERT(xfc); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); + queue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE); nCount = 0; events[nCount++] = MessageQueue_Event(queue); @@ -1422,7 +1471,7 @@ static DWORD WINAPI xf_input_thread(LPVOID arg) if (WaitForSingleObject(events[1], 0) == WAIT_OBJECT_0) { - if (!xf_process_x_events(xfc->context.instance)) + if (!xf_process_x_events(instance)) { running = FALSE; break; @@ -1441,7 +1490,7 @@ static DWORD WINAPI xf_input_thread(LPVOID arg) } MessageQueue_PostQuit(queue, 0); - freerdp_abort_connect(xfc->context.instance); + freerdp_abort_connect(instance); ExitThread(0); return 0; } @@ -1770,10 +1819,17 @@ static void xf_TerminateEventHandler(void* context, const TerminateEventArgs* e) #ifdef WITH_XRENDER static void xf_ZoomingChangeEventHandler(void* context, const ZoomingChangeEventArgs* e) { + int w, h; + rdpSettings* settings; xfContext* xfc = (xfContext*)context; - rdpSettings* settings = xfc->context.settings; - int w = xfc->scaledWidth + e->dx; - int h = xfc->scaledHeight + e->dy; + + WINPR_ASSERT(xfc); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); + + w = xfc->scaledWidth + e->dx; + h = xfc->scaledHeight + e->dy; if (e->dx == 0 && e->dy == 0) return; @@ -1795,7 +1851,13 @@ static void xf_ZoomingChangeEventHandler(void* context, const ZoomingChangeEvent static void xf_PanningChangeEventHandler(void* context, const PanningChangeEventArgs* e) { xfContext* xfc = (xfContext*)context; - rdpSettings* settings = xfc->context.settings; + rdpSettings* settings; + + WINPR_ASSERT(xfc); + WINPR_ASSERT(e); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); if (e->dx == 0 && e->dy == 0) return; @@ -1835,7 +1897,7 @@ static int xfreerdp_client_start(rdpContext* context) return -1; } - if (!(xfc->thread = CreateThread(NULL, 0, xf_client_thread, context->instance, 0, NULL))) + if (!(xfc->common.thread = CreateThread(NULL, 0, xf_client_thread, context->instance, 0, NULL))) { WLog_ERR(TAG, "failed to create client thread"); return -1; @@ -1847,13 +1909,16 @@ static int xfreerdp_client_start(rdpContext* context) static int xfreerdp_client_stop(rdpContext* context) { xfContext* xfc = (xfContext*)context; + + WINPR_ASSERT(xfc); + freerdp_abort_connect(context->instance); - if (xfc->thread) + if (xfc->common.thread) { - WaitForSingleObject(xfc->thread, INFINITE); - CloseHandle(xfc->thread); - xfc->thread = NULL; + WaitForSingleObject(xfc->common.thread, INFINITE); + CloseHandle(xfc->common.thread); + xfc->common.thread = NULL; } return 0; diff --git a/client/X11/xf_cliprdr.c b/client/X11/xf_cliprdr.c index 0a69022bf..302dde08a 100644 --- a/client/X11/xf_cliprdr.c +++ b/client/X11/xf_cliprdr.c @@ -47,6 +47,7 @@ #endif #include +#include #include #include #include @@ -2822,6 +2823,9 @@ xfClipboard* xf_clipboard_new(xfContext* xfc) const char* selectionAtom; xfCliprdrFormat* clientFormat; + WINPR_ASSERT(xfc); + WINPR_ASSERT(xfc->common.context.settings); + if (!(clipboard = (xfClipboard*)calloc(1, sizeof(xfClipboard)))) { WLog_ERR(TAG, "failed to allocate xfClipboard data"); @@ -2836,8 +2840,8 @@ xfClipboard* xf_clipboard_new(xfContext* xfc) clipboard->requestedFormatId = -1; clipboard->root_window = DefaultRootWindow(xfc->display); selectionAtom = "CLIPBOARD"; - if (xfc->context.settings->XSelectionAtom) - selectionAtom = xfc->context.settings->XSelectionAtom; + if (xfc->common.context.settings->XSelectionAtom) + selectionAtom = xfc->common.context.settings->XSelectionAtom; clipboard->clipboard_atom = XInternAtom(xfc->display, selectionAtom, FALSE); if (clipboard->clipboard_atom == None) diff --git a/client/X11/xf_disp.c b/client/X11/xf_disp.c index 7cef1300c..77a9c6cc2 100644 --- a/client/X11/xf_disp.c +++ b/client/X11/xf_disp.c @@ -17,6 +17,7 @@ * limitations under the License. */ +#include #include #include @@ -63,7 +64,13 @@ static UINT xf_disp_sendLayout(DispClientContext* disp, const rdpMonitor* monito static BOOL xf_disp_settings_changed(xfDispContext* xfDisp) { - rdpSettings* settings = xfDisp->xfc->context.settings; + rdpSettings* settings; + + WINPR_ASSERT(xfDisp); + WINPR_ASSERT(xfDisp->xfc); + + settings = xfDisp->xfc->common.context.settings; + WINPR_ASSERT(settings); if (xfDisp->lastSentWidth != xfDisp->targetWidth) return TRUE; @@ -88,7 +95,14 @@ static BOOL xf_disp_settings_changed(xfDispContext* xfDisp) static BOOL xf_update_last_sent(xfDispContext* xfDisp) { - rdpSettings* settings = xfDisp->xfc->context.settings; + rdpSettings* settings; + + WINPR_ASSERT(xfDisp); + WINPR_ASSERT(xfDisp->xfc); + + settings = xfDisp->xfc->common.context.settings; + WINPR_ASSERT(settings); + xfDisp->lastSentWidth = xfDisp->targetWidth; xfDisp->lastSentHeight = xfDisp->targetHeight; xfDisp->lastSentDesktopOrientation = settings->DesktopOrientation; @@ -108,7 +122,7 @@ static BOOL xf_disp_sendResize(xfDispContext* xfDisp) return FALSE; xfc = xfDisp->xfc; - settings = xfc->context.settings; + settings = xfc->common.context.settings; if (!settings) return FALSE; @@ -191,12 +205,12 @@ static BOOL xf_disp_check_context(void* context, xfContext** ppXfc, xfDispContex if (!(xfc->xfDisp)) return FALSE; - if (!xfc->context.settings) + if (!xfc->common.context.settings) return FALSE; *ppXfc = xfc; *ppXfDisp = xfc->xfDisp; - *ppSettings = xfc->context.settings; + *ppSettings = xfc->common.context.settings; return TRUE; } @@ -258,9 +272,16 @@ static void xf_disp_OnTimer(void* context, const TimerEventArgs* e) xfDispContext* xf_disp_new(xfContext* xfc) { xfDispContext* ret; + const rdpSettings* settings; + wPubSub* pubSub; - if (!xfc || !xfc->context.settings || !xfc->context.pubSub) - return NULL; + WINPR_ASSERT(xfc); + + pubSub = xfc->common.context.pubSub; + WINPR_ASSERT(pubSub); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); ret = calloc(1, sizeof(xfDispContext)); @@ -276,11 +297,11 @@ xfDispContext* xf_disp_new(xfContext* xfc) } #endif - ret->lastSentWidth = ret->targetWidth = xfc->context.settings->DesktopWidth; - ret->lastSentHeight = ret->targetHeight = xfc->context.settings->DesktopHeight; - PubSub_SubscribeActivated(xfc->context.pubSub, xf_disp_OnActivated); - PubSub_SubscribeGraphicsReset(xfc->context.pubSub, xf_disp_OnGraphicsReset); - PubSub_SubscribeTimer(xfc->context.pubSub, xf_disp_OnTimer); + ret->lastSentWidth = ret->targetWidth = settings->DesktopWidth; + ret->lastSentHeight = ret->targetHeight = settings->DesktopHeight; + PubSub_SubscribeActivated(pubSub, xf_disp_OnActivated); + PubSub_SubscribeGraphicsReset(pubSub, xf_disp_OnGraphicsReset); + PubSub_SubscribeTimer(pubSub, xf_disp_OnTimer); return ret; } @@ -291,9 +312,10 @@ void xf_disp_free(xfDispContext* disp) if (disp->xfc) { - PubSub_UnsubscribeActivated(disp->xfc->context.pubSub, xf_disp_OnActivated); - PubSub_UnsubscribeGraphicsReset(disp->xfc->context.pubSub, xf_disp_OnGraphicsReset); - PubSub_UnsubscribeTimer(disp->xfc->context.pubSub, xf_disp_OnTimer); + wPubSub* pubSub = disp->xfc->common.context.pubSub; + PubSub_UnsubscribeActivated(pubSub, xf_disp_OnActivated); + PubSub_UnsubscribeGraphicsReset(pubSub, xf_disp_OnGraphicsReset); + PubSub_UnsubscribeTimer(pubSub, xf_disp_OnTimer); } free(disp); @@ -315,7 +337,7 @@ UINT xf_disp_sendLayout(DispClientContext* disp, const rdpMonitor* monitors, UIN WINPR_ASSERT(xfDisp); WINPR_ASSERT(xfDisp->xfc); - settings = xfDisp->xfc->context.settings; + settings = xfDisp->xfc->common.context.settings; WINPR_ASSERT(settings); layouts = calloc(nmonitors, sizeof(DISPLAY_CONTROL_MONITOR_LAYOUT)); @@ -387,7 +409,7 @@ BOOL xf_disp_handle_xevent(xfContext* xfc, const XEvent* event) if (!xfDisp) return FALSE; - settings = xfc->context.settings; + settings = xfc->common.context.settings; if (!settings) return FALSE; @@ -425,8 +447,18 @@ static UINT xf_DisplayControlCaps(DispClientContext* disp, UINT32 maxNumMonitors UINT32 maxMonitorAreaFactorA, UINT32 maxMonitorAreaFactorB) { /* we're called only if dynamic resolution update is activated */ - xfDispContext* xfDisp = (xfDispContext*)disp->custom; - rdpSettings* settings = xfDisp->xfc->context.settings; + xfDispContext* xfDisp; + rdpSettings* settings; + + WINPR_ASSERT(disp); + + xfDisp = (xfDispContext*)disp->custom; + WINPR_ASSERT(xfDisp); + WINPR_ASSERT(xfDisp->xfc); + + settings = xfDisp->xfc->common.context.settings; + WINPR_ASSERT(settings); + WLog_DBG(TAG, "DisplayControlCapsPdu: MaxNumMonitors: %" PRIu32 " MaxMonitorAreaFactorA: %" PRIu32 " MaxMonitorAreaFactorB: %" PRIu32 "", @@ -447,7 +479,7 @@ BOOL xf_disp_init(xfDispContext* xfDisp, DispClientContext* disp) if (!xfDisp || !xfDisp->xfc || !disp) return FALSE; - settings = xfDisp->xfc->context.settings; + settings = xfDisp->xfc->common.context.settings; if (!settings) return FALSE; diff --git a/client/X11/xf_event.c b/client/X11/xf_event.c index 8e8859886..f67489a05 100644 --- a/client/X11/xf_event.c +++ b/client/X11/xf_event.c @@ -24,6 +24,8 @@ #include #include +#include + #include #include @@ -172,6 +174,13 @@ BOOL xf_event_action_script_init(xfContext* xfc) FILE* actionScript; char buffer[1024] = { 0 }; char command[1024] = { 0 }; + const rdpSettings* settings; + + WINPR_ASSERT(xfc); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); + xfc->xevents = ArrayList_New(TRUE); if (!xfc->xevents) @@ -179,7 +188,7 @@ BOOL xf_event_action_script_init(xfContext* xfc) obj = ArrayList_Object(xfc->xevents); obj->fnObjectFree = free; - sprintf_s(command, sizeof(command), "%s xevent", xfc->context.settings->ActionScript); + sprintf_s(command, sizeof(command), "%s xevent", settings->ActionScript); actionScript = popen(command, "r"); if (!actionScript) @@ -247,8 +256,9 @@ static BOOL xf_event_execute_action_script(xfContext* xfc, const XEvent* event) if (!match) return FALSE; - sprintf_s(command, sizeof(command), "%s xevent %s %lu", xfc->context.settings->ActionScript, - xeventName, (unsigned long)xfc->window->handle); + sprintf_s(command, sizeof(command), "%s xevent %s %lu", + xfc->common.context.settings->ActionScript, xeventName, + (unsigned long)xfc->window->handle); actionScript = popen(command, "r"); if (!actionScript) @@ -269,10 +279,10 @@ void xf_adjust_coordinates_to_screen(xfContext* xfc, UINT32* x, UINT32* y) rdpSettings* settings; INT64 tx, ty; - if (!xfc || !xfc->context.settings || !y || !x) + if (!xfc || !xfc->common.context.settings || !y || !x) return; - settings = xfc->context.settings; + settings = xfc->common.context.settings; tx = *x; ty = *y; if (!xfc->remote_app) @@ -299,10 +309,10 @@ void xf_event_adjust_coordinates(xfContext* xfc, int* x, int* y) { rdpSettings* settings; - if (!xfc || !xfc->context.settings || !y || !x) + if (!xfc || !xfc->common.context.settings || !y || !x) return; - settings = xfc->context.settings; + settings = xfc->common.context.settings; if (!xfc->remote_app) { @@ -325,7 +335,13 @@ static BOOL xf_event_Expose(xfContext* xfc, const XExposeEvent* event, BOOL app) { int x, y; int w, h; - rdpSettings* settings = xfc->context.settings; + rdpSettings* settings; + + WINPR_ASSERT(xfc); + WINPR_ASSERT(event); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); if (!app && (settings->SmartSizing || settings->MultiTouchGestures)) { @@ -344,7 +360,7 @@ static BOOL xf_event_Expose(xfContext* xfc, const XExposeEvent* event, BOOL app) if (!app) { - if (xfc->context.gdi->gfx) + if (xfc->common.context.gdi->gfx) { xf_OutputExpose(xfc, x, y, w, h); return TRUE; @@ -376,9 +392,14 @@ BOOL xf_generic_MotionNotify(xfContext* xfc, int x, int y, int state, Window win { rdpInput* input; Window childWindow; - input = xfc->context.input; - if (!xfc->context.settings->MouseMotion) + WINPR_ASSERT(xfc); + WINPR_ASSERT(xfc->common.context.settings); + + input = xfc->common.context.input; + WINPR_ASSERT(input); + + if (!xfc->common.context.settings->MouseMotion) { if ((state & (Button1Mask | Button2Mask | Button3Mask)) == 0) return TRUE; @@ -407,6 +428,7 @@ BOOL xf_generic_MotionNotify(xfContext* xfc, int x, int y, int state, Window win } static BOOL xf_event_MotionNotify(xfContext* xfc, const XMotionEvent* event, BOOL app) { + WINPR_ASSERT(xfc); if (xfc->window) xf_floatbar_set_root_y(xfc->window->floatbar, event->y); @@ -424,6 +446,8 @@ BOOL xf_generic_ButtonEvent(xfContext* xfc, int x, int y, int button, Window win Window childWindow; size_t i; + WINPR_ASSERT(xfc); + for (i = 0; i < ARRAYSIZE(xfc->button_map); i++) { const button_map* cur = &xfc->button_map[i]; @@ -435,7 +459,7 @@ BOOL xf_generic_ButtonEvent(xfContext* xfc, int x, int y, int button, Window win } } - input = xfc->context.input; + input = xfc->common.context.input; if (flags != 0) { @@ -669,8 +693,13 @@ static BOOL xf_event_ConfigureNotify(xfContext* xfc, const XConfigureEvent* even { Window childWindow; xfAppWindow* appWindow; - rdpSettings* settings; - settings = xfc->context.settings; + const rdpSettings* settings; + + WINPR_ASSERT(xfc); + WINPR_ASSERT(event); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); if (!app) { @@ -691,7 +720,7 @@ static BOOL xf_event_ConfigureNotify(xfContext* xfc, const XConfigureEvent* even xfc->offset_x = 0; xfc->offset_y = 0; - if (xfc->context.settings->SmartSizing || xfc->context.settings->MultiTouchGestures) + if (settings->SmartSizing || settings->MultiTouchGestures) { xfc->scaledWidth = xfc->window->width; xfc->scaledHeight = xfc->window->height; @@ -757,8 +786,9 @@ static BOOL xf_event_MapNotify(xfContext* xfc, const XMapEvent* event, BOOL app) { xfAppWindow* appWindow; + WINPR_ASSERT(xfc); if (!app) - gdi_send_suppress_output(xfc->context.gdi, FALSE); + gdi_send_suppress_output(xfc->common.context.gdi, FALSE); else { appWindow = xf_AppWindowFromX11Window(xfc, event->window); @@ -781,10 +811,14 @@ static BOOL xf_event_MapNotify(xfContext* xfc, const XMapEvent* event, BOOL app) static BOOL xf_event_UnmapNotify(xfContext* xfc, const XUnmapEvent* event, BOOL app) { xfAppWindow* appWindow; + + WINPR_ASSERT(xfc); + WINPR_ASSERT(event); + xf_keyboard_release_all_keypress(xfc); if (!app) - gdi_send_suppress_output(xfc->context.gdi, TRUE); + gdi_send_suppress_output(xfc->common.context.gdi, TRUE); else { appWindow = xf_AppWindowFromX11Window(xfc, event->window); @@ -800,6 +834,9 @@ static BOOL xf_event_UnmapNotify(xfContext* xfc, const XUnmapEvent* event, BOOL static BOOL xf_event_PropertyNotify(xfContext* xfc, const XPropertyEvent* event, BOOL app) { + WINPR_ASSERT(xfc); + WINPR_ASSERT(event); + /* * This section handles sending the appropriate commands to the rail server * when the window has been minimized, maximized, restored locally @@ -893,7 +930,7 @@ static BOOL xf_event_PropertyNotify(xfContext* xfc, const XPropertyEvent* event, } } else if (minimizedChanged) - gdi_send_suppress_output(xfc->context.gdi, minimized); + gdi_send_suppress_output(xfc->common.context.gdi, minimized); } return TRUE; @@ -992,8 +1029,17 @@ BOOL xf_event_process(freerdp* instance, const XEvent* event) { BOOL status = TRUE; xfAppWindow* appWindow; - xfContext* xfc = (xfContext*)instance->context; - rdpSettings* settings = xfc->context.settings; + xfContext* xfc; + rdpSettings* settings; + + WINPR_ASSERT(instance); + WINPR_ASSERT(event); + + xfc = (xfContext*)instance->context; + WINPR_ASSERT(xfc); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); if (xfc->remote_app) { diff --git a/client/X11/xf_floatbar.c b/client/X11/xf_floatbar.c index c33f3e992..af12791a3 100644 --- a/client/X11/xf_floatbar.c +++ b/client/X11/xf_floatbar.c @@ -21,6 +21,8 @@ #include #include +#include + #include "xf_floatbar.h" #include "resource/close.xbm" #include "resource/lock.xbm" @@ -98,7 +100,7 @@ static BOOL xf_floatbar_button_onclick_close(xfFloatbar* floatbar) if (!floatbar) return FALSE; - return freerdp_abort_connect(floatbar->xfc->context.instance); + return freerdp_abort_connect(floatbar->xfc->common.context.instance); } static BOOL xf_floatbar_button_onclick_minimize(xfFloatbar* floatbar) diff --git a/client/X11/xf_gdi.c b/client/X11/xf_gdi.c index 06326c256..a276ec4e8 100644 --- a/client/X11/xf_gdi.c +++ b/client/X11/xf_gdi.c @@ -26,6 +26,8 @@ #include #include +#include + #include #include #include @@ -225,7 +227,12 @@ static Pixmap xf_brush_new(xfContext* xfc, UINT32 width, UINT32 height, UINT32 b XImage* image; rdpGdi* gdi; UINT32 brushFormat; - gdi = xfc->context.gdi; + + WINPR_ASSERT(xfc); + + gdi = xfc->common.context.gdi; + WINPR_ASSERT(gdi); + bitmap = XCreatePixmap(xfc->display, xfc->drawable, width, height, xfc->depth); if (data) @@ -233,7 +240,7 @@ static Pixmap xf_brush_new(xfContext* xfc, UINT32 width, UINT32 height, UINT32 b brushFormat = gdi_get_pixel_format(bpp); cdata = (BYTE*)_aligned_malloc(width * height * 4ULL, 16); freerdp_image_copy(cdata, gdi->dstFormat, 0, 0, 0, width, height, data, brushFormat, 0, 0, - 0, &xfc->context.gdi->palette, FREERDP_FLIP_NONE); + 0, &gdi->palette, FREERDP_FLIP_NONE); image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, (char*)cdata, width, height, xfc->scanline_pad, 0); image->byte_order = LSBFirst; @@ -898,7 +905,12 @@ static BOOL xf_gdi_surface_frame_marker(rdpContext* context, rdpSettings* settings; xfContext* xfc = (xfContext*)context; BOOL ret = TRUE; - settings = xfc->context.settings; + + WINPR_ASSERT(xfc); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); + xf_lock_x11(xfc); switch (surface_frame_marker->frameAction) @@ -921,7 +933,8 @@ static BOOL xf_gdi_surface_frame_marker(rdpContext* context, if (settings->FrameAcknowledge > 0) { - IFCALL(xfc->context.update->SurfaceFrameAcknowledge, context, + WINPR_ASSERT(xfc->common.context.update); + IFCALL(xfc->common.context.update->SurfaceFrameAcknowledge, context, surface_frame_marker->frameId); } @@ -1077,7 +1090,7 @@ static BOOL xf_gdi_surface_bits(rdpContext* context, const SURFACE_BITS_COMMAND* if (!freerdp_image_copy(gdi->primary_buffer, gdi->dstFormat, gdi->stride, cmd->destLeft, cmd->destTop, cmd->bmp.width, cmd->bmp.height, pSrcData, format, - 0, 0, 0, &xfc->context.gdi->palette, FREERDP_FLIP_VERTICAL)) + 0, 0, 0, &gdi->palette, FREERDP_FLIP_VERTICAL)) goto fail; region16_union_rect(®ion, ®ion, &cmdRect); diff --git a/client/X11/xf_gfx.c b/client/X11/xf_gfx.c index a01c0c0ce..0258b48a9 100644 --- a/client/X11/xf_gfx.c +++ b/client/X11/xf_gfx.c @@ -23,6 +23,7 @@ #include "config.h" #endif +#include #include #include "xf_gfx.h" #include "xf_rail.h" @@ -37,10 +38,20 @@ static UINT xf_OutputUpdate(xfContext* xfc, xfGfxSurface* surface) UINT32 surfaceX, surfaceY; RECTANGLE_16 surfaceRect; rdpGdi* gdi; + const rdpSettings* settings; UINT32 nbRects, x; double sx, sy; const RECTANGLE_16* rects; - gdi = xfc->context.gdi; + + WINPR_ASSERT(xfc); + WINPR_ASSERT(surface); + + gdi = xfc->common.context.gdi; + WINPR_ASSERT(gdi); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); + surfaceX = surface->gdi.outputOriginX; surfaceY = surface->gdi.outputOriginY; surfaceRect.left = 0; @@ -87,7 +98,7 @@ static UINT xf_OutputUpdate(xfContext* xfc, xfGfxSurface* surface) } else #ifdef WITH_XRENDER - if (xfc->context.settings->SmartSizing || xfc->context.settings->MultiTouchGestures) + if (settings->SmartSizing || settings->MultiTouchGestures) { XPutImage(xfc->display, xfc->primary, xfc->gc, surface->image, nXSrc, nYSrc, nXDst, nYDst, dwidth, dheight); @@ -166,7 +177,14 @@ UINT xf_OutputExpose(xfContext* xfc, UINT32 x, UINT32 y, UINT32 width, UINT32 he RECTANGLE_16 surfaceRect; RECTANGLE_16 intersection; UINT16* pSurfaceIds = NULL; - RdpgfxClientContext* context = xfc->context.gdi->gfx; + RdpgfxClientContext* context; + + WINPR_ASSERT(xfc); + WINPR_ASSERT(xfc->common.context.gdi); + + context = xfc->common.context.gdi->gfx; + WINPR_ASSERT(context); + invalidRect.left = x; invalidRect.top = y; invalidRect.right = x + width; @@ -400,10 +418,19 @@ static UINT xf_DeleteSurface(RdpgfxClientContext* context, void xf_graphics_pipeline_init(xfContext* xfc, RdpgfxClientContext* gfx) { - rdpGdi* gdi = xfc->context.gdi; + rdpGdi* gdi; + const rdpSettings* settings; + WINPR_ASSERT(xfc); + WINPR_ASSERT(gfx); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); + + gdi = xfc->common.context.gdi; + gdi_graphics_pipeline_init(gdi, gfx); - if (!xfc->context.settings->SoftwareGdi) + if (!settings->SoftwareGdi) { gfx->UpdateSurfaces = xf_UpdateSurfaces; gfx->CreateSurface = xf_CreateSurface; @@ -413,6 +440,10 @@ void xf_graphics_pipeline_init(xfContext* xfc, RdpgfxClientContext* gfx) void xf_graphics_pipeline_uninit(xfContext* xfc, RdpgfxClientContext* gfx) { - rdpGdi* gdi = xfc->context.gdi; + rdpGdi* gdi; + + WINPR_ASSERT(xfc); + + gdi = xfc->common.context.gdi; gdi_graphics_pipeline_uninit(gdi, gfx); } diff --git a/client/X11/xf_graphics.c b/client/X11/xf_graphics.c index b5e268018..3e90cf09f 100644 --- a/client/X11/xf_graphics.c +++ b/client/X11/xf_graphics.c @@ -31,6 +31,7 @@ #endif #include +#include #include #include @@ -52,12 +53,12 @@ BOOL xf_decode_color(xfContext* xfc, const UINT32 srcColor, XColor* color) if (!xfc || !color) return FALSE; - gdi = xfc->context.gdi; + gdi = xfc->common.context.gdi; if (!gdi) return FALSE; - settings = xfc->context.settings; + settings = xfc->common.context.settings; if (!settings) return FALSE; @@ -248,7 +249,7 @@ static BOOL _xf_Pointer_GetCursorForCurrentScale(rdpContext* context, const rdpP if (!context || !pointer || !context->gdi) return FALSE; - settings = xfc->context.settings; + settings = xfc->common.context.settings; if (!settings) return FALSE; diff --git a/client/X11/xf_input.c b/client/X11/xf_input.c index b5a532032..65e8b3e0b 100644 --- a/client/X11/xf_input.c +++ b/client/X11/xf_input.c @@ -76,10 +76,14 @@ int xf_input_init(xfContext* xfc, Window window) XIDeviceInfo* info; XIEventMask evmasks[64]; int opcode, event, error; + const rdpSettings* settings; BYTE masks[8][XIMaskLen(XI_LASTEVENT)] = { 0 }; WINPR_ASSERT(xfc); + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); + memset(xfc->contacts, 0, sizeof(xfc->contacts)); xfc->firstDist = -1.0; xfc->z_vector = 0; @@ -102,7 +106,7 @@ int xf_input_init(xfContext* xfc, Window window) return -1; } - if (xfc->context.settings->MultiTouchInput) + if (settings->MultiTouchInput) xfc->use_xinput = TRUE; info = XIQueryDevice(xfc->display, XIAllDevices, &ndevices); @@ -129,7 +133,7 @@ int xf_input_init(xfContext* xfc, Window window) XIAnyClassInfo* class = dev->classes[j]; XITouchClassInfo* t = (XITouchClassInfo*)class; - if (xfc->context.settings->MultiTouchInput) + if (xfc->common.context.settings->MultiTouchInput) { WLog_INFO(TAG, "%s (%d) \"%s\" id: %d", xf_input_get_class_string(class->type), class->type, dev->name, dev->deviceid); @@ -143,7 +147,7 @@ int xf_input_init(xfContext* xfc, Window window) if ((class->type == XITouchClass) && (t->mode == XIDirectTouch) && (strcmp(dev->name, "Virtual core pointer") != 0)) { - if (xfc->context.settings->MultiTouchInput) + if (settings->MultiTouchInput) { WLog_INFO(TAG, "%s %s touch device (id: %d, mode: %d), supporting %d touches.", dev->name, (t->mode == XIDirectTouch) ? "direct" : "dependent", @@ -233,7 +237,7 @@ static void xf_input_detect_pan(xfContext* xfc) rdpContext* ctx; WINPR_ASSERT(xfc); - ctx = &xfc->context; + ctx = &xfc->common.context; WINPR_ASSERT(ctx); if (xfc->active_contacts != 2) @@ -321,7 +325,7 @@ static void xf_input_detect_pinch(xfContext* xfc) rdpContext* ctx; WINPR_ASSERT(xfc); - ctx = &xfc->context; + ctx = &xfc->common.context; WINPR_ASSERT(ctx); if (xfc->active_contacts != 2) @@ -659,13 +663,18 @@ int xf_input_init(xfContext* xfc, Window window) int xf_input_handle_event(xfContext* xfc, const XEvent* event) { #ifdef WITH_XI + const rdpSettings* settings; + WINPR_ASSERT(xfc); - if (xfc->context.settings->MultiTouchInput) + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); + + if (settings->MultiTouchInput) { return xf_input_handle_event_remote(xfc, event); } - if (xfc->context.settings->MultiTouchGestures) + if (settings->MultiTouchGestures) { return xf_input_handle_event_local(xfc, event); } diff --git a/client/X11/xf_keyboard.c b/client/X11/xf_keyboard.c index 45ae89221..793f8224f 100644 --- a/client/X11/xf_keyboard.c +++ b/client/X11/xf_keyboard.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -48,11 +49,14 @@ static void xf_keyboard_send_key(xfContext* xfc, BOOL down, const XKeyEvent* ev) static BOOL xf_sync_kbd_state(xfContext* xfc) { const UINT32 syncFlags = xf_keyboard_get_toggle_keys_state(xfc); - return freerdp_input_send_synchronize_event(xfc->context.input, syncFlags); + + WINPR_ASSERT(xfc); + return freerdp_input_send_synchronize_event(xfc->common.context.input, syncFlags); } static void xf_keyboard_clear(xfContext* xfc) { + WINPR_ASSERT(xfc); ZeroMemory(xfc->KeyboardState, 256 * sizeof(BOOL)); } @@ -63,7 +67,13 @@ static BOOL xf_keyboard_action_script_init(xfContext* xfc) char* keyCombination; char buffer[1024] = { 0 }; char command[1024] = { 0 }; - xfc->actionScriptExists = winpr_PathFileExists(xfc->context.settings->ActionScript); + const rdpSettings* settings; + WINPR_ASSERT(xfc); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); + + xfc->actionScriptExists = winpr_PathFileExists(settings->ActionScript); if (!xfc->actionScriptExists) return FALSE; @@ -75,7 +85,7 @@ static BOOL xf_keyboard_action_script_init(xfContext* xfc) obj = ArrayList_Object(xfc->keyCombinations); obj->fnObjectFree = free; - sprintf_s(command, sizeof(command), "%s key", xfc->context.settings->ActionScript); + sprintf_s(command, sizeof(command), "%s key", settings->ActionScript); keyScript = popen(command, "r"); if (!keyScript) @@ -117,11 +127,18 @@ static void xf_keyboard_action_script_free(xfContext* xfc) BOOL xf_keyboard_init(xfContext* xfc) { + rdpSettings* settings; + + WINPR_ASSERT(xfc); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); + xf_keyboard_clear(xfc); - xfc->KeyboardLayout = xfc->context.settings->KeyboardLayout; + xfc->KeyboardLayout = settings->KeyboardLayout; xfc->KeyboardLayout = - freerdp_keyboard_init_ex(xfc->KeyboardLayout, xfc->context.settings->KeyboardRemappingList); - xfc->context.settings->KeyboardLayout = xfc->KeyboardLayout; + freerdp_keyboard_init_ex(xfc->KeyboardLayout, settings->KeyboardRemappingList); + settings->KeyboardLayout = xfc->KeyboardLayout; if (xfc->modifierMap) XFreeModifiermap(xfc->modifierMap); @@ -178,6 +195,8 @@ void xf_keyboard_release_all_keypress(xfContext* xfc) size_t keycode; DWORD rdp_scancode; + WINPR_ASSERT(xfc); + for (keycode = 0; keycode < ARRAYSIZE(xfc->KeyboardState); keycode++) { if (xfc->KeyboardState[keycode]) @@ -187,9 +206,10 @@ void xf_keyboard_release_all_keypress(xfContext* xfc) // release tab before releasing the windows key. // this stops the start menu from opening on unfocus event. if (rdp_scancode == RDP_SCANCODE_LWIN) - freerdp_input_send_keyboard_event_ex(xfc->context.input, FALSE, RDP_SCANCODE_TAB); + freerdp_input_send_keyboard_event_ex(xfc->common.context.input, FALSE, + RDP_SCANCODE_TAB); - freerdp_input_send_keyboard_event_ex(xfc->context.input, FALSE, rdp_scancode); + freerdp_input_send_keyboard_event_ex(xfc->common.context.input, FALSE, rdp_scancode); xfc->KeyboardState[keycode] = FALSE; } } @@ -210,7 +230,7 @@ void xf_keyboard_send_key(xfContext* xfc, BOOL down, const XKeyEvent* event) WINPR_ASSERT(xfc); WINPR_ASSERT(event); - input = xfc->context.input; + input = xfc->common.context.input; WINPR_ASSERT(input); rdp_scancode = freerdp_keyboard_get_rdp_scancode_from_x11_keycode(event->keycode); @@ -229,7 +249,7 @@ void xf_keyboard_send_key(xfContext* xfc, BOOL down, const XKeyEvent* event) else { BOOL rc; - if (freerdp_settings_get_bool(xfc->context.settings, FreeRDP_UnicodeInput)) + if (freerdp_settings_get_bool(xfc->common.context.settings, FreeRDP_UnicodeInput)) { wchar_t buffer[32] = { 0 }; int rc = 0; @@ -399,10 +419,13 @@ void xf_keyboard_focus_in(xfContext* xfc) Window w; int d, x, y; + WINPR_ASSERT(xfc); if (!xfc->display || !xfc->window) return; - input = xfc->context.input; + input = xfc->common.context.input; + WINPR_ASSERT(input); + syncFlags = xf_keyboard_get_toggle_keys_state(xfc); freerdp_input_send_focus_in_event(input, syncFlags); xk_keyboard_update_modifier_keys(xfc); @@ -480,7 +503,7 @@ static int xf_keyboard_execute_action_script(xfContext* xfc, XF_MODIFIER_KEYS* m if (!match) return 1; - sprintf_s(command, sizeof(command), "%s key %s", xfc->context.settings->ActionScript, + sprintf_s(command, sizeof(command), "%s key %s", xfc->common.context.settings->ActionScript, combination); keyScript = popen(command, "r"); @@ -575,7 +598,7 @@ BOOL xf_keyboard_handle_special_keys(xfContext* xfc, KeySym keysym) if (!xfc->remote_app && xfc->settings->MultiTouchGestures) { - rdpContext* ctx = &xfc->context; + rdpContext* ctx = &xfc->common.context; if (mod.Ctrl && mod.Alt) { diff --git a/client/X11/xf_monitor.c b/client/X11/xf_monitor.c index f02dbade5..f9cef0559 100644 --- a/client/X11/xf_monitor.c +++ b/client/X11/xf_monitor.c @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -116,7 +117,12 @@ int xf_list_monitors(xfContext* xfc) static BOOL xf_is_monitor_id_active(xfContext* xfc, UINT32 id) { UINT32 index; - rdpSettings* settings = xfc->context.settings; + const rdpSettings* settings; + + WINPR_ASSERT(xfc); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); if (!settings->NumMonitorIds) return TRUE; @@ -150,10 +156,10 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight) BOOL useXRandr = FALSE; #endif - if (!xfc || !pMaxWidth || !pMaxHeight || !xfc->context.settings) + if (!xfc || !pMaxWidth || !pMaxHeight || !xfc->common.context.settings) return FALSE; - settings = xfc->context.settings; + settings = xfc->common.context.settings; vscreen = &xfc->vscreen; *pMaxWidth = settings->DesktopWidth; *pMaxHeight = settings->DesktopHeight; diff --git a/client/X11/xf_rail.c b/client/X11/xf_rail.c index 820f4df2f..f44a6468e 100644 --- a/client/X11/xf_rail.c +++ b/client/X11/xf_rail.c @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -153,7 +154,13 @@ void xf_rail_end_local_move(xfContext* xfc, xfAppWindow* appWindow) Window root_window; Window child_window; RAIL_WINDOW_MOVE_ORDER windowMove; - rdpInput* input = xfc->context.input; + rdpInput* input; + + WINPR_ASSERT(xfc); + + input = xfc->common.context.input; + WINPR_ASSERT(input); + /* * For keyboard moves send and explicit update to RDP server */ @@ -792,13 +799,19 @@ static void xf_rail_register_update_callbacks(rdpUpdate* update) static UINT xf_rail_server_execute_result(RailClientContext* context, const RAIL_EXEC_RESULT_ORDER* execResult) { - xfContext* xfc = (xfContext*)context->custom; + xfContext* xfc; + + WINPR_ASSERT(context); + WINPR_ASSERT(execResult); + + xfc = (xfContext*)context->custom; + WINPR_ASSERT(xfc); if (execResult->execResult != RAIL_EXEC_S_OK) { WLog_ERR(TAG, "RAIL exec error: execResult=%s NtError=0x%X\n", error_code_names[execResult->execResult], execResult->rawResult); - freerdp_abort_connect(xfc->context.instance); + freerdp_abort_connect(xfc->common.context.instance); } else { @@ -826,8 +839,17 @@ static UINT xf_rail_server_start_cmd(RailClientContext* context) RAIL_EXEC_ORDER exec = { 0 }; RAIL_SYSPARAM_ORDER sysparam = { 0 }; RAIL_CLIENT_STATUS_ORDER clientStatus = { 0 }; - xfContext* xfc = (xfContext*)context->custom; - rdpSettings* settings = xfc->context.settings; + xfContext* xfc; + rdpSettings* settings; + + WINPR_ASSERT(context); + + xfc = (xfContext*)context->custom; + WINPR_ASSERT(xfc); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); + clientStatus.flags = TS_RAIL_CLIENTSTATUS_ALLOWLOCALMOVESIZE; if (settings->AutoReconnectionEnabled) @@ -1111,7 +1133,7 @@ int xf_rail_init(xfContext* xfc, RailClientContext* rail) wObject* obj = HashTable_ValueObject(xfc->railWindows); obj->fnObjectFree = rail_window_free; } - xfc->railIconCache = RailIconCache_New(xfc->context.settings); + xfc->railIconCache = RailIconCache_New(xfc->common.context.settings); if (!xfc->railIconCache) { diff --git a/client/X11/xf_video.c b/client/X11/xf_video.c index 53c4933a8..cfa27f8e2 100644 --- a/client/X11/xf_video.c +++ b/client/X11/xf_video.c @@ -17,6 +17,7 @@ * limitations under the License. */ +#include #include #include #include @@ -63,6 +64,7 @@ static BOOL xfVideoShowSurface(VideoClientContext* video, const VideoSurface* su { const xfVideoSurface* xfSurface = (const xfVideoSurface*)surface; xfContext* xfc; + const rdpSettings* settings; WINPR_ASSERT(video); WINPR_ASSERT(xfSurface); @@ -70,9 +72,12 @@ static BOOL xfVideoShowSurface(VideoClientContext* video, const VideoSurface* su xfc = video->custom; WINPR_ASSERT(xfc); + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); + #ifdef WITH_XRENDER - if (xfc->context.settings->SmartSizing || xfc->context.settings->MultiTouchGestures) + if (settings->SmartSizing || settings->MultiTouchGestures) { XPutImage(xfc->display, xfc->primary, xfc->gc, xfSurface->image, 0, 0, surface->x, surface->y, surface->w, surface->h); @@ -106,7 +111,7 @@ void xf_video_control_init(xfContext* xfc, VideoClientContext* video) WINPR_ASSERT(xfc); WINPR_ASSERT(video); - gdi_video_control_init(xfc->context.gdi, video); + gdi_video_control_init(xfc->common.context.gdi, video); /* X11 needs to be able to handle 32bpp colors directly. */ if (xfc->depth >= 24) @@ -120,5 +125,6 @@ void xf_video_control_init(xfContext* xfc, VideoClientContext* video) void xf_video_control_uninit(xfContext* xfc, VideoClientContext* video) { - gdi_video_control_uninit(xfc->context.gdi, video); + WINPR_ASSERT(xfc); + gdi_video_control_uninit(xfc->common.context.gdi, video); } diff --git a/client/X11/xf_window.c b/client/X11/xf_window.c index 5b4103b1e..43130c557 100644 --- a/client/X11/xf_window.c +++ b/client/X11/xf_window.c @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -155,10 +156,16 @@ void xf_SetWindowMinimized(xfContext* xfc, xfWindow* window) void xf_SetWindowFullscreen(xfContext* xfc, xfWindow* window, BOOL fullscreen) { UINT32 i; - rdpSettings* settings = xfc->context.settings; + const rdpSettings* settings; int startX, startY; UINT32 width = window->width; UINT32 height = window->height; + + WINPR_ASSERT(xfc); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); + /* xfc->decorations is set by caller depending on settings and whether it is fullscreen or not */ window->decorations = xfc->decorations; @@ -189,21 +196,21 @@ void xf_SetWindowFullscreen(xfContext* xfc, xfWindow* window, BOOL fullscreen) if (fullscreen) { /* Initialize startX and startY with reasonable values */ - startX = xfc->context.settings->MonitorDefArray[0].x; - startY = xfc->context.settings->MonitorDefArray[0].y; + startX = settings->MonitorDefArray[0].x; + startY = settings->MonitorDefArray[0].y; /* Search all monitors to find the lowest startX and startY values */ - for (i = 0; i < xfc->context.settings->MonitorCount; i++) + for (i = 0; i < settings->MonitorCount; i++) { - startX = MIN(startX, xfc->context.settings->MonitorDefArray[i].x); - startY = MIN(startY, xfc->context.settings->MonitorDefArray[i].y); + startX = MIN(startX, settings->MonitorDefArray[i].x); + startY = MIN(startY, settings->MonitorDefArray[i].y); } /* Lastly apply any monitor shift(translation from remote to local coordinate system) * to startX and startY values */ - startX += xfc->context.settings->MonitorLocalShiftX; - startY += xfc->context.settings->MonitorLocalShiftY; + startX += settings->MonitorLocalShiftX; + startY += settings->MonitorLocalShiftY; } /* @@ -480,8 +487,10 @@ xfWindow* xf_CreateDesktopWindow(xfContext* xfc, char* name, int width, int heig if (!window) return NULL; - settings = xfc->context.settings; - parentWindow = (Window)xfc->context.settings->ParentWindowId; + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); + + parentWindow = (Window)settings->ParentWindowId; window->width = width; window->height = height; window->decorations = xfc->decorations; @@ -531,8 +540,8 @@ xfWindow* xf_CreateDesktopWindow(xfContext* xfc, char* name, int width, int heig { classHints->res_name = "xfreerdp"; - if (xfc->context.settings->WmClass) - classHints->res_class = xfc->context.settings->WmClass; + if (settings->WmClass) + classHints->res_class = settings->WmClass; else classHints->res_class = "xfreerdp"; @@ -576,7 +585,7 @@ xfWindow* xf_CreateDesktopWindow(xfContext* xfc, char* name, int width, int heig * monitor instead of the upper-left monitor for remote app mode (which uses all monitors). * This extra call after the window is mapped will position the login window correctly */ - if (xfc->context.settings->RemoteApplicationMode) + if (settings->RemoteApplicationMode) { XMoveWindow(xfc->display, window->handle, 0, 0); } @@ -601,7 +610,8 @@ void xf_ResizeDesktopWindow(xfContext* xfc, xfWindow* window, int width, int hei if (!xfc || !window) return; - settings = xfc->context.settings; + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); if (!(size_hints = XAllocSizeHints())) return; @@ -779,6 +789,14 @@ int xf_AppWindowCreate(xfContext* xfc, xfAppWindow* appWindow) int input_mask; XWMHints* InputModeHint; XClassHint* class_hints; + const rdpSettings* settings; + + WINPR_ASSERT(xfc); + WINPR_ASSERT(appWindow); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); + xf_FixWindowCoordinates(xfc, &appWindow->x, &appWindow->y, &appWindow->width, &appWindow->height); appWindow->decorations = FALSE; @@ -803,9 +821,9 @@ int xf_AppWindowCreate(xfContext* xfc, xfAppWindow* appWindow) { char* class = NULL; - if (xfc->context.settings->WmClass) + if (settings->WmClass) { - class_hints->res_class = xfc->context.settings->WmClass; + class_hints->res_class = settings->WmClass; } else { @@ -1056,6 +1074,12 @@ void xf_UpdateWindowArea(xfContext* xfc, xfAppWindow* appWindow, int x, int y, i int height) { int ax, ay; + const rdpSettings* settings; + + WINPR_ASSERT(xfc); + + settings = xfc->common.context.settings; + WINPR_ASSERT(settings); if (appWindow == NULL) return; @@ -1074,7 +1098,7 @@ void xf_UpdateWindowArea(xfContext* xfc, xfAppWindow* appWindow, int x, int y, i xf_lock_x11(xfc); - if (xfc->context.settings->SoftwareGdi) + if (settings->SoftwareGdi) { XPutImage(xfc->display, xfc->primary, appWindow->gc, xfc->image, ax, ay, ax, ay, width, height); diff --git a/client/X11/xfreerdp.h b/client/X11/xfreerdp.h index 29f885348..f89b6bf70 100644 --- a/client/X11/xfreerdp.h +++ b/client/X11/xfreerdp.h @@ -141,8 +141,7 @@ typedef struct touch_contact struct xf_context { - rdpContext context; - DEFINE_RDP_CLIENT_COMMON(); + rdpClientContext common; GC gc; int xfds; diff --git a/include/freerdp/client.h b/include/freerdp/client.h index be4d1bc8e..646243cb1 100644 --- a/include/freerdp/client.h +++ b/include/freerdp/client.h @@ -66,12 +66,10 @@ extern "C" /* Common Client Interface */ -#define DEFINE_RDP_CLIENT_COMMON() HANDLE thread - struct rdp_client_context { rdpContext context; - DEFINE_RDP_CLIENT_COMMON(); + HANDLE thread; }; /* Common client functions */ diff --git a/server/shadow/Win/win_rdp.c b/server/shadow/Win/win_rdp.c index d083bfd8c..db34861bc 100644 --- a/server/shadow/Win/win_rdp.c +++ b/server/shadow/Win/win_rdp.c @@ -245,7 +245,7 @@ static int shw_freerdp_client_start(rdpContext* context) freerdp* instance = context->instance; shw = (shwContext*)context; - if (!(shw->thread = CreateThread(NULL, 0, shw_client_thread, instance, 0, NULL))) + if (!(shw->common.thread = CreateThread(NULL, 0, shw_client_thread, instance, 0, NULL))) { WLog_ERR(TAG, "Failed to create thread"); return -1; diff --git a/server/shadow/Win/win_rdp.h b/server/shadow/Win/win_rdp.h index 0688da1ba..07dbf3bb9 100644 --- a/server/shadow/Win/win_rdp.h +++ b/server/shadow/Win/win_rdp.h @@ -30,8 +30,7 @@ typedef struct shw_context shwContext; struct shw_context { - rdpContext context; - DEFINE_RDP_CLIENT_COMMON(); + rdpClientContext common; HANDLE StopEvent; freerdp* instance; diff --git a/server/shadow/Win/win_shadow.c b/server/shadow/Win/win_shadow.c index 550f367fd..d4fcf176f 100644 --- a/server/shadow/Win/win_shadow.c +++ b/server/shadow/Win/win_shadow.c @@ -291,9 +291,17 @@ static int win_shadow_surface_copy(winShadowSubsystem* subsystem) rdpGdi* gdi; shwContext* shw; rdpContext* context; + + WINPR_ASSERT(subsystem); shw = subsystem->shw; - context = &shw->context; + WINPR_ASSERT(shw); + + context = &shw->common.context; + WINPR_ASSERT(context); + gdi = context->gdi; + WINPR_ASSERT(gdi); + pDstData = gdi->primary_buffer; nDstStep = gdi->width * 4; DstFormat = gdi->dstFormat;