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.
This commit is contained in:
wm4 2016-10-02 12:33:34 +02:00
parent e3a57272a7
commit 39fc5e1deb
7 changed files with 23 additions and 10 deletions

View File

@ -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 \

View File

@ -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"),

View File

@ -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)

View File

@ -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 {

View File

@ -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;

View File

@ -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)

View File

@ -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);