[vlc-devel] [PATCH] vout: win32: add a module to handle the inhibit mode
Rémi Denis-Courmont
remi at remlab.net
Wed Jan 17 19:08:17 CET 2018
Le keskiviikkona 17. tammikuuta 2018, 18.10.24 EET Steve Lhomme a écrit :
> Inhibit the screensaver when the player is running, and restore the original
> when paused or stopped.
>
> Similar to what is done on XWindows.
>
> Fixes #19463
> ---
> modules/video_output/Makefile.am | 5 +++
> modules/video_output/win32/events.c | 4 --
> modules/video_output/win32/inhibit.c | 71
> ++++++++++++++++++++++++++++++++++++ src/video_output/window.c |
> 3 +-
> 4 files changed, 78 insertions(+), 5 deletions(-)
> create mode 100644 modules/video_output/win32/inhibit.c
>
> diff --git a/modules/video_output/Makefile.am
> b/modules/video_output/Makefile.am index 1a80c5a14e..2361549ed4 100644
> --- a/modules/video_output/Makefile.am
> +++ b/modules/video_output/Makefile.am
> @@ -334,6 +334,11 @@ if HAVE_WIN32_DESKTOP
> vout_LTLIBRARIES += libwingdi_plugin.la
> endif
>
> +libwinhibit_plugin_la_SOURCES = video_output/win32/inhibit.c
> +if HAVE_WIN32_DESKTOP
> +vout_LTLIBRARIES += libwinhibit_plugin.la
> +endif
> +
> libegl_win32_plugin_la_SOURCES = video_output/opengl/egl.c
> libegl_win32_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -DUSE_PLATFORM_WIN32=1
> libegl_win32_plugin_la_CFLAGS = $(AM_CFLAGS) $(EGL_CFLAGS)
> diff --git a/modules/video_output/win32/events.c
> b/modules/video_output/win32/events.c index c13c9dbd80..cea69d95e8 100644
> --- a/modules/video_output/win32/events.c
> +++ b/modules/video_output/win32/events.c
> @@ -188,10 +188,6 @@ static void *EventThread( void *p_this )
> return NULL;
> }
>
> - /* Prevent monitor from powering off */
> - if (var_GetBool(vd, "disable-screensaver"))
> - SetThreadExecutionState( ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED |
> ES_CONTINUOUS ); -
> /* Main loop */
> /* GetMessage will sleep if there's no message in the queue */
> for( ;; )
> diff --git a/modules/video_output/win32/inhibit.c
> b/modules/video_output/win32/inhibit.c new file mode 100644
> index 0000000000..67944c9235
> --- /dev/null
> +++ b/modules/video_output/win32/inhibit.c
> @@ -0,0 +1,71 @@
> +/**************************************************************************
> *** + * inhibit.c: Windows video output common code
> +
> ***************************************************************************
> ** + * Copyright (C) 2018 VLC authors and VideoLAN
> + *
> + * Authors: Steve Lhomme <robux4 at ycbcr.xyz>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU Lesser General Public License as published by
> + * the Free Software Foundation; either version 2.1 of the License, or + *
> (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public License
> + * along with this program; if not, write to the Free Software Foundation,
> + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. +
> ***************************************************************************
> **/ +
> +#ifdef HAVE_CONFIG_H
> +# include "config.h"
> +#endif
> +
> +#include <vlc_common.h>
> +#include <vlc_inhibit.h>
> +#include <vlc_plugin.h>
> +
> +struct vlc_inhibit_sys
> +{
> + EXECUTION_STATE prev_state;
> +};
> +
> +static void Inhibit (vlc_inhibit_t *ih, unsigned mask)
> +{
> + vlc_inhibit_sys_t *sys = ih->p_sys;
> + bool suspend = (mask & VLC_INHIBIT_DISPLAY) != 0;
> + if (suspend)
> + /* Prevent monitor from powering off */
> + sys->prev_state =
> + SetThreadExecutionState( ES_DISPLAY_REQUIRED |
> ES_SYSTEM_REQUIRED | ES_CONTINUOUS ); + else
> + SetThreadExecutionState( sys->prev_state );
> +}
> +
> +int OpenInhibit (vlc_object_t *obj)
> +{
> + vlc_inhibit_t *ih = (vlc_inhibit_t *)obj;
> + ih->p_sys = vlc_obj_malloc(obj, sizeof(vlc_inhibit_sys_t));
> + if (unlikely(ih->p_sys == NULL))
> + return VLC_ENOMEM;
> +
> + ih->inhibit = Inhibit;
> + return VLC_SUCCESS;
> +}
> +
> +void CloseInhibit (vlc_object_t *obj)
> +{
> + VLC_UNUSED(obj);
> +}
Useless.
> +
> +vlc_module_begin ()
> + set_shortname (N_("Windows screensaver"))
> + set_description (N_("Windows screen saver inhibition"))
> + set_category (CAT_ADVANCED)
> + set_subcategory (SUBCAT_ADVANCED_MISC)
> + set_capability ("inhibit", 10)
> + set_callbacks (OpenInhibit, CloseInhibit)
> +vlc_module_end ()
> diff --git a/src/video_output/window.c b/src/video_output/window.c
> index c5e8bef33b..0eb055a47f 100644
> --- a/src/video_output/window.c
> +++ b/src/video_output/window.c
> @@ -78,7 +78,8 @@ vout_window_t *vout_window_New(vlc_object_t *obj, const
> char *module,
>
> /* Hook for screensaver inhibition */
> if (var_InheritBool(obj, "disable-screensaver") &&
> - window->type == VOUT_WINDOW_TYPE_XID) {
> + (window->type == VOUT_WINDOW_TYPE_XID || window->type ==
> VOUT_WINDOW_TYPE_HWND)) + {
> w->inhibit = vlc_inhibit_Create(VLC_OBJECT (window));
> if (w->inhibit != NULL)
> vlc_inhibit_Set(w->inhibit, VLC_INHIBIT_VIDEO);
--
雷米‧德尼-库尔蒙
https://www.remlab.net/
More information about the vlc-devel
mailing list