From 58c392e72ece92c62409a889419ea1e73614d12e Mon Sep 17 00:00:00 2001 From: erbth Date: Fri, 3 Oct 2014 16:27:47 +0200 Subject: [PATCH] Added lock key synchronization to wfreerdp --- client/Windows/wf_client.c | 6 ++++++ client/Windows/wf_event.c | 34 ++++++++++++++++++++++++++++++++-- include/freerdp/freerdp.h | 1 + libfreerdp/core/freerdp.c | 8 ++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/client/Windows/wf_client.c b/client/Windows/wf_client.c index ce93ad81d..40a020bb4 100644 --- a/client/Windows/wf_client.c +++ b/client/Windows/wf_client.c @@ -738,6 +738,12 @@ DWORD WINAPI wf_client_thread(LPVOID lpParam) rcount = 0; wcount = 0; + if (freerdp_focus_required(instance)) + { + wf_event_focus_in(wfc); + wf_event_focus_in(wfc); + } + if (!async_transport) { if (freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount) != TRUE) diff --git a/client/Windows/wf_event.c b/client/Windows/wf_event.c index 0a0c8569e..3ac978124 100644 --- a/client/Windows/wf_event.c +++ b/client/Windows/wf_event.c @@ -132,8 +132,8 @@ LRESULT CALLBACK wf_ll_kbd_proc(int nCode, WPARAM wParam, LPARAM lParam) freerdp_input_send_keyboard_event_ex(input, !(p->flags & LLKHF_UP), rdp_scancode); - if (p->vkCode == VK_CAPITAL) - DEBUG_KBD("caps lock is processed on client side too to toggle caps lock indicator"); + if (p->vkCode == VK_NUMLOCK || p->vkCode == VK_CAPITAL || p->vkCode == VK_SCROLL || p->vkCode == VK_KANA) + DEBUG_KBD("lock keys are processed on client side too to toggle their indicators"); else return 1; @@ -153,6 +153,34 @@ LRESULT CALLBACK wf_ll_kbd_proc(int nCode, WPARAM wParam, LPARAM lParam) return CallNextHookEx(NULL, nCode, wParam, lParam); } +void wf_event_focus_in(wfContext* wfc) +{ + UINT16 syncFlags; + rdpInput* input; + UINT16 mouseX, mouseY; + + input = wfc->instance->input; + + syncFlags = 0; + + if (GetKeyState(VK_NUMLOCK)) + syncFlags |= KBD_SYNC_NUM_LOCK; + + if (GetKeyState(VK_CAPITAL)) + syncFlags |= KBD_SYNC_CAPS_LOCK; + + if (GetKeyState(VK_SCROLL)) + syncFlags |= KBD_SYNC_SCROLL_LOCK; + + if (GetKeyState(VK_KANA)) + syncFlags |= KBD_SYNC_KANA_LOCK; + + mouseX = 0; + mouseY = 0; + + input->FocusInEvent(input, syncFlags, mouseX, mouseY); +} + static int wf_event_process_WM_MOUSEWHEEL(wfContext* wfc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { int delta; @@ -230,6 +258,7 @@ LRESULT CALLBACK wf_event_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam ptr = GetWindowLongPtr(hWnd, GWLP_USERDATA); wfc = (wfContext*) ptr; + if (wfc != NULL) { input = wfc->instance->input; @@ -540,6 +569,7 @@ LRESULT CALLBACK wf_event_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam if (alt_ctrl_down()) g_flipping_in = TRUE; g_focus_hWnd = hWnd; + freerdp_set_focus(wfc->instance); break; case WM_KILLFOCUS: diff --git a/include/freerdp/freerdp.h b/include/freerdp/freerdp.h index bd5846db8..7023e9d2e 100644 --- a/include/freerdp/freerdp.h +++ b/include/freerdp/freerdp.h @@ -254,6 +254,7 @@ FREERDP_API freerdp* freerdp_new(void); FREERDP_API void freerdp_free(freerdp* instance); FREERDP_API BOOL freerdp_focus_required(freerdp* instance); +FREERDP_API void freerdp_set_focus(freerdp* instance); FREERDP_API UINT32 freerdp_get_last_error(rdpContext* context); FREERDP_API void freerdp_set_last_error(rdpContext* context, UINT32 lastError); diff --git a/libfreerdp/core/freerdp.c b/libfreerdp/core/freerdp.c index 196a6cd88..395d59fb2 100644 --- a/libfreerdp/core/freerdp.c +++ b/libfreerdp/core/freerdp.c @@ -358,6 +358,14 @@ FREERDP_API BOOL freerdp_focus_required(freerdp* instance) return bRetCode; } +void freerdp_set_focus(freerdp* instance) +{ + rdpRdp* rdp; + + rdp = instance->context->rdp; + rdp->resendFocus = TRUE; +} + void freerdp_get_version(int* major, int* minor, int* revision) { if (major != NULL)