1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

feat(sdl): support indev LV_EVENT_DELETE (#4792)

Signed-off-by: XiaoweiYan <yanxiaowei@xiaomi.com>
Signed-off-by: YanXiaowei <yanxiaowei@xiaomi.com>
Co-authored-by: XiaoweiYan <yanxiaowei@xiaomi.com>
This commit is contained in:
bjsylvia 2023-11-14 15:26:28 +08:00 committed by GitHub
parent 8cfb718ad3
commit 69d65257bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 1 deletions

View File

@ -31,6 +31,7 @@ typedef struct {
**********************/
static void sdl_keyboard_read(lv_indev_t * indev, lv_indev_data_t * data);
static uint32_t keycode_to_ctrl_key(SDL_Keycode sdl_key);
static void release_indev_cb(lv_event_t * e);
/**********************
* STATIC VARIABLES
@ -57,6 +58,8 @@ lv_indev_t * lv_sdl_keyboard_create(void)
lv_indev_set_read_cb(indev, sdl_keyboard_read);
lv_indev_set_driver_data(indev, dsc);
lv_indev_add_event(indev, release_indev_cb, LV_EVENT_DELETE, indev);
return indev;
}
@ -86,6 +89,18 @@ static void sdl_keyboard_read(lv_indev_t * indev, lv_indev_data_t * data)
}
}
static void release_indev_cb(lv_event_t * e)
{
lv_indev_t * indev = (lv_indev_t *) lv_event_get_user_data(e);
lv_sdl_keyboard_t * dev = lv_indev_get_driver_data(indev);
if(dev) {
lv_indev_set_driver_data(indev, NULL);
lv_indev_set_read_cb(indev, NULL);
lv_free(dev);
LV_LOG_INFO("done");
}
}
void _lv_sdl_keyboard_handler(SDL_Event * event)
{
uint32_t win_id = UINT32_MAX;

View File

@ -25,6 +25,7 @@
* STATIC PROTOTYPES
**********************/
static void sdl_mouse_read(lv_indev_t * indev, lv_indev_data_t * data);
static void release_indev_cb(lv_event_t * e);
/**********************
* STATIC VARIABLES
@ -57,6 +58,8 @@ lv_indev_t * lv_sdl_mouse_create(void)
lv_indev_set_read_cb(indev, sdl_mouse_read);
lv_indev_set_driver_data(indev, dsc);
lv_indev_add_event(indev, release_indev_cb, LV_EVENT_DELETE, indev);
return indev;
}
@ -74,6 +77,18 @@ static void sdl_mouse_read(lv_indev_t * indev, lv_indev_data_t * data)
data->state = dsc->left_button_down ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED;
}
static void release_indev_cb(lv_event_t * e)
{
lv_indev_t * indev = (lv_indev_t *) lv_event_get_user_data(e);
lv_sdl_mouse_t * dsc = lv_indev_get_driver_data(indev);
if(dsc) {
lv_indev_set_driver_data(indev, NULL);
lv_indev_set_read_cb(indev, NULL);
lv_free(dsc);
LV_LOG_INFO("done");
}
}
void _lv_sdl_mouse_handler(SDL_Event * event)
{
uint32_t win_id = UINT32_MAX;

View File

@ -22,6 +22,7 @@
* STATIC PROTOTYPES
**********************/
static void sdl_mousewheel_read(lv_indev_t * indev, lv_indev_data_t * data);
static void release_indev_cb(lv_event_t * e);
/**********************
* STATIC VARIABLES
@ -52,6 +53,8 @@ lv_indev_t * lv_sdl_mousewheel_create(void)
lv_indev_set_read_cb(indev, sdl_mousewheel_read);
lv_indev_set_driver_data(indev, dsc);
lv_indev_add_event(indev, release_indev_cb, LV_EVENT_DELETE, indev);
return indev;
}
@ -68,6 +71,18 @@ static void sdl_mousewheel_read(lv_indev_t * indev, lv_indev_data_t * data)
dsc->diff = 0;
}
static void release_indev_cb(lv_event_t * e)
{
lv_indev_t * indev = (lv_indev_t *) lv_event_get_user_data(e);
lv_sdl_mousewheel_t * dsc = lv_indev_get_driver_data(indev);
if(dsc) {
lv_indev_set_driver_data(indev, NULL);
lv_indev_set_read_cb(indev, NULL);
lv_free(dsc);
LV_LOG_INFO("done");
}
}
void _lv_sdl_mousewheel_handler(SDL_Event * event)
{
uint32_t win_id = UINT32_MAX;

View File

@ -272,7 +272,7 @@ void lv_indev_set_type(lv_indev_t * indev, lv_indev_type_t indev_type)
indev->reset_query = 1;
}
void lv_indev_set_read_cb(lv_indev_t * indev, lv_indev_read_cb_t read_cb)
void lv_indev_set_read_cb(lv_indev_t * indev, lv_indev_read_cb_t read_cb)
{
if(indev == NULL) return;