2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2009-04-13 10:55:41 -04:00
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
2012-11-22 21:20:10 -05:00
|
|
|
const Gio = imports.gi.Gio;
|
2013-11-28 19:45:39 -05:00
|
|
|
const GLib = imports.gi.GLib;
|
2009-04-13 10:55:41 -04:00
|
|
|
const Lang = imports.lang;
|
2009-10-02 11:02:46 -04:00
|
|
|
const Mainloop = imports.mainloop;
|
2011-01-29 17:01:46 -05:00
|
|
|
const Meta = imports.gi.Meta;
|
2009-04-13 10:55:41 -04:00
|
|
|
const Shell = imports.gi.Shell;
|
2009-09-29 12:19:16 -04:00
|
|
|
const St = imports.gi.St;
|
2012-03-07 13:29:13 -05:00
|
|
|
const Atk = imports.gi.Atk;
|
2009-04-13 10:55:41 -04:00
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
2012-11-30 10:16:48 -05:00
|
|
|
const SwitcherPopup = imports.ui.switcherPopup;
|
2009-10-09 09:43:31 -04:00
|
|
|
const Tweener = imports.ui.tweener;
|
2009-04-13 10:55:41 -04:00
|
|
|
|
2011-01-30 14:21:16 -05:00
|
|
|
const APP_ICON_HOVER_TIMEOUT = 200; // milliseconds
|
2011-01-06 14:21:27 -05:00
|
|
|
|
2010-03-17 13:31:03 -04:00
|
|
|
const THUMBNAIL_DEFAULT_SIZE = 256;
|
2009-10-09 09:43:31 -04:00
|
|
|
const THUMBNAIL_POPUP_TIME = 500; // milliseconds
|
2010-06-10 11:22:23 -04:00
|
|
|
const THUMBNAIL_FADE_TIME = 0.1; // seconds
|
2009-10-02 11:02:46 -04:00
|
|
|
|
2012-11-22 21:20:10 -05:00
|
|
|
const WINDOW_PREVIEW_SIZE = 128;
|
|
|
|
const APP_ICON_SIZE = 96;
|
|
|
|
const APP_ICON_SIZE_SMALL = 48;
|
|
|
|
|
2014-02-15 23:25:49 -05:00
|
|
|
const baseIconSizes = [96, 64, 48, 32, 22];
|
2010-03-17 13:31:03 -04:00
|
|
|
|
2012-11-22 21:20:10 -05:00
|
|
|
const AppIconMode = {
|
|
|
|
THUMBNAIL_ONLY: 1,
|
|
|
|
APP_ICON_ONLY: 2,
|
|
|
|
BOTH: 3,
|
|
|
|
};
|
|
|
|
|
2012-12-04 10:26:00 -05:00
|
|
|
function _createWindowClone(window, size) {
|
|
|
|
let windowTexture = window.get_texture();
|
|
|
|
let [width, height] = windowTexture.get_size();
|
|
|
|
let scale = Math.min(1.0, size / width, size / height);
|
|
|
|
return new Clutter.Clone({ source: windowTexture,
|
|
|
|
width: width * scale,
|
|
|
|
height: height * scale,
|
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
|
|
// usual hack for the usual bug in ClutterBinLayout...
|
|
|
|
x_expand: true,
|
|
|
|
y_expand: true });
|
|
|
|
};
|
|
|
|
|
2012-12-03 10:31:50 -05:00
|
|
|
const AppSwitcherPopup = new Lang.Class({
|
|
|
|
Name: 'AppSwitcherPopup',
|
2012-11-30 10:16:48 -05:00
|
|
|
Extends: SwitcherPopup.SwitcherPopup,
|
2009-04-13 10:55:41 -04:00
|
|
|
|
|
|
|
_init : function() {
|
2012-11-30 10:16:48 -05:00
|
|
|
this.parent();
|
2010-03-17 13:31:03 -04:00
|
|
|
|
2012-11-30 10:16:48 -05:00
|
|
|
this._thumbnails = null;
|
2009-10-02 11:02:46 -04:00
|
|
|
this._thumbnailTimeoutId = 0;
|
2012-11-30 10:16:48 -05:00
|
|
|
this._currentWindow = -1;
|
2009-10-09 09:43:31 -04:00
|
|
|
|
2011-01-06 14:21:27 -05:00
|
|
|
this.thumbnailsVisible = false;
|
2010-03-17 13:31:03 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_allocate: function (actor, box, flags) {
|
2012-11-30 10:16:48 -05:00
|
|
|
this.parent(actor, box, flags);
|
2010-03-17 13:31:03 -04:00
|
|
|
|
|
|
|
// Allocate the thumbnails
|
|
|
|
// We try to avoid overflowing the screen so we base the resulting size on
|
|
|
|
// those calculations
|
|
|
|
if (this._thumbnails) {
|
2012-11-30 10:16:48 -05:00
|
|
|
let childBox = this._switcherList.actor.get_allocation_box();
|
|
|
|
let primary = Main.layoutManager.primaryMonitor;
|
|
|
|
|
|
|
|
let leftPadding = this.actor.get_theme_node().get_padding(St.Side.LEFT);
|
|
|
|
let rightPadding = this.actor.get_theme_node().get_padding(St.Side.RIGHT);
|
|
|
|
let bottomPadding = this.actor.get_theme_node().get_padding(St.Side.BOTTOM);
|
|
|
|
let vPadding = this.actor.get_theme_node().get_vertical_padding();
|
|
|
|
let hPadding = leftPadding + rightPadding;
|
|
|
|
|
|
|
|
let icon = this._items[this._selectedIndex].actor;
|
2010-03-17 13:31:03 -04:00
|
|
|
let [posX, posY] = icon.get_transformed_position();
|
|
|
|
let thumbnailCenter = posX + icon.width / 2;
|
|
|
|
let [childMinWidth, childNaturalWidth] = this._thumbnails.actor.get_preferred_width(-1);
|
2010-05-27 13:52:49 -04:00
|
|
|
childBox.x1 = Math.max(primary.x + leftPadding, Math.floor(thumbnailCenter - childNaturalWidth / 2));
|
|
|
|
if (childBox.x1 + childNaturalWidth > primary.x + primary.width - hPadding) {
|
|
|
|
let offset = childBox.x1 + childNaturalWidth - primary.width + hPadding;
|
|
|
|
childBox.x1 = Math.max(primary.x + leftPadding, childBox.x1 - offset - hPadding);
|
2010-03-17 13:31:03 -04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
let spacing = this.actor.get_theme_node().get_length('spacing');
|
2010-03-26 12:47:12 -04:00
|
|
|
|
2010-03-17 13:31:03 -04:00
|
|
|
childBox.x2 = childBox.x1 + childNaturalWidth;
|
2010-05-27 13:52:49 -04:00
|
|
|
if (childBox.x2 > primary.x + primary.width - rightPadding)
|
|
|
|
childBox.x2 = primary.x + primary.width - rightPadding;
|
2012-11-30 10:16:48 -05:00
|
|
|
childBox.y1 = this._switcherList.actor.allocation.y2 + spacing;
|
2012-02-23 13:38:01 -05:00
|
|
|
this._thumbnails.addClones(primary.y + primary.height - bottomPadding - childBox.y1);
|
2010-03-17 13:31:03 -04:00
|
|
|
let [childMinHeight, childNaturalHeight] = this._thumbnails.actor.get_preferred_height(-1);
|
|
|
|
childBox.y2 = childBox.y1 + childNaturalHeight;
|
|
|
|
this._thumbnails.actor.allocate(childBox, flags);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-11-30 10:16:48 -05:00
|
|
|
_createSwitcher: function() {
|
2011-09-29 17:43:59 -04:00
|
|
|
let apps = Shell.AppSystem.get_default().get_running ();
|
2011-07-14 17:23:16 -04:00
|
|
|
|
2011-09-29 17:43:59 -04:00
|
|
|
if (apps.length == 0)
|
2009-09-15 11:11:32 -04:00
|
|
|
return false;
|
|
|
|
|
2011-09-29 17:43:59 -04:00
|
|
|
this._switcherList = new AppSwitcher(apps, this);
|
2012-11-30 10:16:48 -05:00
|
|
|
this._items = this._switcherList.icons;
|
2013-10-25 13:02:59 -04:00
|
|
|
if (this._items.length == 0)
|
|
|
|
return false;
|
2009-09-15 11:11:32 -04:00
|
|
|
|
2012-11-30 10:16:48 -05:00
|
|
|
return true;
|
|
|
|
},
|
2011-04-18 09:52:21 -04:00
|
|
|
|
2012-11-30 10:16:48 -05:00
|
|
|
_initialSelection: function(backward, binding) {
|
2011-06-26 21:54:26 -04:00
|
|
|
if (binding == 'switch-group') {
|
2011-01-29 17:11:25 -05:00
|
|
|
if (backward) {
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(0, this._items[0].cachedWindows.length - 1);
|
2011-01-29 17:11:25 -05:00
|
|
|
} else {
|
2012-11-30 10:16:48 -05:00
|
|
|
if (this._items[0].cachedWindows.length > 1)
|
2011-01-29 17:11:25 -05:00
|
|
|
this._select(0, 1);
|
|
|
|
else
|
|
|
|
this._select(0, 0);
|
|
|
|
}
|
2011-06-26 21:54:26 -04:00
|
|
|
} else if (binding == 'switch-group-backward') {
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(0, this._items[0].cachedWindows.length - 1);
|
2012-11-22 19:18:06 -05:00
|
|
|
} else if (binding == 'switch-applications-backward') {
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(this._items.length - 1);
|
|
|
|
} else if (this._items.length == 1) {
|
2011-02-23 05:52:25 -05:00
|
|
|
this._select(0);
|
2009-10-02 11:02:46 -04:00
|
|
|
} else if (backward) {
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(this._items.length - 1);
|
2009-10-02 11:02:46 -04:00
|
|
|
} else {
|
2011-02-23 05:52:25 -05:00
|
|
|
this._select(1);
|
2009-10-01 05:23:00 -04:00
|
|
|
}
|
2009-09-29 13:29:17 -04:00
|
|
|
},
|
|
|
|
|
2009-10-02 11:02:46 -04:00
|
|
|
_nextWindow : function() {
|
2010-05-06 13:36:01 -04:00
|
|
|
// We actually want the second window if we're in the unset state
|
|
|
|
if (this._currentWindow == -1)
|
|
|
|
this._currentWindow = 0;
|
2012-11-30 10:16:48 -05:00
|
|
|
return SwitcherPopup.mod(this._currentWindow + 1,
|
|
|
|
this._items[this._selectedIndex].cachedWindows.length);
|
2009-10-02 11:02:46 -04:00
|
|
|
},
|
|
|
|
_previousWindow : function() {
|
2010-05-06 13:36:01 -04:00
|
|
|
// Also assume second window here
|
|
|
|
if (this._currentWindow == -1)
|
|
|
|
this._currentWindow = 1;
|
2012-11-30 10:16:48 -05:00
|
|
|
return SwitcherPopup.mod(this._currentWindow - 1,
|
|
|
|
this._items[this._selectedIndex].cachedWindows.length);
|
2009-10-02 11:02:46 -04:00
|
|
|
},
|
|
|
|
|
2012-11-30 10:16:48 -05:00
|
|
|
_keyPressHandler: function(keysym, backwards, action) {
|
|
|
|
if (action == Meta.KeyBindingAction.SWITCH_GROUP) {
|
|
|
|
this._select(this._selectedIndex, backwards ? this._previousWindow() : this._nextWindow());
|
2011-07-05 18:05:45 -04:00
|
|
|
} else if (action == Meta.KeyBindingAction.SWITCH_GROUP_BACKWARD) {
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(this._selectedIndex, this._previousWindow());
|
2012-11-22 19:18:06 -05:00
|
|
|
} else if (action == Meta.KeyBindingAction.SWITCH_APPLICATIONS) {
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(backwards ? this._previous() : this._next());
|
2012-11-22 19:18:06 -05:00
|
|
|
} else if (action == Meta.KeyBindingAction.SWITCH_APPLICATIONS_BACKWARD) {
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(this._previous());
|
2011-02-23 05:52:25 -05:00
|
|
|
} else if (this._thumbnailsFocused) {
|
|
|
|
if (keysym == Clutter.Left)
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(this._selectedIndex, this._previousWindow());
|
2010-07-20 14:22:41 -04:00
|
|
|
else if (keysym == Clutter.Right)
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(this._selectedIndex, this._nextWindow());
|
2010-07-20 14:22:41 -04:00
|
|
|
else if (keysym == Clutter.Up)
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(this._selectedIndex, null, true);
|
2014-05-26 09:27:16 -04:00
|
|
|
else
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2009-10-02 11:02:46 -04:00
|
|
|
} else {
|
2011-02-23 05:52:25 -05:00
|
|
|
if (keysym == Clutter.Left)
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(this._previous());
|
2010-07-20 14:22:41 -04:00
|
|
|
else if (keysym == Clutter.Right)
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(this._next());
|
2010-07-20 14:22:41 -04:00
|
|
|
else if (keysym == Clutter.Down)
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(this._selectedIndex, 0);
|
2014-05-26 09:27:16 -04:00
|
|
|
else
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2009-09-26 10:56:41 -04:00
|
|
|
}
|
2014-05-26 09:27:16 -04:00
|
|
|
|
|
|
|
return Clutter.EVENT_STOP;
|
2009-10-02 11:02:46 -04:00
|
|
|
},
|
|
|
|
|
2012-11-30 10:16:48 -05:00
|
|
|
_scrollHandler: function(direction) {
|
2009-10-09 09:43:31 -04:00
|
|
|
if (direction == Clutter.ScrollDirection.UP) {
|
|
|
|
if (this._thumbnailsFocused) {
|
2010-05-06 13:36:01 -04:00
|
|
|
if (this._currentWindow == 0 || this._currentWindow == -1)
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(this._previous());
|
2009-10-09 09:43:31 -04:00
|
|
|
else
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(this._selectedIndex, this._previousWindow());
|
2009-10-09 09:43:31 -04:00
|
|
|
} else {
|
2012-11-30 10:16:48 -05:00
|
|
|
let nwindows = this._items[this._selectedIndex].cachedWindows.length;
|
2009-10-09 09:43:31 -04:00
|
|
|
if (nwindows > 1)
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(this._selectedIndex, nwindows - 1);
|
2009-10-09 09:43:31 -04:00
|
|
|
else
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(this._previous());
|
2009-10-09 09:43:31 -04:00
|
|
|
}
|
|
|
|
} else if (direction == Clutter.ScrollDirection.DOWN) {
|
|
|
|
if (this._thumbnailsFocused) {
|
2012-11-30 10:16:48 -05:00
|
|
|
if (this._currentWindow == this._items[this._selectedIndex].cachedWindows.length - 1)
|
|
|
|
this._select(this._next());
|
2009-10-09 09:43:31 -04:00
|
|
|
else
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(this._selectedIndex, this._nextWindow());
|
2009-10-09 09:43:31 -04:00
|
|
|
} else {
|
2012-11-30 10:16:48 -05:00
|
|
|
let nwindows = this._items[this._selectedIndex].cachedWindows.length;
|
2009-10-09 09:43:31 -04:00
|
|
|
if (nwindows > 1)
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(this._selectedIndex, 0);
|
2009-10-09 09:43:31 -04:00
|
|
|
else
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(this._next());
|
2009-10-09 09:43:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-11-30 10:16:48 -05:00
|
|
|
_itemActivatedHandler: function(n) {
|
2009-10-09 09:43:31 -04:00
|
|
|
// If the user clicks on the selected app, activate the
|
|
|
|
// selected window; otherwise (eg, they click on an app while
|
2012-11-22 22:39:19 -05:00
|
|
|
// !mouseActive) activate the clicked-on app.
|
2012-11-30 10:16:48 -05:00
|
|
|
if (n == this._selectedIndex && this._currentWindow >= 0)
|
|
|
|
this._select(n, this._currentWindow);
|
2012-11-22 22:39:19 -05:00
|
|
|
else
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(n);
|
2009-10-02 11:02:46 -04:00
|
|
|
},
|
|
|
|
|
2012-11-30 10:16:48 -05:00
|
|
|
_itemEnteredHandler: function(n) {
|
2009-10-09 09:43:31 -04:00
|
|
|
this._select(n);
|
2009-10-02 11:02:46 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_windowActivated : function(thumbnailList, n) {
|
2012-11-30 10:16:48 -05:00
|
|
|
let appIcon = this._items[this._selectedIndex];
|
2010-05-06 13:36:01 -04:00
|
|
|
Main.activateWindow(appIcon.cachedWindows[n]);
|
2009-10-02 11:02:46 -04:00
|
|
|
this.destroy();
|
|
|
|
},
|
|
|
|
|
2009-10-09 09:43:31 -04:00
|
|
|
_windowEntered : function(thumbnailList, n) {
|
2012-11-30 10:16:48 -05:00
|
|
|
if (!this.mouseActive)
|
2009-10-02 11:02:46 -04:00
|
|
|
return;
|
|
|
|
|
2012-11-30 10:16:48 -05:00
|
|
|
this._select(this._selectedIndex, n);
|
2009-10-02 11:02:46 -04:00
|
|
|
},
|
|
|
|
|
2012-12-04 13:45:52 -05:00
|
|
|
_finish : function(timestamp) {
|
2012-11-30 10:16:48 -05:00
|
|
|
let appIcon = this._items[this._selectedIndex];
|
2013-04-07 10:42:42 -04:00
|
|
|
if (this._currentWindow < 0)
|
2013-05-15 02:37:12 -04:00
|
|
|
appIcon.app.activate_window(appIcon.cachedWindows[0], timestamp);
|
2013-04-07 10:42:42 -04:00
|
|
|
else
|
|
|
|
Main.activateWindow(appIcon.cachedWindows[this._currentWindow], timestamp);
|
2013-03-22 11:21:18 -04:00
|
|
|
|
|
|
|
this.parent();
|
2009-10-02 11:02:46 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_onDestroy : function() {
|
2012-11-30 10:16:48 -05:00
|
|
|
this.parent();
|
2009-10-02 11:02:46 -04:00
|
|
|
|
2010-03-17 13:31:03 -04:00
|
|
|
if (this._thumbnails)
|
|
|
|
this._destroyThumbnails();
|
2009-10-02 11:02:46 -04:00
|
|
|
if (this._thumbnailTimeoutId != 0)
|
|
|
|
Mainloop.source_remove(this._thumbnailTimeoutId);
|
|
|
|
},
|
|
|
|
|
2009-10-09 09:43:31 -04:00
|
|
|
/**
|
|
|
|
* _select:
|
|
|
|
* @app: index of the app to select
|
|
|
|
* @window: (optional) index of which of @app's windows to select
|
|
|
|
* @forceAppFocus: optional flag, see below
|
|
|
|
*
|
|
|
|
* Selects the indicated @app, and optional @window, and sets
|
|
|
|
* this._thumbnailsFocused appropriately to indicate whether the
|
|
|
|
* arrow keys should act on the app list or the thumbnail list.
|
|
|
|
*
|
|
|
|
* If @app is specified and @window is unspecified or %null, then
|
|
|
|
* the app is highlighted (ie, given a light background), and the
|
|
|
|
* current thumbnail list, if any, is destroyed. If @app has
|
|
|
|
* multiple windows, and @forceAppFocus is not %true, then a
|
|
|
|
* timeout is started to open a thumbnail list.
|
|
|
|
*
|
|
|
|
* If @app and @window are specified (and @forceAppFocus is not),
|
|
|
|
* then @app will be outlined, a thumbnail list will be created
|
|
|
|
* and focused (if it hasn't been already), and the @window'th
|
|
|
|
* window in it will be highlighted.
|
|
|
|
*
|
|
|
|
* If @app and @window are specified and @forceAppFocus is %true,
|
|
|
|
* then @app will be highlighted, and @window outlined, and the
|
|
|
|
* app list will have the keyboard focus.
|
|
|
|
*/
|
|
|
|
_select : function(app, window, forceAppFocus) {
|
2012-11-30 10:16:48 -05:00
|
|
|
if (app != this._selectedIndex || window == null) {
|
2009-10-09 09:43:31 -04:00
|
|
|
if (this._thumbnails)
|
|
|
|
this._destroyThumbnails();
|
2009-10-02 11:02:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this._thumbnailTimeoutId != 0) {
|
|
|
|
Mainloop.source_remove(this._thumbnailTimeoutId);
|
|
|
|
this._thumbnailTimeoutId = 0;
|
|
|
|
}
|
|
|
|
|
2009-10-09 09:43:31 -04:00
|
|
|
this._thumbnailsFocused = (window != null) && !forceAppFocus;
|
|
|
|
|
2012-11-30 10:16:48 -05:00
|
|
|
this._selectedIndex = app;
|
2010-05-06 13:36:01 -04:00
|
|
|
this._currentWindow = window ? window : -1;
|
2012-11-30 10:16:48 -05:00
|
|
|
this._switcherList.highlight(app, this._thumbnailsFocused);
|
2009-10-02 11:02:46 -04:00
|
|
|
|
|
|
|
if (window != null) {
|
|
|
|
if (!this._thumbnails)
|
|
|
|
this._createThumbnails();
|
2009-10-09 09:43:31 -04:00
|
|
|
this._currentWindow = window;
|
|
|
|
this._thumbnails.highlight(window, forceAppFocus);
|
2012-11-30 10:16:48 -05:00
|
|
|
} else if (this._items[this._selectedIndex].cachedWindows.length > 1 &&
|
2009-10-09 09:43:31 -04:00
|
|
|
!forceAppFocus) {
|
2009-10-02 11:02:46 -04:00
|
|
|
this._thumbnailTimeoutId = Mainloop.timeout_add (
|
|
|
|
THUMBNAIL_POPUP_TIME,
|
2010-05-06 13:36:01 -04:00
|
|
|
Lang.bind(this, this._timeoutPopupThumbnails));
|
2014-04-10 13:26:52 -04:00
|
|
|
GLib.Source.set_name_by_id(this._thumbnailTimeoutId, '[gnome-shell] this._timeoutPopupThumbnails');
|
2009-10-02 11:02:46 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-05-06 13:36:01 -04:00
|
|
|
_timeoutPopupThumbnails: function() {
|
|
|
|
if (!this._thumbnails)
|
|
|
|
this._createThumbnails();
|
|
|
|
this._thumbnailTimeoutId = 0;
|
|
|
|
this._thumbnailsFocused = false;
|
2013-11-28 19:45:39 -05:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2010-05-06 13:36:01 -04:00
|
|
|
},
|
|
|
|
|
2009-10-09 09:43:31 -04:00
|
|
|
_destroyThumbnails : function() {
|
2011-01-06 14:21:27 -05:00
|
|
|
let thumbnailsActor = this._thumbnails.actor;
|
|
|
|
Tweener.addTween(thumbnailsActor,
|
2009-10-09 09:43:31 -04:00
|
|
|
{ opacity: 0,
|
|
|
|
time: THUMBNAIL_FADE_TIME,
|
2010-05-13 15:46:04 -04:00
|
|
|
transition: 'easeOutQuad',
|
2011-01-06 14:21:27 -05:00
|
|
|
onComplete: Lang.bind(this, function() {
|
|
|
|
thumbnailsActor.destroy();
|
|
|
|
this.thumbnailsVisible = false;
|
|
|
|
})
|
2009-10-09 09:43:31 -04:00
|
|
|
});
|
|
|
|
this._thumbnails = null;
|
2012-11-30 10:16:48 -05:00
|
|
|
this._switcherList._items[this._selectedIndex].remove_accessible_state (Atk.StateType.EXPANDED);
|
2009-10-09 09:43:31 -04:00
|
|
|
},
|
|
|
|
|
2009-10-02 11:02:46 -04:00
|
|
|
_createThumbnails : function() {
|
2012-11-30 10:16:48 -05:00
|
|
|
this._thumbnails = new ThumbnailList (this._items[this._selectedIndex].cachedWindows);
|
2009-10-02 11:02:46 -04:00
|
|
|
this._thumbnails.connect('item-activated', Lang.bind(this, this._windowActivated));
|
2009-10-09 09:43:31 -04:00
|
|
|
this._thumbnails.connect('item-entered', Lang.bind(this, this._windowEntered));
|
2009-10-02 11:02:46 -04:00
|
|
|
|
|
|
|
this.actor.add_actor(this._thumbnails.actor);
|
2011-07-21 13:58:43 -04:00
|
|
|
|
|
|
|
// Need to force an allocation so we can figure out whether we
|
|
|
|
// need to scroll when selecting
|
|
|
|
this._thumbnails.actor.get_allocation_box();
|
2009-10-02 11:02:46 -04:00
|
|
|
|
2009-10-09 09:43:31 -04:00
|
|
|
this._thumbnails.actor.opacity = 0;
|
|
|
|
Tweener.addTween(this._thumbnails.actor,
|
|
|
|
{ opacity: 255,
|
|
|
|
time: THUMBNAIL_FADE_TIME,
|
2011-01-06 14:21:27 -05:00
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: Lang.bind(this, function () { this.thumbnailsVisible = true; })
|
2009-10-09 09:43:31 -04:00
|
|
|
});
|
2012-03-07 13:29:13 -05:00
|
|
|
|
2012-11-30 10:16:48 -05:00
|
|
|
this._switcherList._items[this._selectedIndex].add_accessible_state (Atk.StateType.EXPANDED);
|
2009-10-02 11:02:46 -04:00
|
|
|
}
|
2011-11-20 11:07:14 -05:00
|
|
|
});
|
2009-09-15 11:11:32 -04:00
|
|
|
|
2012-11-22 21:20:10 -05:00
|
|
|
const WindowSwitcherPopup = new Lang.Class({
|
|
|
|
Name: 'WindowSwitcherPopup',
|
|
|
|
Extends: SwitcherPopup.SwitcherPopup,
|
|
|
|
|
2013-09-09 16:53:44 -04:00
|
|
|
_init: function(items) {
|
|
|
|
this.parent(items);
|
|
|
|
this._settings = new Gio.Settings({ schema: 'org.gnome.shell.window-switcher' });
|
|
|
|
},
|
|
|
|
|
2012-11-22 21:20:10 -05:00
|
|
|
_getWindowList: function() {
|
2013-09-09 16:53:44 -04:00
|
|
|
let workspace = this._settings.get_boolean('current-workspace-only') ? global.screen.get_active_workspace() : null;
|
2012-11-22 21:20:10 -05:00
|
|
|
return global.display.get_tab_list(Meta.TabList.NORMAL, global.screen, workspace);
|
|
|
|
},
|
|
|
|
|
|
|
|
_createSwitcher: function() {
|
|
|
|
let windows = this._getWindowList();
|
|
|
|
|
|
|
|
if (windows.length == 0)
|
|
|
|
return false;
|
|
|
|
|
2013-09-09 16:53:44 -04:00
|
|
|
let mode = this._settings.get_enum('app-icon-mode');
|
|
|
|
this._switcherList = new WindowList(windows, mode);
|
2012-11-22 21:20:10 -05:00
|
|
|
this._items = this._switcherList.icons;
|
|
|
|
|
2013-10-25 13:02:59 -04:00
|
|
|
if (this._items.length == 0)
|
|
|
|
return false;
|
|
|
|
|
2012-11-22 21:20:10 -05:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
_initialSelection: function(backward, binding) {
|
|
|
|
if (binding == 'switch-windows-backward' || backward)
|
|
|
|
this._select(this._items.length - 1);
|
|
|
|
else if (this._items.length == 1)
|
|
|
|
this._select(0);
|
|
|
|
else
|
|
|
|
this._select(1);
|
|
|
|
},
|
|
|
|
|
|
|
|
_keyPressHandler: function(keysym, backwards, action) {
|
|
|
|
if (action == Meta.KeyBindingAction.SWITCH_WINDOWS) {
|
|
|
|
this._select(backwards ? this._previous() : this._next());
|
|
|
|
} else if (action == Meta.KeyBindingAction.SWITCH_WINDOWS_BACKWARD) {
|
|
|
|
this._select(this._previous());
|
|
|
|
} else {
|
|
|
|
if (keysym == Clutter.Left)
|
|
|
|
this._select(this._previous());
|
|
|
|
else if (keysym == Clutter.Right)
|
|
|
|
this._select(this._next());
|
2014-05-26 09:27:16 -04:00
|
|
|
else
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2012-11-22 21:20:10 -05:00
|
|
|
}
|
2014-05-26 09:27:16 -04:00
|
|
|
|
|
|
|
return Clutter.EVENT_STOP;
|
2012-11-22 21:20:10 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_finish: function() {
|
|
|
|
Main.activateWindow(this._items[this._selectedIndex].window);
|
2013-03-22 11:21:18 -04:00
|
|
|
|
|
|
|
this.parent();
|
2012-11-22 21:20:10 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-11-20 12:56:27 -05:00
|
|
|
const AppIcon = new Lang.Class({
|
|
|
|
Name: 'AppIcon',
|
2009-11-12 17:46:59 -05:00
|
|
|
|
|
|
|
_init: function(app) {
|
|
|
|
this.app = app;
|
2010-05-13 15:46:04 -04:00
|
|
|
this.actor = new St.BoxLayout({ style_class: 'alt-tab-app',
|
2009-11-12 17:46:59 -05:00
|
|
|
vertical: true });
|
2010-03-17 13:31:03 -04:00
|
|
|
this.icon = null;
|
2011-02-25 07:49:34 -05:00
|
|
|
this._iconBin = new St.Bin({ x_fill: true, y_fill: true });
|
2010-02-17 04:52:11 -05:00
|
|
|
|
2010-03-17 13:31:03 -04:00
|
|
|
this.actor.add(this._iconBin, { x_fill: false, y_fill: false } );
|
|
|
|
this.label = new St.Label({ text: this.app.get_name() });
|
|
|
|
this.actor.add(this.label, { x_fill: false });
|
|
|
|
},
|
|
|
|
|
|
|
|
set_size: function(size) {
|
|
|
|
this.icon = this.app.create_icon_texture(size);
|
|
|
|
this._iconBin.child = this.icon;
|
2009-11-12 17:46:59 -05:00
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2009-11-12 17:46:59 -05:00
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
const AppSwitcher = new Lang.Class({
|
|
|
|
Name: 'AppSwitcher',
|
2012-11-30 10:16:48 -05:00
|
|
|
Extends: SwitcherPopup.SwitcherList,
|
2009-09-15 11:11:32 -04:00
|
|
|
|
2011-09-29 17:43:59 -04:00
|
|
|
_init : function(apps, altTabPopup) {
|
2011-11-20 11:07:14 -05:00
|
|
|
this.parent(true);
|
2009-09-15 11:11:32 -04:00
|
|
|
|
2011-09-29 17:43:59 -04:00
|
|
|
this.icons = [];
|
|
|
|
this._arrows = [];
|
|
|
|
|
|
|
|
let windowTracker = Shell.WindowTracker.get_default();
|
2013-07-04 13:24:30 -04:00
|
|
|
let settings = new Gio.Settings({ schema: 'org.gnome.shell.app-switcher' });
|
|
|
|
let workspace = settings.get_boolean('current-workspace-only') ? global.screen.get_active_workspace()
|
|
|
|
: null;
|
2011-09-29 17:43:59 -04:00
|
|
|
let allWindows = global.display.get_tab_list(Meta.TabList.NORMAL,
|
2013-07-04 13:24:30 -04:00
|
|
|
global.screen, workspace);
|
2011-09-29 17:43:59 -04:00
|
|
|
|
2011-07-14 17:23:16 -04:00
|
|
|
// Construct the AppIcons, add to the popup
|
2011-09-29 17:43:59 -04:00
|
|
|
for (let i = 0; i < apps.length; i++) {
|
|
|
|
let appIcon = new AppIcon(apps[i]);
|
Create ShellApp, rebase things on it
Previously, we had ShellAppInfo, which contains fundamental
information about an application, and methods on ShellAppMonitor
to retrieve "live" information like the window list.
AppIcon ended up being used as the "App" class which was painful
for various reasons; among them that we need to handle window
list changes, and some consumers weren't ready for that.
Clean things up a bit by introducing a new ShellApp class in C,
which currently wraps a ShellAppInfo.
AppIcon then is more like the display actor for a ShellApp. Notably,
the ".windows" property moves out of it. The altTab code which
won't handle dynamic changes instead is changed to maintain a
cached version.
ShellAppMonitor gains some more methods related to ShellApp now.
In the future, we might consider changing ShellApp to be a GInterface,
which could be implemented by ShellDesktopFileApp, ShellWindowApp.
Then we could axe ShellAppInfo from the "public" API and it would
return to being an internal loss mitigation layer for GMenu.
https://bugzilla.gnome.org/show_bug.cgi?id=598227
2009-10-11 16:40:00 -04:00
|
|
|
// Cache the window list now; we don't handle dynamic changes here,
|
|
|
|
// and we don't want to be continually retrieving it
|
2011-09-29 17:43:59 -04:00
|
|
|
appIcon.cachedWindows = allWindows.filter(function(w) {
|
|
|
|
return windowTracker.get_window_app (w) == appIcon.app;
|
|
|
|
});
|
2014-01-17 10:05:09 -05:00
|
|
|
if (appIcon.cachedWindows.length > 0)
|
2013-07-04 13:24:30 -04:00
|
|
|
this._addIcon(appIcon);
|
2014-01-17 10:05:09 -05:00
|
|
|
else if (workspace == null)
|
|
|
|
throw new Error('%s appears to be running, but doesn\'t have any windows'.format(appIcon.app.get_name()));
|
2009-10-02 11:02:46 -04:00
|
|
|
}
|
2009-08-13 12:52:50 -04:00
|
|
|
|
2009-10-09 09:43:31 -04:00
|
|
|
this._curApp = -1;
|
2010-03-17 13:31:03 -04:00
|
|
|
this._iconSize = 0;
|
2011-01-06 14:21:27 -05:00
|
|
|
this._altTabPopup = altTabPopup;
|
|
|
|
this._mouseTimeOutId = 0;
|
2012-12-01 14:40:13 -05:00
|
|
|
|
|
|
|
this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
|
|
|
|
},
|
|
|
|
|
|
|
|
_onDestroy: function() {
|
|
|
|
if (this._mouseTimeOutId != 0)
|
|
|
|
Mainloop.source_remove(this._mouseTimeOutId);
|
2010-03-17 13:31:03 -04:00
|
|
|
},
|
|
|
|
|
2014-02-15 22:45:28 -05:00
|
|
|
_setIconSize: function() {
|
2010-03-17 13:31:03 -04:00
|
|
|
let j = 0;
|
|
|
|
while(this._items.length > 1 && this._items[j].style_class != 'item-box') {
|
|
|
|
j++;
|
|
|
|
}
|
2010-12-22 09:36:23 -05:00
|
|
|
let themeNode = this._items[j].get_theme_node();
|
2014-02-15 22:45:28 -05:00
|
|
|
|
2010-12-22 09:36:23 -05:00
|
|
|
let iconPadding = themeNode.get_horizontal_padding();
|
|
|
|
let iconBorder = themeNode.get_border_width(St.Side.LEFT) + themeNode.get_border_width(St.Side.RIGHT);
|
2010-03-17 13:31:03 -04:00
|
|
|
let [iconMinHeight, iconNaturalHeight] = this.icons[j].label.get_preferred_height(-1);
|
2010-12-22 09:36:23 -05:00
|
|
|
let iconSpacing = iconNaturalHeight + iconPadding + iconBorder;
|
2010-03-17 13:31:03 -04:00
|
|
|
let totalSpacing = this._list.spacing * (this._items.length - 1);
|
|
|
|
|
2010-06-17 11:17:57 -04:00
|
|
|
// We just assume the whole screen here due to weirdness happing with the passed width
|
2011-06-13 09:54:05 -04:00
|
|
|
let primary = Main.layoutManager.primaryMonitor;
|
2010-06-17 11:17:57 -04:00
|
|
|
let parentPadding = this.actor.get_parent().get_theme_node().get_horizontal_padding();
|
2011-01-16 07:34:31 -05:00
|
|
|
let availWidth = primary.width - parentPadding - this.actor.get_theme_node().get_horizontal_padding();
|
2010-06-17 11:17:57 -04:00
|
|
|
|
2014-02-15 23:25:49 -05:00
|
|
|
let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
|
|
|
|
let iconSizes = baseIconSizes.map(function(s) {
|
|
|
|
return s * scaleFactor;
|
|
|
|
});
|
|
|
|
|
2014-02-15 22:45:28 -05:00
|
|
|
if (this._items.length == 1) {
|
2014-02-15 23:25:49 -05:00
|
|
|
this._iconSize = baseIconSizes[0];
|
2014-02-15 22:45:28 -05:00
|
|
|
} else {
|
2014-02-15 23:25:49 -05:00
|
|
|
for(let i = 0; i < baseIconSizes.length; i++) {
|
|
|
|
this._iconSize = baseIconSizes[i];
|
2014-02-15 22:45:28 -05:00
|
|
|
let height = iconSizes[i] + iconSpacing;
|
2010-03-17 13:31:03 -04:00
|
|
|
let w = height * this._items.length + totalSpacing;
|
2010-06-17 11:17:57 -04:00
|
|
|
if (w <= availWidth)
|
2014-02-15 22:45:28 -05:00
|
|
|
break;
|
|
|
|
}
|
2010-03-17 13:31:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for(let i = 0; i < this.icons.length; i++) {
|
|
|
|
if (this.icons[i].icon != null)
|
|
|
|
break;
|
|
|
|
this.icons[i].set_size(this._iconSize);
|
|
|
|
}
|
2014-02-15 22:45:28 -05:00
|
|
|
},
|
2010-03-17 13:31:03 -04:00
|
|
|
|
2014-02-15 22:45:28 -05:00
|
|
|
_getPreferredHeight: function (actor, forWidth, alloc) {
|
|
|
|
this._setIconSize();
|
|
|
|
this.parent(actor, forWidth, alloc);
|
2010-04-18 16:59:19 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_allocate: function (actor, box, flags) {
|
2009-10-02 11:02:46 -04:00
|
|
|
// Allocate the main list items
|
2011-11-20 11:07:14 -05:00
|
|
|
this.parent(actor, box, flags);
|
2009-10-02 11:02:46 -04:00
|
|
|
|
|
|
|
let arrowHeight = Math.floor(this.actor.get_theme_node().get_padding(St.Side.BOTTOM) / 3);
|
|
|
|
let arrowWidth = arrowHeight * 2;
|
|
|
|
|
|
|
|
// Now allocate each arrow underneath its item
|
|
|
|
let childBox = new Clutter.ActorBox();
|
|
|
|
for (let i = 0; i < this._items.length; i++) {
|
|
|
|
let itemBox = this._items[i].allocation;
|
|
|
|
childBox.x1 = Math.floor(itemBox.x1 + (itemBox.x2 - itemBox.x1 - arrowWidth) / 2);
|
|
|
|
childBox.x2 = childBox.x1 + arrowWidth;
|
|
|
|
childBox.y1 = itemBox.y2 + arrowHeight;
|
|
|
|
childBox.y2 = childBox.y1 + arrowHeight;
|
|
|
|
this._arrows[i].allocate(childBox, flags);
|
2009-09-21 13:44:42 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-01-06 14:21:27 -05:00
|
|
|
// We override SwitcherList's _onItemEnter method to delay
|
|
|
|
// activation when the thumbnail list is open
|
|
|
|
_onItemEnter: function (index) {
|
|
|
|
if (this._mouseTimeOutId != 0)
|
|
|
|
Mainloop.source_remove(this._mouseTimeOutId);
|
|
|
|
if (this._altTabPopup.thumbnailsVisible) {
|
|
|
|
this._mouseTimeOutId = Mainloop.timeout_add(APP_ICON_HOVER_TIMEOUT,
|
|
|
|
Lang.bind(this, function () {
|
|
|
|
this._enterItem(index);
|
2011-01-25 09:30:19 -05:00
|
|
|
this._mouseTimeOutId = 0;
|
2013-11-28 19:45:39 -05:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2011-01-06 14:21:27 -05:00
|
|
|
}));
|
2014-04-10 13:26:52 -04:00
|
|
|
GLib.Source.set_name_by_id(this._mouseTimeOutId, '[gnome-shell] this._enterItem');
|
2011-01-06 14:21:27 -05:00
|
|
|
} else
|
|
|
|
this._itemEntered(index);
|
|
|
|
},
|
|
|
|
|
|
|
|
_enterItem: function(index) {
|
|
|
|
let [x, y, mask] = global.get_pointer();
|
|
|
|
let pickedActor = global.stage.get_actor_at_pos(Clutter.PickMode.ALL, x, y);
|
|
|
|
if (this._items[index].contains(pickedActor))
|
|
|
|
this._itemEntered(index);
|
|
|
|
},
|
|
|
|
|
2009-10-09 09:43:31 -04:00
|
|
|
// We override SwitcherList's highlight() method to also deal with
|
|
|
|
// the AppSwitcher->ThumbnailList arrows. Apps with only 1 window
|
|
|
|
// will hide their arrows by default, but show them when their
|
|
|
|
// thumbnails are visible (ie, when the app icon is supposed to be
|
|
|
|
// in justOutline mode). Apps with multiple windows will normally
|
|
|
|
// show a dim arrow, but show a bright arrow when they are
|
2010-03-31 16:01:34 -04:00
|
|
|
// highlighted.
|
2009-10-09 09:43:31 -04:00
|
|
|
highlight : function(n, justOutline) {
|
|
|
|
if (this._curApp != -1) {
|
|
|
|
if (this.icons[this._curApp].cachedWindows.length == 1)
|
|
|
|
this._arrows[this._curApp].hide();
|
|
|
|
else
|
2010-03-31 16:01:34 -04:00
|
|
|
this._arrows[this._curApp].remove_style_pseudo_class('highlighted');
|
2009-10-09 09:43:31 -04:00
|
|
|
}
|
2009-09-21 13:44:42 -04:00
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
this.parent(n, justOutline);
|
2009-10-09 09:43:31 -04:00
|
|
|
this._curApp = n;
|
2009-09-28 23:31:54 -04:00
|
|
|
|
2009-10-09 09:43:31 -04:00
|
|
|
if (this._curApp != -1) {
|
|
|
|
if (justOutline && this.icons[this._curApp].cachedWindows.length == 1)
|
|
|
|
this._arrows[this._curApp].show();
|
|
|
|
else
|
2010-03-31 16:01:34 -04:00
|
|
|
this._arrows[this._curApp].add_style_pseudo_class('highlighted');
|
2009-10-09 09:43:31 -04:00
|
|
|
}
|
2009-04-13 10:55:41 -04:00
|
|
|
},
|
|
|
|
|
2009-10-02 11:02:46 -04:00
|
|
|
_addIcon : function(appIcon) {
|
|
|
|
this.icons.push(appIcon);
|
2012-03-07 13:29:13 -05:00
|
|
|
let item = this.addItem(appIcon.actor, appIcon.label);
|
2009-10-02 11:02:46 -04:00
|
|
|
|
2009-10-09 09:43:31 -04:00
|
|
|
let n = this._arrows.length;
|
2010-03-31 16:01:34 -04:00
|
|
|
let arrow = new St.DrawingArea({ style_class: 'switcher-arrow' });
|
2012-11-30 10:16:48 -05:00
|
|
|
arrow.connect('repaint', function() { SwitcherPopup.drawArrow(arrow, St.Side.BOTTOM); });
|
2009-10-02 11:02:46 -04:00
|
|
|
this._list.add_actor(arrow);
|
|
|
|
this._arrows.push(arrow);
|
2009-10-09 09:43:31 -04:00
|
|
|
|
|
|
|
if (appIcon.cachedWindows.length == 1)
|
|
|
|
arrow.hide();
|
2012-03-07 13:29:13 -05:00
|
|
|
else
|
|
|
|
item.add_accessible_state (Atk.StateType.EXPANDABLE);
|
2009-10-02 11:02:46 -04:00
|
|
|
}
|
2011-11-20 11:07:14 -05:00
|
|
|
});
|
2009-09-21 13:04:30 -04:00
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
const ThumbnailList = new Lang.Class({
|
|
|
|
Name: 'ThumbnailList',
|
2012-11-30 10:16:48 -05:00
|
|
|
Extends: SwitcherPopup.SwitcherList,
|
2009-10-02 11:02:46 -04:00
|
|
|
|
|
|
|
_init : function(windows) {
|
2011-11-20 11:07:14 -05:00
|
|
|
this.parent(false);
|
2009-10-02 11:02:46 -04:00
|
|
|
|
2010-03-17 13:31:03 -04:00
|
|
|
this._labels = new Array();
|
|
|
|
this._thumbnailBins = new Array();
|
|
|
|
this._clones = new Array();
|
|
|
|
this._windows = windows;
|
|
|
|
|
2009-10-02 11:02:46 -04:00
|
|
|
for (let i = 0; i < windows.length; i++) {
|
2010-05-13 15:46:04 -04:00
|
|
|
let box = new St.BoxLayout({ style_class: 'thumbnail-box',
|
2009-10-09 09:43:31 -04:00
|
|
|
vertical: true });
|
|
|
|
|
2010-05-13 15:46:04 -04:00
|
|
|
let bin = new St.Bin({ style_class: 'thumbnail' });
|
2009-12-18 18:50:40 -05:00
|
|
|
|
|
|
|
box.add_actor(bin);
|
2010-03-17 13:31:03 -04:00
|
|
|
this._thumbnailBins.push(bin);
|
2009-10-09 09:43:31 -04:00
|
|
|
|
2009-11-13 14:38:38 -05:00
|
|
|
let title = windows[i].get_title();
|
|
|
|
if (title) {
|
|
|
|
let name = new St.Label({ text: title });
|
|
|
|
// St.Label doesn't support text-align so use a Bin
|
|
|
|
let bin = new St.Bin({ x_align: St.Align.MIDDLE });
|
2010-03-17 13:31:03 -04:00
|
|
|
this._labels.push(bin);
|
2009-11-13 14:38:38 -05:00
|
|
|
bin.add_actor(name);
|
|
|
|
box.add_actor(bin);
|
2011-03-08 13:33:57 -05:00
|
|
|
|
|
|
|
this.addItem(box, name);
|
|
|
|
} else {
|
|
|
|
this.addItem(box, null);
|
2009-11-13 14:38:38 -05:00
|
|
|
}
|
2009-10-09 09:43:31 -04:00
|
|
|
|
2009-09-21 13:04:30 -04:00
|
|
|
}
|
2010-03-17 13:31:03 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
addClones : function (availHeight) {
|
|
|
|
if (!this._thumbnailBins.length)
|
|
|
|
return;
|
|
|
|
let totalPadding = this._items[0].get_theme_node().get_horizontal_padding() + this._items[0].get_theme_node().get_vertical_padding();
|
|
|
|
totalPadding += this.actor.get_theme_node().get_horizontal_padding() + this.actor.get_theme_node().get_vertical_padding();
|
|
|
|
let [labelMinHeight, labelNaturalHeight] = this._labels[0].get_preferred_height(-1);
|
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
|
|
|
let spacing = this._items[0].child.get_theme_node().get_length('spacing');
|
2014-02-16 04:13:26 -05:00
|
|
|
let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
|
|
|
|
let thumbnailSize = THUMBNAIL_DEFAULT_SIZE * scaleFactor;
|
2010-03-17 13:31:03 -04:00
|
|
|
|
2014-02-16 04:13:26 -05:00
|
|
|
availHeight = Math.min(availHeight - labelNaturalHeight - totalPadding - spacing, thumbnailSize);
|
2010-03-17 13:31:03 -04:00
|
|
|
let binHeight = availHeight + this._items[0].get_theme_node().get_vertical_padding() + this.actor.get_theme_node().get_vertical_padding() - spacing;
|
2014-02-16 04:13:26 -05:00
|
|
|
binHeight = Math.min(thumbnailSize, binHeight);
|
2010-03-17 13:31:03 -04:00
|
|
|
|
|
|
|
for (let i = 0; i < this._thumbnailBins.length; i++) {
|
|
|
|
let mutterWindow = this._windows[i].get_compositor_private();
|
2011-02-09 14:42:44 -05:00
|
|
|
if (!mutterWindow)
|
|
|
|
continue;
|
|
|
|
|
2014-02-16 04:13:26 -05:00
|
|
|
let clone = _createWindowClone(mutterWindow, thumbnailSize);
|
2010-03-17 13:31:03 -04:00
|
|
|
this._thumbnailBins[i].set_height(binHeight);
|
|
|
|
this._thumbnailBins[i].add_actor(clone);
|
|
|
|
this._clones.push(clone);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we only do this once
|
|
|
|
this._thumbnailBins = new Array();
|
2009-04-13 10:55:41 -04:00
|
|
|
}
|
2011-11-20 11:07:14 -05:00
|
|
|
});
|
2011-02-10 14:41:24 -05:00
|
|
|
|
2012-11-22 21:20:10 -05:00
|
|
|
const WindowIcon = new Lang.Class({
|
|
|
|
Name: 'WindowIcon',
|
|
|
|
|
2013-09-09 16:53:44 -04:00
|
|
|
_init: function(window, mode) {
|
2012-11-22 21:20:10 -05:00
|
|
|
this.window = window;
|
|
|
|
|
|
|
|
this.actor = new St.BoxLayout({ style_class: 'alt-tab-app',
|
|
|
|
vertical: true });
|
|
|
|
this._icon = new St.Widget({ layout_manager: new Clutter.BinLayout() });
|
|
|
|
|
|
|
|
this.actor.add(this._icon, { x_fill: false, y_fill: false } );
|
|
|
|
this.label = new St.Label({ text: window.get_title() });
|
|
|
|
|
|
|
|
let tracker = Shell.WindowTracker.get_default();
|
|
|
|
this.app = tracker.get_window_app(window);
|
|
|
|
|
|
|
|
let mutterWindow = this.window.get_compositor_private();
|
|
|
|
let size;
|
|
|
|
|
|
|
|
this._icon.destroy_all_children();
|
|
|
|
|
2013-09-09 16:53:44 -04:00
|
|
|
switch (mode) {
|
2012-11-22 21:20:10 -05:00
|
|
|
case AppIconMode.THUMBNAIL_ONLY:
|
|
|
|
size = WINDOW_PREVIEW_SIZE;
|
|
|
|
this._icon.add_actor(_createWindowClone(mutterWindow, WINDOW_PREVIEW_SIZE));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AppIconMode.BOTH:
|
|
|
|
size = WINDOW_PREVIEW_SIZE;
|
|
|
|
this._icon.add_actor(_createWindowClone(mutterWindow, WINDOW_PREVIEW_SIZE));
|
|
|
|
|
|
|
|
if (this.app)
|
|
|
|
this._icon.add_actor(this._createAppIcon(this.app,
|
|
|
|
APP_ICON_SIZE_SMALL));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AppIconMode.APP_ICON_ONLY:
|
|
|
|
size = APP_ICON_SIZE;
|
|
|
|
this._icon.add_actor(this._createAppIcon(this.app, size));
|
|
|
|
}
|
|
|
|
|
|
|
|
this._icon.set_size(size, size);
|
|
|
|
},
|
|
|
|
|
|
|
|
_createAppIcon: function(app, size) {
|
|
|
|
let appIcon = app ? app.create_icon_texture(size)
|
|
|
|
: new St.Icon({ icon_name: 'icon-missing',
|
|
|
|
icon_size: size });
|
|
|
|
appIcon.x_expand = appIcon.y_expand = true;
|
|
|
|
appIcon.x_align = appIcon.y_align = Clutter.ActorAlign.END;
|
|
|
|
|
|
|
|
return appIcon;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const WindowList = new Lang.Class({
|
|
|
|
Name: 'WindowList',
|
|
|
|
Extends: SwitcherPopup.SwitcherList,
|
|
|
|
|
2013-09-09 16:53:44 -04:00
|
|
|
_init : function(windows, mode) {
|
2012-11-22 21:20:10 -05:00
|
|
|
this.parent(true);
|
|
|
|
|
|
|
|
this._label = new St.Label({ x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER });
|
|
|
|
this.actor.add_actor(this._label);
|
|
|
|
|
|
|
|
this.windows = windows;
|
|
|
|
this.icons = [];
|
|
|
|
|
|
|
|
for (let i = 0; i < windows.length; i++) {
|
|
|
|
let win = windows[i];
|
2013-09-09 16:53:44 -04:00
|
|
|
let icon = new WindowIcon(win, mode);
|
2012-11-22 21:20:10 -05:00
|
|
|
|
|
|
|
this.addItem(icon.actor, icon.label);
|
|
|
|
this.icons.push(icon);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_getPreferredHeight: function(actor, forWidth, alloc) {
|
|
|
|
this.parent(actor, forWidth, alloc);
|
|
|
|
|
|
|
|
let spacing = this.actor.get_theme_node().get_padding(St.Side.BOTTOM);
|
|
|
|
let [labelMin, labelNat] = this._label.get_preferred_height(-1);
|
|
|
|
alloc.min_size += labelMin + spacing;
|
|
|
|
alloc.natural_size += labelNat + spacing;
|
|
|
|
},
|
|
|
|
|
|
|
|
_allocateTop: function(actor, box, flags) {
|
|
|
|
let childBox = new Clutter.ActorBox();
|
|
|
|
childBox.x1 = box.x1;
|
|
|
|
childBox.x2 = box.x2;
|
|
|
|
childBox.y2 = box.y2;
|
|
|
|
childBox.y1 = childBox.y2 - this._label.height;
|
|
|
|
this._label.allocate(childBox, flags);
|
|
|
|
|
|
|
|
let spacing = this.actor.get_theme_node().get_padding(St.Side.BOTTOM);
|
|
|
|
box.y2 -= this._label.height + spacing;
|
|
|
|
this.parent(actor, box, flags);
|
|
|
|
},
|
|
|
|
|
|
|
|
highlight: function(index, justOutline) {
|
|
|
|
this.parent(index, justOutline);
|
|
|
|
|
|
|
|
this._label.set_text(index == -1 ? '' : this.icons[index].label.text);
|
|
|
|
}
|
|
|
|
});
|