2008-12-01 14:51:43 -05:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2008-11-20 19:53:11 -05:00
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
2009-04-01 15:51:17 -04:00
|
|
|
const Pango = imports.gi.Pango;
|
2009-07-07 16:08:41 -04:00
|
|
|
const GLib = imports.gi.GLib;
|
2008-11-20 19:53:11 -05:00
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const Gtk = imports.gi.Gtk;
|
|
|
|
const Shell = imports.gi.Shell;
|
2009-04-01 15:51:17 -04:00
|
|
|
const Lang = imports.lang;
|
2009-02-02 18:02:16 -05:00
|
|
|
const Signals = imports.signals;
|
2009-11-12 17:46:59 -05:00
|
|
|
const St = imports.gi.St;
|
2009-06-30 16:35:39 -04:00
|
|
|
const Mainloop = imports.mainloop;
|
2009-08-14 09:30:48 -04:00
|
|
|
const Gettext = imports.gettext.domain('gnome-shell');
|
|
|
|
const _ = Gettext.gettext;
|
2008-11-20 19:53:11 -05:00
|
|
|
|
2009-10-15 19:28:29 -04:00
|
|
|
const AppFavorites = imports.ui.appFavorites;
|
2009-06-30 16:35:39 -04:00
|
|
|
const DND = imports.ui.dnd;
|
2008-12-19 23:27:57 -05:00
|
|
|
const GenericDisplay = imports.ui.genericDisplay;
|
2009-07-31 17:20:26 -04:00
|
|
|
const Main = imports.ui.main;
|
2009-11-29 17:45:30 -05:00
|
|
|
const Search = imports.ui.search;
|
2010-01-21 21:33:48 -05:00
|
|
|
const Workspace = imports.ui.workspace;
|
2009-04-01 15:51:17 -04:00
|
|
|
|
2009-11-12 17:46:59 -05:00
|
|
|
const APPICON_SIZE = 48;
|
|
|
|
const WELL_MAX_COLUMNS = 8;
|
2010-03-10 08:52:28 -05:00
|
|
|
const MENU_POPUP_TIMEOUT = 600;
|
2009-04-23 10:41:24 -04:00
|
|
|
|
2010-02-15 19:50:36 -05:00
|
|
|
function AllAppView() {
|
|
|
|
this._init();
|
2008-11-20 19:53:11 -05:00
|
|
|
}
|
|
|
|
|
2010-02-15 19:50:36 -05:00
|
|
|
AllAppView.prototype = {
|
|
|
|
_init: function(apps) {
|
|
|
|
this.actor = new St.BoxLayout({ vertical: true });
|
|
|
|
this._grid = new WellGrid(true);
|
|
|
|
this._appSystem = Shell.AppSystem.get_default();
|
|
|
|
this.actor.add(this._grid.actor, { y_align: St.Align.START, expand: true });
|
2008-12-01 14:51:43 -05:00
|
|
|
},
|
2008-12-19 23:27:57 -05:00
|
|
|
|
2010-02-15 19:50:36 -05:00
|
|
|
_removeAll: function() {
|
|
|
|
this._grid.removeAll();
|
|
|
|
this._apps = [];
|
2009-07-02 00:35:26 -04:00
|
|
|
},
|
|
|
|
|
2010-02-15 19:50:36 -05:00
|
|
|
_addApp: function(app) {
|
2010-05-08 10:06:28 -04:00
|
|
|
let appIcon = new AppWellIcon(this._appSystem.get_app(app.get_id()));
|
|
|
|
appIcon.connect('launching', Lang.bind(this, function() {
|
2010-02-15 19:50:36 -05:00
|
|
|
this.emit('launching');
|
|
|
|
}));
|
2010-05-08 10:06:28 -04:00
|
|
|
appIcon._draggable.connect('drag-begin', Lang.bind(this, function() {
|
2010-02-15 19:50:36 -05:00
|
|
|
this.emit('drag-begin');
|
|
|
|
}));
|
2009-03-20 12:06:34 -04:00
|
|
|
|
2010-05-08 10:06:28 -04:00
|
|
|
this._grid.addItem(appIcon.actor);
|
2009-03-20 12:06:34 -04:00
|
|
|
|
2010-05-08 10:06:28 -04:00
|
|
|
this._apps.push(appIcon);
|
2009-06-29 15:08:48 -04:00
|
|
|
},
|
|
|
|
|
2010-02-15 19:50:36 -05:00
|
|
|
refresh: function(apps) {
|
|
|
|
let ids = [];
|
|
|
|
for (let i in apps)
|
|
|
|
ids.push(i);
|
|
|
|
ids.sort(function(a, b) {
|
|
|
|
return apps[a].get_name().localeCompare(apps[b].get_name());
|
|
|
|
});
|
|
|
|
|
|
|
|
this._removeAll();
|
2009-08-17 20:29:54 -04:00
|
|
|
|
2010-02-15 19:50:36 -05:00
|
|
|
for (let i = 0; i < ids.length; i++) {
|
|
|
|
this._addApp(apps[ids[i]]);
|
|
|
|
}
|
2009-03-20 12:06:34 -04:00
|
|
|
}
|
2008-12-19 23:27:57 -05:00
|
|
|
};
|
2008-11-20 19:53:11 -05:00
|
|
|
|
2010-02-15 19:50:36 -05:00
|
|
|
Signals.addSignalMethods(AllAppView.prototype);
|
|
|
|
|
2008-12-19 23:27:57 -05:00
|
|
|
/* This class represents a display containing a collection of application items.
|
2010-02-15 19:50:36 -05:00
|
|
|
* The applications are sorted based on their name.
|
2008-12-19 23:27:57 -05:00
|
|
|
*/
|
2010-02-15 19:50:36 -05:00
|
|
|
function AllAppDisplay() {
|
|
|
|
this._init();
|
2008-11-20 19:53:11 -05:00
|
|
|
}
|
|
|
|
|
2010-02-15 19:50:36 -05:00
|
|
|
AllAppDisplay.prototype = {
|
|
|
|
_init: function() {
|
2009-06-18 12:27:19 -04:00
|
|
|
this._appSystem = Shell.AppSystem.get_default();
|
2010-02-15 19:50:36 -05:00
|
|
|
this._appSystem.connect('installed-changed', Lang.bind(this, function() {
|
|
|
|
Main.queueDeferredWork(this._workId);
|
2009-04-23 10:41:24 -04:00
|
|
|
}));
|
2009-04-01 15:51:17 -04:00
|
|
|
|
2010-03-03 18:10:16 -05:00
|
|
|
let bin = new St.BoxLayout({ style_class: 'all-app-controls-panel',
|
|
|
|
reactive: true });
|
2010-02-15 19:50:36 -05:00
|
|
|
this.actor = new St.BoxLayout({ style_class: 'all-app', vertical: true });
|
|
|
|
this.actor.hide();
|
2009-04-01 15:51:17 -04:00
|
|
|
|
2010-02-22 17:07:42 -05:00
|
|
|
let view = new St.ScrollView({ x_fill: true,
|
|
|
|
y_fill: false,
|
|
|
|
style_class: 'all-app-scroll-view',
|
|
|
|
vshadows: true });
|
2010-02-15 19:50:36 -05:00
|
|
|
this._scrollView = view;
|
|
|
|
this.actor.add(bin);
|
|
|
|
this.actor.add(view, { expand: true, y_fill: false, y_align: St.Align.START });
|
2009-06-17 18:42:05 -04:00
|
|
|
|
2010-02-15 19:50:36 -05:00
|
|
|
this._appView = new AllAppView();
|
|
|
|
this._appView.connect('launching', Lang.bind(this, this.close));
|
|
|
|
this._appView.connect('drag-begin', Lang.bind(this, this.close));
|
|
|
|
this._scrollView.add_actor(this._appView.actor);
|
2008-12-01 14:51:43 -05:00
|
|
|
|
2010-02-22 11:54:16 -05:00
|
|
|
this._scrollView.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
|
2009-04-01 15:51:17 -04:00
|
|
|
|
2010-02-15 19:50:36 -05:00
|
|
|
this._workId = Main.initializeDeferredWork(this.actor, Lang.bind(this, this._redisplay));
|
2008-12-01 14:51:43 -05:00
|
|
|
},
|
|
|
|
|
2010-02-15 19:50:36 -05:00
|
|
|
_redisplay: function() {
|
|
|
|
let apps = this._appSystem.get_flattened_apps().filter(function(app) {
|
|
|
|
return !app.get_is_nodisplay();
|
|
|
|
});
|
2008-12-01 14:51:43 -05:00
|
|
|
|
2010-02-15 19:50:36 -05:00
|
|
|
this._appView.refresh(apps);
|
2008-12-01 14:51:43 -05:00
|
|
|
},
|
|
|
|
|
2010-02-15 19:50:36 -05:00
|
|
|
toggle: function() {
|
|
|
|
this.emit('open-state-changed', !this.actor.visible);
|
2009-04-01 15:51:17 -04:00
|
|
|
|
2010-02-15 19:50:36 -05:00
|
|
|
this.actor.visible = !this.actor.visible;
|
2008-12-01 14:51:43 -05:00
|
|
|
},
|
|
|
|
|
2010-02-15 19:50:36 -05:00
|
|
|
close: function() {
|
|
|
|
if (!this.actor.visible)
|
|
|
|
return;
|
|
|
|
this.toggle();
|
2009-04-01 15:51:17 -04:00
|
|
|
}
|
2008-12-01 14:51:43 -05:00
|
|
|
};
|
2008-11-20 19:53:11 -05:00
|
|
|
|
2010-02-15 19:50:36 -05:00
|
|
|
Signals.addSignalMethods(AllAppDisplay.prototype);
|
2009-06-30 16:35:39 -04:00
|
|
|
|
2010-02-22 11:39:10 -05:00
|
|
|
function AppSearchResultDisplay(provider) {
|
|
|
|
this._init(provider);
|
|
|
|
}
|
|
|
|
|
|
|
|
AppSearchResultDisplay.prototype = {
|
|
|
|
__proto__: Search.SearchResultDisplay.prototype,
|
|
|
|
|
|
|
|
_init: function (provider) {
|
|
|
|
Search.SearchResultDisplay.prototype._init.call(this, provider);
|
|
|
|
this._spacing = 0;
|
|
|
|
this.actor = new St.Bin({ name: 'dashAppSearchResults',
|
|
|
|
x_align: St.Align.START });
|
|
|
|
this.actor.connect('style-changed', Lang.bind(this, this._onStyleChanged));
|
|
|
|
let container = new Shell.GenericContainer();
|
|
|
|
this._container = container;
|
|
|
|
this.actor.set_child(container);
|
|
|
|
container.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
|
|
|
|
container.connect('get-preferred-height', Lang.bind(this, this._getPreferredHeight));
|
|
|
|
container.connect('allocate', Lang.bind(this, this._allocate));
|
|
|
|
},
|
|
|
|
|
|
|
|
_getPreferredWidth: function (actor, forHeight, alloc) {
|
|
|
|
let children = actor.get_children();
|
|
|
|
|
|
|
|
for (let i = 0; i < children.length; i++) {
|
|
|
|
let [minSize, natSize] = children[i].get_preferred_width(forHeight);
|
|
|
|
alloc.natural_size += natSize;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_getPreferredHeight: function (actor, forWidth, alloc) {
|
|
|
|
let children = actor.get_children();
|
|
|
|
|
|
|
|
for (let i = 0; i < children.length; i++) {
|
|
|
|
let [minSize, natSize] = children[i].get_preferred_height(forWidth);
|
|
|
|
if (minSize > alloc.min_size)
|
|
|
|
alloc.min_size = minSize;
|
|
|
|
if (natSize > alloc.natural_size)
|
|
|
|
alloc.natural_size = natSize;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_allocate: function (actor, box, flags) {
|
|
|
|
let availWidth = box.x2 - box.x1;
|
|
|
|
let availHeight = box.y2 - box.y1;
|
|
|
|
|
|
|
|
let children = actor.get_children();
|
|
|
|
|
|
|
|
let x = 0;
|
|
|
|
let i;
|
|
|
|
for (i = 0; i < children.length; i++) {
|
|
|
|
let child = children[i];
|
|
|
|
let childBox = new Clutter.ActorBox();
|
|
|
|
|
|
|
|
let [minWidth, minHeight, natWidth, natHeight] = child.get_preferred_size();
|
|
|
|
|
|
|
|
if (x + natWidth > availWidth) {
|
|
|
|
actor.set_skip_paint(child, true);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let yPadding = Math.max(0, availHeight - natHeight);
|
|
|
|
|
|
|
|
childBox.x1 = x;
|
|
|
|
childBox.x2 = childBox.x1 + natWidth;
|
|
|
|
childBox.y1 = Math.floor(yPadding / 2);
|
|
|
|
childBox.y2 = availHeight - childBox.y1;
|
|
|
|
|
|
|
|
x = childBox.x2 + this._spacing;
|
|
|
|
|
|
|
|
child.allocate(childBox, flags);
|
|
|
|
actor.set_skip_paint(child, false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onStyleChanged: function () {
|
|
|
|
let themeNode = this.actor.get_theme_node();
|
|
|
|
let [success, len] = themeNode.get_length('spacing', false);
|
|
|
|
if (success)
|
|
|
|
this._spacing = len;
|
|
|
|
this._container.queue_relayout();
|
|
|
|
},
|
|
|
|
|
|
|
|
renderResults: function(results, terms) {
|
|
|
|
let appSys = Shell.AppSystem.get_default();
|
|
|
|
for (let i = 0; i < results.length && i < WELL_MAX_COLUMNS; i++) {
|
|
|
|
let result = results[i];
|
|
|
|
let app = appSys.get_app(result);
|
|
|
|
let display = new AppWellIcon(app);
|
|
|
|
this._container.add_actor(display.actor);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
clear: function () {
|
|
|
|
this._container.get_children().forEach(function (actor) { actor.destroy(); });
|
|
|
|
this.selectionIndex = -1;
|
|
|
|
},
|
|
|
|
|
|
|
|
getVisibleResultCount: function() {
|
|
|
|
let nChildren = this._container.get_children().length;
|
|
|
|
return nChildren - this._container.get_n_skip_paint();
|
|
|
|
},
|
|
|
|
|
|
|
|
selectIndex: function (index) {
|
|
|
|
let nVisible = this.getVisibleResultCount();
|
|
|
|
let children = this._container.get_children();
|
|
|
|
if (this.selectionIndex >= 0) {
|
|
|
|
let prevActor = children[this.selectionIndex];
|
|
|
|
prevActor._delegate.setSelected(false);
|
|
|
|
}
|
|
|
|
this.selectionIndex = -1;
|
|
|
|
if (index >= nVisible)
|
|
|
|
return false;
|
|
|
|
else if (index < 0)
|
|
|
|
return false;
|
|
|
|
let targetActor = children[index];
|
|
|
|
targetActor._delegate.setSelected(true);
|
|
|
|
this.selectionIndex = index;
|
|
|
|
return true;
|
2010-03-04 15:08:24 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
activateSelected: function() {
|
|
|
|
if (this.selectionIndex < 0)
|
|
|
|
return;
|
|
|
|
let children = this._container.get_children();
|
|
|
|
let targetActor = children[this.selectionIndex];
|
2010-03-15 09:50:05 -04:00
|
|
|
this.provider.activateResult(targetActor._delegate.app.get_id());
|
2010-02-22 11:39:10 -05:00
|
|
|
}
|
2010-03-15 09:50:05 -04:00
|
|
|
};
|
2010-02-22 11:39:10 -05:00
|
|
|
|
2009-11-29 17:45:30 -05:00
|
|
|
function BaseAppSearchProvider() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseAppSearchProvider.prototype = {
|
|
|
|
__proto__: Search.SearchProvider.prototype,
|
|
|
|
|
|
|
|
_init: function(name) {
|
|
|
|
Search.SearchProvider.prototype._init.call(this, name);
|
|
|
|
this._appSys = Shell.AppSystem.get_default();
|
|
|
|
},
|
|
|
|
|
|
|
|
getResultMeta: function(resultId) {
|
|
|
|
let app = this._appSys.get_app(resultId);
|
|
|
|
if (!app)
|
|
|
|
return null;
|
|
|
|
return { 'id': resultId,
|
|
|
|
'name': app.get_name(),
|
|
|
|
'icon': app.create_icon_texture(Search.RESULT_ICON_SIZE)};
|
|
|
|
},
|
|
|
|
|
|
|
|
activateResult: function(id) {
|
2010-02-15 17:11:09 -05:00
|
|
|
let app = this._appSys.get_app(id);
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 14:07:44 -04:00
|
|
|
app.activate();
|
2010-02-15 17:11:09 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
dragActivateResult: function(id) {
|
2009-11-29 17:45:30 -05:00
|
|
|
let app = this._appSys.get_app(id);
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 14:07:44 -04:00
|
|
|
app.open_new_window();
|
2009-11-29 17:45:30 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function AppSearchProvider() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
AppSearchProvider.prototype = {
|
|
|
|
__proto__: BaseAppSearchProvider.prototype,
|
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
BaseAppSearchProvider.prototype._init.call(this, _("APPLICATIONS"));
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialResultSet: function(terms) {
|
|
|
|
return this._appSys.initial_search(false, terms);
|
|
|
|
},
|
|
|
|
|
|
|
|
getSubsearchResultSet: function(previousResults, terms) {
|
|
|
|
return this._appSys.subsearch(false, previousResults, terms);
|
|
|
|
},
|
|
|
|
|
2010-02-22 11:39:10 -05:00
|
|
|
createResultContainerActor: function () {
|
|
|
|
return new AppSearchResultDisplay(this);
|
|
|
|
},
|
|
|
|
|
|
|
|
createResultActor: function (resultMeta, terms) {
|
|
|
|
return new AppIcon(resultMeta.id);
|
|
|
|
},
|
|
|
|
|
2009-11-29 17:45:30 -05:00
|
|
|
expandSearch: function(terms) {
|
2010-05-13 15:46:04 -04:00
|
|
|
log('TODO expand search');
|
2009-11-29 17:45:30 -05:00
|
|
|
}
|
2010-03-15 09:50:05 -04:00
|
|
|
};
|
2009-11-29 17:45:30 -05:00
|
|
|
|
|
|
|
function PrefsSearchProvider() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
PrefsSearchProvider.prototype = {
|
|
|
|
__proto__: BaseAppSearchProvider.prototype,
|
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
BaseAppSearchProvider.prototype._init.call(this, _("PREFERENCES"));
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialResultSet: function(terms) {
|
|
|
|
return this._appSys.initial_search(true, terms);
|
|
|
|
},
|
|
|
|
|
|
|
|
getSubsearchResultSet: function(previousResults, terms) {
|
|
|
|
return this._appSys.subsearch(true, previousResults, terms);
|
|
|
|
},
|
|
|
|
|
|
|
|
expandSearch: function(terms) {
|
|
|
|
let controlCenter = this._appSys.load_from_desktop_file('gnomecc.desktop');
|
|
|
|
controlCenter.launch();
|
|
|
|
Main.overview.hide();
|
|
|
|
}
|
2010-03-15 09:50:05 -04:00
|
|
|
};
|
2009-11-12 17:46:59 -05:00
|
|
|
|
2009-12-08 12:51:05 -05:00
|
|
|
function AppIcon(app) {
|
|
|
|
this._init(app);
|
2009-09-01 14:15:29 -04:00
|
|
|
}
|
|
|
|
|
2009-12-08 12:51:05 -05:00
|
|
|
AppIcon.prototype = {
|
|
|
|
_init : function(app) {
|
2009-11-12 17:46:59 -05:00
|
|
|
this.app = app;
|
2009-09-11 17:13:50 -04:00
|
|
|
|
2009-12-08 12:51:05 -05:00
|
|
|
this.actor = new St.Bin({ style_class: 'app-icon',
|
|
|
|
x_fill: true,
|
|
|
|
y_fill: true });
|
2009-11-12 17:46:59 -05:00
|
|
|
this.actor._delegate = this;
|
|
|
|
|
|
|
|
let box = new St.BoxLayout({ vertical: true });
|
|
|
|
this.actor.set_child(box);
|
|
|
|
|
|
|
|
this.icon = this.app.create_icon_texture(APPICON_SIZE);
|
|
|
|
|
|
|
|
box.add(this.icon, { expand: true, x_fill: false, y_fill: false });
|
|
|
|
|
|
|
|
this._name = new St.Label({ text: this.app.get_name() });
|
|
|
|
this._name.clutter_text.line_alignment = Pango.Alignment.CENTER;
|
2010-01-07 00:40:21 -05:00
|
|
|
box.add_actor(this._name);
|
2009-12-08 12:51:05 -05:00
|
|
|
}
|
2010-03-15 09:50:05 -04:00
|
|
|
};
|
2009-12-08 12:51:05 -05:00
|
|
|
|
|
|
|
function AppWellIcon(app) {
|
|
|
|
this._init(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
AppWellIcon.prototype = {
|
|
|
|
_init : function(app) {
|
|
|
|
this.app = app;
|
|
|
|
this.actor = new St.Clickable({ style_class: 'app-well-app',
|
|
|
|
reactive: true,
|
|
|
|
x_fill: true,
|
|
|
|
y_fill: true });
|
|
|
|
this.actor._delegate = this;
|
|
|
|
|
|
|
|
this._icon = new AppIcon(app);
|
|
|
|
this.actor.set_child(this._icon.actor);
|
|
|
|
|
|
|
|
this.actor.connect('clicked', Lang.bind(this, this._onClicked));
|
|
|
|
this._menu = null;
|
|
|
|
|
2010-03-26 21:35:34 -04:00
|
|
|
this._draggable = DND.makeDraggable(this.actor);
|
|
|
|
this._draggable.connect('drag-begin', Lang.bind(this,
|
|
|
|
function () {
|
|
|
|
this._removeMenuTimeout();
|
2010-05-08 10:06:28 -04:00
|
|
|
Main.overview.beginItemDrag(this);
|
|
|
|
}));
|
|
|
|
this._draggable.connect('drag-end', Lang.bind(this,
|
|
|
|
function () {
|
|
|
|
Main.overview.endItemDrag(this);
|
2010-03-26 21:35:34 -04:00
|
|
|
}));
|
2009-12-08 12:51:05 -05:00
|
|
|
|
|
|
|
this.actor.connect('button-press-event', Lang.bind(this, this._onButtonPress));
|
2010-01-07 00:40:21 -05:00
|
|
|
this.actor.connect('show', Lang.bind(this, this._onShow));
|
|
|
|
this.actor.connect('hide', Lang.bind(this, this._onHideDestroy));
|
|
|
|
this.actor.connect('destroy', Lang.bind(this, this._onHideDestroy));
|
|
|
|
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 14:07:44 -04:00
|
|
|
this._stateChangedId = 0;
|
2010-03-10 08:52:28 -05:00
|
|
|
this._menuTimeoutId = 0;
|
2010-01-07 00:40:21 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_onShow: function() {
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 14:07:44 -04:00
|
|
|
this._stateChangedId = this.app.connect('notify::state',
|
|
|
|
Lang.bind(this,
|
|
|
|
this._onStateChanged));
|
|
|
|
this._onStateChanged();
|
2010-01-07 00:40:21 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_onHideDestroy: function() {
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 14:07:44 -04:00
|
|
|
if (this._stateChangedId > 0)
|
|
|
|
this.app.disconnect(this._stateChangedId);
|
2010-03-10 08:52:28 -05:00
|
|
|
this._removeMenuTimeout();
|
|
|
|
},
|
|
|
|
|
|
|
|
_removeMenuTimeout: function() {
|
|
|
|
if (this._menuTimeoutId > 0) {
|
|
|
|
Mainloop.source_remove(this._menuTimeoutId);
|
|
|
|
this._menuTimeoutId = 0;
|
|
|
|
}
|
2010-01-07 00:40:21 -05:00
|
|
|
},
|
|
|
|
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 14:07:44 -04:00
|
|
|
_onStateChanged: function() {
|
|
|
|
if (this.app.state != Shell.AppState.STOPPED)
|
|
|
|
this.actor.add_style_class_name('running');
|
|
|
|
else
|
|
|
|
this.actor.remove_style_class_name('running');
|
2009-11-12 17:46:59 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_onButtonPress: function(actor, event) {
|
2010-03-10 08:52:28 -05:00
|
|
|
let button = event.get_button();
|
|
|
|
if (button == 1) {
|
|
|
|
this._removeMenuTimeout();
|
|
|
|
this._menuTimeoutId = Mainloop.timeout_add(MENU_POPUP_TIMEOUT,
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
this.popupMenu(button);
|
|
|
|
}));
|
|
|
|
}
|
2009-11-12 17:46:59 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_onClicked: function(actor, event) {
|
2010-03-10 08:52:28 -05:00
|
|
|
this._removeMenuTimeout();
|
|
|
|
|
2009-11-12 17:46:59 -05:00
|
|
|
let button = event.get_button();
|
|
|
|
if (button == 1) {
|
|
|
|
this._onActivate(event);
|
2010-04-14 16:22:41 -04:00
|
|
|
} else if (button == 2) {
|
2010-05-12 15:19:40 -04:00
|
|
|
let newWorkspace = Main.overview.workspaces.addWorkspace();
|
2010-05-13 14:29:00 -04:00
|
|
|
if (newWorkspace != null) {
|
|
|
|
newWorkspace.activate(global.get_current_time());
|
|
|
|
this.emit('launching');
|
|
|
|
this.app.open_new_window();
|
|
|
|
Main.overview.hide();
|
|
|
|
}
|
2009-11-12 17:46:59 -05:00
|
|
|
} else if (button == 3) {
|
|
|
|
// Don't bind to the right click here; we want left click outside the
|
|
|
|
// area to deactivate as well.
|
|
|
|
this.popupMenu(0);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2010-02-15 19:50:36 -05:00
|
|
|
getId: function() {
|
|
|
|
return this.app.get_id();
|
|
|
|
},
|
|
|
|
|
2009-11-12 17:46:59 -05:00
|
|
|
popupMenu: function(activatingButton) {
|
2010-03-10 08:52:28 -05:00
|
|
|
this._removeMenuTimeout();
|
|
|
|
this.actor.fake_release();
|
|
|
|
|
2009-11-12 17:46:59 -05:00
|
|
|
if (!this._menu) {
|
|
|
|
this._menu = new AppIconMenu(this);
|
|
|
|
this._menu.connect('highlight-window', Lang.bind(this, function (menu, window) {
|
|
|
|
this.highlightWindow(window);
|
|
|
|
}));
|
|
|
|
this._menu.connect('activate-window', Lang.bind(this, function (menu, window) {
|
|
|
|
this.activateWindow(window);
|
|
|
|
}));
|
|
|
|
this._menu.connect('popup', Lang.bind(this, function (menu, isPoppedUp) {
|
|
|
|
if (isPoppedUp) {
|
|
|
|
this._onMenuPoppedUp();
|
2009-09-08 15:53:49 -04:00
|
|
|
} else {
|
2009-11-12 17:46:59 -05:00
|
|
|
this._onMenuPoppedDown();
|
2009-09-08 15:53:49 -04:00
|
|
|
}
|
2009-11-12 17:46:59 -05:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
this._menu.popup(activatingButton);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2009-12-08 12:51:05 -05:00
|
|
|
highlightWindow: function(metaWindow) {
|
2010-01-17 08:48:29 -05:00
|
|
|
if (this._didActivateWindow)
|
|
|
|
return;
|
2009-12-08 12:51:05 -05:00
|
|
|
if (!this._getRunning())
|
|
|
|
return;
|
|
|
|
Main.overview.getWorkspacesForWindow(metaWindow).setHighlightWindow(metaWindow);
|
|
|
|
},
|
|
|
|
|
|
|
|
activateWindow: function(metaWindow) {
|
|
|
|
if (metaWindow) {
|
|
|
|
this._didActivateWindow = true;
|
2010-02-17 14:05:06 -05:00
|
|
|
Main.activateWindow(metaWindow);
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 14:07:44 -04:00
|
|
|
} else {
|
2009-12-08 12:51:05 -05:00
|
|
|
Main.overview.hide();
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 14:07:44 -04:00
|
|
|
}
|
2009-12-08 12:51:05 -05:00
|
|
|
},
|
|
|
|
|
2010-02-22 11:39:10 -05:00
|
|
|
setSelected: function (isSelected) {
|
|
|
|
this._selected = isSelected;
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 14:07:44 -04:00
|
|
|
if (this._selected)
|
|
|
|
this.actor.add_style_class_name('selected');
|
|
|
|
else
|
|
|
|
this.actor.remove_style_class_name('selected');
|
2010-02-22 11:39:10 -05:00
|
|
|
},
|
|
|
|
|
2009-12-08 12:51:05 -05:00
|
|
|
_onMenuPoppedUp: function() {
|
|
|
|
if (this._getRunning()) {
|
|
|
|
Main.overview.getWorkspacesForWindow(null).setApplicationWindowSelection(this.app.get_id());
|
|
|
|
this._setWindowSelection = true;
|
2010-01-17 08:48:29 -05:00
|
|
|
this._didActivateWindow = false;
|
2009-12-08 12:51:05 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onMenuPoppedDown: function() {
|
2010-03-19 13:47:34 -04:00
|
|
|
this.actor.sync_hover();
|
|
|
|
|
2009-12-08 12:51:05 -05:00
|
|
|
if (this._didActivateWindow)
|
|
|
|
return;
|
|
|
|
if (!this._setWindowSelection)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Main.overview.getWorkspacesForWindow(null).setApplicationWindowSelection(null);
|
|
|
|
this._setWindowSelection = false;
|
2009-11-12 17:46:59 -05:00
|
|
|
},
|
|
|
|
|
2009-12-08 12:51:05 -05:00
|
|
|
_getRunning: function() {
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 14:07:44 -04:00
|
|
|
return this.app.state != Shell.AppState.STOPPED;
|
2009-12-08 12:51:05 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_onActivate: function (event) {
|
2010-02-15 19:50:36 -05:00
|
|
|
this.emit('launching');
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 14:07:44 -04:00
|
|
|
let modifiers = Shell.get_event_state(event);
|
2009-12-08 12:51:05 -05:00
|
|
|
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 14:07:44 -04:00
|
|
|
if (modifiers & Clutter.ModifierType.CONTROL_MASK
|
|
|
|
&& this.app.state == Shell.AppState.RUNNING) {
|
|
|
|
this.app.open_new_window();
|
2009-12-08 12:51:05 -05:00
|
|
|
} else {
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 14:07:44 -04:00
|
|
|
this.app.activate();
|
2009-12-08 12:51:05 -05:00
|
|
|
}
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 14:07:44 -04:00
|
|
|
Main.overview.hide();
|
2009-09-01 14:15:29 -04:00
|
|
|
},
|
|
|
|
|
2009-08-17 20:29:54 -04:00
|
|
|
shellWorkspaceLaunch : function() {
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 14:07:44 -04:00
|
|
|
this.app.open_new_window();
|
2009-08-17 20:29:54 -04:00
|
|
|
},
|
|
|
|
|
2009-09-11 17:13:50 -04:00
|
|
|
getDragActor: function() {
|
2009-11-12 17:46:59 -05:00
|
|
|
return this.app.create_icon_texture(APPICON_SIZE);
|
2009-06-30 16:35:39 -04:00
|
|
|
},
|
|
|
|
|
2010-02-04 16:57:38 -05:00
|
|
|
// Returns the original actor that should align with the actor
|
|
|
|
// we show as the item is being dragged.
|
2009-06-30 16:35:39 -04:00
|
|
|
getDragActorSource: function() {
|
2010-02-04 16:57:38 -05:00
|
|
|
return this._icon.icon;
|
2009-09-01 14:15:29 -04:00
|
|
|
}
|
2010-03-15 09:50:05 -04:00
|
|
|
};
|
2009-12-08 12:51:05 -05:00
|
|
|
Signals.addSignalMethods(AppWellIcon.prototype);
|
2009-11-12 17:46:59 -05:00
|
|
|
|
|
|
|
function AppIconMenu(source) {
|
|
|
|
this._init(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
AppIconMenu.prototype = {
|
|
|
|
_init: function(source) {
|
|
|
|
this._source = source;
|
|
|
|
|
|
|
|
this.actor = new Shell.GenericContainer({ reactive: true });
|
|
|
|
this.actor.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
|
|
|
|
this.actor.connect('get-preferred-height', Lang.bind(this, this._getPreferredHeight));
|
|
|
|
this.actor.connect('allocate', Lang.bind(this, this._allocate));
|
|
|
|
|
2010-03-31 14:57:07 -04:00
|
|
|
this._windowContainer = new Shell.Menu({ style_class: 'app-well-menu',
|
|
|
|
vertical: true,
|
|
|
|
width: Main.overview._dash.actor.width });
|
2009-11-12 17:46:59 -05:00
|
|
|
this._windowContainer.connect('unselected', Lang.bind(this, this._onItemUnselected));
|
|
|
|
this._windowContainer.connect('selected', Lang.bind(this, this._onItemSelected));
|
|
|
|
this._windowContainer.connect('cancelled', Lang.bind(this, this._onWindowSelectionCancelled));
|
|
|
|
this._windowContainer.connect('activate', Lang.bind(this, this._onItemActivate));
|
2010-03-31 14:57:07 -04:00
|
|
|
this.actor.add_actor(this._windowContainer);
|
2009-11-12 17:46:59 -05:00
|
|
|
|
|
|
|
// Stay popped up on release over application icon
|
|
|
|
this._windowContainer.set_persistent_source(this._source.actor);
|
|
|
|
|
|
|
|
// Intercept events while the menu has the pointer grab to do window-related effects
|
|
|
|
this._windowContainer.connect('enter-event', Lang.bind(this, this._onMenuEnter));
|
|
|
|
this._windowContainer.connect('leave-event', Lang.bind(this, this._onMenuLeave));
|
|
|
|
this._windowContainer.connect('button-release-event', Lang.bind(this, this._onMenuButtonRelease));
|
|
|
|
|
2010-03-31 16:01:34 -04:00
|
|
|
this._arrow = new St.DrawingArea({ style_class: 'app-well-menu-arrow' });
|
2010-03-03 18:00:05 -05:00
|
|
|
this._arrow.connect('repaint', Lang.bind(this, function (area) {
|
2010-03-31 16:01:34 -04:00
|
|
|
Shell.draw_box_pointer(area, Shell.PointerDirection.LEFT);
|
2009-11-12 17:46:59 -05:00
|
|
|
}));
|
|
|
|
this.actor.add_actor(this._arrow);
|
|
|
|
|
|
|
|
// Chain our visibility and lifecycle to that of the source
|
|
|
|
source.actor.connect('notify::mapped', Lang.bind(this, function () {
|
|
|
|
if (!source.actor.mapped)
|
|
|
|
this._windowContainer.popdown();
|
|
|
|
}));
|
|
|
|
source.actor.connect('destroy', Lang.bind(this, function () { this.actor.destroy(); }));
|
|
|
|
|
2010-05-06 17:18:10 -04:00
|
|
|
Main.uiGroup.add_actor(this.actor);
|
2009-11-12 17:46:59 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_getPreferredWidth: function(actor, forHeight, alloc) {
|
2010-03-31 14:57:07 -04:00
|
|
|
let [menuMin, menuNatural] = this._windowContainer.get_preferred_width(forHeight);
|
2010-03-31 16:01:34 -04:00
|
|
|
let [arrowMin, arrowNatural] = this._arrow.get_preferred_width(forHeight);
|
|
|
|
alloc.min_size = menuMin + arrowMin;
|
|
|
|
alloc.natural_size = menuNatural + arrowNatural;
|
2009-11-12 17:46:59 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_getPreferredHeight: function(actor, forWidth, alloc) {
|
2010-03-31 14:57:07 -04:00
|
|
|
let [min, natural] = this._windowContainer.get_preferred_height(forWidth);
|
2009-11-12 17:46:59 -05:00
|
|
|
alloc.min_size = min;
|
|
|
|
alloc.natural_size = natural;
|
|
|
|
},
|
|
|
|
|
|
|
|
_allocate: function(actor, box, flags) {
|
|
|
|
let childBox = new Clutter.ActorBox();
|
2010-03-31 14:57:07 -04:00
|
|
|
let themeNode = this._windowContainer.get_theme_node();
|
2009-11-12 17:46:59 -05:00
|
|
|
|
|
|
|
let width = box.x2 - box.x1;
|
|
|
|
let height = box.y2 - box.y1;
|
|
|
|
|
2010-03-31 16:01:34 -04:00
|
|
|
let [arrowMinWidth, arrowWidth] = this._arrow.get_preferred_width(height);
|
|
|
|
|
2009-11-12 17:46:59 -05:00
|
|
|
childBox.x1 = 0;
|
2010-03-31 16:01:34 -04:00
|
|
|
childBox.x2 = arrowWidth;
|
|
|
|
childBox.y1 = Math.floor((height / 2) - (arrowWidth / 2));
|
|
|
|
childBox.y2 = childBox.y1 + arrowWidth;
|
2009-11-12 17:46:59 -05:00
|
|
|
this._arrow.allocate(childBox, flags);
|
|
|
|
|
|
|
|
// Ensure the arrow is above the border area
|
|
|
|
let border = themeNode.get_border_width(St.Side.LEFT);
|
2010-03-31 16:01:34 -04:00
|
|
|
childBox.x1 = arrowWidth - border;
|
2009-11-12 17:46:59 -05:00
|
|
|
childBox.x2 = width;
|
|
|
|
childBox.y1 = 0;
|
|
|
|
childBox.y2 = height;
|
2010-03-31 14:57:07 -04:00
|
|
|
this._windowContainer.allocate(childBox, flags);
|
2009-11-12 17:46:59 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_redisplay: function() {
|
|
|
|
this._windowContainer.remove_all();
|
|
|
|
|
|
|
|
let windows = this._source.app.get_windows();
|
|
|
|
|
|
|
|
this._windowContainer.show();
|
|
|
|
|
|
|
|
let iconsDiffer = false;
|
2010-02-09 12:42:07 -05:00
|
|
|
let texCache = St.TextureCache.get_default();
|
2009-11-12 17:46:59 -05:00
|
|
|
if (windows.length > 0) {
|
|
|
|
let firstIcon = windows[0].mini_icon;
|
|
|
|
for (let i = 1; i < windows.length; i++) {
|
|
|
|
if (!texCache.pixbuf_equal(windows[i].mini_icon, firstIcon)) {
|
|
|
|
iconsDiffer = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display the app windows menu items and the separator between windows
|
|
|
|
// of the current desktop and other windows.
|
|
|
|
let activeWorkspace = global.screen.get_active_workspace();
|
|
|
|
let separatorShown = windows.length > 0 && windows[0].get_workspace() != activeWorkspace;
|
|
|
|
|
|
|
|
for (let i = 0; i < windows.length; i++) {
|
|
|
|
if (!separatorShown && windows[i].get_workspace() != activeWorkspace) {
|
|
|
|
this._appendSeparator();
|
|
|
|
separatorShown = true;
|
|
|
|
}
|
|
|
|
let box = this._appendMenuItem(windows[i].title);
|
|
|
|
box._window = windows[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (windows.length > 0)
|
|
|
|
this._appendSeparator();
|
|
|
|
|
|
|
|
let isFavorite = AppFavorites.getAppFavorites().isFavorite(this._source.app.get_id());
|
|
|
|
|
|
|
|
this._newWindowMenuItem = windows.length > 0 ? this._appendMenuItem(_("New Window")) : null;
|
|
|
|
|
|
|
|
if (windows.length > 0)
|
|
|
|
this._appendSeparator();
|
|
|
|
this._toggleFavoriteMenuItem = this._appendMenuItem(isFavorite ? _("Remove from Favorites")
|
|
|
|
: _("Add to Favorites"));
|
|
|
|
|
|
|
|
this._highlightedItem = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
_appendSeparator: function () {
|
2010-05-13 15:46:04 -04:00
|
|
|
let bin = new St.Bin({ style_class: 'app-well-menu-separator' });
|
2010-03-31 14:57:07 -04:00
|
|
|
this._windowContainer.add_actor(bin);
|
2009-11-12 17:46:59 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_appendMenuItem: function(labelText) {
|
|
|
|
let box = new St.BoxLayout({ style_class: 'app-well-menu-item',
|
|
|
|
reactive: true });
|
|
|
|
let label = new St.Label({ text: labelText });
|
|
|
|
box.add(label);
|
2010-03-31 14:57:07 -04:00
|
|
|
this._windowContainer.add_actor(box);
|
2009-11-12 17:46:59 -05:00
|
|
|
return box;
|
|
|
|
},
|
|
|
|
|
|
|
|
popup: function(activatingButton) {
|
|
|
|
let [stageX, stageY] = this._source.actor.get_transformed_position();
|
|
|
|
let [stageWidth, stageHeight] = this._source.actor.get_transformed_size();
|
|
|
|
|
|
|
|
this._redisplay();
|
|
|
|
|
2009-12-03 15:59:52 -05:00
|
|
|
this._windowContainer.popup(activatingButton, global.get_current_time());
|
2009-11-12 17:46:59 -05:00
|
|
|
|
|
|
|
this.emit('popup', true);
|
|
|
|
|
|
|
|
let x, y;
|
|
|
|
x = Math.floor(stageX + stageWidth);
|
|
|
|
y = Math.floor(stageY + (stageHeight / 2) - (this.actor.height / 2));
|
|
|
|
|
|
|
|
this.actor.set_position(x, y);
|
|
|
|
this.actor.show();
|
|
|
|
},
|
|
|
|
|
|
|
|
popdown: function() {
|
|
|
|
this._windowContainer.popdown();
|
|
|
|
this.emit('popup', false);
|
|
|
|
this.actor.hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
selectWindow: function(metaWindow) {
|
|
|
|
this._selectMenuItemForWindow(metaWindow);
|
|
|
|
},
|
|
|
|
|
|
|
|
_findMetaWindowForActor: function (actor) {
|
2010-01-21 21:33:48 -05:00
|
|
|
if (actor._delegate instanceof Workspace.WindowClone)
|
2009-11-12 17:46:59 -05:00
|
|
|
return actor._delegate.metaWindow;
|
|
|
|
else if (actor.get_meta_window)
|
|
|
|
return actor.get_meta_window();
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
// This function is called while the menu has a pointer grab; what we want
|
|
|
|
// to do is see if the mouse was released over a window representation
|
|
|
|
_onMenuButtonRelease: function (actor, event) {
|
|
|
|
let metaWindow = this._findMetaWindowForActor(event.get_source());
|
|
|
|
if (metaWindow) {
|
|
|
|
this.emit('activate-window', metaWindow);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateHighlight: function (item) {
|
|
|
|
if (this._highlightedItem) {
|
2010-03-19 11:37:04 -04:00
|
|
|
this._highlightedItem.remove_style_pseudo_class('hover');
|
2009-11-12 17:46:59 -05:00
|
|
|
this.emit('highlight-window', null);
|
|
|
|
}
|
|
|
|
this._highlightedItem = item;
|
|
|
|
if (this._highlightedItem) {
|
2010-03-19 11:37:04 -04:00
|
|
|
item.add_style_pseudo_class('hover');
|
2009-11-12 17:46:59 -05:00
|
|
|
let window = this._highlightedItem._window;
|
|
|
|
if (window)
|
|
|
|
this.emit('highlight-window', window);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_selectMenuItemForWindow: function (metaWindow) {
|
|
|
|
let children = this._windowContainer.get_children();
|
|
|
|
for (let i = 0; i < children.length; i++) {
|
|
|
|
let child = children[i];
|
|
|
|
let menuMetaWindow = child._window;
|
|
|
|
if (menuMetaWindow == metaWindow)
|
|
|
|
this._updateHighlight(child);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Called while menu has a pointer grab
|
|
|
|
_onMenuEnter: function (actor, event) {
|
|
|
|
let metaWindow = this._findMetaWindowForActor(event.get_source());
|
|
|
|
if (metaWindow) {
|
|
|
|
this._selectMenuItemForWindow(metaWindow);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Called while menu has a pointer grab
|
|
|
|
_onMenuLeave: function (actor, event) {
|
|
|
|
let metaWindow = this._findMetaWindowForActor(event.get_source());
|
|
|
|
if (metaWindow) {
|
|
|
|
this._updateHighlight(null);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onItemUnselected: function (actor, child) {
|
|
|
|
this._updateHighlight(null);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onItemSelected: function (actor, child) {
|
|
|
|
this._updateHighlight(child);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onItemActivate: function (actor, child) {
|
|
|
|
if (child._window) {
|
|
|
|
let metaWindow = child._window;
|
|
|
|
this.emit('activate-window', metaWindow);
|
|
|
|
} else if (child == this._newWindowMenuItem) {
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 14:07:44 -04:00
|
|
|
this._source.app.open_new_window();
|
2009-11-12 17:46:59 -05:00
|
|
|
this.emit('activate-window', null);
|
|
|
|
} else if (child == this._toggleFavoriteMenuItem) {
|
|
|
|
let favs = AppFavorites.getAppFavorites();
|
|
|
|
let isFavorite = favs.isFavorite(this._source.app.get_id());
|
|
|
|
if (isFavorite)
|
|
|
|
favs.removeFavorite(this._source.app.get_id());
|
|
|
|
else
|
|
|
|
favs.addFavorite(this._source.app.get_id());
|
|
|
|
}
|
|
|
|
this.popdown();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onWindowSelectionCancelled: function () {
|
|
|
|
this.emit('highlight-window', null);
|
|
|
|
this.popdown();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Signals.addSignalMethods(AppIconMenu.prototype);
|
2009-09-01 14:15:29 -04:00
|
|
|
|
2009-08-06 15:39:09 -04:00
|
|
|
function WellGrid() {
|
|
|
|
this._init();
|
2009-06-30 16:35:39 -04:00
|
|
|
}
|
|
|
|
|
2009-08-06 15:39:09 -04:00
|
|
|
WellGrid.prototype = {
|
|
|
|
_init: function() {
|
2010-05-13 15:46:04 -04:00
|
|
|
this.actor = new St.BoxLayout({ name: 'dashAppWell', vertical: true });
|
2009-11-12 17:46:59 -05:00
|
|
|
// Pulled from CSS, but hardcode some defaults here
|
|
|
|
this._spacing = 0;
|
|
|
|
this._item_size = 48;
|
|
|
|
this._grid = new Shell.GenericContainer();
|
2010-02-15 19:50:36 -05:00
|
|
|
this.actor.add(this._grid, { expand: true, y_align: St.Align.START });
|
2009-11-12 17:46:59 -05:00
|
|
|
this.actor.connect('style-changed', Lang.bind(this, this._onStyleChanged));
|
|
|
|
|
|
|
|
this._grid.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
|
|
|
|
this._grid.connect('get-preferred-height', Lang.bind(this, this._getPreferredHeight));
|
|
|
|
this._grid.connect('allocate', Lang.bind(this, this._allocate));
|
2009-06-30 16:35:39 -04:00
|
|
|
},
|
|
|
|
|
2009-08-06 15:39:09 -04:00
|
|
|
_getPreferredWidth: function (grid, forHeight, alloc) {
|
2009-11-12 17:46:59 -05:00
|
|
|
let children = this._grid.get_children();
|
|
|
|
let nColumns = children.length;
|
|
|
|
let totalSpacing = Math.max(0, nColumns - 1) * this._spacing;
|
|
|
|
// Kind of a lie, but not really an issue right now. If
|
|
|
|
// we wanted to support some sort of hidden/overflow that would
|
|
|
|
// need higher level design
|
|
|
|
alloc.min_size = this._item_size;
|
|
|
|
alloc.natural_size = nColumns * this._item_size + totalSpacing;
|
2009-08-06 15:39:09 -04:00
|
|
|
},
|
2009-06-30 16:35:39 -04:00
|
|
|
|
2009-08-06 15:39:09 -04:00
|
|
|
_getPreferredHeight: function (grid, forWidth, alloc) {
|
2009-11-12 17:46:59 -05:00
|
|
|
let children = this._grid.get_children();
|
|
|
|
let [nColumns, usedWidth] = this._computeLayout(forWidth);
|
|
|
|
let nRows;
|
|
|
|
if (nColumns > 0)
|
|
|
|
nRows = Math.ceil(children.length / nColumns);
|
|
|
|
else
|
|
|
|
nRows = 0;
|
|
|
|
let totalSpacing = Math.max(0, nRows - 1) * this._spacing;
|
|
|
|
let height = nRows * this._item_size + totalSpacing;
|
|
|
|
alloc.min_size = height;
|
|
|
|
alloc.natural_size = height;
|
2009-08-06 15:39:09 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_allocate: function (grid, box, flags) {
|
2009-11-12 17:46:59 -05:00
|
|
|
let children = this._grid.get_children();
|
2009-08-06 15:39:09 -04:00
|
|
|
let availWidth = box.x2 - box.x1;
|
|
|
|
let availHeight = box.y2 - box.y1;
|
|
|
|
|
2009-11-12 17:46:59 -05:00
|
|
|
let [nColumns, usedWidth] = this._computeLayout(availWidth);
|
2009-08-06 15:39:09 -04:00
|
|
|
|
2009-11-12 17:46:59 -05:00
|
|
|
let overallPaddingX = Math.floor((availWidth - usedWidth) / 2);
|
2009-08-06 15:39:09 -04:00
|
|
|
|
2009-11-12 17:46:59 -05:00
|
|
|
let x = box.x1 + overallPaddingX;
|
2009-08-06 15:39:09 -04:00
|
|
|
let y = box.y1;
|
|
|
|
let columnIndex = 0;
|
|
|
|
for (let i = 0; i < children.length; i++) {
|
2009-11-12 17:46:59 -05:00
|
|
|
let [childMinWidth, childMinHeight, childNaturalWidth, childNaturalHeight]
|
|
|
|
= children[i].get_preferred_size();
|
2009-08-06 15:39:09 -04:00
|
|
|
|
2009-08-14 04:35:48 -04:00
|
|
|
/* Center the item in its allocation horizontally */
|
2009-11-12 17:46:59 -05:00
|
|
|
let width = Math.min(this._item_size, childNaturalWidth);
|
|
|
|
let childXSpacing = Math.max(0, width - childNaturalWidth) / 2;
|
|
|
|
let height = Math.min(this._item_size, childNaturalHeight);
|
|
|
|
let childYSpacing = Math.max(0, height - childNaturalHeight) / 2;
|
2009-08-06 15:39:09 -04:00
|
|
|
|
|
|
|
let childBox = new Clutter.ActorBox();
|
2009-11-12 17:46:59 -05:00
|
|
|
childBox.x1 = Math.floor(x + childXSpacing);
|
|
|
|
childBox.y1 = Math.floor(y + childYSpacing);
|
2009-08-06 15:39:09 -04:00
|
|
|
childBox.x2 = childBox.x1 + width;
|
2009-11-12 17:46:59 -05:00
|
|
|
childBox.y2 = childBox.y1 + height;
|
2009-08-06 15:39:09 -04:00
|
|
|
children[i].allocate(childBox, flags);
|
|
|
|
|
|
|
|
columnIndex++;
|
2009-11-12 17:46:59 -05:00
|
|
|
if (columnIndex == nColumns) {
|
2009-08-06 15:39:09 -04:00
|
|
|
columnIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (columnIndex == 0) {
|
2009-11-12 17:46:59 -05:00
|
|
|
y += this._item_size + this._spacing;
|
|
|
|
x = box.x1 + overallPaddingX;
|
2009-08-06 15:39:09 -04:00
|
|
|
} else {
|
2009-11-12 17:46:59 -05:00
|
|
|
x += this._item_size + this._spacing;
|
2009-08-06 15:39:09 -04:00
|
|
|
}
|
2009-07-07 16:08:41 -04:00
|
|
|
}
|
2009-07-04 17:28:34 -04:00
|
|
|
},
|
|
|
|
|
2009-08-06 15:39:09 -04:00
|
|
|
_computeLayout: function (forWidth) {
|
2009-11-12 17:46:59 -05:00
|
|
|
let children = this._grid.get_children();
|
2009-09-24 00:01:57 -04:00
|
|
|
let nColumns = 0;
|
|
|
|
let usedWidth = 0;
|
2009-11-12 17:46:59 -05:00
|
|
|
while (nColumns < WELL_MAX_COLUMNS &&
|
|
|
|
nColumns < children.length &&
|
|
|
|
(usedWidth + this._item_size <= forWidth)) {
|
|
|
|
usedWidth += this._item_size + this._spacing;
|
|
|
|
nColumns += 1;
|
2009-09-24 00:01:57 -04:00
|
|
|
}
|
2009-08-06 15:39:09 -04:00
|
|
|
|
2009-11-12 17:46:59 -05:00
|
|
|
if (nColumns > 0)
|
|
|
|
usedWidth -= this._spacing;
|
2009-07-02 00:35:26 -04:00
|
|
|
|
2009-11-12 17:46:59 -05:00
|
|
|
return [nColumns, usedWidth];
|
|
|
|
},
|
2009-06-30 16:35:39 -04:00
|
|
|
|
2009-11-12 17:46:59 -05:00
|
|
|
_onStyleChanged: function() {
|
|
|
|
let themeNode = this.actor.get_theme_node();
|
|
|
|
let [success, len] = themeNode.get_length('spacing', false);
|
|
|
|
if (success)
|
|
|
|
this._spacing = len;
|
|
|
|
[success, len] = themeNode.get_length('-shell-grid-item-size', false);
|
|
|
|
if (success)
|
|
|
|
this._item_size = len;
|
|
|
|
this._grid.queue_relayout();
|
|
|
|
},
|
2009-08-06 15:39:09 -04:00
|
|
|
|
2009-11-12 17:46:59 -05:00
|
|
|
removeAll: function () {
|
|
|
|
this._grid.get_children().forEach(Lang.bind(this, function (child) {
|
|
|
|
child.destroy();
|
|
|
|
}));
|
2009-08-06 15:39:09 -04:00
|
|
|
},
|
|
|
|
|
2009-11-12 17:46:59 -05:00
|
|
|
addItem: function(actor) {
|
|
|
|
this._grid.add_actor(actor);
|
2009-06-30 16:35:39 -04:00
|
|
|
}
|
2010-03-15 09:50:05 -04:00
|
|
|
};
|
2009-06-30 16:35:39 -04:00
|
|
|
|
2009-08-06 15:39:09 -04:00
|
|
|
function AppWell() {
|
|
|
|
this._init();
|
2009-06-30 16:35:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
AppWell.prototype = {
|
2009-08-06 15:39:09 -04:00
|
|
|
_init : function() {
|
2009-06-30 16:35:39 -04:00
|
|
|
this._menus = [];
|
|
|
|
this._menuDisplays = [];
|
|
|
|
|
2009-10-15 19:28:29 -04:00
|
|
|
this._favorites = [];
|
|
|
|
|
2010-03-31 16:40:32 -04:00
|
|
|
this._grid = new WellGrid();
|
|
|
|
this.actor = this._grid.actor;
|
2009-08-06 15:39:09 -04:00
|
|
|
this.actor._delegate = this;
|
|
|
|
|
2009-12-03 12:19:38 -05:00
|
|
|
this._workId = Main.initializeDeferredWork(this.actor, Lang.bind(this, this._redisplay));
|
2009-10-02 20:17:34 -04:00
|
|
|
|
2009-10-15 19:28:29 -04:00
|
|
|
this._tracker = Shell.WindowTracker.get_default();
|
2009-06-30 16:35:39 -04:00
|
|
|
this._appSystem = Shell.AppSystem.get_default();
|
|
|
|
|
2009-12-03 12:19:38 -05:00
|
|
|
this._appSystem.connect('installed-changed', Lang.bind(this, this._queueRedisplay));
|
|
|
|
AppFavorites.getAppFavorites().connect('changed', Lang.bind(this, this._queueRedisplay));
|
|
|
|
this._tracker.connect('app-running-changed', Lang.bind(this, this._queueRedisplay));
|
2009-06-30 16:35:39 -04:00
|
|
|
},
|
|
|
|
|
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
|
|
|
_appIdListToHash: function(apps) {
|
|
|
|
let ids = {};
|
|
|
|
for (let i = 0; i < apps.length; i++)
|
|
|
|
ids[apps[i].get_id()] = apps[i];
|
|
|
|
return ids;
|
2009-08-06 15:39:09 -04:00
|
|
|
},
|
|
|
|
|
2009-12-03 12:19:38 -05:00
|
|
|
_queueRedisplay: function () {
|
|
|
|
Main.queueDeferredWork(this._workId);
|
2009-10-02 20:17:34 -04:00
|
|
|
},
|
|
|
|
|
2009-08-06 15:39:09 -04:00
|
|
|
_redisplay: function () {
|
|
|
|
this._grid.removeAll();
|
2009-07-30 15:40:26 -04:00
|
|
|
|
2009-10-15 19:28:29 -04:00
|
|
|
let favorites = AppFavorites.getAppFavorites().getFavoriteMap();
|
2009-08-06 15:39:09 -04:00
|
|
|
|
|
|
|
/* hardcode here pending some design about how exactly desktop contexts behave */
|
2010-05-13 15:46:04 -04:00
|
|
|
let contextId = '';
|
2009-07-30 15:40:26 -04:00
|
|
|
|
2009-10-15 19:28:29 -04:00
|
|
|
let running = this._tracker.get_running_apps(contextId);
|
2009-10-14 17:25:17 -04:00
|
|
|
let runningIds = this._appIdListToHash(running);
|
2009-08-06 15:39:09 -04:00
|
|
|
|
2009-11-12 17:46:59 -05:00
|
|
|
let nFavorites = 0;
|
2009-10-15 19:28:29 -04:00
|
|
|
for (let id in favorites) {
|
|
|
|
let app = favorites[id];
|
2009-12-08 12:51:05 -05:00
|
|
|
let display = new AppWellIcon(app);
|
2009-11-12 17:46:59 -05:00
|
|
|
this._grid.addItem(display.actor);
|
|
|
|
nFavorites++;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < running.length; i++) {
|
|
|
|
let app = running[i];
|
2009-10-15 19:28:29 -04:00
|
|
|
if (app.get_id() in favorites)
|
2009-10-14 15:36:58 -04:00
|
|
|
continue;
|
2009-12-08 12:51:05 -05:00
|
|
|
let display = new AppWellIcon(app);
|
2009-11-12 17:46:59 -05:00
|
|
|
this._grid.addItem(display.actor);
|
2009-08-06 15:39:09 -04:00
|
|
|
}
|
2009-10-27 07:54:23 -04:00
|
|
|
|
2009-11-12 17:46:59 -05:00
|
|
|
if (running.length == 0 && nFavorites == 0) {
|
|
|
|
let text = new St.Label({ text: _("Drag here to add favorites")});
|
|
|
|
this._grid.actor.set_child(text);
|
2009-10-27 07:54:23 -04:00
|
|
|
}
|
2009-08-06 15:39:09 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
// Draggable target interface
|
|
|
|
acceptDrop : function(source, actor, x, y, time) {
|
2009-08-14 04:35:48 -04:00
|
|
|
let app = null;
|
2010-02-15 19:50:36 -05:00
|
|
|
if (source instanceof AppWellIcon) {
|
2009-10-15 19:28:29 -04:00
|
|
|
app = this._appSystem.get_app(source.getId());
|
2010-01-21 21:33:48 -05:00
|
|
|
} else if (source instanceof Workspace.WindowClone) {
|
2009-10-15 19:28:29 -04:00
|
|
|
app = this._tracker.get_window_app(source.metaWindow);
|
2009-08-06 15:39:09 -04:00
|
|
|
}
|
|
|
|
|
2009-08-14 04:35:48 -04:00
|
|
|
// Don't allow favoriting of transient apps
|
|
|
|
if (app == null || app.is_transient()) {
|
2009-08-06 15:39:09 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-14 04:35:48 -04:00
|
|
|
let id = app.get_id();
|
|
|
|
|
2009-10-15 19:28:29 -04:00
|
|
|
let favorites = AppFavorites.getAppFavorites().getFavoriteMap();
|
2009-08-06 15:39:09 -04:00
|
|
|
|
2009-10-15 19:28:29 -04:00
|
|
|
let srcIsFavorite = (id in favorites);
|
2009-08-06 15:39:09 -04:00
|
|
|
|
2009-09-25 16:20:43 -04:00
|
|
|
if (srcIsFavorite) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2009-10-15 19:28:29 -04:00
|
|
|
Mainloop.idle_add(Lang.bind(this, function () {
|
|
|
|
AppFavorites.getAppFavorites().addFavorite(id);
|
2009-08-06 15:39:09 -04:00
|
|
|
return false;
|
2009-10-15 19:28:29 -04:00
|
|
|
}));
|
2009-08-06 15:39:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2009-06-30 16:35:39 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Signals.addSignalMethods(AppWell.prototype);
|