2008-12-01 19:51:43 +00:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2008-10-31 23:09:46 +00:00
|
|
|
|
2008-11-21 00:53:11 +00:00
|
|
|
const Signals = imports.signals;
|
|
|
|
const Mainloop = imports.mainloop;
|
2008-11-06 14:00:14 +00:00
|
|
|
const Tweener = imports.tweener.tweener;
|
2008-11-21 00:53:11 +00:00
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const Gtk = imports.gi.Gtk;
|
2008-10-31 23:09:46 +00:00
|
|
|
|
2008-12-04 15:20:37 +00:00
|
|
|
const Workspaces = imports.ui.workspaces;
|
2008-11-09 18:01:59 +00:00
|
|
|
const Main = imports.ui.main;
|
2008-10-31 23:09:46 +00:00
|
|
|
const Panel = imports.ui.panel;
|
2008-11-21 00:53:11 +00:00
|
|
|
const Meta = imports.gi.Meta;
|
|
|
|
const Shell = imports.gi.Shell;
|
2008-12-01 23:01:55 +00:00
|
|
|
const Big = imports.gi.Big;
|
2008-11-21 00:53:11 +00:00
|
|
|
const AppDisplay = imports.ui.appdisplay;
|
2008-10-31 23:09:46 +00:00
|
|
|
|
|
|
|
const OVERLAY_BACKGROUND_COLOR = new Clutter.Color();
|
|
|
|
OVERLAY_BACKGROUND_COLOR.from_pixel(0x000000ff);
|
|
|
|
|
2008-11-21 00:53:11 +00:00
|
|
|
const SIDESHOW_PAD = 6;
|
|
|
|
const SIDESHOW_MIN_WIDTH = 250;
|
|
|
|
const SIDESHOW_SEARCH_BG_COLOR = new Clutter.Color();
|
|
|
|
SIDESHOW_SEARCH_BG_COLOR.from_pixel(0xffffffff);
|
|
|
|
const SIDESHOW_TEXT_COLOR = new Clutter.Color();
|
|
|
|
SIDESHOW_TEXT_COLOR.from_pixel(0xffffffff);
|
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
// Time for initial animation going into overlay mode
|
2008-11-23 04:12:37 +00:00
|
|
|
const ANIMATION_TIME = 0.5;
|
2008-11-06 14:00:14 +00:00
|
|
|
|
2008-12-04 15:20:37 +00:00
|
|
|
// How much of the screen the workspace grid takes up
|
|
|
|
const WORKSPACE_GRID_SCALE = 0.75;
|
2008-11-06 14:00:14 +00:00
|
|
|
|
2008-12-04 15:16:16 +00:00
|
|
|
function Sideshow(parent, width) {
|
|
|
|
this._init(parent, width);
|
2008-11-21 00:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Sideshow.prototype = {
|
2008-12-04 15:16:16 +00:00
|
|
|
_init : function(parent, width) {
|
2008-12-01 19:51:43 +00:00
|
|
|
let me = this;
|
|
|
|
|
|
|
|
let global = Shell.Global.get();
|
2008-12-01 22:43:06 +00:00
|
|
|
this.actor = new Clutter.Group();
|
2008-12-04 15:16:16 +00:00
|
|
|
parent.add_actor(this.actor);
|
2008-12-01 19:51:43 +00:00
|
|
|
let icontheme = Gtk.IconTheme.get_default();
|
2008-12-01 23:01:55 +00:00
|
|
|
let rect = new Big.Box({ background_color: SIDESHOW_SEARCH_BG_COLOR,
|
|
|
|
corner_radius: 4,
|
|
|
|
x: SIDESHOW_PAD,
|
|
|
|
y: Panel.PANEL_HEIGHT + SIDESHOW_PAD,
|
|
|
|
width: width,
|
|
|
|
height: 24});
|
2008-12-01 22:43:06 +00:00
|
|
|
this.actor.add_actor(rect);
|
2008-12-01 19:51:43 +00:00
|
|
|
|
|
|
|
let searchIconTexture = new Clutter.Texture({ x: SIDESHOW_PAD + 2,
|
|
|
|
y: rect.y + 2 });
|
|
|
|
let searchIconPath = icontheme.lookup_icon('gtk-find', 16, 0).get_filename();
|
|
|
|
searchIconTexture.set_from_file(searchIconPath);
|
2008-12-01 22:43:06 +00:00
|
|
|
this.actor.add_actor(searchIconTexture);
|
2008-12-01 19:51:43 +00:00
|
|
|
|
|
|
|
this._searchEntry = new Clutter.Entry({
|
|
|
|
font_name: "Sans 14px",
|
|
|
|
x: searchIconTexture.x
|
|
|
|
+ searchIconTexture.width + 4,
|
|
|
|
y: searchIconTexture.y,
|
|
|
|
width: rect.width - (searchIconTexture.x),
|
|
|
|
height: searchIconTexture.height});
|
2008-12-01 22:43:06 +00:00
|
|
|
this.actor.add_actor(this._searchEntry);
|
2008-12-01 19:51:43 +00:00
|
|
|
global.stage.set_key_focus(this._searchEntry);
|
|
|
|
this._searchQueued = false;
|
|
|
|
this._searchActive = false;
|
|
|
|
this._searchEntry.connect('notify::text', function (se, prop) {
|
|
|
|
if (me._searchQueued)
|
|
|
|
return;
|
|
|
|
Mainloop.timeout_add(250, function() {
|
|
|
|
let text = me._searchEntry.text;
|
|
|
|
me._searchQueued = false;
|
|
|
|
me._searchActive = text != '';
|
|
|
|
me._appdisplay.setSearch(text);
|
|
|
|
return false;
|
|
|
|
});
|
2008-11-21 00:53:11 +00:00
|
|
|
});
|
2008-12-01 19:51:43 +00:00
|
|
|
this._searchEntry.connect('activate', function (se) {
|
2008-12-03 20:18:10 +00:00
|
|
|
me._searchEntry.text = '';
|
2008-12-01 19:51:43 +00:00
|
|
|
me._appdisplay.searchActivate();
|
2008-11-28 23:06:07 +00:00
|
|
|
return true;
|
2008-12-01 19:51:43 +00:00
|
|
|
});
|
|
|
|
this._searchEntry.connect('key-press-event', function (se, e) {
|
|
|
|
let code = e.get_code();
|
2008-12-03 19:24:50 +00:00
|
|
|
if (code == 9) {
|
|
|
|
me._searchEntry.text = '';
|
|
|
|
return true;
|
|
|
|
} else if (code == 111) {
|
2008-12-01 19:51:43 +00:00
|
|
|
me._appdisplay.selectUp();
|
|
|
|
return true;
|
|
|
|
} else if (code == 116) {
|
|
|
|
me._appdisplay.selectDown();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
let appsText = new Clutter.Label({ color: SIDESHOW_TEXT_COLOR,
|
|
|
|
font_name: "Sans Bold 14px",
|
|
|
|
text: "Applications",
|
|
|
|
x: SIDESHOW_PAD,
|
|
|
|
y: this._searchEntry.y + this._searchEntry.height + 10,
|
|
|
|
height: 16});
|
2008-12-01 22:43:06 +00:00
|
|
|
this.actor.add_actor(appsText);
|
2008-12-01 19:51:43 +00:00
|
|
|
|
|
|
|
let menuY = appsText.y + appsText.height + 6;
|
2008-12-01 22:43:06 +00:00
|
|
|
this._appdisplay = new AppDisplay.AppDisplay(width, global.screen_height - menuY);
|
|
|
|
this._appdisplay.actor.x = SIDESHOW_PAD;
|
|
|
|
this._appdisplay.actor.y = menuY;
|
|
|
|
this.actor.add_actor(this._appdisplay.actor);
|
2008-12-01 19:51:43 +00:00
|
|
|
|
|
|
|
/* Proxy the activated signal */
|
|
|
|
this._appdisplay.connect('activated', function(appdisplay) {
|
|
|
|
me.emit('activated');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
show: function() {
|
|
|
|
this._appdisplay.show();
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
|
|
|
}
|
2008-11-21 00:53:11 +00:00
|
|
|
};
|
|
|
|
Signals.addSignalMethods(Sideshow.prototype);
|
|
|
|
|
2008-10-31 23:09:46 +00:00
|
|
|
function Overlay() {
|
|
|
|
this._init();
|
2008-11-21 00:53:11 +00:00
|
|
|
}
|
2008-10-31 23:09:46 +00:00
|
|
|
|
|
|
|
Overlay.prototype = {
|
2008-12-01 19:51:43 +00:00
|
|
|
_init : function() {
|
|
|
|
let me = this;
|
2008-11-28 20:12:20 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
let global = Shell.Global.get();
|
2008-11-28 20:12:20 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
this._group = new Clutter.Group();
|
|
|
|
this.visible = false;
|
2008-11-28 20:12:20 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
let background = new Clutter.Rectangle({ color: OVERLAY_BACKGROUND_COLOR,
|
|
|
|
reactive: true,
|
|
|
|
x: 0,
|
|
|
|
y: Panel.PANEL_HEIGHT,
|
|
|
|
width: global.screen_width,
|
|
|
|
height: global.screen_width - Panel.PANEL_HEIGHT });
|
|
|
|
this._group.add_actor(background);
|
2008-11-28 20:12:20 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
this._group.hide();
|
|
|
|
global.overlay_group.add_actor(this._group);
|
2008-11-28 20:12:20 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
// TODO - recalculate everything when desktop size changes
|
|
|
|
this._recalculateSize();
|
2008-11-28 20:12:20 +00:00
|
|
|
|
2008-12-04 15:20:37 +00:00
|
|
|
this._workspaces = new Workspaces.Workspaces(
|
|
|
|
this._workspaceGridX, this._workspaceGridY,
|
|
|
|
this._workspaceGridWidth, this._workspaceGridHeight);
|
|
|
|
this._group.add_actor(this._workspaces._group);
|
2008-12-02 16:15:00 +00:00
|
|
|
|
2008-12-04 15:20:37 +00:00
|
|
|
this._sideshow = new Sideshow(this._group, this._workspaceGridX - 10);
|
2008-12-01 19:51:43 +00:00
|
|
|
this._sideshow.connect('activated', function(sideshow) {
|
|
|
|
// TODO - have some sort of animation/effect while
|
|
|
|
// transitioning to the new app. We definitely need
|
|
|
|
// startup-notification integration at least.
|
|
|
|
me._deactivate();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2008-12-02 16:15:00 +00:00
|
|
|
_recalculateSize: function() {
|
2008-12-01 19:51:43 +00:00
|
|
|
let global = Shell.Global.get();
|
|
|
|
let screenWidth = global.screen_width;
|
|
|
|
let screenHeight = global.screen_height;
|
2008-12-02 16:15:00 +00:00
|
|
|
|
2008-12-04 15:20:37 +00:00
|
|
|
// The area allocated for the workspace grid
|
|
|
|
this._workspaceGridWidth = screenWidth * WORKSPACE_GRID_SCALE;
|
|
|
|
this._workspaceGridHeight = screenHeight * WORKSPACE_GRID_SCALE;
|
|
|
|
this._workspaceGridX = screenWidth - this._workspaceGridWidth - 10;
|
|
|
|
this._workspaceGridY = Panel.PANEL_HEIGHT + (screenHeight - this._workspaceGridHeight - Panel.PANEL_HEIGHT) / 2;
|
2008-12-01 19:51:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
show : function() {
|
|
|
|
if (this.visible)
|
|
|
|
return;
|
2008-11-28 20:12:20 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
this.visible = true;
|
2008-11-28 20:12:20 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
let global = Shell.Global.get();
|
2008-11-28 20:12:20 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
this._recalculateSize();
|
2008-11-28 20:12:20 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
this._sideshow.show();
|
2008-12-04 15:20:37 +00:00
|
|
|
this._workspaces.show();
|
|
|
|
this._workspaces._group.raise_top();
|
2008-12-01 19:51:43 +00:00
|
|
|
|
|
|
|
// All the the actors in the window group are completely obscured,
|
|
|
|
// hiding the group holding them while the overlay is displayed greatly
|
|
|
|
// increases performance of the overlay especially when there are many
|
|
|
|
// windows visible.
|
|
|
|
//
|
|
|
|
// If we switched to displaying the actors in the overlay rather than
|
|
|
|
// clones of them, this would obviously no longer be necessary.
|
2008-12-02 16:15:00 +00:00
|
|
|
global.window_group.hide();
|
2008-12-01 19:51:43 +00:00
|
|
|
this._group.show();
|
|
|
|
},
|
|
|
|
|
|
|
|
hide : function() {
|
|
|
|
if (!this.visible)
|
|
|
|
return;
|
|
|
|
|
2008-12-04 15:20:37 +00:00
|
|
|
this._workspaces.hide();
|
2008-12-04 15:16:16 +00:00
|
|
|
this._sideshow.hide();
|
|
|
|
|
|
|
|
// Dummy tween, just waiting for the workspace animation
|
|
|
|
Tweener.addTween(this,
|
|
|
|
{ time: ANIMATION_TIME,
|
|
|
|
onComplete: this._hideDone,
|
|
|
|
onCompleteScope: this
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_hideDone: function() {
|
2008-12-01 19:51:43 +00:00
|
|
|
let global = Shell.Global.get();
|
|
|
|
|
|
|
|
this.visible = false;
|
2008-12-02 16:15:00 +00:00
|
|
|
global.window_group.show();
|
2008-12-04 15:16:16 +00:00
|
|
|
this._group.lower_bottom();
|
2008-12-01 19:51:43 +00:00
|
|
|
this._group.hide();
|
2008-12-04 15:20:37 +00:00
|
|
|
this._workspaces.hideDone();
|
2008-12-01 19:51:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_deactivate : function() {
|
|
|
|
Main.hide_overlay();
|
|
|
|
}
|
2008-10-31 23:09:46 +00:00
|
|
|
};
|