diff --git a/src/module/module_sdl2.c b/src/module/module_sdl2.c index 7c9c7e6744d2783e4afc0494d112ec1ed3c78882..4dd3baf16505fa654c855a18fee7ef10c098fae7 100644 --- a/src/module/module_sdl2.c +++ b/src/module/module_sdl2.c @@ -52,15 +52,11 @@ sdl_thread__(struct lkt_thread_arg *arg) int w, h; free(arg); (void) self; - RETURN_UNLESS(sdl2, "Big nope here, the sdl window pointer is NULL", NULL); + RETURN_UNLESS(sdl2 && sdl2->window, "Big nope here, the sdl window pointer is NULL", NULL); fprintf(stderr, " * Started SDL thread\n"); - /* SDL events won't change the database, only the mpv one's will. - Do this to be able to put the SDL stuff inside a thread and don't change - to much things. */ loop: - if (!SDL_PollEvent(&event)) - sched_yield(); + RETURN_UNLESS(SDL_WaitEvent(&event), "Failed to wait SDL event", NULL); switch (event.type) { case SDL_QUIT: @@ -70,8 +66,8 @@ loop: case SDL_WINDOWEVENT: if (event.window.event == SDL_WINDOWEVENT_EXPOSED) redraw = 1; - break; + case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_SPACE) { const char *cmd_pause[] = { "cycle", "pause", NULL }; @@ -81,14 +77,12 @@ loop: case SDL_KEYUP: if (event.key.keysym.sym == SDLK_F11) { - if (sdl2->is_fullscreen) { + if (sdl2->is_fullscreen) SDL_SetWindowFullscreen(sdl2->window, 0); - sdl2->is_fullscreen = 0; - } else { - /* May use SDL_WINDOW_FULLSCREEN_DESKTOP, need to check. */ + else SDL_SetWindowFullscreen(sdl2->window, SDL_WINDOW_FULLSCREEN); - sdl2->is_fullscreen = 1; - } + /* May use SDL_WINDOW_FULLSCREEN_DESKTOP, need to check. */ + sdl2->is_fullscreen = 1 - sdl2->is_fullscreen; } break; @@ -158,9 +152,7 @@ on_mpv_render_update(void *ctx) extern int module_set_function(void *arg__, void *handle__) { - if (NULL == arg__ || handle__ == NULL) - return 1; - + RETURN_UNLESS(arg__ && handle__, "Invalid argument", 1); struct lkt_win *win = (struct lkt_win *) arg__; win->new = module_sdl2_new;