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.
This commit is contained in:
Dan Winship 2009-05-07 09:47:48 -04:00
parent 17fb280884
commit 062e1aa78b
5 changed files with 29 additions and 45 deletions

View File

@ -3,6 +3,7 @@
const Clutter = imports.gi.Clutter; const Clutter = imports.gi.Clutter;
const Gdk = imports.gi.Gdk; const Gdk = imports.gi.Gdk;
const Gio = imports.gi.Gio; const Gio = imports.gi.Gio;
const Lang = imports.lang;
const Mainloop = imports.mainloop; const Mainloop = imports.mainloop;
const Meta = imports.gi.Meta; const Meta = imports.gi.Meta;
const Shell = imports.gi.Shell; const Shell = imports.gi.Shell;
@ -19,7 +20,6 @@ DEFAULT_BACKGROUND_COLOR.from_pixel(0x2266bbff);
let panel = null; let panel = null;
let overlay = null; let overlay = null;
let overlayActive = false;
let runDialog = null; let runDialog = null;
let wm = null; let wm = null;
let recorder = null; let recorder = null;
@ -61,20 +61,11 @@ function start() {
} }
}); });
overlay = new Overlay.Overlay();
panel = new Panel.Panel(); panel = new Panel.Panel();
overlay = new Overlay.Overlay();
wm = new WindowManager.WindowManager(); 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() { global.screen.connect('toggle-recording', function() {
if (recorder == null) { if (recorder == null) {
// We have to initialize GStreamer first. This isn't done // We have to initialize GStreamer first. This isn't done
@ -92,8 +83,9 @@ function start() {
} }
}); });
display.connect('overlay-key', toggleOverlay); let display = global.screen.get_display();
global.connect('panel-main-menu', toggleOverlay); 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 // Need to update struts on new workspaces when they are added
global.screen.connect('notify::n-workspaces', _setStageArea); global.screen.connect('notify::n-workspaces', _setStageArea);
@ -154,19 +146,6 @@ function endModal() {
inModal = false; inModal = false;
} }
function showOverlay() {
if (startModal()) {
overlayActive = true;
overlay.show();
}
}
function hideOverlay() {
overlay.hide();
overlayActive = false;
endModal();
}
function createAppLaunchContext() { function createAppLaunchContext() {
let global = Shell.Global.get(); let global = Shell.Global.get();
let screen = global.screen; let screen = global.screen;

View File

@ -754,7 +754,7 @@ Overlay.prototype = {
// TODO - have some sort of animation/effect while // TODO - have some sort of animation/effect while
// transitioning to the new app. We definitely need // transitioning to the new app. We definitely need
// startup-notification integration at least. // startup-notification integration at least.
me._deactivate(); me.hide();
}); });
this._sideshow.connect('more-activated', function(sideshow) { this._sideshow.connect('more-activated', function(sideshow) {
if (me._workspaces != null) { if (me._workspaces != null) {
@ -795,6 +795,8 @@ Overlay.prototype = {
show : function() { show : function() {
if (this.visible) if (this.visible)
return; return;
if (!Main.startModal())
return;
this.visible = true; this.visible = true;
@ -854,6 +856,8 @@ Overlay.prototype = {
onCompleteScope: this onCompleteScope: this
}); });
this.emit('showing');
}, },
hide : function() { hide : function() {
@ -885,6 +889,15 @@ Overlay.prototype = {
onComplete: this._hideDone, onComplete: this._hideDone,
onCompleteScope: this onCompleteScope: this
}); });
this.emit('hiding');
},
toggle: function() {
if (this.visible)
this.hide();
else
this.show();
}, },
//// Private methods //// //// Private methods ////
@ -903,6 +916,8 @@ Overlay.prototype = {
this._sideshow.actor.raise_top(); this._sideshow.actor.raise_top();
this._sideshow.actor.remove_clip(); this._sideshow.actor.remove_clip();
this.emit('shown');
}, },
_hideDone: function() { _hideDone: function() {
@ -919,12 +934,12 @@ Overlay.prototype = {
this.visible = false; this.visible = false;
this._hideInProgress = false; this._hideInProgress = false;
},
_deactivate : function() { Main.endModal();
Main.hideOverlay(); this.emit('hidden');
} }
}; };
Signals.addSignalMethods(Overlay.prototype);
Tweener.registerSpecialProperty("clipHeightBottom", _clipHeightBottomGet, _clipHeightBottomSet); Tweener.registerSpecialProperty("clipHeightBottom", _clipHeightBottomGet, _clipHeightBottomSet);

View File

@ -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 // have the overlay act like a menu that allows the user to release the mouse on the activity the user wants
// to switch to. // to switch to.
this.button.button.connect('button-press-event', this.button.button.connect('button-press-event',
function(o, event) { Lang.bind(Main.overlay, Main.overlay.toggle));
if (Main.overlay.visible) Main.overlay.connect('hiding', Lang.bind(this.button, this.button.release));
Main.hideOverlay();
else
Main.showOverlay();
return true;
});
this.actor.add_actor(box); this.actor.add_actor(box);
@ -217,9 +211,5 @@ Panel.prototype = {
this._clock.set_text(displayDate.toLocaleFormat("%a %b %e, %l:%M %p")); this._clock.set_text(displayDate.toLocaleFormat("%a %b %e, %l:%M %p"));
Mainloop.timeout_add(msecRemaining, Lang.bind(this, this._updateClock)); Mainloop.timeout_add(msecRemaining, Lang.bind(this, this._updateClock));
return false; return false;
},
overlayHidden: function() {
this.button.release();
} }
}; };

View File

@ -86,7 +86,7 @@ WindowManager.prototype = {
}, },
_shouldAnimate : function(actor) { _shouldAnimate : function(actor) {
if (Main.overlayActive) if (Main.overlay.visible)
return false; return false;
if (actor && (actor.get_window_type() != Meta.CompWindowType.NORMAL)) if (actor && (actor.get_window_type() != Meta.CompWindowType.NORMAL))
return false; return false;

View File

@ -292,7 +292,7 @@ Workspace.prototype = {
Lang.bind(this, Lang.bind(this,
function(clone, time) { function(clone, time) {
this._metaWorkspace.activate(time); this._metaWorkspace.activate(time);
Main.hideOverlay(); Main.overlay.hide();
})); }));
this.actor.add_actor(this._desktop.actor); this.actor.add_actor(this._desktop.actor);
@ -721,7 +721,7 @@ Workspace.prototype = {
workspace.activate_with_focus(clone.metaWindow, time); workspace.activate_with_focus(clone.metaWindow, time);
} else } else
clone.metaWindow.activate(time); clone.metaWindow.activate(time);
Main.hideOverlay(); Main.overlay.hide();
}, },
_removeSelf : function(actor, event) { _removeSelf : function(actor, event) {