[vlc-commits] vout: win32: add a module to handle the inhibit mode

Steve Lhomme git at videolan.org
Thu Jan 18 08:38:45 CET 2018


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Wed Jan 17 17:06:14 2018 +0100| [f92cc6cab2abf9428f07c9e9cbc4f70b2ff58afd] | committer: Steve Lhomme

vout: win32: add a module to handle the inhibit mode

Inhibit the screensaver when the player is running, and restore the original
when paused or stopped.

Similar to what is done on X11 windows.

Fixes #19463

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f92cc6cab2abf9428f07c9e9cbc4f70b2ff58afd
---

 modules/video_output/Makefile.am     |  5 +++
 modules/video_output/win32/events.c  |  4 ---
 modules/video_output/win32/inhibit.c | 66 ++++++++++++++++++++++++++++++++++++
 src/video_output/window.c            |  3 +-
 4 files changed, 73 insertions(+), 5 deletions(-)

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 efc616fdb5..319c70d94b 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..0bc71420fa
--- /dev/null
+++ b/modules/video_output/win32/inhibit.c
@@ -0,0 +1,66 @@
+/*****************************************************************************
+ * 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 );
+}
+
+static 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;
+}
+
+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, NULL)
+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);



More information about the vlc-commits mailing list