Skip to content

Commit

Permalink
Added proxy input state sync (FreeRDP#7282)
Browse files Browse the repository at this point in the history
The proxy server component might receive input related events
before the proxy client has established the connection to the
target machine.
With this change, the current keyboard state is cached and sent
to the target when it is ready. All input events received before
the target is ready are discarded.

(cherry picked from commit 4d23bc9)
  • Loading branch information
akallabeth committed Nov 7, 2022
1 parent b14fe5a commit 6a907ee
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions server/proxy/pf_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ struct p_client_context
UINT64 frames_count;

wHashTable* vc_ids; /* channel_name -> channel_id map */

BOOL input_state_sync_pending;
UINT32 input_state;
};
typedef struct p_client_context pClientContext;

Expand Down
31 changes: 30 additions & 1 deletion server/proxy/pf_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,28 @@
#include "pf_context.h"
#include "pf_modules.h"

static BOOL pf_server_check_and_sync_input_state(pClientContext* pc)
{
if (freerdp_get_state(&pc->context) < CONNECTION_STATE_ACTIVE)
return FALSE;
if (pc->input_state_sync_pending)
{
BOOL rc = freerdp_input_send_synchronize_event(pc->context.input, pc->input_state);
if (rc)
pc->input_state_sync_pending = FALSE;
}
return TRUE;
}

static BOOL pf_server_synchronize_event(rdpInput* input, UINT32 flags)
{
pServerContext* ps = (pServerContext*)input->context;
pClientContext* pc = ps->pdata->pc;
return freerdp_input_send_synchronize_event(pc->context.input, flags);

pc->input_state = flags;
pc->input_state_sync_pending = TRUE;
pf_server_check_and_sync_input_state(pc);
return TRUE;
}

static BOOL pf_server_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
Expand All @@ -37,6 +54,9 @@ static BOOL pf_server_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
proxyConfig* config = ps->pdata->config;
proxyKeyboardEventInfo event;

if (!pf_server_check_and_sync_input_state(pc))
return TRUE;

if (!config->Keyboard)
return TRUE;

Expand All @@ -55,6 +75,9 @@ static BOOL pf_server_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT
pClientContext* pc = ps->pdata->pc;
proxyConfig* config = ps->pdata->config;

if (!pf_server_check_and_sync_input_state(pc))
return TRUE;

if (!config->Keyboard)
return TRUE;

Expand All @@ -68,6 +91,9 @@ static BOOL pf_server_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT1
proxyConfig* config = ps->pdata->config;
proxyMouseEventInfo event;

if (!pf_server_check_and_sync_input_state(pc))
return TRUE;

if (!config->Mouse)
return TRUE;

Expand All @@ -87,6 +113,9 @@ static BOOL pf_server_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16
pClientContext* pc = ps->pdata->pc;
proxyConfig* config = ps->pdata->config;

if (!pf_server_check_and_sync_input_state(pc))
return TRUE;

if (!config->Mouse)
return TRUE;

Expand Down

0 comments on commit 6a907ee

Please sign in to comment.