diff --git a/src/module/module_sdl2.c b/src/module/module_sdl2.c
index 4dd3baf16505fa654c855a18fee7ef10c098fae7..40f738d732bf8c7232cf3267eeb9c221c50d1457 100644
--- a/src/module/module_sdl2.c
+++ b/src/module/module_sdl2.c
@@ -18,17 +18,17 @@
 #define WIDTH   400
 #define HEIGHT  200
 
-static Uint32 wakeup_on_mpv_render_update, wakeup_on_mpv_events;
+static volatile Uint32 wakeup_on_mpv_render_update, wakeup_on_mpv_events;
 
 struct module_sdl2_window {
     /* Related to SDL2 */
-    SDL_Window *window;
-    SDL_GLContext glcontext;
+    volatile SDL_Window *window;
+    volatile SDL_GLContext glcontext;
     int is_fullscreen;
 
     /* Mpv related */
-    mpv_handle *mpv;
-    mpv_render_context *mpv_gl;
+    volatile mpv_handle *mpv;
+    volatile mpv_render_context *mpv_gl;
     volatile int mpv_time_pos;  // Don't write it in the database       //
     volatile int mpv_duration;  // Because don't need to be persistent  //
 
@@ -44,8 +44,8 @@ struct module_sdl2_window {
 static void *
 sdl_thread__(struct lkt_thread_arg *arg)
 {
-    struct lkt_win *win = arg->args;
-    struct lkt_thread *self = arg->self;
+    struct lkt_win *const win       = arg->args;
+    struct lkt_thread *self         = arg->self;
     struct module_sdl2_window *sdl2 = win->window;
     SDL_Event event;
     uint64_t flags, redraw = 0;
@@ -56,7 +56,7 @@ sdl_thread__(struct lkt_thread_arg *arg)
     fprintf(stderr, " * Started SDL thread\n");
 
 loop:
-    RETURN_UNLESS(SDL_WaitEvent(&event), "Failed to wait SDL event", NULL);
+    SDL_PollEvent(&event);
 
     switch (event.type) {
     case SDL_QUIT:
@@ -71,16 +71,16 @@ loop:
     case SDL_KEYDOWN:
         if (event.key.keysym.sym == SDLK_SPACE) {
             const char *cmd_pause[] = { "cycle", "pause", NULL };
-            mpv_command_async(sdl2->mpv, 0, cmd_pause);
+            mpv_command_async((mpv_handle *) sdl2->mpv, 0, cmd_pause);
         }
         break;
 
     case SDL_KEYUP:
         if (event.key.keysym.sym == SDLK_F11) {
             if (sdl2->is_fullscreen)
-                SDL_SetWindowFullscreen(sdl2->window, 0);
+                SDL_SetWindowFullscreen((SDL_Window *) sdl2->window, 0);
             else
-                SDL_SetWindowFullscreen(sdl2->window, SDL_WINDOW_FULLSCREEN);
+                SDL_SetWindowFullscreen((SDL_Window *) sdl2->window, SDL_WINDOW_FULLSCREEN);
             /* May use SDL_WINDOW_FULLSCREEN_DESKTOP, need to check. */
             sdl2->is_fullscreen = 1 - sdl2->is_fullscreen;
         }
@@ -88,17 +88,17 @@ loop:
 
     default:
         if (event.type == wakeup_on_mpv_render_update) {
-            flags = mpv_render_context_update(sdl2->mpv_gl);
+            flags = mpv_render_context_update((mpv_render_context *) sdl2->mpv_gl);
             if (flags & MPV_RENDER_UPDATE_FRAME)
                 redraw = 1;
-            if (event.type == wakeup_on_mpv_events)
-                sdl2->mpv_wakeup = 1;
         }
         /* Handle mpv events are not done here. */
+        if (event.type == wakeup_on_mpv_events)
+            sdl2->mpv_wakeup = 1;
     }
 
     if (redraw) {
-        SDL_GetWindowSize(sdl2->window, &w, &h);
+        SDL_GetWindowSize((SDL_Window *) sdl2->window, &w, &h);
         /* Specify the default framebuffer (0) as target. This will
            render onto the entire screen. If you want to show the video
            in a smaller rectangle or apply fancy transformations, you'll
@@ -115,8 +115,8 @@ loop:
                 }
             }, {0}
         };
-        mpv_render_context_render(sdl2->mpv_gl, params);
-        SDL_GL_SwapWindow(sdl2->window);
+        mpv_render_context_render((mpv_render_context *) sdl2->mpv_gl, params);
+        SDL_GL_SwapWindow((SDL_Window *) sdl2->window);
         redraw = 0;
     }
     goto loop;  /* A loop without indentation. */
@@ -226,12 +226,12 @@ module_sdl2_new(struct lkt_win *const win)
         sdl2->window = SDL_CreateWindow("lektord", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                                         WIDTH, HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
         RETURN_UNLESS(sdl2->window, "Failed to create the window", false);
-        sdl2->glcontext = SDL_GL_CreateContext(sdl2->window);
+        sdl2->glcontext = SDL_GL_CreateContext((SDL_Window *) sdl2->window);
         RETURN_UNLESS(sdl2->glcontext, "Failed to create the SDL context", false);
     }
 
     /* Init mpv here */
-    RETURN_IF(init_mpv__(&sdl2->mpv), "Failed to init mpv", false);
+    RETURN_IF(init_mpv__((mpv_handle **) &sdl2->mpv), "Failed to init mpv", false);
 
     mpv_render_param params[] = {
         { MPV_RENDER_PARAM_API_TYPE, MPV_RENDER_API_TYPE_OPENGL },
@@ -252,10 +252,11 @@ module_sdl2_new(struct lkt_win *const win)
     };
 
     /* Init mpv_gl here */
-    RETURN_IF(init_mpv_gl__(sdl2->mpv, &sdl2->mpv_gl, params), "Failed to init mpv_gl", false);
+    RETURN_IF(init_mpv_gl__((mpv_handle *) sdl2->mpv, (mpv_render_context **) &sdl2->mpv_gl, params),
+              "Failed to init mpv_gl", false);
 
     /* Finish */
-    SDL_SetWindowTitle(sdl2->window, "Lektord");
+    SDL_SetWindowTitle((SDL_Window *) sdl2->window, "Lektord");
     SDL_DisableScreenSaver();
     win->window = sdl2;
 
@@ -266,7 +267,7 @@ module_sdl2_new(struct lkt_win *const win)
         arg->args = win;
         sdl2->launched = 1;
         RETURN_IF(lkt_th_new(&sdl2->self, LKT_DEFAULT_LIST_SIZE, sdl_thread__, arg),
-                "Failed to launch the SDL thread", false);
+                  "Failed to launch the SDL thread", false);
     }
 
     return true;
@@ -284,16 +285,16 @@ module_sdl2_free(struct lkt_win *const win)
 {
     RETURN_UNLESS(win && win->window, "Invalid arguments", NOTHING);
     struct module_sdl2_window *sdl2 = win->window;
-    mpv_render_context_free(sdl2->mpv_gl);
+    mpv_render_context_free((mpv_render_context *) sdl2->mpv_gl);
     sdl2->mpv_gl = NULL;
-    lmpv_free(&sdl2->mpv);
+    lmpv_free((mpv_handle **) &sdl2->mpv);
 }
 
 bool
 module_sdl2_toggle_pause(struct lkt_win *const win)
 {
     RETURN_UNLESS(win && win->window, "Invalid arguments", false);
-    return ! lmpv_toggle_pause(((struct module_sdl2_window *) win->window)->mpv);
+    return ! lmpv_toggle_pause((mpv_handle *) ((struct module_sdl2_window *) win->window)->mpv);
 }
 
 bool
@@ -301,7 +302,7 @@ module_sdl2_load_file(struct lkt_win *const win, const char *filepath)
 {
     RETURN_UNLESS(win && win->window, "Invalid arguments", false);
     struct module_sdl2_window *sdl2 = win->window;
-    bool ret = ! lmpv_load_file(sdl2->mpv, filepath);
+    bool ret = ! lmpv_load_file((mpv_handle *) sdl2->mpv, filepath);
     sdl2->mpv_duration = 0;
     sdl2->mpv_time_pos = 0;
     return ret;
@@ -311,7 +312,7 @@ bool
 module_sdl2_set_volume(struct lkt_win *const win, int vol)
 {
     RETURN_UNLESS(win && win->window, "Invalid arguments", false);
-    return ! lmpv_set_volume(((struct module_sdl2_window *) win->window)->mpv, vol);
+    return ! lmpv_set_volume((mpv_handle *) ((struct module_sdl2_window *) win->window)->mpv, vol);
 }
 
 bool
@@ -337,10 +338,8 @@ module_sdl2_handle_events(struct lkt_win *const win, sqlite3 *db, enum mpd_idle_
     RETURN_UNLESS(sdl2, "Can't handle events from a NULL window", false);
     if (sdl2->mpv_wakeup) {
         sdl2->mpv_wakeup = 0;
-        return ! lmpv_handle(win, sdl2->mpv, db, mpd_idle_events,
-                             (int *) &sdl2->mpv_time_pos,
-                             (int *) &sdl2->mpv_duration);
-    }
-    else
+        return ! lmpv_handle(win, (mpv_handle *) sdl2->mpv, db, mpd_idle_events,
+                             (int *) &sdl2->mpv_time_pos, (int *) &sdl2->mpv_duration);
+    } else
         return true;
 }