13#include <freerdp/config.h>
17#include <freerdp/freerdp.h>
18#include <freerdp/log.h>
20#define TAG CLIENT_TAG("android")
22#include "android_freerdp.h"
23#include "android_cliprdr.h"
29 if (aCtx->event_queue->count >= aCtx->event_queue->size)
31 size_t new_size = aCtx->event_queue->size;
34 if (new_size >= SIZE_MAX - 128ull)
38 }
while (new_size <= aCtx->event_queue->count);
40 realloc((
void*)aCtx->event_queue->events,
sizeof(
ANDROID_EVENT*) * new_size);
45 aCtx->event_queue->events = new_events;
46 aCtx->event_queue->size = new_size;
49 aCtx->event_queue->events[(aCtx->event_queue->count)++] = event;
50 return SetEvent(aCtx->event_queue->isSet);
60 event = queue->events[0];
71 event = queue->events[0];
74 for (
size_t i = 0; i < queue->count; i++)
76 queue->events[i] = queue->events[i + 1];
89 context = inst->context;
90 WINPR_ASSERT(context);
92 while (android_peek_event(queue))
106 rc = freerdp_input_send_keyboard_event(context->input, key_event->flags,
107 key_event->scancode);
111 case EVENT_TYPE_KEY_UNICODE:
115 rc = freerdp_input_send_unicode_keyboard_event(context->input, key_event->flags,
116 key_event->scancode);
120 case EVENT_TYPE_CURSOR:
124 rc = freerdp_input_send_mouse_event(context->input, cursor_event->flags,
125 cursor_event->x, cursor_event->y);
129 case EVENT_TYPE_CLIPBOARD:
132 const char* mimeType = clipboard_event->mimeType;
133 UINT32 formatId = ClipboardRegisterFormat(afc->clipboard, mimeType);
134 UINT32 size = clipboard_event->data_length;
137 ClipboardSetData(afc->clipboard, formatId, clipboard_event->data, size);
139 ClipboardEmpty(afc->clipboard);
141 rc = (android_cliprdr_send_client_format_list(afc->cliprdr) == CHANNEL_RC_OK);
145 case EVENT_TYPE_DISCONNECT:
150 android_event_free(event);
159HANDLE android_get_handle(freerdp* inst)
163 if (!inst || !inst->context)
168 if (!aCtx->event_queue || !aCtx->event_queue->isSet)
171 return aCtx->event_queue->isSet;
174BOOL android_check_handle(freerdp* inst)
178 if (!inst || !inst->context)
183 if (!aCtx->event_queue || !aCtx->event_queue->isSet)
186 if (WaitForSingleObject(aCtx->event_queue->isSet, 0) == WAIT_OBJECT_0)
188 if (!ResetEvent(aCtx->event_queue->isSet))
191 if (!android_process_event(aCtx->event_queue, inst))
205 event->type = EVENT_TYPE_KEY;
206 event->flags = flags;
207 event->scancode = scancode;
224 event->type = EVENT_TYPE_KEY_UNICODE;
225 event->flags = flags;
226 event->scancode = key;
243 event->type = EVENT_TYPE_CURSOR;
246 event->flags = flags;
263 event->type = EVENT_TYPE_DISCONNECT;
267static void android_event_disconnect_free(
ANDROID_EVENT* event)
273 const char* mimeType)
281 event->type = EVENT_TYPE_CLIPBOARD;
282 event->mimeType = mimeType ? _strdup(mimeType) : nullptr;
284 if (mimeType && !event->mimeType)
290 if (data && data_length > 0)
292 const BOOL isText = !mimeType || strcmp(mimeType,
"text/plain") == 0;
294 event->data = isText ? calloc(data_length + 1,
sizeof(
char)) : malloc(data_length);
298 free(event->mimeType);
303 memcpy(event->data, data, data_length);
304 event->data_length = isText ? data_length + 1 : data_length;
315 free(event->mimeType);
320BOOL android_event_queue_init(freerdp* inst)
328 WLog_ERR(TAG,
"android_event_queue_init: memory allocation failed");
334 queue->isSet = CreateEventA(
nullptr, TRUE, FALSE,
nullptr);
346 WLog_ERR(TAG,
"android_event_queue_init: memory allocation failed");
347 (void)CloseHandle(queue->isSet);
352 aCtx->event_queue = queue;
356void android_event_queue_uninit(freerdp* inst)
361 if (!inst || !inst->context)
365 queue = aCtx->event_queue;
371 (void)CloseHandle(queue->isSet);
372 queue->isSet =
nullptr;
378 queue->events =
nullptr;
398 case EVENT_TYPE_KEY_UNICODE:
402 case EVENT_TYPE_CURSOR:
406 case EVENT_TYPE_DISCONNECT:
410 case EVENT_TYPE_CLIPBOARD: