From 93673b8dec86dfacd003c4906dab1cb6c2832ffc Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Mon, 20 Apr 2020 14:54:28 +0200
Subject: [PATCH] Draw won't draw in the SDL window

---
 src/module/module_sdl2.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/src/module/module_sdl2.c b/src/module/module_sdl2.c
index 7c9c7e67..4dd3baf1 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;
-- 
GitLab