[gnome-shell] Port to GnomeIdleMonitor



commit d106191e6ae2aa98ea60a268fb877dc037af9b02
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Aug 20 00:06:50 2012 -0400

    Port to GnomeIdleMonitor
    
    https://bugzilla.gnome.org/show_bug.cgi?id=682224

 configure.ac             |    2 +-
 js/ui/messageTray.js     |   32 +++-
 js/ui/pointerWatcher.js  |   18 ++-
 js/ui/unlockDialog.js    |    5 +-
 src/Makefile.am          |    2 -
 src/shell-idle-monitor.c |  429 ----------------------------------------------
 src/shell-idle-monitor.h |   74 --------
 7 files changed, 36 insertions(+), 526 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 7b10ae9..d01be39 100644
--- a/configure.ac
+++ b/configure.ac
@@ -74,7 +74,7 @@ TELEPATHY_LOGGER_MIN_VERSION=0.2.4
 POLKIT_MIN_VERSION=0.100
 STARTUP_NOTIFICATION_MIN_VERSION=0.11
 GCR_MIN_VERSION=3.3.90
-GNOME_DESKTOP_REQUIRED_VERSION=3.5.1
+GNOME_DESKTOP_REQUIRED_VERSION=3.6.0
 GNOME_MENUS_REQUIRED_VERSION=3.5.3
 
 # Collect more than 20 libraries for a prize!
diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js
index 9fb7e79..791ea9e 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -4,6 +4,7 @@ const Clutter = imports.gi.Clutter;
 const GLib = imports.gi.GLib;
 const Gio = imports.gi.Gio;
 const Gtk = imports.gi.Gtk;
+const GnomeDesktop = imports.gi.GnomeDesktop;
 const Atk = imports.gi.Atk;
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
@@ -1452,10 +1453,10 @@ const MessageTray = new Lang.Class({
         this._closeButton.connect('clicked', Lang.bind(this, this._onCloseClicked));
         this._notificationWidget.add_actor(this._closeButton);
 
-        this._idleMonitorWatchId = 0;
+        this._idleMonitorBecameActiveId = 0;
         this._userActiveWhileNotificationShown = false;
 
-        this.idleMonitor = Shell.IdleMonitor.get();
+        this.idleMonitor = new GnomeDesktop.IdleMonitor();
 
         this._grabHelper = new GrabHelper.GrabHelper(this.actor);
         this._grabHelper.addActor(this._summaryBoxPointer.actor);
@@ -2167,20 +2168,26 @@ const MessageTray = new Lang.Class({
                     });
     },
 
-    _onIdleMonitorWatch: function(monitor, id, userBecameIdle) {
-        this.idleMonitor.remove_watch(this._idleMonitorWatchId);
-        this._idleMonitorWatchId = 0;
-        if (!userBecameIdle)
-            this._updateNotificationTimeout(2000);
+    _onIdleMonitorBecameActive: function() {
+        this.idleMonitor.disconnect(this._idleMonitorBecameActiveId);
+        this._idleMonitorBecameActiveId = 0;
+
         this._userActiveWhileNotificationShown = true;
+        this._updateNotificationTimeout(2000);
         this._updateState();
     },
 
     _showNotification: function() {
         this._notification = this._notificationQueue.shift();
-        this._userActiveWhileNotificationShown = this.idleMonitor.get_idletime() <= IDLE_TIME;
-        this._idleMonitorWatchId = this.idleMonitor.add_watch(IDLE_TIME,
-                                                              Lang.bind(this, this._onIdleMonitorWatch));
+
+        let userIdle = this.idleMonitor.get_idletime() > IDLE_TIME;
+        if (userIdle) {
+            this._userActiveWhileNotificationShown = false;
+            this._idleMonitorBecameActiveId = this.idleMonitor.connect('became-active', Lang.bind(this, this._onIdleMonitorBecameActive));
+        } else {
+            this._userActiveWhileNotificationShown = true;
+        }
+
         this._notificationClickedId = this._notification.connect('done-displaying',
                                                                  Lang.bind(this, this._escapeTray));
         this._notification.connect('unfocused', Lang.bind(this, function() {
@@ -2293,6 +2300,11 @@ const MessageTray = new Lang.Class({
     _hideNotification: function() {
         this._grabHelper.ungrab({ actor: this._notification.actor });
 
+        if (this._idleMonitorBecameActiveId) {
+            this.idleMonitor.disconnect(this._idleMonitorBecameActiveId);
+            this._idleMonitorBecameActiveId = 0;
+        }
+
         if (this._notificationExpandedId) {
             this._notification.disconnect(this._notificationExpandedId);
             this._notificationExpandedId = 0;
diff --git a/js/ui/pointerWatcher.js b/js/ui/pointerWatcher.js
index 9c5d1fa..9f7f290 100644
--- a/js/ui/pointerWatcher.js
+++ b/js/ui/pointerWatcher.js
@@ -2,6 +2,7 @@
 
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
+const GnomeDesktop = imports.gi.GnomeDesktop;
 const Shell = imports.gi.Shell;
 
 // We stop polling if the user is idle for more than this amount of time
@@ -40,9 +41,9 @@ const PointerWatcher = new Lang.Class({
     Name: 'PointerWatcher',
 
     _init: function() {
-        let idleMonitor = Shell.IdleMonitor.get();
-        idleMonitor.add_watch(IDLE_TIME,
-                              Lang.bind(this, this._onIdleMonitorWatch));
+        let idleMonitor = new GnomeDesktop.IdleMonitor();
+        idleMonitor.connect('became-active', Lang.bind(this, this._onIdleMonitorBecameActive));
+        idleMonitor.add_watch(IDLE_TIME, Lang.bind(this, this._onIdleMonitorBecameIdle));
         this._idle = idleMonitor.get_idletime() > IDLE_TIME;
         this._watches = [];
         this.pointerX = null;
@@ -78,11 +79,14 @@ const PointerWatcher = new Lang.Class({
         }
     },
 
-    _onIdleMonitorWatch: function(monitor, id, userBecameIdle) {
-        this._idle = userBecameIdle;
-        if (!userBecameIdle)
-            this._updatePointer();
+    _onIdleMonitorBecameActive: function(monitor) {
+        this._idle = false;
+        this._updatePointer();
+        this._updateTimeout();
+    },
 
+    _onIdleMonitorBecameIdle: function(monitor) {
+        this._idle = true;
         this._updateTimeout();
     },
 
diff --git a/js/ui/unlockDialog.js b/js/ui/unlockDialog.js
index 7b30182..c86f13c 100644
--- a/js/ui/unlockDialog.js
+++ b/js/ui/unlockDialog.js
@@ -5,6 +5,7 @@ const Clutter = imports.gi.Clutter;
 const Gdm  = imports.gi.Gdm;
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
+const GnomeDesktop = imports.gi.GnomeDesktop;
 const Gtk = imports.gi.Gtk;
 const Lang = imports.lang;
 const Signals = imports.signals;
@@ -195,9 +196,7 @@ const UnlockDialog = new Lang.Class({
             return false;
         }));
 
-        this._idleMonitor = Shell.IdleMonitor.get();
-        // this dialog is only created after user activity (curtain drag or
-        // escape key press), so the timeout will fire after IDLE_TIMEOUT seconds of inactivity
+        this._idleMonitor = new GnomeDesktop.IdleMonitor();
         this._idleWatchId = this._idleMonitor.add_watch(IDLE_TIMEOUT * 1000, Lang.bind(this, this._escape));
     },
 
diff --git a/src/Makefile.am b/src/Makefile.am
index a390691..bcae257 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -113,7 +113,6 @@ shell_public_headers_h =		\
 	shell-generic-container.h	\
 	shell-gtk-embed.h		\
 	shell-global.h			\
-	shell-idle-monitor.h		\
 	shell-invert-lightness-effect.h	\
 	shell-mobile-providers.h	\
 	shell-mount-operation.h		\
@@ -158,7 +157,6 @@ libgnome_shell_la_SOURCES =		\
 	shell-generic-container.c	\
 	shell-gtk-embed.c		\
 	shell-global.c			\
-	shell-idle-monitor.c		\
 	shell-invert-lightness-effect.c	\
 	shell-keyring-prompt.h		\
 	shell-keyring-prompt.c		\



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