[Xfce4-commits] [apps/xfce4-screensaver] 01/01: Optional screensaver inhibition for fullscreen apps (games, videos, etc)

noreply at xfce.org noreply at xfce.org
Fri Aug 2 03:34:56 CEST 2019


This is an automated email from the git hooks/post-receive script.

b   l   u   e   s   a   b   r   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-screensaver.

commit 0b609052dc06932a4768daf534353fc8646f060b
Author: Sean Davis <smd.seandavis at gmail.com>
Date:   Thu Aug 1 21:34:47 2019 -0400

    Optional screensaver inhibition for fullscreen apps (games, videos, etc)
---
 configure.ac                         |  2 ++
 src/Makefile.am                      |  2 ++
 src/gs-listener-x11.c                | 40 ++++++++++++++++++++++++++--
 src/gs-prefs.c                       | 17 ++++++++++++
 src/gs-prefs.h                       |  8 ++++++
 src/xfce4-screensaver-preferences.c  | 51 ++++++++++++++++++++++++++++++++++++
 src/xfce4-screensaver-preferences.ui | 30 +++++++++++++++++++++
 7 files changed, 148 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 65bdad3..cc618cf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -59,6 +59,7 @@ LIBXFCONF_REQUIRED=4.12.1
 LIBXFCE4UI_REQUIRED=4.12.1
 LIBXFCE4UTIL_REQUIRED=4.12.1
 LIBGARCON_REQUIRED=0.5.0
+LIBWNCK_REQUIRED=3.20
 
 AC_CHECK_HEADERS(unistd.h)
 AC_CHECK_HEADERS(crypt.h sys/select.h)
@@ -94,6 +95,7 @@ PKG_CHECK_MODULES(XFCE_SCREENSAVER,
         libxklavier >= $LIBXKLAVIER_REQUIRED
         libxfconf-0 >= $LIBXFCONF_REQUIRED
         garcon-gtk3-1 >= $LIBGARCON_REQUIRED
+        libwnck-3.0 >= $LIBWNCK_REQUIRED
         $RANDR_PACKAGE)
 AC_SUBST(XFCE_SCREENSAVER_CFLAGS)
 AC_SUBST(XFCE_SCREENSAVER_LIBS)
diff --git a/src/Makefile.am b/src/Makefile.am
index c5b5690..d1f6787 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -33,6 +33,7 @@ AM_CPPFLAGS = \
 	$(LIBXKLAVIER_CFLAGS)                       \
 	$(SYSTEMD_CFLAGS)                           \
 	$(ELOGIND_CFLAGS)                           \
+	$(WNCK_LIBS)								\
 	$(NULL)
 
 bin_PROGRAMS = \
@@ -214,6 +215,7 @@ xfce4_screensaver_LDADD = \
 	$(SAVER_LIBS)             \
 	$(SYSTEMD_LIBS)           \
 	$(ELOGIND_LIBS)           \
+	$(WNCK_LIBS)			  \
 	$(NULL)
 
 xfce4_screensaver_LDFLAGS = -export-dynamic
diff --git a/src/gs-listener-x11.c b/src/gs-listener-x11.c
index 3a26ff2..e33d3d6 100644
--- a/src/gs-listener-x11.c
+++ b/src/gs-listener-x11.c
@@ -32,6 +32,9 @@
 #include <gtk/gtk.h>
 #include <gtk/gtkx.h>
 
+#define WNCK_I_KNOW_THIS_IS_UNSTABLE = 1
+#include <libwnck/libwnck.h>
+
 #include <X11/extensions/scrnsaver.h>
 
 #include "gs-listener-x11.h"
@@ -108,11 +111,30 @@ get_x11_idle_info (guint *idle_time,
 }
 
 static gboolean
+check_fullscreen_window () {
+    WnckScreen *screen;
+    WnckWindow *window;
+
+    screen = wnck_screen_get_default ();
+    if (screen == NULL) {
+        return FALSE;
+    }
+
+    window = wnck_screen_get_active_window (screen);
+    if (window == NULL) {
+        return FALSE;
+    }
+
+    return wnck_window_is_fullscreen (window);
+}
+
+static gboolean
 lock_timer (GSListenerX11 *listener) {
     guint    idle_time;
     guint    lock_time = 0;
     gint     state;
     gboolean lock_state;
+    gboolean fullscreen_inhibition = FALSE;
 
     if (!listener->priv->prefs->saver_enabled)
         return TRUE;
@@ -125,14 +147,28 @@ lock_timer (GSListenerX11 *listener) {
                   listener->priv->prefs->lock_with_saver_enabled &&
                   lock_time >= listener->priv->lock_timeout);
 
-    gs_debug("Idle: %is, Saver: %s, Saver Timeout: %is, Lock: %s, Lock Timeout: %is, Lock Timer: %is, Lock Status: %s",
+    if (listener->priv->prefs->fullscreen_inhibit) {
+        fullscreen_inhibition = check_fullscreen_window();
+    }
+
+    gs_debug("Idle: %is, Saver: %s, Saver Timeout: %is, Lock: %s, Lock Timeout: %is, Lock Timer: %is, Lock Status: %s, Fullscreen: %s",
              idle_time,
              listener->priv->prefs->idle_activation_enabled ? "Enabled" : "Disabled",
              listener->priv->timeout,
              listener->priv->prefs->lock_with_saver_enabled ? "Enabled" : "Disabled",
              listener->priv->lock_timeout,
              lock_time,
-             lock_state ? "Locked" : "Unlocked");
+             lock_state ? "Locked" : "Unlocked",
+             fullscreen_inhibition ? "Inhibited" : "Uninhibited");
+
+    if (fullscreen_inhibition) {
+        if (idle_time < listener->priv->timeout) {
+            reset_timer(listener, listener->priv->timeout - idle_time);
+        } else {
+            reset_timer(listener, 30);
+        }
+        return FALSE;
+    }
 
     if (listener->priv->prefs->idle_activation_enabled &&
             idle_time >= listener->priv->timeout &&
diff --git a/src/gs-prefs.c b/src/gs-prefs.c
index 0b5e5e2..fef0bc9 100644
--- a/src/gs-prefs.c
+++ b/src/gs-prefs.c
@@ -221,6 +221,12 @@ _gs_prefs_set_lock_with_saver_enabled (GSPrefs  *prefs,
 }
 
 static void
+_gs_prefs_set_fullscreen_inhibit (GSPrefs *prefs,
+                                  gboolean value) {
+    prefs->fullscreen_inhibit = value;
+}
+
+static void
 _gs_prefs_set_keyboard_enabled (GSPrefs  *prefs,
                                 gboolean  value) {
     prefs->keyboard_enabled = value;
@@ -328,6 +334,11 @@ gs_prefs_load_from_settings (GSPrefs *prefs) {
                                     DEFAULT_KEY_IDLE_DELAY);
     _gs_prefs_set_timeout (prefs, value);
 
+    bvalue = xfconf_channel_get_bool (prefs->priv->channel,
+                                      KEY_FULLSCREEN_INHIBIT,
+                                      DEFAULT_KEY_FULLSCREEN_INHIBIT);
+    _gs_prefs_set_fullscreen_inhibit (prefs, bvalue);
+
     value = xfconf_channel_get_int (prefs->priv->channel,
                                     KEY_LOCK_WITH_SAVER_DELAY,
                                     DEFAULT_KEY_LOCK_WITH_SAVER_DELAY);
@@ -464,6 +475,11 @@ key_changed_cb (XfconfChannel *channel,
 
         enabled = xfconf_channel_get_bool (channel, property, DEFAULT_KEY_LOCK_WITH_SAVER_ENABLED);
         _gs_prefs_set_lock_with_saver_enabled (prefs, enabled);
+    } else if (strcmp (property, KEY_FULLSCREEN_INHIBIT) == 0) {
+        gboolean enabled;
+
+        enabled = xfconf_channel_get_bool (channel, property, DEFAULT_KEY_FULLSCREEN_INHIBIT);
+        _gs_prefs_set_fullscreen_inhibit (prefs, enabled);
     } else if (strcmp (property, KEY_CYCLE_DELAY) == 0) {
         int delay;
 
@@ -536,6 +552,7 @@ gs_prefs_init (GSPrefs *prefs) {
     prefs->idle_activation_enabled  = TRUE;
     prefs->sleep_activation_enabled = TRUE;
     prefs->lock_with_saver_enabled  = TRUE;
+    prefs->fullscreen_inhibit       = FALSE;
     prefs->logout_enabled           = FALSE;
     prefs->user_switch_enabled      = FALSE;
 
diff --git a/src/gs-prefs.h b/src/gs-prefs.h
index 70ca1e4..be02a7b 100644
--- a/src/gs-prefs.h
+++ b/src/gs-prefs.h
@@ -70,6 +70,13 @@ G_BEGIN_DECLS
 #define DEFAULT_KEY_IDLE_DELAY 5
 
 /**
+ * Inhibit when an application is fullscreen
+ * Set this to TRUE to inhibit the screensaver when the focused application is fullscreen.
+ */
+#define KEY_FULLSCREEN_INHIBIT "/saver/fullscreen-inhibit"
+#define DEFAULT_KEY_FULLSCREEN_INHIBIT FALSE
+
+/**
  * Screensaver themes
  * This key specifies the list of themes to be used by the screensaver. It's ignored
  * when "mode" key is "blank-only", should provide the theme name when "mode" is "single",
@@ -208,6 +215,7 @@ typedef struct
     guint            lock_timeout;   /* how long after activation locking starts */
     guint            logout_timeout; /* how long until the logout option appears */
     guint            cycle;          /* how long each theme should run */
+    guint            fullscreen_inhibit : 1; /* inhibit screensaver when an application is fullscreen */
 
     char            *logout_command;   /* command to use to logout */
     char            *keyboard_command; /* command to use to embed a keyboard */
diff --git a/src/xfce4-screensaver-preferences.c b/src/xfce4-screensaver-preferences.c
index a2ff4a7..a73bfcb 100644
--- a/src/xfce4-screensaver-preferences.c
+++ b/src/xfce4-screensaver-preferences.c
@@ -402,6 +402,27 @@ config_set_lock_with_saver_enabled (gboolean lock) {
 }
 
 static gboolean
+config_get_fullscreen_inhibit (gboolean *is_writable) {
+    gboolean inhibit;
+
+    if (is_writable) {
+        *is_writable = !xfconf_channel_is_property_locked (screensaver_channel,
+                                                           KEY_FULLSCREEN_INHIBIT);
+    }
+
+    inhibit = xfconf_channel_get_bool (screensaver_channel,
+                                       KEY_FULLSCREEN_INHIBIT,
+                                       DEFAULT_KEY_FULLSCREEN_INHIBIT);
+
+    return inhibit;
+}
+
+static void
+config_set_fullscreen_inhibit (gboolean inhibit) {
+    xfconf_channel_set_bool (screensaver_channel, KEY_FULLSCREEN_INHIBIT, inhibit);
+}
+
+static gboolean
 config_get_keyboard_enabled (gboolean *is_writable) {
     gboolean enabled;
 
@@ -1122,6 +1143,11 @@ lock_with_saver_toggled_cb (GtkSwitch *widget, gpointer user_data) {
 }
 
 static void
+fullscreen_inhibit_toggled_cb (GtkSwitch *widget, gpointer user_data) {
+    config_set_fullscreen_inhibit (gtk_switch_get_active (widget));
+}
+
+static void
 idle_activation_toggled_cb (GtkSwitch *widget, gpointer user_data) {
     gboolean writable;
 
@@ -1263,6 +1289,19 @@ ui_set_lock_with_saver_enabled (gboolean enabled) {
 }
 
 static void
+ui_set_fullscreen_inhibit_enabled (gboolean enabled) {
+    GtkWidget *widget;
+    gboolean   active;
+
+    widget = GTK_WIDGET (gtk_builder_get_object (builder, "saver_fullscreen_inhibit_enabled"));
+
+    active = gtk_switch_get_active (GTK_SWITCH (widget));
+    if (active != enabled) {
+        gtk_switch_set_active (GTK_SWITCH (widget), enabled);
+    }
+}
+
+static void
 ui_set_idle_activation_enabled (gboolean enabled) {
     GtkWidget *widget;
     gboolean   active;
@@ -1445,6 +1484,10 @@ key_changed_cb (XfconfChannel *channel, const gchar *key, gpointer data) {
         gboolean enabled;
         enabled = xfconf_channel_get_bool (channel, key, DEFAULT_KEY_LOCK_WITH_SAVER_ENABLED);
         ui_set_lock_with_saver_enabled (enabled);
+    } else if (strcmp (key, KEY_FULLSCREEN_INHIBIT) == 0) {
+        gboolean enabled;
+        enabled = xfconf_channel_get_bool (channel, key, DEFAULT_KEY_FULLSCREEN_INHIBIT);
+        ui_set_fullscreen_inhibit_enabled (enabled);
     } else if (strcmp (key, KEY_CYCLE_DELAY) == 0) {
         int delay;
         delay = xfconf_channel_get_int (channel, key, DEFAULT_KEY_CYCLE_DELAY);
@@ -2000,6 +2043,14 @@ configure_capplet (void) {
     g_signal_connect (widget, "notify::active",
                       G_CALLBACK (lock_with_saver_toggled_cb), NULL);
 
+    /* Fullscreen inhibit enabled */
+    widget = GTK_WIDGET (gtk_builder_get_object (builder, "saver_fullscreen_inhibit_enabled"));
+    enabled = config_get_fullscreen_inhibit (&is_writable);
+    ui_set_fullscreen_inhibit_enabled (enabled);
+    set_widget_writable (widget, is_writable);
+    g_signal_connect (widget, "notify::active",
+                      G_CALLBACK (fullscreen_inhibit_toggled_cb), NULL);
+
     /* Cycle delay */
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "saver_themes_cycle_delay"));
     delay = config_get_cycle_delay (&is_writable);
diff --git a/src/xfce4-screensaver-preferences.ui b/src/xfce4-screensaver-preferences.ui
index e88118c..1f73fca 100644
--- a/src/xfce4-screensaver-preferences.ui
+++ b/src/xfce4-screensaver-preferences.ui
@@ -833,6 +833,36 @@ Simon Steinbeiß
                             <property name="top_attach">3</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkLabel" id="saver_fullscreen_inhibit_label">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="margin_top">12</property>
+                            <property name="label" translatable="yes">Inhibit screensaver for fullscreen applications</property>
+                            <property name="xalign">0</property>
+                            <attributes>
+                              <attribute name="weight" value="bold"/>
+                            </attributes>
+                          </object>
+                          <packing>
+                            <property name="left_attach">0</property>
+                            <property name="top_attach">4</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkSwitch" id="saver_fullscreen_inhibit_enabled">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="halign">end</property>
+                            <property name="valign">center</property>
+                            <property name="margin_top">12</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="top_attach">4</property>
+                            <property name="width">2</property>
+                          </packing>
+                        </child>
                       </object>
                       <packing>
                         <property name="expand">False</property>

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list