From 39fc5e1deb0c5753e7123529e4dd5c750aed1e8d Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 2 Oct 2016 12:33:34 +0200 Subject: [PATCH] player: make --stop-screensaver runtime-changeable Move the screensaver enable/disable determination to a central place, and call it if the stop-screensaver property is changed. Also, do not stop the screensaver when in idle mode (i.e. no file is loaded). Fixes #3615. --- options/m_option.h | 3 ++- options/options.c | 2 +- player/command.c | 3 +++ player/core.h | 1 + player/loadfile.c | 2 ++ player/playloop.c | 17 +++++++++++++---- player/video.c | 5 +---- 7 files changed, 23 insertions(+), 10 deletions(-) diff --git a/options/m_option.h b/options/m_option.h index 69113bbd8c..d784d8f54d 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -390,7 +390,8 @@ struct m_option { #define UPDATE_INPUT (1 << 13) // mostly --input-* options #define UPDATE_AUDIO (1 << 14) // --audio-channels etc. #define UPDATE_PRIORITY (1 << 15) // --priority (Windows-only) -#define UPDATE_OPT_LAST (1 << 15) +#define UPDATE_SCREENSAVER (1 << 16) // --stop-screensaver +#define UPDATE_OPT_LAST (1 << 16) // All bits between _FIRST and _LAST (inclusive) #define UPDATE_OPTS_MASK \ diff --git a/options/options.c b/options/options.c index f8f5f707a5..d1e46ef4c6 100644 --- a/options/options.c +++ b/options/options.c @@ -540,7 +540,7 @@ const m_option_t mp_opts[] = { OPT_CHOICE_OR_INT("cursor-autohide", cursor_autohide_delay, 0, 0, 30000, ({"no", -1}, {"always", -2})), OPT_FLAG("cursor-autohide-fs-only", cursor_autohide_fs, 0), - OPT_FLAG("stop-screensaver", stop_screensaver, 0), + OPT_FLAG("stop-screensaver", stop_screensaver, UPDATE_SCREENSAVER), OPT_STRING("heartbeat-cmd", heartbeat_cmd, 0, .deprecation_message = "use Lua scripting instead"), diff --git a/player/command.c b/player/command.c index 7c0cfb82ee..a714123558 100644 --- a/player/command.c +++ b/player/command.c @@ -5720,6 +5720,9 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags) if (flags & UPDATE_PRIORITY) update_priority(mpctx); + + if (flags & UPDATE_SCREENSAVER) + update_screensaver_state(mpctx); } void mp_notify_property(struct MPContext *mpctx, const char *property) diff --git a/player/core.h b/player/core.h index 770df4aa6e..bf6a768e82 100644 --- a/player/core.h +++ b/player/core.h @@ -542,6 +542,7 @@ void mp_idle(struct MPContext *mpctx); void idle_loop(struct MPContext *mpctx); int handle_force_window(struct MPContext *mpctx, bool force); void seek_to_last_frame(struct MPContext *mpctx); +void update_screensaver_state(struct MPContext *mpctx); // scripting.c struct mp_scripting { diff --git a/player/loadfile.c b/player/loadfile.c index ba0e0bd257..ec8ddd6004 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -1123,6 +1123,7 @@ reopen_file: mpctx->playback_initialized = true; mp_notify(mpctx, MPV_EVENT_FILE_LOADED, NULL); + update_screensaver_state(mpctx); if (mpctx->max_frames == 0) { if (!mpctx->stop_play) @@ -1177,6 +1178,7 @@ terminate_playback: uninit_audio_out(mpctx); mpctx->playback_initialized = false; + update_screensaver_state(mpctx); if (mpctx->stop_play == PT_RELOAD_FILE) { mpctx->stop_play = KEEP_PLAYING; diff --git a/player/playloop.c b/player/playloop.c index fc4cfe859e..18a51f33d0 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -125,8 +125,7 @@ void pause_player(struct MPContext *mpctx) { mpctx->opts->pause = 1; - if (mpctx->video_out) - vo_control(mpctx->video_out, VOCTRL_RESTORE_SCREENSAVER, NULL); + update_screensaver_state(mpctx); if (mpctx->paused) goto end; @@ -152,8 +151,7 @@ void unpause_player(struct MPContext *mpctx) { mpctx->opts->pause = 0; - if (mpctx->video_out && mpctx->opts->stop_screensaver) - vo_control(mpctx->video_out, VOCTRL_KILL_SCREENSAVER, NULL); + update_screensaver_state(mpctx); if (!mpctx->paused) goto end; @@ -177,6 +175,17 @@ end: mp_notify(mpctx, mpctx->opts->pause ? MPV_EVENT_PAUSE : MPV_EVENT_UNPAUSE, 0); } +void update_screensaver_state(struct MPContext *mpctx) +{ + if (!mpctx->video_out) + return; + + bool saver_state = mpctx->opts->pause || !mpctx->opts->stop_screensaver || + !mpctx->playback_initialized; + vo_control(mpctx->video_out, saver_state ? VOCTRL_RESTORE_SCREENSAVER + : VOCTRL_KILL_SCREENSAVER, NULL); +} + void add_step_frame(struct MPContext *mpctx, int dir) { if (!mpctx->vo_chain) diff --git a/player/video.c b/player/video.c index 69128025b7..ff72f92d8e 100644 --- a/player/video.c +++ b/player/video.c @@ -449,7 +449,6 @@ int reinit_video_chain(struct MPContext *mpctx) int reinit_video_chain_src(struct MPContext *mpctx, struct lavfi_pad *src) { - struct MPOpts *opts = mpctx->opts; struct track *track = NULL; struct sh_stream *sh = NULL; if (!src) { @@ -513,9 +512,7 @@ int reinit_video_chain_src(struct MPContext *mpctx, struct lavfi_pad *src) recreate_video_filters(mpctx); - bool saver_state = opts->pause || !opts->stop_screensaver; - vo_control(vo_c->vo, saver_state ? VOCTRL_RESTORE_SCREENSAVER - : VOCTRL_KILL_SCREENSAVER, NULL); + update_screensaver_state(mpctx); vo_set_paused(vo_c->vo, mpctx->paused);