Skip to content

Commit

Permalink
Use lv_ll_t to fix the keyboard queue issue when enabling IME support.
Browse files Browse the repository at this point in the history
  • Loading branch information
MouriNaruto committed Dec 5, 2023
1 parent 5b3717b commit 7ed4237
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 35 deletions.
43 changes: 10 additions & 33 deletions LvglWindowsSimulator/win32drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,12 @@ static void lv_win32_push_key_to_keyboard_queue(
uint32_t key,
lv_indev_state_t state)
{
lv_win32_keypad_queue_item_t* current =
(lv_win32_keypad_queue_item_t*)(_aligned_malloc(
sizeof(lv_win32_keypad_queue_item_t),
MEMORY_ALLOCATION_ALIGNMENT));
lv_win32_keypad_queue_item_t* current = (lv_win32_keypad_queue_item_t*)(
_lv_ll_ins_tail(&context->keypad.queue));
if (current)
{
current->key = key;
current->state = state;
InterlockedPushEntrySList(
context->keypad.queue,
&current->ItemEntry);
}
}

Expand Down Expand Up @@ -679,15 +674,15 @@ static void lv_win32_keypad_driver_read_callback(

EnterCriticalSection(&context->keypad.mutex);

lv_win32_keypad_queue_item_t* current =
(lv_win32_keypad_queue_item_t*)(InterlockedPopEntrySList(
context->keypad.queue));
lv_win32_keypad_queue_item_t* current = (lv_win32_keypad_queue_item_t*)(
_lv_ll_get_head(&context->keypad.queue));
if (current)
{
data->key = current->key;
data->state = current->state;

_aligned_free(current);
_lv_ll_remove(&context->keypad.queue, current);
lv_free(current);

data->continue_reading = true;
}
Expand Down Expand Up @@ -831,14 +826,9 @@ static LRESULT CALLBACK lv_win32_window_message_callback(
context->display_device_object);

InitializeCriticalSection(&context->keypad.mutex);
context->keypad.queue = _aligned_malloc(
sizeof(SLIST_HEADER),
MEMORY_ALLOCATION_ALIGNMENT);
if (!context->keypad.queue)
{
return -1;
}
InitializeSListHead(context->keypad.queue);
_lv_ll_init(
&context->keypad.queue,
sizeof(lv_win32_keypad_queue_item_t));
context->keypad.utf16_high_surrogate = 0;
context->keypad.utf16_low_surrogate = 0;
context->keyboard_device_object = lv_indev_create();
Expand Down Expand Up @@ -1353,20 +1343,7 @@ static LRESULT CALLBACK lv_win32_window_message_callback(
context->keyboard_device_object;
context->keyboard_device_object = NULL;
lv_indev_delete(keyboard_device_object);
do
{
PSLIST_ENTRY current = InterlockedPopEntrySList(
context->keypad.queue);
if (!current)
{
_aligned_free(context->keypad.queue);
context->keypad.queue = NULL;
break;
}

_aligned_free(current);

} while (true);
_lv_ll_clear(&context->keypad.queue);
DeleteCriticalSection(&context->keypad.mutex);

free(context);
Expand Down
3 changes: 1 addition & 2 deletions LvglWindowsSimulator/win32drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,14 @@ typedef struct _lv_windows_pointer_device_context_t

typedef struct _lv_win32_keypad_queue_item_t
{
SLIST_ENTRY ItemEntry;
uint32_t key;
lv_indev_state_t state;
} lv_win32_keypad_queue_item_t;

typedef struct _lv_windows_keypad_device_context_t
{
CRITICAL_SECTION mutex;
PSLIST_HEADER queue;
lv_ll_t queue;
uint16_t utf16_high_surrogate;
uint16_t utf16_low_surrogate;
} lv_windows_keypad_device_context_t;
Expand Down

0 comments on commit 7ed4237

Please sign in to comment.