diff --git a/configure.ac b/configure.ac index 65bdad328c32586514087393821cc3ae4ead7ae1..cc618cf0ee5a29dbec0af8feea58730846dbeaf2 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 c5b5690ff5eade5ec4525ce16cbb21940f2c8675..d1f6787f4e348574fb3ffb8799cb98850fbeb5db 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 3a26ff2c815b2cef884a63451b9d48d481d3a34b..e33d3d6eaf359553a3fbc5c12e4dbf8f13c199fe 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" @@ -107,12 +110,31 @@ get_x11_idle_info (guint *idle_time, return TRUE; } +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 0b5e5e27c779e38f6c6ec024bf899511f963bccc..fef0bc95ee79d499b8c6a27c260a7e90f8346cc8 100644 --- a/src/gs-prefs.c +++ b/src/gs-prefs.c @@ -220,6 +220,12 @@ _gs_prefs_set_lock_with_saver_enabled (GSPrefs *prefs, prefs->lock_with_saver_enabled = value; } +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) { @@ -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 70ca1e44533a2e7980ac648ef8b7c6e8de9c5093..be02a7b7d7a23f9b8018d70edc787960bff766d7 100644 --- a/src/gs-prefs.h +++ b/src/gs-prefs.h @@ -69,6 +69,13 @@ G_BEGIN_DECLS #define KEY_IDLE_DELAY "/saver/idle-activation/delay" #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 @@ -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 a2ff4a7e0d48e6504337063900e368bdba684c18..a73bfcbec8d249b6c8a88e32ed028700e4a0305b 100644 --- a/src/xfce4-screensaver-preferences.c +++ b/src/xfce4-screensaver-preferences.c @@ -401,6 +401,27 @@ config_set_lock_with_saver_enabled (gboolean lock) { xfconf_channel_set_bool (screensaver_channel, KEY_LOCK_WITH_SAVER_ENABLED, 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; @@ -1121,6 +1142,11 @@ lock_with_saver_toggled_cb (GtkSwitch *widget, gpointer user_data) { writable); } +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; @@ -1262,6 +1288,19 @@ ui_set_lock_with_saver_enabled (gboolean enabled) { writable); } +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; @@ -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 e88118cf727da8124abca5a097a9608ffce318c2..1f73fcae23b3e5c3c6bbf3e008d104b5b16590dc 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>