19#include <winpr/assert.h>
20#include <freerdp/config.h>
22#include <freerdp/log.h>
25#define TAG SERVER_TAG("shadow.input")
28static BOOL shadow_input_synchronize_event(rdpInput* input, UINT32 flags)
31 rdpShadowClient* client = (rdpShadowClient*)input->context;
33 WINPR_ASSERT(client->server);
34 rdpShadowSubsystem* subsystem = client->server->subsystem;
35 WINPR_ASSERT(subsystem);
37 WLog_DBG(TAG,
"[%s] flags=0x%04" PRIx16, client->mayInteract ?
"use" :
"discard", flags);
38 if (!client->mayInteract)
41 return IFCALLRESULT(TRUE, subsystem->SynchronizeEvent, subsystem, client, flags);
45static BOOL shadow_input_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code)
48 rdpShadowClient* client = (rdpShadowClient*)input->context;
50 WINPR_ASSERT(client->server);
51 rdpShadowSubsystem* subsystem = client->server->subsystem;
52 WINPR_ASSERT(subsystem);
54 WLog_DBG(TAG,
"[%s] flags=0x%04" PRIx16, client->mayInteract ?
"use" :
"discard", flags);
55 if (!client->mayInteract)
58 return IFCALLRESULT(TRUE, subsystem->KeyboardEvent, subsystem, client, flags, code);
62static BOOL shadow_input_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
65 rdpShadowClient* client = (rdpShadowClient*)input->context;
67 WINPR_ASSERT(client->server);
68 rdpShadowSubsystem* subsystem = client->server->subsystem;
69 WINPR_ASSERT(subsystem);
71 WLog_DBG(TAG,
"[%s] flags=0x%04" PRIx16, client->mayInteract ?
"use" :
"discard", flags);
72 if (!client->mayInteract)
75 return IFCALLRESULT(TRUE, subsystem->UnicodeKeyboardEvent, subsystem, client, flags, code);
79static BOOL shadow_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
82 rdpShadowClient* client = (rdpShadowClient*)input->context;
84 WINPR_ASSERT(client->server);
85 rdpShadowSubsystem* subsystem = client->server->subsystem;
86 WINPR_ASSERT(subsystem);
88 if (client->server->shareSubRect)
90 x += client->server->subRect.left;
91 y += client->server->subRect.top;
94 if ((flags & (PTR_FLAGS_WHEEL | PTR_FLAGS_HWHEEL | PTR_FLAGS_WHEEL_NEGATIVE)) == 0)
99 if ((client->pointerX == subsystem->pointerX) && (client->pointerY == subsystem->pointerY))
101 flags &= ~PTR_FLAGS_MOVE;
103 if (!(flags & (PTR_FLAGS_BUTTON1 | PTR_FLAGS_BUTTON2 | PTR_FLAGS_BUTTON3)))
108 WLog_DBG(TAG,
"[%s] flags=0x%04" PRIx16
", x=%" PRIu16
", y=%" PRIu16,
109 client->mayInteract ?
"use" :
"discard", flags, x, y);
110 if (!client->mayInteract)
113 return IFCALLRESULT(TRUE, subsystem->MouseEvent, subsystem, client, flags, x, y);
117static BOOL shadow_input_rel_mouse_event(rdpInput* input, UINT16 flags, INT16 xDelta, INT16 yDelta)
121 rdpShadowClient* client = (rdpShadowClient*)input->context;
122 WINPR_ASSERT(client);
123 WINPR_ASSERT(client->server);
125 rdpShadowSubsystem* subsystem = client->server->subsystem;
126 WINPR_ASSERT(subsystem);
128 WLog_DBG(TAG,
"[%s] flags=0x%04" PRIx16
", x=%" PRId16
", y=%" PRId16,
129 client->mayInteract ?
"use" :
"discard", flags, xDelta, yDelta);
130 const uint16_t mask = PTR_FLAGS_MOVE | PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1 | PTR_FLAGS_BUTTON2 |
131 PTR_FLAGS_BUTTON3 | PTR_XFLAGS_BUTTON1 | PTR_XFLAGS_BUTTON2;
132 if ((flags & mask) != 0)
134 WLog_WARN(TAG,
"Unknown flags 0x%04x", WINPR_CXX_COMPAT_CAST(
unsigned, flags & ~mask));
136 if (!client->mayInteract)
139 return IFCALLRESULT(TRUE, subsystem->RelMouseEvent, subsystem, client, flags, xDelta, yDelta);
143static BOOL shadow_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
146 rdpShadowClient* client = (rdpShadowClient*)input->context;
147 WINPR_ASSERT(client);
148 WINPR_ASSERT(client->server);
149 rdpShadowSubsystem* subsystem = client->server->subsystem;
150 WINPR_ASSERT(subsystem);
152 if (client->server->shareSubRect)
154 x += client->server->subRect.left;
155 y += client->server->subRect.top;
158 client->pointerX = x;
159 client->pointerY = y;
161 WLog_DBG(TAG,
"[%s] flags=0x%04" PRIx16
", x=%" PRIu16
", y=%" PRIu16,
162 client->mayInteract ?
"use" :
"discard", flags, x, y);
163 if (!client->mayInteract)
166 return IFCALLRESULT(TRUE, subsystem->ExtendedMouseEvent, subsystem, client, flags, x, y);
169void shadow_input_register_callbacks(rdpInput* input)
172 input->SynchronizeEvent = shadow_input_synchronize_event;
173 input->KeyboardEvent = shadow_input_keyboard_event;
174 input->UnicodeKeyboardEvent = shadow_input_unicode_keyboard_event;
175 input->MouseEvent = shadow_input_mouse_event;
176 input->ExtendedMouseEvent = shadow_input_extended_mouse_event;
177 input->RelMouseEvent = shadow_input_rel_mouse_event;