Skip to content
Extraits de code Groupes Projets

Resolve "SDL2 module"

1 file
+ 20
10
Comparer les modifications
  • Côte à côte
  • En ligne
+ 20
10
@@ -36,6 +36,7 @@ struct module_sdl2_window {
pthread_mutex_t mtx;
struct lkt_thread self;
volatile int launched;
volatile int mpv_wakeup;
};
/* Thread related functions */
@@ -51,8 +52,8 @@ sdl_thread__(struct lkt_thread_arg *arg)
int w, h;
free(arg);
(void) self;
if (sdl2 == NULL)
return false;
RETURN_UNLESS(sdl2, "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
@@ -96,6 +97,8 @@ loop:
flags = mpv_render_context_update(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. */
}
@@ -217,8 +220,8 @@ module_sdl2_new(struct lkt_win *const win)
if (sdl2 == NULL) {
sdl2 = calloc(1, sizeof(struct module_sdl2_window));
memset(sdl2, 0, sizeof(struct module_sdl2_window));
RETURN_UNLESS(sdl2, "Out of memory", false);
memset(sdl2, 0, sizeof(struct module_sdl2_window));
/* Yeah, this is how it is done. */
pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
@@ -259,19 +262,21 @@ 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);
/* Finish */
SDL_SetWindowTitle(sdl2->window, "Lektord");
SDL_DisableScreenSaver();
win->window = sdl2;
/* Start the SDL thread */
if (!sdl2->launched) {
struct lkt_thread_arg *arg = calloc(1, sizeof(struct lkt_thread_arg));
RETURN_UNLESS(arg, "Out of memory", false);
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);
}
/* Finish */
SDL_SetWindowTitle(sdl2->window, "Lektord");
SDL_DisableScreenSaver();
win->window = sdl2;
return true;
}
@@ -338,7 +343,12 @@ module_sdl2_handle_events(struct lkt_win *const win, sqlite3 *db, enum mpd_idle_
{
struct module_sdl2_window *sdl2 = win->window;
RETURN_UNLESS(sdl2, "Can't handle events from a NULL window", false);
return ! lmpv_handle(win, sdl2->mpv, db, mpd_idle_events,
(int *) &sdl2->mpv_time_pos,
(int *) &sdl2->mpv_duration);
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 true;
}
Chargement en cours