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 UINT32 formatId = ClipboardRegisterFormat(afc->clipboard,
"text/plain");
133 UINT32 size = clipboard_event->data_length;
136 ClipboardSetData(afc->clipboard, formatId, clipboard_event->data, size);
138 ClipboardEmpty(afc->clipboard);
140 rc = (android_cliprdr_send_client_format_list(afc->cliprdr) == CHANNEL_RC_OK);
144 case EVENT_TYPE_DISCONNECT:
149 android_event_free(event);
158HANDLE android_get_handle(freerdp* inst)
162 if (!inst || !inst->context)
167 if (!aCtx->event_queue || !aCtx->event_queue->isSet)
170 return aCtx->event_queue->isSet;
173BOOL android_check_handle(freerdp* inst)
177 if (!inst || !inst->context)
182 if (!aCtx->event_queue || !aCtx->event_queue->isSet)
185 if (WaitForSingleObject(aCtx->event_queue->isSet, 0) == WAIT_OBJECT_0)
187 if (!ResetEvent(aCtx->event_queue->isSet))
190 if (!android_process_event(aCtx->event_queue, inst))
204 event->type = EVENT_TYPE_KEY;
205 event->flags = flags;
206 event->scancode = scancode;
223 event->type = EVENT_TYPE_KEY_UNICODE;
224 event->flags = flags;
225 event->scancode = key;
242 event->type = EVENT_TYPE_CURSOR;
245 event->flags = flags;
262 event->type = EVENT_TYPE_DISCONNECT;
266static void android_event_disconnect_free(
ANDROID_EVENT* event)
279 event->type = EVENT_TYPE_CLIPBOARD;
283 event->data = calloc(data_length + 1,
sizeof(
char));
291 memcpy(event->data, data, data_length);
292 event->data_length = data_length + 1;
307BOOL android_event_queue_init(freerdp* inst)
315 WLog_ERR(TAG,
"android_event_queue_init: memory allocation failed");
321 queue->isSet = CreateEventA(NULL, TRUE, FALSE, NULL);
333 WLog_ERR(TAG,
"android_event_queue_init: memory allocation failed");
334 (void)CloseHandle(queue->isSet);
339 aCtx->event_queue = queue;
343void android_event_queue_uninit(freerdp* inst)
348 if (!inst || !inst->context)
352 queue = aCtx->event_queue;
358 (void)CloseHandle(queue->isSet);
365 queue->events = NULL;
385 case EVENT_TYPE_KEY_UNICODE:
389 case EVENT_TYPE_CURSOR:
393 case EVENT_TYPE_DISCONNECT:
397 case EVENT_TYPE_CLIPBOARD: