From 22bd0a43e6fd3d0fd0eaab201799224ea66af9c2 Mon Sep 17 00:00:00 2001 From: garbb Date: Wed, 14 Sep 2022 20:55:18 -0700 Subject: [PATCH] add windows client assistance request control menu item --- client/Windows/wf_client.c | 40 ++++++++++++++++++++++++++++---------- client/Windows/wf_client.h | 3 +++ client/Windows/wf_event.c | 4 ++++ 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/client/Windows/wf_client.c b/client/Windows/wf_client.c index a2742189e..4190e647b 100644 --- a/client/Windows/wf_client.c +++ b/client/Windows/wf_client.c @@ -272,10 +272,24 @@ static BOOL wf_pre_connect(freerdp* instance) return TRUE; } +static void wf_append_item_to_system_menu(HMENU hMenu, UINT fMask, UINT wID, const wchar_t* text, + wfContext* wfc) +{ + MENUITEMINFO item_info = { 0 }; + item_info.fMask = fMask; + item_info.cbSize = sizeof(MENUITEMINFO); + item_info.wID = wID; + item_info.fType = MFT_STRING; + item_info.dwTypeData = _wcsdup(text); + item_info.cch = (UINT)_wcslen(text); + if (wfc) + item_info.dwItemData = (ULONG_PTR)wfc; + InsertMenuItem(hMenu, wfc->systemMenuInsertPosition++, TRUE, &item_info); +} + static void wf_add_system_menu(wfContext* wfc) { HMENU hMenu; - MENUITEMINFO item_info; if (wfc->fullscreen && !wfc->fullscreen_toggle) { @@ -288,20 +302,19 @@ static void wf_add_system_menu(wfContext* wfc) } hMenu = GetSystemMenu(wfc->hwnd, FALSE); - ZeroMemory(&item_info, sizeof(MENUITEMINFO)); - item_info.fMask = MIIM_CHECKMARKS | MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_DATA; - item_info.cbSize = sizeof(MENUITEMINFO); - item_info.wID = SYSCOMMAND_ID_SMARTSIZING; - item_info.fType = MFT_STRING; - item_info.dwTypeData = _wcsdup(_T("Smart sizing")); - item_info.cch = (UINT)_wcslen(_T("Smart sizing")); - item_info.dwItemData = (ULONG_PTR)wfc; - InsertMenuItem(hMenu, 6, TRUE, &item_info); + + wf_append_item_to_system_menu(hMenu, + MIIM_CHECKMARKS | MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_DATA, + SYSCOMMAND_ID_SMARTSIZING, L"Smart sizing", wfc); if (wfc->common.context.settings->SmartSizing) { CheckMenuItem(hMenu, SYSCOMMAND_ID_SMARTSIZING, MF_CHECKED); } + + if (wfc->common.context.settings->RemoteAssistanceMode) + wf_append_item_to_system_menu(hMenu, MIIM_FTYPE | MIIM_ID | MIIM_STRING, + SYSCOMMAND_ID_REQUEST_CONTROL, L"Request control", wfc); } static WCHAR* wf_window_get_title(rdpSettings* settings) @@ -1355,6 +1368,13 @@ static int wfreerdp_client_start(rdpContext* context) hWndParent = (HWND)context->settings->ParentWindowId; context->settings->EmbeddedWindow = (hWndParent) ? TRUE : FALSE; wfc->hWndParent = hWndParent; + + /* initial windows system item position where we will insert new menu item + * after default 5 items (restore, move, size, minimize, maximize) + * gets incremented each time wf_append_item_to_system_menu is called + * or maybe could use GetMenuItemCount() to get initial item count ? */ + wfc->systemMenuInsertPosition = 6; + wfc->hInstance = hInstance; wfc->cursor = LoadCursor(NULL, IDC_ARROW); wfc->icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1)); diff --git a/client/Windows/wf_client.h b/client/Windows/wf_client.h index d78cb4426..08803ad0c 100644 --- a/client/Windows/wf_client.h +++ b/client/Windows/wf_client.h @@ -56,6 +56,7 @@ extern "C" // System menu constants #define SYSCOMMAND_ID_SMARTSIZING 1000 +#define SYSCOMMAND_ID_REQUEST_CONTROL 1001 typedef struct { @@ -96,6 +97,8 @@ extern "C" LPCTSTR wndClassName; HCURSOR hDefaultCursor; + UINT systemMenuInsertPosition; + HWND hwnd; BOOL is_shown; ITaskbarList3* taskBarList; diff --git a/client/Windows/wf_event.c b/client/Windows/wf_event.c index dda7f9cc7..a9a995f20 100644 --- a/client/Windows/wf_event.c +++ b/client/Windows/wf_event.c @@ -690,6 +690,10 @@ LRESULT CALLBACK wf_event_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam wf_send_resize(wfc); } } + else if (wParam == SYSCOMMAND_ID_REQUEST_CONTROL) + { + freerdp_client_encomsp_set_control(wfc->common.encomsp, TRUE); + } else { processed = FALSE;