vo_sdl: add support for screensaver VOCTRL's

Previously vo_sdl would unconditonally disable the screensaver,
ignoring the `stop-screensaver` option.
This commit is contained in:
sfan5 2018-05-14 13:55:04 +02:00 committed by Jan Ekström
parent 5056777b86
commit 7f625ea29b
1 changed files with 24 additions and 3 deletions

View File

@ -180,6 +180,7 @@ struct priv {
int brightness, contrast; int brightness, contrast;
char *window_title; char *window_title;
Uint32 wakeup_event; Uint32 wakeup_event;
bool screensaver_enabled;
// options // options
int allow_sw; int allow_sw;
@ -402,10 +403,22 @@ static void check_resize(struct vo *vo)
resize(vo, w, h); resize(vo, w, h);
} }
static inline void set_screensaver(bool enabled)
{
if (!!enabled == !!SDL_IsScreenSaverEnabled())
return;
if (enabled)
SDL_EnableScreenSaver();
else
SDL_DisableScreenSaver();
}
static void set_fullscreen(struct vo *vo) static void set_fullscreen(struct vo *vo)
{ {
struct priv *vc = vo->priv; struct priv *vc = vo->priv;
int fs = vo->opts->fullscreen; int fs = vo->opts->fullscreen;
SDL_bool prev_screensaver_state = SDL_IsScreenSaverEnabled();
Uint32 fs_flag; Uint32 fs_flag;
if (vc->switch_mode) if (vc->switch_mode)
@ -428,7 +441,7 @@ static void set_fullscreen(struct vo *vo)
} }
// toggling fullscreen might recreate the window, so better guard for this // toggling fullscreen might recreate the window, so better guard for this
SDL_DisableScreenSaver(); set_screensaver(prev_screensaver_state);
force_resize(vo); force_resize(vo);
} }
@ -507,8 +520,7 @@ static int reconfig(struct vo *vo, struct mp_image_params *params)
resize(vo, win_w, win_h); resize(vo, win_w, win_h);
SDL_DisableScreenSaver(); set_screensaver(vc->screensaver_enabled);
set_fullscreen(vo); set_fullscreen(vo);
SDL_ShowWindow(vc->window); SDL_ShowWindow(vc->window);
@ -917,6 +929,14 @@ static int control(struct vo *vo, uint32_t request, void *data)
case VOCTRL_SET_CURSOR_VISIBILITY: case VOCTRL_SET_CURSOR_VISIBILITY:
SDL_ShowCursor(*(bool *)data); SDL_ShowCursor(*(bool *)data);
return true; return true;
case VOCTRL_KILL_SCREENSAVER:
vc->screensaver_enabled = false;
set_screensaver(vc->screensaver_enabled);
return VO_TRUE;
case VOCTRL_RESTORE_SCREENSAVER:
vc->screensaver_enabled = true;
set_screensaver(vc->screensaver_enabled);
return VO_TRUE;
case VOCTRL_UPDATE_WINDOW_TITLE: case VOCTRL_UPDATE_WINDOW_TITLE:
talloc_free(vc->window_title); talloc_free(vc->window_title);
vc->window_title = talloc_strdup(vc, (char *)data); vc->window_title = talloc_strdup(vc, (char *)data);
@ -936,6 +956,7 @@ const struct vo_driver video_out_sdl = {
.priv_defaults = &(const struct priv) { .priv_defaults = &(const struct priv) {
.renderer_index = -1, .renderer_index = -1,
.vsync = 1, .vsync = 1,
.screensaver_enabled = false,
}, },
.options = (const struct m_option []){ .options = (const struct m_option []){
OPT_FLAG("sw", allow_sw, 0), OPT_FLAG("sw", allow_sw, 0),