2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-02-12 17:52:15 -05:00
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Mainloop = imports.mainloop;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const St = imports.gi.St;
|
2010-05-06 17:18:10 -04:00
|
|
|
const Main = imports.ui.main;
|
2010-02-12 17:52:15 -05:00
|
|
|
|
|
|
|
const Tweener = imports.ui.tweener;
|
|
|
|
|
2010-06-10 11:22:23 -04:00
|
|
|
const ANIMATION_TIME = 0.1;
|
2010-02-12 17:52:15 -05:00
|
|
|
const DISPLAY_TIMEOUT = 600;
|
|
|
|
|
2011-02-09 10:00:29 -05:00
|
|
|
const UP = -1;
|
|
|
|
const DOWN = 1;
|
2010-02-12 17:52:15 -05:00
|
|
|
|
2011-11-20 12:56:27 -05:00
|
|
|
const WorkspaceSwitcherPopup = new Lang.Class({
|
|
|
|
Name: 'WorkspaceSwitcherPopup',
|
2010-02-12 17:52:15 -05:00
|
|
|
|
|
|
|
_init : function() {
|
2010-06-09 13:09:48 -04:00
|
|
|
this.actor = new St.Group({ reactive: true,
|
2010-02-12 17:52:15 -05:00
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: global.screen_width,
|
2010-06-09 13:09:48 -04:00
|
|
|
height: global.screen_height,
|
|
|
|
style_class: 'workspace-switcher-group' });
|
2010-05-06 17:18:10 -04:00
|
|
|
Main.uiGroup.add_actor(this.actor);
|
2010-02-12 17:52:15 -05:00
|
|
|
|
2010-05-13 15:46:04 -04:00
|
|
|
this._container = new St.BoxLayout({ style_class: 'workspace-switcher-container' });
|
2010-06-09 13:09:48 -04:00
|
|
|
this._list = new Shell.GenericContainer({ style_class: 'workspace-switcher' });
|
|
|
|
this._itemSpacing = 0;
|
2011-02-09 10:00:29 -05:00
|
|
|
this._childHeight = 0;
|
|
|
|
this._childWidth = 0;
|
2010-06-09 13:09:48 -04:00
|
|
|
this._list.connect('style-changed', Lang.bind(this, function() {
|
StThemeNode: simplify use of get_color/get_double/get_length
Although within St itself there are situations where the semantics of
these functions (return TRUE or FALSE and return the actual value in
an out parameter) is useful, it's mostly just annoying at the
application level, where you generally know that the CSS property is
going to specified, and there is no especially sane fallback if it's
not.
So rename the current methods to lookup_color, lookup_double, and
lookup_length, and add new get_color, get_double, and get_length
methods that don't take an "inherit" parameter, and return their
values directly. (Well, except for get_color, due to the lack of (out
caller-allocates) in gjs.)
And update the code to use either the old or new methods as appropriate.
https://bugzilla.gnome.org/show_bug.cgi?id=632590
2010-09-26 17:38:36 -04:00
|
|
|
this._itemSpacing = this._list.get_theme_node().get_length('spacing');
|
2010-06-09 13:09:48 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
this._list.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
|
|
|
|
this._list.connect('get-preferred-height', Lang.bind(this, this._getPreferredHeight));
|
|
|
|
this._list.connect('allocate', Lang.bind(this, this._allocate));
|
2010-02-12 17:52:15 -05:00
|
|
|
this._container.add(this._list);
|
2010-02-16 16:34:57 -05:00
|
|
|
|
2010-02-12 17:52:15 -05:00
|
|
|
this.actor.add_actor(this._container);
|
|
|
|
|
2010-02-16 16:34:57 -05:00
|
|
|
this._redraw();
|
|
|
|
|
2010-02-12 17:52:15 -05:00
|
|
|
this._position();
|
|
|
|
|
2011-02-09 17:57:23 -05:00
|
|
|
this.actor.hide();
|
|
|
|
|
2010-02-12 17:52:15 -05:00
|
|
|
this._timeoutId = Mainloop.timeout_add(DISPLAY_TIMEOUT, Lang.bind(this, this._onTimeout));
|
|
|
|
},
|
|
|
|
|
2011-02-09 10:00:29 -05:00
|
|
|
_getPreferredHeight : function (actor, forWidth, alloc) {
|
2010-06-09 13:09:48 -04:00
|
|
|
let children = this._list.get_children();
|
2011-06-13 09:54:05 -04:00
|
|
|
let primary = Main.layoutManager.primaryMonitor;
|
2010-06-09 13:09:48 -04:00
|
|
|
|
2011-02-09 10:00:29 -05:00
|
|
|
let availHeight = primary.height;
|
|
|
|
availHeight -= Main.panel.actor.height;
|
|
|
|
availHeight -= this.actor.get_theme_node().get_vertical_padding();
|
|
|
|
availHeight -= this._container.get_theme_node().get_vertical_padding();
|
|
|
|
availHeight -= this._list.get_theme_node().get_vertical_padding();
|
2010-06-09 13:09:48 -04:00
|
|
|
|
2011-02-09 10:00:29 -05:00
|
|
|
let height = 0;
|
2010-06-09 13:09:48 -04:00
|
|
|
for (let i = 0; i < children.length; i++) {
|
2011-02-09 10:00:29 -05:00
|
|
|
let [childMinHeight, childNaturalHeight] = children[i].get_preferred_height(-1);
|
|
|
|
let [childMinWidth, childNaturalWidth] = children[i].get_preferred_width(childNaturalHeight);
|
|
|
|
height += childNaturalHeight * primary.width / primary.height;
|
2010-06-09 13:09:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
let spacing = this._itemSpacing * (global.screen.n_workspaces - 1);
|
2011-02-09 10:00:29 -05:00
|
|
|
height += spacing;
|
|
|
|
height = Math.min(height, availHeight);
|
2010-06-09 13:09:48 -04:00
|
|
|
|
2011-02-09 10:00:29 -05:00
|
|
|
this._childHeight = (height - spacing) / global.screen.n_workspaces;
|
2010-06-09 13:09:48 -04:00
|
|
|
|
2011-02-09 10:00:29 -05:00
|
|
|
alloc.min_size = height;
|
|
|
|
alloc.natural_size = height;
|
2010-06-09 13:09:48 -04:00
|
|
|
},
|
|
|
|
|
2011-02-09 10:00:29 -05:00
|
|
|
_getPreferredWidth : function (actor, forHeight, alloc) {
|
2011-06-13 09:54:05 -04:00
|
|
|
let primary = Main.layoutManager.primaryMonitor;
|
2011-02-09 10:00:29 -05:00
|
|
|
this._childWidth = Math.round(this._childHeight * primary.width / primary.height);
|
2010-06-09 13:09:48 -04:00
|
|
|
|
2011-02-09 10:00:29 -05:00
|
|
|
alloc.min_size = this._childWidth;
|
|
|
|
alloc.natural_size = this._childWidth;
|
2010-06-09 13:09:48 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_allocate : function (actor, box, flags) {
|
|
|
|
let children = this._list.get_children();
|
|
|
|
let childBox = new Clutter.ActorBox();
|
|
|
|
|
2011-02-09 10:00:29 -05:00
|
|
|
let y = box.y1;
|
|
|
|
let prevChildBoxY2 = box.y1 - this._itemSpacing;
|
2010-06-09 13:09:48 -04:00
|
|
|
for (let i = 0; i < children.length; i++) {
|
2011-02-09 10:00:29 -05:00
|
|
|
childBox.x1 = box.x1;
|
|
|
|
childBox.x2 = box.x1 + this._childWidth;
|
|
|
|
childBox.y1 = prevChildBoxY2 + this._itemSpacing;
|
|
|
|
childBox.y2 = Math.round(y + this._childHeight);
|
|
|
|
y += this._childHeight + this._itemSpacing;
|
|
|
|
prevChildBoxY2 = childBox.y2;
|
2010-06-09 13:09:48 -04:00
|
|
|
children[i].allocate(childBox, flags);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-02-12 17:52:15 -05:00
|
|
|
_redraw : function(direction, activeWorkspaceIndex) {
|
2012-02-16 13:27:09 -05:00
|
|
|
this._list.destroy_all_children();
|
2010-02-12 17:52:15 -05:00
|
|
|
|
|
|
|
for (let i = 0; i < global.screen.n_workspaces; i++) {
|
|
|
|
let indicator = null;
|
|
|
|
|
2011-02-09 10:00:29 -05:00
|
|
|
if (i == activeWorkspaceIndex && direction == UP)
|
|
|
|
indicator = new St.Bin({ style_class: 'ws-switcher-active-up' });
|
|
|
|
else if(i == activeWorkspaceIndex && direction == DOWN)
|
|
|
|
indicator = new St.Bin({ style_class: 'ws-switcher-active-down' });
|
2010-02-12 17:52:15 -05:00
|
|
|
else
|
|
|
|
indicator = new St.Bin({ style_class: 'ws-switcher-box' });
|
|
|
|
|
2010-06-09 13:09:48 -04:00
|
|
|
this._list.add_actor(indicator);
|
2010-02-12 17:52:15 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_position: function() {
|
2011-06-13 09:54:05 -04:00
|
|
|
let primary = Main.layoutManager.primaryMonitor;
|
2010-05-27 13:57:08 -04:00
|
|
|
this._container.x = primary.x + Math.floor((primary.width - this._container.width) / 2);
|
2011-02-09 10:00:29 -05:00
|
|
|
this._container.y = primary.y + Main.panel.actor.height +
|
|
|
|
Math.floor(((primary.height - Main.panel.actor.height) - this._container.height) / 2);
|
2010-02-12 17:52:15 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_show : function() {
|
|
|
|
Tweener.addTween(this._container, { opacity: 255,
|
|
|
|
time: ANIMATION_TIME,
|
2010-05-13 15:46:04 -04:00
|
|
|
transition: 'easeOutQuad'
|
2010-02-12 17:52:15 -05:00
|
|
|
});
|
|
|
|
this._position();
|
|
|
|
this.actor.show();
|
|
|
|
},
|
|
|
|
|
|
|
|
display : function(direction, activeWorkspaceIndex) {
|
|
|
|
this._redraw(direction, activeWorkspaceIndex);
|
|
|
|
if (this._timeoutId != 0)
|
|
|
|
Mainloop.source_remove(this._timeoutId);
|
|
|
|
this._timeoutId = Mainloop.timeout_add(DISPLAY_TIMEOUT, Lang.bind(this, this._onTimeout));
|
|
|
|
this._show();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onTimeout : function() {
|
|
|
|
Mainloop.source_remove(this._timeoutId);
|
|
|
|
this._timeoutId = 0;
|
|
|
|
Tweener.addTween(this._container, { opacity: 0.0,
|
|
|
|
time: ANIMATION_TIME,
|
2010-05-13 15:46:04 -04:00
|
|
|
transition: 'easeOutQuad',
|
2010-03-15 09:50:05 -04:00
|
|
|
onComplete: function() { this.actor.hide(); },
|
2010-02-12 17:52:15 -05:00
|
|
|
onCompleteScope: this
|
|
|
|
});
|
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|