1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

feat(sdl): free resources automatically on display removal (#4294)

Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>
This commit is contained in:
hanhsuan 2023-06-19 20:28:12 +08:00 committed by GitHub
parent 03a9828a56
commit 0ef7dc0ae3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View File

@ -158,6 +158,8 @@ void lv_disp_remove(lv_disp_t * disp)
bool was_default = false;
if(disp == lv_disp_get_default()) was_default = true;
lv_disp_send_event(disp, LV_EVENT_DELETE, NULL);
/*Detach the input devices*/
lv_indev_t * indev;
indev = lv_indev_get_next(NULL);

View File

@ -39,6 +39,7 @@ static void window_update(lv_disp_t * disp);
static void clean_up(lv_disp_t * disp);
static void texture_resize(lv_disp_t * disp);
static void sdl_event_handler(lv_timer_t * t);
static void release_disp_cb(lv_event_t * e);
/***********************
* GLOBAL PROTOTYPES
@ -89,6 +90,7 @@ lv_disp_t * lv_sdl_window_create(lv_coord_t hor_res, lv_coord_t ver_res)
lv_free(dsc);
return NULL;
}
lv_disp_add_event(disp, release_disp_cb, LV_EVENT_DELETE, disp);
lv_disp_set_driver_data(disp, dsc);
window_create(disp);
@ -141,6 +143,15 @@ void lv_sdl_window_set_title(lv_disp_t * disp, const char * title)
SDL_SetWindowTitle(dsc->window, title);
}
void lv_sdl_quit()
{
if(inited) {
SDL_Quit();
lv_timer_del(event_handler_timer);
inited = false;
}
}
/**********************
* STATIC FUNCTIONS
**********************/
@ -236,7 +247,6 @@ static void clean_up(lv_disp_t * disp)
SDL_DestroyWindow(dsc->window);
lv_free(dsc);
lv_disp_remove(disp);
}
static void window_create(lv_disp_t * disp)
@ -335,4 +345,10 @@ static int tick_thread(void * ptr)
}
#endif
static void release_disp_cb(lv_event_t * e)
{
lv_disp_t * disp = (lv_disp_t *) lv_event_get_user_data(e);
clean_up(disp);
}
#endif /*LV_USE_SDL*/

View File

@ -41,6 +41,8 @@ lv_disp_t * _lv_sdl_get_disp_from_win_id(uint32_t win_id);
void lv_sdl_window_set_title(lv_disp_t * disp, const char * title);
void lv_sdl_quit();
/**********************
* MACROS
**********************/