[Xfce4-commits] [apps/xfce4-screensaver] 03/05: rework screensaver activation and locking

noreply at xfce.org noreply at xfce.org
Mon Jul 22 01:49:40 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 08561ea5a6ff3777dfdb8d093c2b579e46f1851a
Author: Alexander Butenko <a.butenka at gmail.com>
Date:   Mon Jul 15 09:57:51 2019 -0400

    rework screensaver activation and locking
    
    Signed-off-by: Sean Davis <smd.seandavis at gmail.com>
---
 src/gs-listener-dbus.c | 23 +++++-------
 src/gs-listener-dbus.h |  2 +-
 src/gs-manager.c       | 93 ++++++------------------------------------------
 src/gs-manager.h       | 12 ++-----
 src/gs-monitor.c       | 96 +++++++-------------------------------------------
 src/gs-window-x11.c    | 11 ------
 src/gs-window.h        |  2 --
 7 files changed, 35 insertions(+), 204 deletions(-)

diff --git a/src/gs-listener-dbus.c b/src/gs-listener-dbus.c
index ff0650f..c501015 100644
--- a/src/gs-listener-dbus.c
+++ b/src/gs-listener-dbus.c
@@ -317,7 +317,7 @@ listener_check_activation (GSListener *listener) {
     res = FALSE;
     if (!inhibited) {
         gs_debug ("Trying to activate");
-        res = gs_listener_set_active (listener, TRUE);
+        res = gs_listener_activate_saver (listener, TRUE);
     }
 
     return res;
@@ -369,8 +369,8 @@ listener_set_active_internal (GSListener *listener,
 }
 
 gboolean
-gs_listener_set_active (GSListener *listener,
-                        gboolean    active) {
+gs_listener_activate_saver (GSListener *listener,
+                            gboolean    active) {
     gboolean res;
 
     g_return_val_if_fail (GS_IS_LISTENER (listener), FALSE);
@@ -397,7 +397,7 @@ listener_property_set_bool (GSListener  *listener,
 
     switch (prop_id) {
         case PROP_ACTIVE:
-            gs_listener_set_active (listener, value);
+            gs_listener_activate_saver (listener, value);
             ret = TRUE;
             break;
         default:
@@ -1343,7 +1343,7 @@ listener_dbus_handle_system_message (DBusConnection *connection,
         if (dbus_message_is_signal (message, LOGIND_SESSION_INTERFACE, "Unlock")) {
             if (_listener_message_path_is_our_session (listener, message)) {
                 gs_debug ("Systemd requested session unlock");
-                gs_listener_set_active (listener, FALSE);
+                gs_listener_activate_saver (listener, FALSE);
             }
 
             return DBUS_HANDLER_RESULT_HANDLED;
@@ -1385,13 +1385,8 @@ listener_dbus_handle_system_message (DBusConnection *connection,
                 if (properties_changed_match (message, "Active")) {
                     gboolean new_active;
 
-                    /* Instead of going via the
-                     * bus to read the new
-                     * property state, let's
-                     * shortcut this and ask
-                     * directly the low-level
-                     * information */
-
+                    /* Instead of going via the bus to read the new property state, let's
+                     * shortcut this and ask directly the low-level information */
                     new_active = sd_session_is_active (listener->priv->session_id) != 0;
                     if (new_active)
                         g_signal_emit (listener, signals[SIMULATE_USER_ACTIVITY], 0);
@@ -1432,7 +1427,7 @@ listener_dbus_handle_system_message (DBusConnection *connection,
     } else if (dbus_message_is_signal (message, CK_SESSION_INTERFACE, "Unlock")) {
         if (_listener_message_path_is_our_session (listener, message)) {
             gs_debug ("Console kit requested session unlock");
-            gs_listener_set_active (listener, FALSE);
+            gs_listener_activate_saver (listener, FALSE);
         }
 
         return DBUS_HANDLER_RESULT_HANDLED;
@@ -1672,7 +1667,7 @@ gs_listener_set_property (GObject      *object,
 
     switch (prop_id) {
         case PROP_ACTIVE:
-            gs_listener_set_active (self, g_value_get_boolean (value));
+            gs_listener_activate_saver (self, g_value_get_boolean (value));
             break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
diff --git a/src/gs-listener-dbus.h b/src/gs-listener-dbus.h
index 18af08d..048a404 100644
--- a/src/gs-listener-dbus.h
+++ b/src/gs-listener-dbus.h
@@ -76,7 +76,7 @@ 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    gs_listener_activate_saver                  (GSListener *listener,
                                                          gboolean    active);
 gboolean    gs_listener_set_session_idle                (GSListener *listener,
                                                          gboolean    idle);
diff --git a/src/gs-manager.c b/src/gs-manager.c
index a0a4036..32533c2 100644
--- a/src/gs-manager.c
+++ b/src/gs-manager.c
@@ -23,8 +23,6 @@
 
 #include <config.h>
 
-#include <time.h>
-
 #include <gdk/gdk.h>
 #include <gdk/gdkx.h>
 #include <gio/gio.h>
@@ -54,12 +52,9 @@ struct GSManagerPrivate {
     /* State */
     guint           active : 1;
     guint           lock_active : 1;
-    guint           saver_active : 1;
 
     guint           dialog_up : 1;
 
-    time_t          activate_time;
-
     guint           lock_timeout_id;
     guint           cycle_timeout_id;
 
@@ -269,22 +264,8 @@ gs_manager_set_throttled (GSManager *manager,
 }
 
 void
-gs_manager_get_lock_active (GSManager *manager,
-                            gboolean  *lock_active) {
-    if (lock_active != NULL) {
-        *lock_active = FALSE;
-    }
-
-    g_return_if_fail (GS_IS_MANAGER (manager));
-
-    if (lock_active != NULL) {
-        *lock_active = manager->priv->lock_active;
-    }
-}
-
-void
-gs_manager_set_lock_active (GSManager *manager,
-                            gboolean   lock_active) {
+gs_manager_enable_locker (GSManager *manager,
+                          gboolean   lock_active) {
     GSList *l;
 
     g_return_if_fail (GS_IS_MANAGER (manager));
@@ -300,42 +281,10 @@ gs_manager_set_lock_active (GSManager *manager,
     }
 }
 
-void
-gs_manager_get_saver_active (GSManager *manager,
-                             gboolean  *saver_active) {
-    if (saver_active != NULL) {
-        *saver_active = FALSE;
-    }
-
-    g_return_if_fail (GS_IS_MANAGER (manager));
-
-    if (saver_active != NULL) {
-        *saver_active = manager->priv->saver_active;
-    }
-}
-
-void
-gs_manager_set_saver_active (GSManager *manager,
-                             gboolean   saver_active) {
-    GSList *l;
-
-    g_return_if_fail (GS_IS_MANAGER (manager));
-
-    gs_debug ("Setting saver active: %d", saver_active);
-
-    if (manager->priv->saver_active != saver_active) {
-        manager->priv->saver_active = saver_active;
-    }
-
-    for (l = manager->priv->windows; l; l = l->next) {
-        gs_window_set_saver_active(l->data, saver_active);
-    }
-}
-
 static gboolean
 activate_lock_timeout (GSManager *manager) {
-    gs_debug ("Locking screen after idling timeout");
-    gs_manager_set_lock_active (manager, TRUE);
+    gs_debug ("Locking screen on idle timeout");
+    gs_manager_enable_locker (manager, TRUE);
     manager->priv->lock_timeout_id = 0;
 
     return FALSE;
@@ -352,14 +301,11 @@ remove_lock_timer (GSManager *manager) {
 static void
 add_lock_timer (GSManager *manager,
                 glong      timeout) {
-    gboolean locked;
-
     if (!manager->priv->prefs->lock_enabled)
         return;
     if (!manager->priv->prefs->lock_with_saver_enabled)
         return;
-    gs_manager_get_lock_active (manager, &locked);
-    if (locked)
+    if (manager->priv->lock_active)
         return;
 
     gs_debug ("Scheduling screen lock after screensaver is idling for %i sec", timeout);
@@ -449,7 +395,7 @@ gs_manager_set_property (GObject      *object,
             gs_manager_set_status_message (self, g_value_get_string (value));
             break;
         case PROP_ACTIVE:
-            gs_manager_set_active (self, g_value_get_boolean (value));
+            gs_manager_activate_saver (self, g_value_get_boolean (value));
             break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -756,8 +702,6 @@ manager_show_window (GSManager *manager,
 
     manager_add_job_for_window (manager, window, job);
 
-    manager->priv->activate_time = time (NULL);
-
     remove_lock_timer (manager);
     add_lock_timer (manager, manager->priv->prefs->lock_timeout);
 
@@ -1041,7 +985,6 @@ gs_manager_finalize (GObject *object) {
     gs_manager_destroy_windows (manager);
 
     manager->priv->active = FALSE;
-    manager->priv->activate_time = 0;
 
     g_object_unref (manager->priv->grab);
 
@@ -1179,34 +1122,20 @@ gs_manager_deactivate (GSManager *manager) {
 
     /* reset state */
     manager->priv->active = FALSE;
-    manager->priv->activate_time = 0;
     manager->priv->dialog_up = FALSE;
 
-    gs_manager_set_lock_active (manager, FALSE);
+    gs_manager_enable_locker (manager, FALSE);
 
     return TRUE;
 }
 
 gboolean
-gs_manager_set_active (GSManager *manager,
-                       gboolean   active) {
-    gboolean res;
-
+gs_manager_activate_saver (GSManager *manager,
+                           gboolean   active) {
     if (active) {
-        res = gs_manager_activate (manager);
-    } else {
-        res = gs_manager_deactivate (manager);
+        return gs_manager_activate (manager);
     }
-
-    return res;
-}
-
-gboolean
-gs_manager_get_active (GSManager *manager) {
-    g_return_val_if_fail (manager != NULL, FALSE);
-    g_return_val_if_fail (GS_IS_MANAGER (manager), FALSE);
-
-    return manager->priv->active;
+    return gs_manager_deactivate (manager);
 }
 
 gboolean
diff --git a/src/gs-manager.h b/src/gs-manager.h
index b06e17a..fa615b4 100644
--- a/src/gs-manager.h
+++ b/src/gs-manager.h
@@ -56,20 +56,12 @@ GType       gs_manager_get_type                (void);
 
 GSManager * gs_manager_new                     (void);
 
-gboolean    gs_manager_set_active              (GSManager   *manager,
+gboolean    gs_manager_activate_saver          (GSManager   *manager,
                                                 gboolean     active);
-gboolean    gs_manager_get_active              (GSManager   *manager);
-
 gboolean    gs_manager_cycle                   (GSManager   *manager);
 
-void        gs_manager_get_lock_active         (GSManager   *manager,
-                                                gboolean    *lock_active);
-void        gs_manager_set_lock_active         (GSManager   *manager,
+void        gs_manager_enable_locker           (GSManager   *manager,
                                                 gboolean     lock_active);
-void        gs_manager_get_saver_active        (GSManager   *manager,
-                                                gboolean    *saver_active);
-void        gs_manager_set_saver_active        (GSManager   *manager,
-                                                gboolean     saver_active);
 void        gs_manager_set_status_message      (GSManager   *manager,
                                                 const char  *message);
 void        gs_manager_set_throttled           (GSManager   *manager,
diff --git a/src/gs-monitor.c b/src/gs-monitor.c
index 0f3d8c5..ffdaa4a 100644
--- a/src/gs-monitor.c
+++ b/src/gs-monitor.c
@@ -35,7 +35,6 @@
 #include <gdk/gdkx.h>
 
 #include "gs-debug.h"
-#include "gs-grab.h"
 #include "gs-listener-dbus.h"
 #include "gs-listener-x11.h"
 #include "gs-manager.h"
@@ -52,12 +51,8 @@ struct GSMonitorPrivate {
     GSListenerX11 *listener_x11;
     GSManager* manager;
     GSPrefs* prefs;
-    GSGrab* grab;
-    guint release_grab_id;
 };
 
-#define FADE_TIMEOUT 10000
-
 G_DEFINE_TYPE_WITH_PRIVATE(GSMonitor, gs_monitor, G_TYPE_OBJECT)
 
 static void gs_monitor_class_init(GSMonitorClass* klass) {
@@ -66,56 +61,8 @@ static void gs_monitor_class_init(GSMonitorClass* klass) {
     object_class->finalize = gs_monitor_finalize;
 }
 
-static void manager_activated_cb(GSManager* manager, GSMonitor* monitor) {
-    /* Nothing */
-}
-
 static void manager_deactivated_cb(GSManager* manager, GSMonitor* monitor) {
-    gs_listener_set_active (monitor->priv->listener, FALSE);
-}
-
-static void gs_monitor_lock_screen(GSMonitor* monitor) {
-    gboolean res;
-    gboolean locked;
-    gboolean active;
-
-    /* set lock flag before trying to activate screensaver
-       in case something tries to react to the ActiveChanged signal */
-    gs_manager_get_lock_active(monitor->priv->manager, &locked);
-    gs_manager_set_lock_active(monitor->priv->manager, TRUE);
-    active = gs_manager_get_active(monitor->priv->manager);
-
-    if (!active) {
-        res = gs_listener_set_active(monitor->priv->listener, TRUE);
-
-        if (!res) {
-            /* if we've failed then restore lock status */
-            gs_manager_set_lock_active(monitor->priv->manager, locked);
-            gs_debug("Unable to lock the screen");
-        }
-    }
-}
-
-static void gs_monitor_save_screen(GSMonitor* monitor) {
-    gboolean res;
-    gboolean saved;
-    gboolean active;
-
-    /* set lock flag before trying to activate screensaver
-       in case something tries to react to the ActiveChanged signal */
-    gs_manager_get_saver_active(monitor->priv->manager, &saved);
-    gs_manager_set_saver_active(monitor->priv->manager, TRUE);
-    active = gs_manager_get_active(monitor->priv->manager);
-
-    if (!active) {
-        res = gs_listener_set_active(monitor->priv->listener, TRUE);
-
-        if (!res) {
-            /* if we've failed then restore lock status */
-            gs_manager_set_saver_active(monitor->priv->manager, saved);
-            gs_debug("Unable to save the screen");
-        }
-    }
+    gs_listener_activate_saver (monitor->priv->listener, FALSE);
 }
 
 static void gs_monitor_simulate_user_activity(GSMonitor* monitor) {
@@ -132,22 +79,23 @@ static void gs_monitor_simulate_user_activity(GSMonitor* monitor) {
 
 static void listener_lock_cb(GSListener* listener, GSMonitor* monitor) {
     if (monitor->priv->prefs->lock_enabled) {
-        gs_monitor_lock_screen(monitor);
+        gs_manager_enable_locker(monitor->priv->manager, TRUE);
+        gs_listener_activate_saver(monitor->priv->listener, TRUE);
     } else {
         gs_debug("Locking disabled by the administrator");
     }
 }
 
 static void listener_x11_activate_cb(GSListenerX11* listener, GSMonitor* monitor) {
-    gs_monitor_save_screen(monitor);
+    gs_listener_activate_saver(monitor->priv->listener, TRUE);
 }
 
 static void listener_x11_lock_cb(GSListenerX11* listener, GSMonitor* monitor) {
-    gs_monitor_lock_screen(monitor);
+    listener_lock_cb (NULL, monitor);
 }
 
 static void listener_quit_cb(GSListener* listener, GSMonitor* monitor) {
-    gs_listener_set_active(monitor->priv->listener, FALSE);
+    gs_listener_activate_saver(monitor->priv->listener, FALSE);
     xfce4_screensaver_quit();
 }
 
@@ -168,21 +116,13 @@ static void listener_show_message_cb(GSListener* listener,
 
 static gboolean listener_active_changed_cb(GSListener* listener, gboolean active, GSMonitor* monitor) {
     gboolean res;
-    gboolean ret;
-
-    res = gs_manager_set_active(monitor->priv->manager, active);
 
+    res = gs_manager_activate_saver(monitor->priv->manager, active);
     if (!res) {
         gs_debug("Unable to set manager active: %d", active);
-        ret = FALSE;
-        goto done;
+        return FALSE;
     }
-
-    ret = TRUE;
-
-    done:
-
-    return ret;
+    return TRUE;
 }
 
 static void listener_throttle_changed_cb(GSListener* listener, gboolean throttled, GSMonitor* monitor) {
@@ -228,16 +168,6 @@ static void connect_listener_signals(GSMonitor* monitor) {
                      G_CALLBACK(listener_x11_lock_cb), monitor);
 }
 
-static void disconnect_manager_signals(GSMonitor* monitor) {
-    g_signal_handlers_disconnect_by_func(monitor->priv->manager, manager_activated_cb, monitor);
-    g_signal_handlers_disconnect_by_func(monitor->priv->manager, manager_deactivated_cb, monitor);
-}
-
-static void connect_manager_signals(GSMonitor* monitor) {
-    g_signal_connect(monitor->priv->manager, "activated", G_CALLBACK(manager_activated_cb), monitor);
-    g_signal_connect(monitor->priv->manager, "deactivated", G_CALLBACK(manager_deactivated_cb), monitor);
-}
-
 static void gs_monitor_init(GSMonitor* monitor) {
     monitor->priv = gs_monitor_get_instance_private (monitor);
 
@@ -247,10 +177,9 @@ static void gs_monitor_init(GSMonitor* monitor) {
     monitor->priv->listener_x11 = gs_listener_x11_new();
     connect_listener_signals(monitor);
 
-    monitor->priv->grab = gs_grab_new();
-
     monitor->priv->manager = gs_manager_new();
-    connect_manager_signals(monitor);
+    g_signal_connect(monitor->priv->manager, "deactivated",
+                     G_CALLBACK(manager_deactivated_cb), monitor);
 }
 
 static void gs_monitor_finalize(GObject* object) {
@@ -264,9 +193,8 @@ static void gs_monitor_finalize(GObject* object) {
     g_return_if_fail(monitor->priv != NULL);
 
     disconnect_listener_signals(monitor);
-    disconnect_manager_signals(monitor);
+    g_signal_handlers_disconnect_by_func(monitor->priv->manager, manager_deactivated_cb, monitor);
 
-    g_object_unref(monitor->priv->grab);
     g_object_unref(monitor->priv->listener);
     g_object_unref(monitor->priv->listener_x11);
     g_object_unref(monitor->priv->manager);
diff --git a/src/gs-window-x11.c b/src/gs-window-x11.c
index 2b1de18..81bb74b 100644
--- a/src/gs-window-x11.c
+++ b/src/gs-window-x11.c
@@ -69,7 +69,6 @@ struct GSWindowPrivate {
     guint            dialog_up : 1;
 
     gboolean         lock_active;
-    gboolean         saver_active;
     char            *status_message;
     GSPrefs         *prefs;
 
@@ -1609,16 +1608,6 @@ gs_window_set_lock_active (GSWindow *window,
 }
 
 void
-gs_window_set_saver_active (GSWindow *window,
-                            gboolean  active) {
-    g_return_if_fail (GS_IS_WINDOW (window));
-
-    gs_debug("Setting saver active: %i", active);
-
-    window->priv->saver_active = active;
-}
-
-void
 gs_window_cancel_unlock_request (GSWindow  *window) {
     /* FIXME: This is a bit of a hammer approach...
      * Maybe we should send a delete-event to the plug?
diff --git a/src/gs-window.h b/src/gs-window.h
index fb809b4..d74cd65 100644
--- a/src/gs-window.h
+++ b/src/gs-window.h
@@ -67,8 +67,6 @@ GdkMonitor *gs_window_get_monitor             (GSWindow        *window);
 
 void        gs_window_set_lock_active         (GSWindow        *window,
                                                gboolean         active);
-void        gs_window_set_saver_active        (GSWindow        *window,
-                                               gboolean         active);
 void        gs_window_set_status_message      (GSWindow        *window,
                                                const char      *status_message);
 void        gs_window_show_message            (GSWindow        *window,

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


More information about the Xfce4-commits mailing list