[gnome-shell] Reorganize overlay hiding/showing code



commit 062e1aa78b4a3bea2d548eef9c3f236019268c5e
Author: Dan Winship <danw gnome org>
Date:   Thu May 7 09:47:48 2009 -0400

    Reorganize overlay hiding/showing code
    
    Rather than having main.js manage this, put it into overlay.js, and
    have the overlay object emit signals that other code can watch to do
    things when the overlay is showing/shown/hiding/hidden.
---
 js/ui/main.js          |   31 +++++--------------------------
 js/ui/overlay.js       |   23 +++++++++++++++++++----
 js/ui/panel.js         |   14 ++------------
 js/ui/windowManager.js |    2 +-
 js/ui/workspaces.js    |    4 ++--
 5 files changed, 29 insertions(+), 45 deletions(-)

diff --git a/js/ui/main.js b/js/ui/main.js
index c68e425..531ac38 100644
--- a/js/ui/main.js
+++ b/js/ui/main.js
@@ -3,6 +3,7 @@
 const Clutter = imports.gi.Clutter;
 const Gdk = imports.gi.Gdk;
 const Gio = imports.gi.Gio;
+const Lang = imports.lang;
 const Mainloop = imports.mainloop;
 const Meta = imports.gi.Meta;
 const Shell = imports.gi.Shell;
@@ -19,7 +20,6 @@ DEFAULT_BACKGROUND_COLOR.from_pixel(0x2266bbff);
 
 let panel = null;
 let overlay = null;
-let overlayActive = false;
 let runDialog = null;
 let wm = null;
 let recorder = null;
@@ -61,20 +61,11 @@ function start() {
         }
     });
 
+    overlay = new Overlay.Overlay();
     panel = new Panel.Panel();
 
-    overlay = new Overlay.Overlay();
     wm = new WindowManager.WindowManager();
     
-    let display = global.screen.get_display();
-    let toggleOverlay = function(display) {
-        if (overlay.visible) {
-            hideOverlay();
-        } else {
-            showOverlay();
-        }
-    };
-
     global.screen.connect('toggle-recording', function() {
         if (recorder == null) {
             // We have to initialize GStreamer first. This isn't done
@@ -92,8 +83,9 @@ function start() {
         }
     });
 
-    display.connect('overlay-key', toggleOverlay);
-    global.connect('panel-main-menu', toggleOverlay);
+    let display = global.screen.get_display();
+    display.connect('overlay-key', Lang.bind(overlay, overlay.toggle));
+    global.connect('panel-main-menu', Lang.bind(overlay, overlay.toggle));
     
     // Need to update struts on new workspaces when they are added
     global.screen.connect('notify::n-workspaces', _setStageArea);
@@ -154,19 +146,6 @@ function endModal() {
     inModal = false;
 }
 
-function showOverlay() {
-    if (startModal()) {
-        overlayActive = true;
-        overlay.show();
-    }
-}
-
-function hideOverlay() {
-    overlay.hide();
-    overlayActive = false;
-    endModal();
-}
-
 function createAppLaunchContext() {
     let global = Shell.Global.get();
     let screen = global.screen;
diff --git a/js/ui/overlay.js b/js/ui/overlay.js
index 2172bac..79eff4f 100644
--- a/js/ui/overlay.js
+++ b/js/ui/overlay.js
@@ -754,7 +754,7 @@ Overlay.prototype = {
             // TODO - have some sort of animation/effect while
             // transitioning to the new app.  We definitely need
             // startup-notification integration at least.
-            me._deactivate();
+            me.hide();
         });
         this._sideshow.connect('more-activated', function(sideshow) {
             if (me._workspaces != null) {
@@ -795,6 +795,8 @@ Overlay.prototype = {
     show : function() {
         if (this.visible)
             return;
+        if (!Main.startModal())
+            return;
 
         this.visible = true;
 
@@ -854,6 +856,8 @@ Overlay.prototype = {
                            onCompleteScope: this
 
                          });
+
+        this.emit('showing');
     },
 
     hide : function() {
@@ -885,6 +889,15 @@ Overlay.prototype = {
                            onComplete: this._hideDone,
                            onCompleteScope: this
                          });
+
+        this.emit('hiding');
+    },
+
+    toggle: function() {
+        if (this.visible)
+            this.hide();
+        else
+            this.show();
     },
 
     //// Private methods ////
@@ -903,6 +916,8 @@ Overlay.prototype = {
 
         this._sideshow.actor.raise_top();
         this._sideshow.actor.remove_clip();
+
+        this.emit('shown');
     },
 
     _hideDone: function() {
@@ -919,12 +934,12 @@ Overlay.prototype = {
 
         this.visible = false; 
         this._hideInProgress = false;
-    },
 
-    _deactivate : function() {
-        Main.hideOverlay();
+        Main.endModal();
+        this.emit('hidden');
     }
 };
+Signals.addSignalMethods(Overlay.prototype);
 
 Tweener.registerSpecialProperty("clipHeightBottom", _clipHeightBottomGet, _clipHeightBottomSet);
 
diff --git a/js/ui/panel.js b/js/ui/panel.js
index 20c4fa7..6084a50 100644
--- a/js/ui/panel.js
+++ b/js/ui/panel.js
@@ -150,14 +150,8 @@ Panel.prototype = {
         // have the overlay act like a menu that allows the user to release the mouse on the activity the user wants
         // to switch to.
         this.button.button.connect('button-press-event',
-            function(o, event) {
-                if (Main.overlay.visible)
-                    Main.hideOverlay();
-                else
-                    Main.showOverlay();
-
-                return true;
-            });
+                                   Lang.bind(Main.overlay, Main.overlay.toggle));
+        Main.overlay.connect('hiding', Lang.bind(this.button, this.button.release));
 
         this.actor.add_actor(box);
 
@@ -217,9 +211,5 @@ Panel.prototype = {
         this._clock.set_text(displayDate.toLocaleFormat("%a %b %e, %l:%M %p"));
         Mainloop.timeout_add(msecRemaining, Lang.bind(this, this._updateClock));
         return false;
-    },
-
-    overlayHidden: function() {
-        this.button.release();
     }
 };
diff --git a/js/ui/windowManager.js b/js/ui/windowManager.js
index bc6cd31..c7f307c 100644
--- a/js/ui/windowManager.js
+++ b/js/ui/windowManager.js
@@ -86,7 +86,7 @@ WindowManager.prototype = {
     },
 
     _shouldAnimate : function(actor) {
-        if (Main.overlayActive)
+        if (Main.overlay.visible)
             return false;
         if (actor && (actor.get_window_type() != Meta.CompWindowType.NORMAL))
             return false;
diff --git a/js/ui/workspaces.js b/js/ui/workspaces.js
index 2febce0..d7208f2 100644
--- a/js/ui/workspaces.js
+++ b/js/ui/workspaces.js
@@ -292,7 +292,7 @@ Workspace.prototype = {
                               Lang.bind(this,
                                         function(clone, time) {
                                             this._metaWorkspace.activate(time);
-                                            Main.hideOverlay();
+                                            Main.overlay.hide();
                                         }));
         this.actor.add_actor(this._desktop.actor);
 
@@ -721,7 +721,7 @@ Workspace.prototype = {
             workspace.activate_with_focus(clone.metaWindow, time);
         } else
             clone.metaWindow.activate(time);
-        Main.hideOverlay();
+        Main.overlay.hide();
     },
 
     _removeSelf : function(actor, event) {



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