[gnome-shell] ShellIdleMonitor: turn it into a singleton



commit 6a9b1996e41abd187d27e9a3e3034496077fe926
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Thu Aug 16 21:11:54 2012 +0200

    ShellIdleMonitor: turn it into a singleton
    
    It doesn't make sense to have multiple ShellIdleMonitors, since
    each has its own GDK filter function, but they all get the same
    events. In preparation for having it accessed from other places
    than the message tray, make it a singleton.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=682041

 js/ui/messageTray.js     |    2 +-
 src/shell-idle-monitor.c |   16 +++++++++++-----
 src/shell-idle-monitor.h |    2 +-
 3 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js
index 1ce114e..eabf6a7 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -1508,7 +1508,7 @@ const MessageTray = new Lang.Class({
         this._idleMonitorWatchId = 0;
         this._backFromAway = false;
 
-        this.idleMonitor = new Shell.IdleMonitor();
+        this.idleMonitor = Shell.IdleMonitor.get();
 
         // To simplify the summary item animation code, we pretend
         // that there's an invisible SummaryItem to the left of the
diff --git a/src/shell-idle-monitor.c b/src/shell-idle-monitor.c
index 22581d1..592f477 100644
--- a/src/shell-idle-monitor.c
+++ b/src/shell-idle-monitor.c
@@ -316,15 +316,21 @@ shell_idle_monitor_init (ShellIdleMonitor *monitor)
         monitor->priv->counter = None;
 }
 
+/**
+ * shell_idle_monitor_get:
+ *
+ * Returns: (transfer none): the global #ShellIdleMonitor.
+ */
 ShellIdleMonitor *
-shell_idle_monitor_new (void)
+shell_idle_monitor_get (void)
 {
-        GObject *idle_monitor;
+        static ShellIdleMonitor *idle_monitor;
 
-        idle_monitor = g_object_new (SHELL_TYPE_IDLE_MONITOR,
-                                     NULL);
+        if (G_UNLIKELY (idle_monitor == NULL))
+                idle_monitor = g_object_new (SHELL_TYPE_IDLE_MONITOR,
+                                             NULL);
 
-        return SHELL_IDLE_MONITOR (idle_monitor);
+        return idle_monitor;
 }
 
 static gboolean
diff --git a/src/shell-idle-monitor.h b/src/shell-idle-monitor.h
index 1086d92..2fcd082 100644
--- a/src/shell-idle-monitor.h
+++ b/src/shell-idle-monitor.h
@@ -56,7 +56,7 @@ typedef void (*ShellIdleMonitorWatchFunc) (ShellIdleMonitor *monitor,
 
 GType              shell_idle_monitor_get_type     (void);
 
-ShellIdleMonitor * shell_idle_monitor_new          (void);
+ShellIdleMonitor * shell_idle_monitor_get          (void);
 
 guint              shell_idle_monitor_add_watch    (ShellIdleMonitor         *monitor,
                                                     guint                     interval,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]