[Xfce4-commits] [apps/xfce4-screensaver] 01/01: Add sleep lock option to the Preferences dialog
noreply at xfce.org
noreply at xfce.org
Fri Mar 15 03:31:33 CET 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 8cea5d3ecd895dba5ba69d5477fa9bb2ff17f040
Author: Sean Davis <smd.seandavis at gmail.com>
Date: Thu Mar 14 22:30:46 2019 -0400
Add sleep lock option to the Preferences dialog
---
src/gs-listener-dbus.c | 31 ++++++++++++++++---
src/gs-listener-dbus.h | 28 +++++++++--------
src/gs-monitor.c | 1 +
src/gs-prefs.c | 51 +++++++++++++++++++++++-------
src/gs-prefs.h | 10 ++++++
src/xfce4-screensaver-preferences.c | 58 ++++++++++++++++++++++++++++++++++
src/xfce4-screensaver-preferences.ui | 60 +++++++++++++++++++++++++++---------
7 files changed, 195 insertions(+), 44 deletions(-)
diff --git a/src/gs-listener-dbus.c b/src/gs-listener-dbus.c
index 0ea39fc..715cf48 100644
--- a/src/gs-listener-dbus.c
+++ b/src/gs-listener-dbus.c
@@ -34,7 +34,6 @@
#include <dbus/dbus-glib-lowlevel.h>
#include <libxfce4util/libxfce4util.h>
-#include <xfconf/xfconf.h>
#ifdef WITH_SYSTEMD
#include <systemd/sd-login.h>
@@ -88,6 +87,7 @@ struct GSListenerPrivate {
guint session_idle : 1;
guint active : 1;
guint activation_enabled : 1;
+ guint sleep_activation_enabled : 1;
guint throttled : 1;
GHashTable *inhibitors;
GHashTable *throttlers;
@@ -128,6 +128,7 @@ enum {
PROP_ACTIVE,
PROP_SESSION_IDLE,
PROP_ACTIVATION_ENABLED,
+ PROP_SLEEP_ACTIVATION_ENABLED,
};
enum {
@@ -495,6 +496,16 @@ gs_listener_set_activation_enabled (GSListener *listener,
}
}
+void
+gs_listener_set_sleep_activation_enabled (GSListener *listener,
+ gboolean enabled) {
+ g_return_if_fail (GS_IS_LISTENER (listener));
+
+ if (listener->priv->sleep_activation_enabled != enabled) {
+ listener->priv->sleep_activation_enabled = enabled;
+ }
+}
+
static dbus_bool_t
listener_property_set_bool (GSListener *listener,
guint prop_id,
@@ -1492,10 +1503,7 @@ listener_dbus_handle_system_message (DBusConnection *connection,
dbus_error_init (&error);
dbus_message_get_args (message, &error, DBUS_TYPE_BOOLEAN, &active, DBUS_TYPE_INVALID);
if (active) {
- XfconfChannel *channel = xfconf_channel_get ("xfce4-power-manager");
- const gchar *property = "/xfce4-power-manager/lock-screen-suspend-hibernate";
- gboolean lock_screen = xfconf_channel_get_bool (channel, property, TRUE);
- if (lock_screen) {
+ if (listener->priv->sleep_activation_enabled) {
gs_debug ("Logind requested session lock");
g_signal_emit (listener, signals[LOCK], 0);
} else {
@@ -1808,6 +1816,9 @@ gs_listener_set_property (GObject *object,
case PROP_ACTIVATION_ENABLED:
gs_listener_set_activation_enabled (self, g_value_get_boolean (value));
break;
+ case PROP_SLEEP_ACTIVATION_ENABLED:
+ gs_listener_set_sleep_activation_enabled (self, g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1833,6 +1844,9 @@ gs_listener_get_property (GObject *object,
case PROP_ACTIVATION_ENABLED:
g_value_set_boolean (value, self->priv->activation_enabled);
break;
+ case PROP_SLEEP_ACTIVATION_ENABLED:
+ g_value_set_boolean (value, self->priv->sleep_activation_enabled);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1937,6 +1951,13 @@ gs_listener_class_init (GSListenerClass *klass) {
NULL,
TRUE,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_SLEEP_ACTIVATION_ENABLED,
+ g_param_spec_boolean ("sleep-activation-enabled",
+ NULL,
+ NULL,
+ TRUE,
+ G_PARAM_READWRITE));
}
static gboolean
diff --git a/src/gs-listener-dbus.h b/src/gs-listener-dbus.h
index 1cf5dbb..668004d 100644
--- a/src/gs-listener-dbus.h
+++ b/src/gs-listener-dbus.h
@@ -69,21 +69,23 @@ typedef enum
#define GS_LISTENER_ERROR gs_listener_error_quark ()
-GQuark gs_listener_error_quark (void);
+GQuark gs_listener_error_quark (void);
-GType gs_listener_get_type (void);
+GType gs_listener_get_type (void);
-GSListener *gs_listener_new (void);
-gboolean gs_listener_acquire (GSListener *listener,
- GError **error);
-gboolean gs_listener_set_active (GSListener *listener,
- gboolean active);
-gboolean gs_listener_set_session_idle (GSListener *listener,
- gboolean idle);
-void gs_listener_set_activation_enabled (GSListener *listener,
- gboolean enabled);
-gboolean gs_listener_get_activation_enabled (GSListener *listener);
-gboolean gs_listener_is_inhibited (GSListener *listener);
+GSListener *gs_listener_new (void);
+gboolean gs_listener_acquire (GSListener *listener,
+ GError **error);
+gboolean gs_listener_set_active (GSListener *listener,
+ gboolean active);
+gboolean gs_listener_set_session_idle (GSListener *listener,
+ gboolean idle);
+void gs_listener_set_activation_enabled (GSListener *listener,
+ gboolean enabled);
+void gs_listener_set_sleep_activation_enabled (GSListener *listener,
+ gboolean enabled);
+gboolean gs_listener_get_activation_enabled (GSListener *listener);
+gboolean gs_listener_is_inhibited (GSListener *listener);
G_END_DECLS
diff --git a/src/gs-monitor.c b/src/gs-monitor.c
index e94fe3d..385842a 100644
--- a/src/gs-monitor.c
+++ b/src/gs-monitor.c
@@ -218,6 +218,7 @@ static void _gs_monitor_update_from_prefs(GSMonitor* monitor, GSPrefs* prefs) {
/* enable activation when allowed */
gs_listener_set_activation_enabled(monitor->priv->listener, monitor->priv->prefs->idle_activation_enabled);
+ gs_listener_set_sleep_activation_enabled(monitor->priv->listener, monitor->priv->prefs->sleep_activation_enabled);
gs_listener_x11_set_activation_enabled(monitor->priv->listener_x11, monitor->priv->prefs->idle_activation_enabled);
gs_listener_x11_set_timeout(monitor->priv->listener_x11, monitor->priv->prefs->timeout);
gs_listener_x11_set_saver_enabled(monitor->priv->listener_x11, monitor->priv->prefs->saver_enabled);
diff --git a/src/gs-prefs.c b/src/gs-prefs.c
index e300af8..c8c09c0 100644
--- a/src/gs-prefs.c
+++ b/src/gs-prefs.c
@@ -39,6 +39,7 @@ static void gs_prefs_finalize (GObject *object);
struct GSPrefsPrivate {
XfconfChannel *channel;
+ XfconfChannel *xfpm_channel;
};
enum {
@@ -173,6 +174,12 @@ _gs_prefs_set_idle_activation_enabled (GSPrefs *prefs,
}
static void
+_gs_prefs_set_sleep_activation_enabled (GSPrefs *prefs,
+ gboolean value) {
+ prefs->sleep_activation_enabled = value;
+}
+
+static void
_gs_prefs_set_saver_enabled (GSPrefs *prefs,
gboolean value) {
prefs->saver_enabled = value;
@@ -267,6 +274,11 @@ gs_prefs_load_from_settings (GSPrefs *prefs) {
DEFAULT_KEY_IDLE_ACTIVATION_ENABLED);
_gs_prefs_set_idle_activation_enabled (prefs, bvalue);
+ bvalue = xfconf_channel_get_bool (prefs->priv->xfpm_channel,
+ KEY_LOCK_ON_SLEEP,
+ DEFAULT_KEY_LOCK_ON_SLEEP);
+ _gs_prefs_set_sleep_activation_enabled (prefs, bvalue);
+
bvalue = xfconf_channel_get_bool (prefs->priv->channel,
KEY_SAVER_ENABLED,
DEFAULT_KEY_SAVER_ENABLED);
@@ -381,6 +393,11 @@ key_changed_cb (XfconfChannel *channel,
enabled = xfconf_channel_get_bool (channel, property, DEFAULT_KEY_IDLE_ACTIVATION_ENABLED);
_gs_prefs_set_idle_activation_enabled (prefs, enabled);
+ } else if (strcmp (property, KEY_LOCK_ON_SLEEP) == 0) {
+ gboolean enabled;
+
+ enabled = xfconf_channel_get_bool (channel, property, DEFAULT_KEY_LOCK_ON_SLEEP);
+ _gs_prefs_set_sleep_activation_enabled (prefs, enabled);
} else if (strcmp (property, KEY_SAVER_ENABLED) == 0) {
gboolean enabled;
@@ -452,19 +469,26 @@ gs_prefs_init (GSPrefs *prefs) {
G_CALLBACK (key_changed_cb),
prefs);
- prefs->saver_enabled = TRUE;
- prefs->lock_enabled = TRUE;
- prefs->idle_activation_enabled = TRUE;
- prefs->lock_with_saver_enabled = TRUE;
- prefs->logout_enabled = FALSE;
- prefs->user_switch_enabled = FALSE;
+ prefs->priv->xfpm_channel = xfconf_channel_get (XFPM_XFCONF_CHANNEL);
+ g_signal_connect (prefs->priv->xfpm_channel,
+ "property-changed",
+ G_CALLBACK (key_changed_cb),
+ prefs);
- prefs->timeout = 600000;
- prefs->lock_timeout = 0;
- prefs->logout_timeout = 14400000;
- prefs->cycle = 600000;
+ prefs->saver_enabled = TRUE;
+ prefs->lock_enabled = TRUE;
+ prefs->idle_activation_enabled = TRUE;
+ prefs->sleep_activation_enabled = TRUE;
+ prefs->lock_with_saver_enabled = TRUE;
+ prefs->logout_enabled = FALSE;
+ prefs->user_switch_enabled = FALSE;
- prefs->mode = GS_MODE_SINGLE;
+ prefs->timeout = 600000;
+ prefs->lock_timeout = 0;
+ prefs->logout_timeout = 14400000;
+ prefs->cycle = 600000;
+
+ prefs->mode = GS_MODE_SINGLE;
gs_prefs_load_from_settings (prefs);
}
@@ -485,6 +509,11 @@ gs_prefs_finalize (GObject *object) {
prefs->priv->channel = NULL;
}
+ if (prefs->priv->xfpm_channel) {
+ g_object_unref (prefs->priv->xfpm_channel);
+ prefs->priv->xfpm_channel = NULL;
+ }
+
if (prefs->themes) {
g_slist_foreach (prefs->themes, (GFunc)g_free, NULL);
g_slist_free (prefs->themes);
diff --git a/src/gs-prefs.h b/src/gs-prefs.h
index da9686f..717c766 100644
--- a/src/gs-prefs.h
+++ b/src/gs-prefs.h
@@ -36,6 +36,7 @@ G_BEGIN_DECLS
#define GS_PREFS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GS_TYPE_PREFS, GSPrefsClass))
#define SETTINGS_XFCONF_CHANNEL "xfce4-screensaver"
+#define XFPM_XFCONF_CHANNEL "xfce4-power-manager"
/**
* Enable screensaver
@@ -105,6 +106,14 @@ G_BEGIN_DECLS
#define DEFAULT_KEY_LOCK_WITH_SAVER_DELAY 0
/**
+ * Lock on suspend/hibernate
+ * Set this to TRUE to lock the screen when the system goes to sleep
+ * Shared with Xfce Power Manager
+ */
+#define KEY_LOCK_ON_SLEEP "/xfce4-power-manager/lock-screen-suspend-hibernate"
+#define DEFAULT_KEY_LOCK_ON_SLEEP TRUE
+
+/**
* Allow embedding a keyboard into the window
* Set this to TRUE to allow embedding a keyboard into the window when trying to unlock.
* The "keyboard_command" key must be set with the appropriate command.
@@ -181,6 +190,7 @@ typedef struct
guint lock_enabled : 1; /* global lock switch */
guint idle_activation_enabled : 1; /* whether to activate when idle */
+ guint sleep_activation_enabled : 1; /* whether to activate on suspend/hibernate */
guint lock_with_saver_enabled : 1; /* whether to lock when active */
guint logout_enabled : 1; /* Whether to offer the logout option */
guint user_switch_enabled : 1; /* Whether to offer the user switch option */
diff --git a/src/xfce4-screensaver-preferences.c b/src/xfce4-screensaver-preferences.c
index 99414f2..c58667f 100644
--- a/src/xfce4-screensaver-preferences.c
+++ b/src/xfce4-screensaver-preferences.c
@@ -70,6 +70,7 @@ static GtkBuilder *builder = NULL;
static GSThemeManager *theme_manager = NULL;
static GSJob *job = NULL;
static XfconfChannel *screensaver_channel = NULL;
+static XfconfChannel *xfpm_channel = NULL;
static gboolean idle_delay_writable;
static gboolean lock_delay_writable;
@@ -339,6 +340,27 @@ config_set_saver_enabled (gboolean lock) {
}
static gboolean
+config_get_lock_on_suspend_hibernate_enabled (gboolean *is_writable) {
+ gboolean lock;
+
+ if (is_writable) {
+ *is_writable = !xfconf_channel_is_property_locked (xfpm_channel,
+ KEY_LOCK_ON_SLEEP);
+ }
+
+ lock = xfconf_channel_get_bool (xfpm_channel,
+ KEY_LOCK_ON_SLEEP,
+ DEFAULT_KEY_LOCK_ON_SLEEP);
+
+ return lock;
+}
+
+static void
+config_set_lock_on_suspend_hibernate_enabled (gboolean lock) {
+ xfconf_channel_set_bool (xfpm_channel, KEY_LOCK_ON_SLEEP, lock);
+}
+
+static gboolean
config_get_lock_enabled (gboolean *is_writable) {
gboolean lock;
@@ -1119,6 +1141,11 @@ saver_toggled_cb (GtkSwitch *widget, gpointer user_data) {
}
static void
+lock_on_suspend_hibernate_toggled_cb (GtkSwitch *widget, gpointer user_data) {
+ config_set_lock_on_suspend_hibernate_enabled (gtk_switch_get_active (widget));
+}
+
+static void
lock_toggled_cb (GtkSwitch *widget, gpointer user_data) {
gboolean writable;
@@ -1233,6 +1260,19 @@ ui_set_saver_enabled (gboolean enabled) {
}
static void
+ui_set_lock_on_suspend_hibernate_enabled (gboolean enabled) {
+ GtkWidget *widget;
+ gboolean active;
+
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "lock_suspend_hibernate_enabled"));
+
+ active = gtk_switch_get_active (GTK_SWITCH (widget));
+ if (active != enabled) {
+ gtk_switch_set_active (GTK_SWITCH (widget), enabled);
+ }
+}
+
+static void
ui_set_lock_enabled (gboolean enabled) {
GtkWidget *widget;
gboolean active;
@@ -1445,6 +1485,10 @@ key_changed_cb (XfconfChannel *channel, const gchar *key, gpointer data) {
gboolean enabled;
enabled = xfconf_channel_get_bool (channel, key, DEFAULT_KEY_SAVER_ENABLED);
ui_set_saver_enabled (enabled);
+ } else if (strcmp (key, KEY_LOCK_ON_SLEEP) == 0) {
+ gboolean enabled;
+ enabled = xfconf_channel_get_bool (channel, key, DEFAULT_KEY_LOCK_ON_SLEEP);
+ ui_set_lock_on_suspend_hibernate_enabled (enabled);
} else if (strcmp (key, KEY_LOCK_ENABLED) == 0) {
gboolean enabled;
enabled = xfconf_channel_get_bool (channel, key, DEFAULT_KEY_LOCK_ENABLED);
@@ -1904,6 +1948,12 @@ configure_capplet (void) {
G_CALLBACK (key_changed_cb),
NULL);
+ xfpm_channel = xfconf_channel_get(XFPM_XFCONF_CHANNEL);
+ g_signal_connect (xfpm_channel,
+ "property-changed",
+ G_CALLBACK (key_changed_cb),
+ NULL);
+
/* Idle delay */
widget = GTK_WIDGET (gtk_builder_get_object (builder, "saver_idle_activation_delay"));
delay = config_get_idle_delay (&idle_delay_writable);
@@ -1962,6 +2012,14 @@ configure_capplet (void) {
g_signal_connect (widget, "notify::active",
G_CALLBACK (saver_toggled_cb), NULL);
+ /* Lock on suspend/hibernate enabled */
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "lock_suspend_hibernate_enabled"));
+ enabled = config_get_lock_on_suspend_hibernate_enabled (&is_writable);
+ ui_set_lock_on_suspend_hibernate_enabled (enabled);
+ set_widget_writable (widget, is_writable);
+ g_signal_connect (widget, "notify::active",
+ G_CALLBACK (lock_on_suspend_hibernate_toggled_cb), NULL);
+
/* Lock enabled */
widget = GTK_WIDGET (gtk_builder_get_object (builder, "lock_enabled"));
enabled = config_get_lock_enabled (&is_writable);
diff --git a/src/xfce4-screensaver-preferences.ui b/src/xfce4-screensaver-preferences.ui
index af9afd6..fdcecd4 100644
--- a/src/xfce4-screensaver-preferences.ui
+++ b/src/xfce4-screensaver-preferences.ui
@@ -940,7 +940,7 @@ Simon Steinbeiß
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">2</property>
+ <property name="top_attach">3</property>
<property name="width">2</property>
</packing>
</child>
@@ -954,7 +954,7 @@ Simon Steinbeiß
</object>
<packing>
<property name="left_attach">2</property>
- <property name="top_attach">2</property>
+ <property name="top_attach">3</property>
</packing>
</child>
<child>
@@ -967,7 +967,7 @@ Simon Steinbeiß
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">3</property>
+ <property name="top_attach">4</property>
</packing>
</child>
<child>
@@ -977,7 +977,7 @@ Simon Steinbeiß
</object>
<packing>
<property name="left_attach">1</property>
- <property name="top_attach">3</property>
+ <property name="top_attach">4</property>
<property name="width">2</property>
</packing>
</child>
@@ -995,7 +995,7 @@ Simon Steinbeiß
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">4</property>
+ <property name="top_attach">5</property>
</packing>
</child>
<child>
@@ -1008,7 +1008,7 @@ Simon Steinbeiß
</object>
<packing>
<property name="left_attach">1</property>
- <property name="top_attach">4</property>
+ <property name="top_attach">5</property>
<property name="width">2</property>
</packing>
</child>
@@ -1025,7 +1025,7 @@ Simon Steinbeiß
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">5</property>
+ <property name="top_attach">6</property>
<property name="width">2</property>
</packing>
</child>
@@ -1039,7 +1039,7 @@ Simon Steinbeiß
</object>
<packing>
<property name="left_attach">2</property>
- <property name="top_attach">5</property>
+ <property name="top_attach">6</property>
</packing>
</child>
<child>
@@ -1052,7 +1052,7 @@ Simon Steinbeiß
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">6</property>
+ <property name="top_attach">7</property>
</packing>
</child>
<child>
@@ -1062,7 +1062,7 @@ Simon Steinbeiß
</object>
<packing>
<property name="left_attach">1</property>
- <property name="top_attach">6</property>
+ <property name="top_attach">7</property>
<property name="width">2</property>
</packing>
</child>
@@ -1076,7 +1076,7 @@ Simon Steinbeiß
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">7</property>
+ <property name="top_attach">8</property>
</packing>
</child>
<child>
@@ -1087,7 +1087,7 @@ Simon Steinbeiß
</object>
<packing>
<property name="left_attach">1</property>
- <property name="top_attach">7</property>
+ <property name="top_attach">8</property>
</packing>
</child>
<child>
@@ -1101,7 +1101,7 @@ Simon Steinbeiß
</object>
<packing>
<property name="left_attach">2</property>
- <property name="top_attach">7</property>
+ <property name="top_attach">8</property>
</packing>
</child>
<child>
@@ -1117,7 +1117,7 @@ Simon Steinbeiß
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">8</property>
+ <property name="top_attach">9</property>
<property name="width">2</property>
</packing>
</child>
@@ -1131,7 +1131,37 @@ Simon Steinbeiß
</object>
<packing>
<property name="left_attach">2</property>
- <property name="top_attach">8</property>
+ <property name="top_attach">9</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="lock_suspend_hibernate_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_top">12</property>
+ <property name="label" translatable="yes">Lock Screen with System Sleep</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">2</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSwitch" id="lock_suspend_hibernate_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">2</property>
+ <property name="top_attach">2</property>
</packing>
</child>
</object>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list