mirror of
https://github.com/lvgl/lvgl.git
synced 2024-11-23 09:43:41 +08:00
fix(Windows): use global lock (#6425)
This commit is contained in:
parent
f8c26ea150
commit
af041657aa
1
Kconfig
1
Kconfig
@ -1699,6 +1699,7 @@ menu "LVGL configuration"
|
||||
|
||||
config LV_USE_WINDOWS
|
||||
bool "Use LVGL Windows backend"
|
||||
depends on LV_OS_WINDOWS
|
||||
default n
|
||||
|
||||
config LV_USE_OPENGLES
|
||||
|
@ -79,6 +79,8 @@ Usage
|
||||
return -1;
|
||||
}
|
||||
|
||||
lv_lock();
|
||||
|
||||
lv_indev_t* pointer_device = lv_windows_acquire_pointer_indev(display);
|
||||
if (!pointer_device)
|
||||
{
|
||||
@ -99,6 +101,8 @@ Usage
|
||||
|
||||
lv_demo_widgets();
|
||||
|
||||
lv_unlock();
|
||||
|
||||
while (1)
|
||||
{
|
||||
uint32_t time_till_next = lv_timer_handler();
|
||||
|
@ -36,6 +36,13 @@ static void lv_windows_delay_callback(uint32_t ms);
|
||||
static void lv_windows_check_display_existence_timer_callback(
|
||||
lv_timer_t * timer);
|
||||
|
||||
static bool lv_windows_window_message_callback_nolock(
|
||||
HWND hWnd,
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam,
|
||||
LRESULT * plResult);
|
||||
|
||||
static LRESULT CALLBACK lv_windows_window_message_callback(
|
||||
HWND hWnd,
|
||||
UINT uMsg,
|
||||
@ -452,11 +459,12 @@ static BOOL lv_windows_enable_child_window_dpi_message(
|
||||
return function(WindowHandle, TRUE);
|
||||
}
|
||||
|
||||
static LRESULT CALLBACK lv_windows_window_message_callback(
|
||||
static bool lv_windows_window_message_callback_nolock(
|
||||
HWND hWnd,
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
LPARAM lParam,
|
||||
LRESULT * plResult)
|
||||
{
|
||||
switch(uMsg) {
|
||||
case WM_CREATE: {
|
||||
@ -646,15 +654,15 @@ static LRESULT CALLBACK lv_windows_window_message_callback(
|
||||
lv_windows_window_context_t * context = (lv_windows_window_context_t *)(
|
||||
lv_windows_get_window_context(hWnd));
|
||||
if(context) {
|
||||
LRESULT lResult = 0;
|
||||
if(context->pointer.indev &&
|
||||
lv_windows_pointer_device_window_message_handler(
|
||||
hWnd,
|
||||
uMsg,
|
||||
wParam,
|
||||
lParam,
|
||||
&lResult)) {
|
||||
return lResult;
|
||||
plResult)) {
|
||||
// Handled
|
||||
return true;
|
||||
}
|
||||
else if(context->keypad.indev &&
|
||||
lv_windows_keypad_device_window_message_handler(
|
||||
@ -662,8 +670,9 @@ static LRESULT CALLBACK lv_windows_window_message_callback(
|
||||
uMsg,
|
||||
wParam,
|
||||
lParam,
|
||||
&lResult)) {
|
||||
return lResult;
|
||||
plResult)) {
|
||||
// Handled
|
||||
return true;
|
||||
}
|
||||
else if(context->encoder.indev &&
|
||||
lv_windows_encoder_device_window_message_handler(
|
||||
@ -671,16 +680,41 @@ static LRESULT CALLBACK lv_windows_window_message_callback(
|
||||
uMsg,
|
||||
wParam,
|
||||
lParam,
|
||||
&lResult)) {
|
||||
return lResult;
|
||||
plResult)) {
|
||||
// Handled
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
|
||||
// Not Handled
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
// Handled
|
||||
*plResult = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static LRESULT CALLBACK lv_windows_window_message_callback(
|
||||
HWND hWnd,
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
lv_lock();
|
||||
|
||||
LRESULT lResult = 0;
|
||||
bool Handled = lv_windows_window_message_callback_nolock(
|
||||
hWnd,
|
||||
uMsg,
|
||||
wParam,
|
||||
lParam,
|
||||
&lResult);
|
||||
|
||||
lv_unlock();
|
||||
|
||||
return Handled ? lResult : DefWindowProcW(hWnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
#endif // LV_USE_WINDOWS
|
||||
|
@ -1,4 +1,4 @@
|
||||
/**
|
||||
/**
|
||||
* @file lv_windows_context.h
|
||||
*
|
||||
*/
|
||||
@ -19,8 +19,20 @@ extern "C" {
|
||||
|
||||
#if LV_USE_WINDOWS
|
||||
|
||||
#if LV_USE_OS != LV_OS_WINDOWS
|
||||
#error [lv_windows] LV_OS_WINDOWS is required. Enable it in lv_conf.h (LV_USE_OS LV_OS_WINDOWS)
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#ifndef CREATE_WAITABLE_TIMER_MANUAL_RESET
|
||||
#define CREATE_WAITABLE_TIMER_MANUAL_RESET 0x00000001
|
||||
#endif
|
||||
|
||||
#ifndef CREATE_WAITABLE_TIMER_HIGH_RESOLUTION
|
||||
#define CREATE_WAITABLE_TIMER_HIGH_RESOLUTION 0x00000002
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
@ -41,7 +53,6 @@ typedef struct _lv_windows_keypad_queue_item_t {
|
||||
} lv_windows_keypad_queue_item_t;
|
||||
|
||||
typedef struct _lv_windows_keypad_context_t {
|
||||
CRITICAL_SECTION mutex;
|
||||
lv_ll_t queue;
|
||||
uint16_t utf16_high_surrogate;
|
||||
uint16_t utf16_low_surrogate;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/**
|
||||
/**
|
||||
* @file lv_windows_input.c
|
||||
*
|
||||
*/
|
||||
@ -128,7 +128,6 @@ lv_indev_t * lv_windows_acquire_keypad_indev(lv_display_t * display)
|
||||
}
|
||||
|
||||
if(!context->keypad.indev) {
|
||||
InitializeCriticalSection(&context->keypad.mutex);
|
||||
_lv_ll_init(
|
||||
&context->keypad.queue,
|
||||
sizeof(lv_windows_keypad_queue_item_t));
|
||||
@ -421,8 +420,6 @@ static void lv_windows_keypad_driver_read_callback(
|
||||
return;
|
||||
}
|
||||
|
||||
EnterCriticalSection(&context->keypad.mutex);
|
||||
|
||||
lv_windows_keypad_queue_item_t * current = (lv_windows_keypad_queue_item_t *)(
|
||||
_lv_ll_get_head(&context->keypad.queue));
|
||||
if(current) {
|
||||
@ -434,8 +431,6 @@ static void lv_windows_keypad_driver_read_callback(
|
||||
|
||||
data->continue_reading = true;
|
||||
}
|
||||
|
||||
LeaveCriticalSection(&context->keypad.mutex);
|
||||
}
|
||||
|
||||
static void lv_windows_release_keypad_device_event_callback(lv_event_t * e)
|
||||
@ -456,7 +451,6 @@ static void lv_windows_release_keypad_device_event_callback(lv_event_t * e)
|
||||
return;
|
||||
}
|
||||
|
||||
DeleteCriticalSection(&context->keypad.mutex);
|
||||
_lv_ll_clear(&context->keypad.queue);
|
||||
context->keypad.utf16_high_surrogate = 0;
|
||||
context->keypad.utf16_low_surrogate = 0;
|
||||
@ -571,8 +565,6 @@ bool lv_windows_keypad_device_window_message_handler(
|
||||
lv_windows_window_context_t * context = (lv_windows_window_context_t *)(
|
||||
lv_windows_get_window_context(hWnd));
|
||||
if(context) {
|
||||
EnterCriticalSection(&context->keypad.mutex);
|
||||
|
||||
bool skip_translation = false;
|
||||
uint32_t translated_key = 0;
|
||||
|
||||
@ -627,8 +619,6 @@ bool lv_windows_keypad_device_window_message_handler(
|
||||
? LV_INDEV_STATE_RELEASED
|
||||
: LV_INDEV_STATE_PRESSED));
|
||||
}
|
||||
|
||||
LeaveCriticalSection(&context->keypad.mutex);
|
||||
}
|
||||
|
||||
break;
|
||||
@ -637,8 +627,6 @@ bool lv_windows_keypad_device_window_message_handler(
|
||||
lv_windows_window_context_t * context = (lv_windows_window_context_t *)(
|
||||
lv_windows_get_window_context(hWnd));
|
||||
if(context) {
|
||||
EnterCriticalSection(&context->keypad.mutex);
|
||||
|
||||
uint16_t raw_code_point = (uint16_t)(wParam);
|
||||
|
||||
if(raw_code_point >= 0x20 && raw_code_point != 0x7F) {
|
||||
@ -677,8 +665,6 @@ bool lv_windows_keypad_device_window_message_handler(
|
||||
lvgl_code_point,
|
||||
LV_INDEV_STATE_RELEASED);
|
||||
}
|
||||
|
||||
LeaveCriticalSection(&context->keypad.mutex);
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -387,6 +387,7 @@ endif()
|
||||
if(WIN32)
|
||||
add_definitions(-DLV_USE_LINUX_FBDEV=0)
|
||||
add_definitions(-DLV_USE_WINDOWS=1)
|
||||
add_definitions(-DLV_USE_OS=LV_OS_WINDOWS)
|
||||
endif()
|
||||
|
||||
# disable test targets for build only tests
|
||||
|
Loading…
Reference in New Issue
Block a user