2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
Rewrite Dash, remove hardcoded width/height from GenericDisplay
This patch is a near-total rewrite of the Dash. First, the dash
code moves into a separate file, dash.js.
Inside dash.js, the components are more broken up into separate
classes; in particular there's now a Pane class and a MoreLink
class. Instead of each section of the dash, when activated,
attempting to close all N-1 other sections, instead there
is the concept of a single "active pane", and when e.g. activating
the More link for documents, if we know there's an active pane
which happens to be the apps, close it.
Many redundant containers were removed from the dash, and all
manual width, height and x/y offsets are entirely gone. We move
the visual apperance closer to the design by using the view-more.svg,
etc.
To complete the removal of height/width calculations from the dash,
we also had to do the same for GenericDisplay. Also clean up
the positioning inside overlay.js so calculation of children's
positioning is inside a single function that flows from screen.width
and screen.height, so in the future we can stop passing the width
into the Dash constructor and call this once and work on screen
resizing.
2009-07-31 22:12:01 -04:00
|
|
|
|
2011-01-20 10:23:43 -05:00
|
|
|
const Clutter = imports.gi.Clutter;
|
Rewrite Dash, remove hardcoded width/height from GenericDisplay
This patch is a near-total rewrite of the Dash. First, the dash
code moves into a separate file, dash.js.
Inside dash.js, the components are more broken up into separate
classes; in particular there's now a Pane class and a MoreLink
class. Instead of each section of the dash, when activated,
attempting to close all N-1 other sections, instead there
is the concept of a single "active pane", and when e.g. activating
the More link for documents, if we know there's an active pane
which happens to be the apps, close it.
Many redundant containers were removed from the dash, and all
manual width, height and x/y offsets are entirely gone. We move
the visual apperance closer to the design by using the view-more.svg,
etc.
To complete the removal of height/width calculations from the dash,
we also had to do the same for GenericDisplay. Also clean up
the positioning inside overlay.js so calculation of children's
positioning is inside a single function that flows from screen.width
and screen.height, so in the future we can stop passing the width
into the Dash constructor and call this once and work on screen
resizing.
2009-07-31 22:12:01 -04:00
|
|
|
const Signals = imports.signals;
|
|
|
|
const Lang = imports.lang;
|
2010-11-07 20:51:02 -05:00
|
|
|
const Meta = imports.gi.Meta;
|
2010-07-21 19:29:02 -04:00
|
|
|
const Shell = imports.gi.Shell;
|
2009-10-22 13:33:09 -04:00
|
|
|
const St = imports.gi.St;
|
2011-12-16 17:46:07 -05:00
|
|
|
const Mainloop = imports.mainloop;
|
Rewrite Dash, remove hardcoded width/height from GenericDisplay
This patch is a near-total rewrite of the Dash. First, the dash
code moves into a separate file, dash.js.
Inside dash.js, the components are more broken up into separate
classes; in particular there's now a Pane class and a MoreLink
class. Instead of each section of the dash, when activated,
attempting to close all N-1 other sections, instead there
is the concept of a single "active pane", and when e.g. activating
the More link for documents, if we know there's an active pane
which happens to be the apps, close it.
Many redundant containers were removed from the dash, and all
manual width, height and x/y offsets are entirely gone. We move
the visual apperance closer to the design by using the view-more.svg,
etc.
To complete the removal of height/width calculations from the dash,
we also had to do the same for GenericDisplay. Also clean up
the positioning inside overlay.js so calculation of children's
positioning is inside a single function that flows from screen.width
and screen.height, so in the future we can stop passing the width
into the Dash constructor and call this once and work on screen
resizing.
2009-07-31 22:12:01 -04:00
|
|
|
|
|
|
|
const AppDisplay = imports.ui.appDisplay;
|
2010-07-21 19:29:02 -04:00
|
|
|
const AppFavorites = imports.ui.appFavorites;
|
2010-02-07 12:59:30 -05:00
|
|
|
const DND = imports.ui.dnd;
|
2010-11-07 20:51:02 -05:00
|
|
|
const IconGrid = imports.ui.iconGrid;
|
Rewrite Dash, remove hardcoded width/height from GenericDisplay
This patch is a near-total rewrite of the Dash. First, the dash
code moves into a separate file, dash.js.
Inside dash.js, the components are more broken up into separate
classes; in particular there's now a Pane class and a MoreLink
class. Instead of each section of the dash, when activated,
attempting to close all N-1 other sections, instead there
is the concept of a single "active pane", and when e.g. activating
the More link for documents, if we know there's an active pane
which happens to be the apps, close it.
Many redundant containers were removed from the dash, and all
manual width, height and x/y offsets are entirely gone. We move
the visual apperance closer to the design by using the view-more.svg,
etc.
To complete the removal of height/width calculations from the dash,
we also had to do the same for GenericDisplay. Also clean up
the positioning inside overlay.js so calculation of children's
positioning is inside a single function that flows from screen.width
and screen.height, so in the future we can stop passing the width
into the Dash constructor and call this once and work on screen
resizing.
2009-07-31 22:12:01 -04:00
|
|
|
const Main = imports.ui.main;
|
2011-01-21 06:06:13 -05:00
|
|
|
const Tweener = imports.ui.tweener;
|
2010-07-21 19:29:02 -04:00
|
|
|
const Workspace = imports.ui.workspace;
|
2009-11-29 17:45:30 -05:00
|
|
|
|
2011-01-21 06:06:13 -05:00
|
|
|
const DASH_ANIMATION_TIME = 0.2;
|
2011-12-16 17:46:07 -05:00
|
|
|
const DASH_ITEM_LABEL_SHOW_TIME = 0.15;
|
|
|
|
const DASH_ITEM_LABEL_HIDE_TIME = 0.1;
|
|
|
|
const DASH_ITEM_HOVER_TIMEOUT = 300;
|
2011-01-21 06:06:13 -05:00
|
|
|
|
2011-01-20 10:23:43 -05:00
|
|
|
// A container like StBin, but taking the child's scale into account
|
|
|
|
// when requesting a size
|
2011-11-20 11:07:14 -05:00
|
|
|
const DashItemContainer = new Lang.Class({
|
|
|
|
Name: 'DashItemContainer',
|
2011-01-20 10:23:43 -05:00
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
this.actor = new Shell.GenericContainer({ style_class: 'dash-item-container' });
|
|
|
|
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));
|
|
|
|
this.actor._delegate = this;
|
|
|
|
|
2012-03-15 15:18:53 -04:00
|
|
|
this.label = null;
|
2011-12-16 17:46:07 -05:00
|
|
|
|
2011-01-20 10:23:43 -05:00
|
|
|
this.child = null;
|
2011-01-21 06:06:13 -05:00
|
|
|
this._childScale = 1;
|
|
|
|
this._childOpacity = 255;
|
2011-09-19 17:47:16 -04:00
|
|
|
this.animatingOut = false;
|
2011-01-20 10:23:43 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_allocate: function(actor, box, flags) {
|
|
|
|
if (this.child == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let availWidth = box.x2 - box.x1;
|
|
|
|
let availHeight = box.y2 - box.y1;
|
|
|
|
let [minChildWidth, minChildHeight, natChildWidth, natChildHeight] =
|
|
|
|
this.child.get_preferred_size();
|
|
|
|
let [childScaleX, childScaleY] = this.child.get_scale();
|
|
|
|
|
|
|
|
let childWidth = Math.min(natChildWidth * childScaleX, availWidth);
|
|
|
|
let childHeight = Math.min(natChildHeight * childScaleY, availHeight);
|
|
|
|
|
|
|
|
let childBox = new Clutter.ActorBox();
|
|
|
|
childBox.x1 = (availWidth - childWidth) / 2;
|
|
|
|
childBox.y1 = (availHeight - childHeight) / 2;
|
|
|
|
childBox.x2 = childBox.x1 + childWidth;
|
|
|
|
childBox.y2 = childBox.y1 + childHeight;
|
|
|
|
|
|
|
|
this.child.allocate(childBox, flags);
|
|
|
|
},
|
|
|
|
|
|
|
|
_getPreferredHeight: function(actor, forWidth, alloc) {
|
|
|
|
alloc.min_size = 0;
|
|
|
|
alloc.natural_size = 0;
|
|
|
|
|
|
|
|
if (this.child == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let [minHeight, natHeight] = this.child.get_preferred_height(forWidth);
|
|
|
|
alloc.min_size += minHeight * this.child.scale_y;
|
|
|
|
alloc.natural_size += natHeight * this.child.scale_y;
|
|
|
|
},
|
|
|
|
|
|
|
|
_getPreferredWidth: function(actor, forHeight, alloc) {
|
|
|
|
alloc.min_size = 0;
|
|
|
|
alloc.natural_size = 0;
|
|
|
|
|
|
|
|
if (this.child == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let [minWidth, natWidth] = this.child.get_preferred_width(forHeight);
|
|
|
|
alloc.min_size = minWidth * this.child.scale_y;
|
|
|
|
alloc.natural_size = natWidth * this.child.scale_y;
|
|
|
|
},
|
|
|
|
|
2011-12-16 17:46:07 -05:00
|
|
|
showLabel: function() {
|
2012-03-15 15:18:53 -04:00
|
|
|
if (this.label == null)
|
2011-12-16 17:46:07 -05:00
|
|
|
return;
|
|
|
|
|
2012-03-15 15:18:53 -04:00
|
|
|
this.label.opacity = 0;
|
|
|
|
this.label.show();
|
2011-12-16 17:46:07 -05:00
|
|
|
|
|
|
|
let [stageX, stageY] = this.actor.get_transformed_position();
|
|
|
|
|
|
|
|
let itemHeight = this.actor.allocation.y2 - this.actor.allocation.y1;
|
|
|
|
|
2012-03-15 15:18:53 -04:00
|
|
|
let labelHeight = this.label.get_height();
|
2011-12-16 17:46:07 -05:00
|
|
|
let yOffset = Math.floor((itemHeight - labelHeight) / 2)
|
|
|
|
|
|
|
|
let y = stageY + yOffset;
|
|
|
|
|
2012-03-15 15:18:53 -04:00
|
|
|
let node = this.label.get_theme_node();
|
2011-12-16 17:46:07 -05:00
|
|
|
let xOffset = node.get_length('-x-offset');
|
|
|
|
|
|
|
|
let x;
|
2012-02-13 20:37:28 -05:00
|
|
|
if (Clutter.get_default_text_direction() == Clutter.TextDirection.RTL)
|
2012-03-15 15:18:53 -04:00
|
|
|
x = stageX - this.label.get_width() - xOffset;
|
2011-12-16 17:46:07 -05:00
|
|
|
else
|
|
|
|
x = stageX + this.actor.get_width() + xOffset;
|
|
|
|
|
2012-03-15 15:18:53 -04:00
|
|
|
this.label.set_position(x, y);
|
|
|
|
Tweener.addTween(this.label,
|
2011-12-16 17:46:07 -05:00
|
|
|
{ opacity: 255,
|
|
|
|
time: DASH_ITEM_LABEL_SHOW_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
setLabelText: function(text) {
|
2012-03-15 15:18:53 -04:00
|
|
|
if (this.label == null)
|
|
|
|
this.label = new St.Label({ style_class: 'dash-label'});
|
2011-12-16 17:46:07 -05:00
|
|
|
|
2012-03-15 15:18:53 -04:00
|
|
|
this.label.set_text(text);
|
|
|
|
Main.layoutManager.addChrome(this.label);
|
|
|
|
this.label.hide();
|
2011-12-16 17:46:07 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
hideLabel: function () {
|
2012-03-15 15:18:53 -04:00
|
|
|
this.label.opacity = 255;
|
|
|
|
Tweener.addTween(this.label,
|
2011-12-16 17:46:07 -05:00
|
|
|
{ opacity: 0,
|
|
|
|
time: DASH_ITEM_LABEL_HIDE_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: Lang.bind(this, function() {
|
2012-03-15 15:18:53 -04:00
|
|
|
this.label.hide();
|
2011-12-16 17:46:07 -05:00
|
|
|
})
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-01-20 10:23:43 -05:00
|
|
|
setChild: function(actor) {
|
|
|
|
if (this.child == actor)
|
|
|
|
return;
|
|
|
|
|
2012-02-16 13:27:09 -05:00
|
|
|
this.actor.destroy_all_children();
|
2011-01-20 10:23:43 -05:00
|
|
|
|
|
|
|
this.child = actor;
|
|
|
|
this.actor.add_actor(this.child);
|
2011-01-21 06:06:13 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
animateIn: function() {
|
|
|
|
if (this.child == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.childScale = 0;
|
|
|
|
this.childOpacity = 0;
|
|
|
|
Tweener.addTween(this,
|
|
|
|
{ childScale: 1.0,
|
|
|
|
childOpacity: 255,
|
|
|
|
time: DASH_ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad'
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
animateOutAndDestroy: function() {
|
|
|
|
if (this.child == null) {
|
|
|
|
this.actor.destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-19 17:47:16 -04:00
|
|
|
this.animatingOut = true;
|
2011-01-21 06:06:13 -05:00
|
|
|
this.childScale = 1.0;
|
|
|
|
Tweener.addTween(this,
|
|
|
|
{ childScale: 0.0,
|
|
|
|
childOpacity: 0,
|
|
|
|
time: DASH_ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: Lang.bind(this, function() {
|
|
|
|
this.actor.destroy();
|
|
|
|
})
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
set childScale(scale) {
|
|
|
|
this._childScale = scale;
|
|
|
|
|
|
|
|
if (this.child == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.child.set_scale_with_gravity(scale, scale,
|
|
|
|
Clutter.Gravity.CENTER);
|
|
|
|
this.actor.queue_relayout();
|
|
|
|
},
|
|
|
|
|
|
|
|
get childScale() {
|
|
|
|
return this._childScale;
|
|
|
|
},
|
|
|
|
|
|
|
|
set childOpacity(opacity) {
|
|
|
|
this._childOpacity = opacity;
|
|
|
|
|
|
|
|
if (this.child == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.child.set_opacity(opacity);
|
|
|
|
this.actor.queue_redraw();
|
|
|
|
},
|
|
|
|
|
|
|
|
get childOpacity() {
|
|
|
|
return this._childOpacity;
|
2011-01-20 10:23:43 -05:00
|
|
|
}
|
2011-11-20 11:07:14 -05:00
|
|
|
});
|
2010-11-07 20:51:02 -05:00
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
const RemoveFavoriteIcon = new Lang.Class({
|
|
|
|
Name: 'RemoveFavoriteIcon',
|
|
|
|
Extends: DashItemContainer,
|
2011-01-20 10:23:43 -05:00
|
|
|
|
2010-11-07 20:51:02 -05:00
|
|
|
_init: function() {
|
2011-11-20 11:07:14 -05:00
|
|
|
this.parent();
|
2011-01-20 10:23:43 -05:00
|
|
|
|
|
|
|
this._iconBin = new St.Bin({ style_class: 'remove-favorite' });
|
2010-11-07 20:51:02 -05:00
|
|
|
this._iconActor = null;
|
|
|
|
this.icon = new IconGrid.BaseIcon(_("Remove"),
|
|
|
|
{ setSizeManually: true,
|
2011-01-20 09:27:13 -05:00
|
|
|
showLabel: false,
|
2010-11-07 20:51:02 -05:00
|
|
|
createIcon: Lang.bind(this, this._createIcon) });
|
2011-01-20 10:23:43 -05:00
|
|
|
this._iconBin.set_child(this.icon.actor);
|
|
|
|
this._iconBin._delegate = this;
|
|
|
|
|
|
|
|
this.setChild(this._iconBin);
|
2010-11-07 20:51:02 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_createIcon: function(size) {
|
|
|
|
this._iconActor = new St.Icon({ icon_name: 'user-trash',
|
|
|
|
style_class: 'remove-favorite-icon',
|
|
|
|
icon_size: size });
|
|
|
|
return this._iconActor;
|
|
|
|
},
|
|
|
|
|
|
|
|
setHover: function(hovered) {
|
2011-01-20 10:23:43 -05:00
|
|
|
this._iconBin.set_hover(hovered);
|
2010-11-07 20:51:02 -05:00
|
|
|
if (this._iconActor)
|
|
|
|
this._iconActor.set_hover(hovered);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Rely on the dragged item being a favorite
|
|
|
|
handleDragOver: function(source, actor, x, y, time) {
|
|
|
|
return DND.DragMotionResult.MOVE_DROP;
|
|
|
|
},
|
|
|
|
|
|
|
|
acceptDrop: function(source, actor, x, y, time) {
|
|
|
|
let app = null;
|
|
|
|
if (source instanceof AppDisplay.AppWellIcon) {
|
|
|
|
let appSystem = Shell.AppSystem.get_default();
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 13:35:01 -04:00
|
|
|
app = appSystem.lookup_app(source.getId());
|
2011-01-30 20:25:00 -05:00
|
|
|
} else if (source.metaWindow) {
|
2010-11-07 20:51:02 -05:00
|
|
|
let tracker = Shell.WindowTracker.get_default();
|
|
|
|
app = tracker.get_window_app(source.metaWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
let id = app.get_id();
|
|
|
|
|
|
|
|
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this,
|
|
|
|
function () {
|
|
|
|
AppFavorites.getAppFavorites().removeFavorite(id);
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-20 11:07:14 -05:00
|
|
|
});
|
2010-11-07 20:51:02 -05:00
|
|
|
|
2011-11-20 11:07:14 -05:00
|
|
|
const DragPlaceholderItem = new Lang.Class({
|
|
|
|
Name: 'DragPlaceholderItem',
|
|
|
|
Extends: DashItemContainer,
|
2011-01-20 10:23:43 -05:00
|
|
|
|
|
|
|
_init: function() {
|
2011-11-20 11:07:14 -05:00
|
|
|
this.parent();
|
2011-05-04 22:47:07 -04:00
|
|
|
this.setChild(new St.Bin({ style_class: 'placeholder' }));
|
2011-01-20 10:23:43 -05:00
|
|
|
}
|
2011-11-20 11:07:14 -05:00
|
|
|
});
|
2011-01-20 10:23:43 -05:00
|
|
|
|
2011-11-20 12:56:27 -05:00
|
|
|
const Dash = new Lang.Class({
|
|
|
|
Name: 'Dash',
|
2010-07-21 19:29:02 -04:00
|
|
|
|
|
|
|
_init : function() {
|
|
|
|
this._maxHeight = -1;
|
2011-02-11 19:17:10 -05:00
|
|
|
this.iconSize = 64;
|
2011-02-02 10:44:07 -05:00
|
|
|
this._shownInitially = false;
|
2010-11-07 20:51:02 -05:00
|
|
|
|
|
|
|
this._dragPlaceholder = null;
|
|
|
|
this._dragPlaceholderPos = -1;
|
2011-01-21 06:06:13 -05:00
|
|
|
this._animatingPlaceholdersCount = 0;
|
2010-11-07 20:51:02 -05:00
|
|
|
this._favRemoveTarget = null;
|
2012-01-20 10:14:16 -05:00
|
|
|
this._showLabelTimeoutId = 0;
|
|
|
|
this._resetHoverTimeoutId = 0;
|
|
|
|
this._labelShowing = false;
|
2010-07-21 19:29:02 -04:00
|
|
|
|
|
|
|
this._box = new St.BoxLayout({ name: 'dash',
|
|
|
|
vertical: true,
|
|
|
|
clip_to_allocation: true });
|
|
|
|
this._box._delegate = this;
|
|
|
|
|
|
|
|
this.actor = new St.Bin({ y_align: St.Align.START, child: this._box });
|
|
|
|
this.actor.connect('notify::height', Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
if (this._maxHeight != this.actor.height)
|
|
|
|
this._queueRedisplay();
|
|
|
|
this._maxHeight = this.actor.height;
|
|
|
|
}));
|
|
|
|
|
|
|
|
this._workId = Main.initializeDeferredWork(this._box, Lang.bind(this, this._redisplay));
|
|
|
|
|
|
|
|
this._tracker = Shell.WindowTracker.get_default();
|
|
|
|
this._appSystem = Shell.AppSystem.get_default();
|
|
|
|
|
|
|
|
this._appSystem.connect('installed-changed', Lang.bind(this, this._queueRedisplay));
|
|
|
|
AppFavorites.getAppFavorites().connect('changed', Lang.bind(this, this._queueRedisplay));
|
apps: Ensure running apps override new .desktop file data
This patch fixes the "apps vanish from alt-TAB bug".
If a "package system" rips away and possibly replaces .desktop files
at some random time, we have historically used inotify to detect this
and reread state (in a racy way, but...). In GNOME 2, this was
generally not too problematic because the menu widget was totally
separate from the list of windows - and the data they operate on was
disjoint as well.
In GNOME 3 we unify these, and this creates architectural problems
because the windows are tied to the app.
What this patch tries to do is, when rereading the application state,
if we have a running application, we keep that app around instead of
making a new instance. This ensures we preserve any state such as the
set of open windows.
This requires moving the running state into ShellAppSystem. Adjust
callers as necessary, and while we're at it drop the unused "contexts"
stuff.
This is just a somewhat quick band-aid; a REAL fix would require us
having low-level control over application installation. As long as
we're on top of random broken tar+wget wrappers, it will be gross.
A slight future improvement to this patch would add an explicit
"merge" between the old and new data. I think probably we always keep
around the ShellApp corresponding to a given ID, but replace its
GMenuTreeEntry.
https://bugzilla.gnome.org/show_bug.cgi?id=657990
2011-09-03 10:32:06 -04:00
|
|
|
this._appSystem.connect('app-state-changed', Lang.bind(this, this._queueRedisplay));
|
2010-11-07 20:51:02 -05:00
|
|
|
|
2011-02-11 18:01:59 -05:00
|
|
|
Main.overview.connect('item-drag-begin',
|
|
|
|
Lang.bind(this, this._onDragBegin));
|
|
|
|
Main.overview.connect('item-drag-end',
|
|
|
|
Lang.bind(this, this._onDragEnd));
|
2011-03-09 10:56:08 -05:00
|
|
|
Main.overview.connect('item-drag-cancelled',
|
|
|
|
Lang.bind(this, this._onDragCancelled));
|
2011-02-11 18:01:59 -05:00
|
|
|
Main.overview.connect('window-drag-begin',
|
|
|
|
Lang.bind(this, this._onDragBegin));
|
2011-03-09 10:56:08 -05:00
|
|
|
Main.overview.connect('window-drag-cancelled',
|
|
|
|
Lang.bind(this, this._onDragCancelled));
|
2011-02-11 18:01:59 -05:00
|
|
|
Main.overview.connect('window-drag-end',
|
|
|
|
Lang.bind(this, this._onDragEnd));
|
2010-11-07 20:51:02 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_onDragBegin: function() {
|
2011-03-09 10:56:08 -05:00
|
|
|
this._dragCancelled = false;
|
2010-11-07 20:51:02 -05:00
|
|
|
this._dragMonitor = {
|
|
|
|
dragMotion: Lang.bind(this, this._onDragMotion)
|
|
|
|
};
|
|
|
|
DND.addDragMonitor(this._dragMonitor);
|
|
|
|
},
|
|
|
|
|
2011-03-09 10:56:08 -05:00
|
|
|
_onDragCancelled: function() {
|
|
|
|
this._dragCancelled = true;
|
|
|
|
this._endDrag();
|
|
|
|
},
|
|
|
|
|
2010-11-07 20:51:02 -05:00
|
|
|
_onDragEnd: function() {
|
2011-03-09 10:56:08 -05:00
|
|
|
if (this._dragCancelled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._endDrag();
|
|
|
|
},
|
|
|
|
|
|
|
|
_endDrag: function() {
|
2010-11-07 20:51:02 -05:00
|
|
|
this._clearDragPlaceholder();
|
|
|
|
if (this._favRemoveTarget) {
|
2011-01-21 06:06:13 -05:00
|
|
|
this._favRemoveTarget.animateOutAndDestroy();
|
|
|
|
this._favRemoveTarget.actor.connect('destroy', Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
this._favRemoveTarget = null;
|
|
|
|
}));
|
2011-09-19 17:47:16 -04:00
|
|
|
this._adjustIconSize();
|
2010-11-07 20:51:02 -05:00
|
|
|
}
|
2011-06-27 12:59:56 -04:00
|
|
|
DND.removeDragMonitor(this._dragMonitor);
|
2010-11-07 20:51:02 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_onDragMotion: function(dragEvent) {
|
|
|
|
let app = null;
|
|
|
|
if (dragEvent.source instanceof AppDisplay.AppWellIcon)
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 13:35:01 -04:00
|
|
|
app = this._appSystem.lookup_app(dragEvent.source.getId());
|
2011-01-30 20:25:00 -05:00
|
|
|
else if (dragEvent.source.metaWindow)
|
2010-11-07 20:51:02 -05:00
|
|
|
app = this._tracker.get_window_app(dragEvent.source.metaWindow);
|
|
|
|
else
|
|
|
|
return DND.DragMotionResult.CONTINUE;
|
|
|
|
|
|
|
|
let id = app.get_id();
|
|
|
|
|
|
|
|
let favorites = AppFavorites.getAppFavorites().getFavoriteMap();
|
|
|
|
|
|
|
|
let srcIsFavorite = (id in favorites);
|
|
|
|
|
2011-05-03 13:22:06 -04:00
|
|
|
if (srcIsFavorite &&
|
2011-11-24 15:44:49 -05:00
|
|
|
app.get_state() != Shell.AppState.RUNNING &&
|
2011-05-03 13:22:06 -04:00
|
|
|
dragEvent.source.actor &&
|
|
|
|
this.actor.contains (dragEvent.source.actor) &&
|
|
|
|
this._favRemoveTarget == null) {
|
2010-11-07 20:51:02 -05:00
|
|
|
this._favRemoveTarget = new RemoveFavoriteIcon();
|
2011-02-11 19:17:10 -05:00
|
|
|
this._favRemoveTarget.icon.setIconSize(this.iconSize);
|
2010-11-07 20:51:02 -05:00
|
|
|
this._box.add(this._favRemoveTarget.actor);
|
2010-12-16 16:13:47 -05:00
|
|
|
this._adjustIconSize();
|
2011-01-21 06:06:13 -05:00
|
|
|
this._favRemoveTarget.animateIn();
|
2010-11-07 20:51:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let favRemoveHovered = false;
|
|
|
|
if (this._favRemoveTarget)
|
|
|
|
favRemoveHovered =
|
|
|
|
this._favRemoveTarget.actor.contains(dragEvent.targetActor);
|
|
|
|
|
|
|
|
if (!this._box.contains(dragEvent.targetActor) || favRemoveHovered)
|
|
|
|
this._clearDragPlaceholder();
|
|
|
|
|
|
|
|
if (this._favRemoveTarget)
|
|
|
|
this._favRemoveTarget.setHover(favRemoveHovered);
|
|
|
|
|
|
|
|
return DND.DragMotionResult.CONTINUE;
|
|
|
|
},
|
|
|
|
|
2010-07-21 19:29:02 -04:00
|
|
|
_appIdListToHash: function(apps) {
|
|
|
|
let ids = {};
|
|
|
|
for (let i = 0; i < apps.length; i++)
|
|
|
|
ids[apps[i].get_id()] = apps[i];
|
|
|
|
return ids;
|
|
|
|
},
|
|
|
|
|
|
|
|
_queueRedisplay: function () {
|
|
|
|
Main.queueDeferredWork(this._workId);
|
|
|
|
},
|
|
|
|
|
2011-01-20 10:23:43 -05:00
|
|
|
_createAppItem: function(app) {
|
2011-01-13 10:02:55 -05:00
|
|
|
let display = new AppDisplay.AppWellIcon(app,
|
2011-01-20 09:27:13 -05:00
|
|
|
{ setSizeManually: true,
|
|
|
|
showLabel: false });
|
2010-11-07 20:51:02 -05:00
|
|
|
display._draggable.connect('drag-begin',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
display.actor.opacity = 50;
|
|
|
|
}));
|
|
|
|
display._draggable.connect('drag-end',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
display.actor.opacity = 255;
|
|
|
|
}));
|
2011-02-09 19:41:51 -05:00
|
|
|
|
2011-01-20 10:23:43 -05:00
|
|
|
let item = new DashItemContainer();
|
|
|
|
item.setChild(display.actor);
|
|
|
|
|
2011-12-16 17:46:07 -05:00
|
|
|
item.setLabelText(app.get_name());
|
2012-03-15 15:23:47 -04:00
|
|
|
// Override default AppWellIcon label_actor
|
|
|
|
display.actor.label_actor = item.label;
|
|
|
|
|
2010-11-27 16:31:14 -05:00
|
|
|
|
2011-12-16 17:46:07 -05:00
|
|
|
display.icon.setIconSize(this.iconSize);
|
|
|
|
display.actor.connect('notify::hover',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
this._onHover(item, display)
|
|
|
|
}));
|
2011-01-20 10:23:43 -05:00
|
|
|
return item;
|
2010-11-07 20:51:02 -05:00
|
|
|
},
|
|
|
|
|
2011-12-16 17:46:07 -05:00
|
|
|
_onHover: function (item, display) {
|
|
|
|
if (display.actor.get_hover() && !display.isMenuUp) {
|
2012-01-20 10:14:16 -05:00
|
|
|
if (this._showLabelTimeoutId == 0) {
|
|
|
|
let timeout = this._labelShowing ? 0 : DASH_ITEM_HOVER_TIMEOUT;
|
|
|
|
this._showLabelTimeoutId = Mainloop.timeout_add(timeout,
|
2011-12-16 17:46:07 -05:00
|
|
|
Lang.bind(this, function() {
|
2012-01-20 10:14:16 -05:00
|
|
|
this._labelShowing = true;
|
2011-12-16 17:46:07 -05:00
|
|
|
item.showLabel();
|
|
|
|
return false;
|
|
|
|
}));
|
2012-01-20 10:14:16 -05:00
|
|
|
if (this._resetHoverTimeoutId > 0) {
|
|
|
|
Mainloop.source_remove(this._resetHoverTimeoutId);
|
|
|
|
this._resetHoverTimeoutId = 0;
|
|
|
|
}
|
2011-12-16 17:46:07 -05:00
|
|
|
}
|
|
|
|
} else {
|
2012-01-20 10:14:16 -05:00
|
|
|
if (this._showLabelTimeoutId > 0)
|
|
|
|
Mainloop.source_remove(this._showLabelTimeoutId);
|
|
|
|
this._showLabelTimeoutId = 0;
|
2011-12-16 17:46:07 -05:00
|
|
|
item.hideLabel();
|
2012-01-20 10:14:16 -05:00
|
|
|
if (this._labelShowing) {
|
|
|
|
this._resetHoverTimeoutId = Mainloop.timeout_add(DASH_ITEM_HOVER_TIMEOUT,
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
this._labelShowing = false;
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
}
|
2011-12-16 17:46:07 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-11-27 16:31:14 -05:00
|
|
|
_adjustIconSize: function() {
|
2011-09-20 11:59:25 -04:00
|
|
|
// For the icon size, we only consider children which are "proper"
|
|
|
|
// icons (i.e. ignoring drag placeholders) and which are not
|
|
|
|
// animating out (which means they will be destroyed at the end of
|
|
|
|
// the animation)
|
|
|
|
let iconChildren = this._box.get_children().filter(function(actor) {
|
|
|
|
return actor._delegate.child &&
|
|
|
|
actor._delegate.child._delegate &&
|
|
|
|
actor._delegate.child._delegate.icon &&
|
|
|
|
!actor._delegate.animatingOut;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (iconChildren.length == 0) {
|
2010-11-27 16:31:14 -05:00
|
|
|
this._box.add_style_pseudo_class('empty');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._box.remove_style_pseudo_class('empty');
|
|
|
|
|
|
|
|
if (this._maxHeight == -1)
|
|
|
|
return;
|
|
|
|
|
2011-09-19 17:47:16 -04:00
|
|
|
|
2011-10-19 12:27:24 -04:00
|
|
|
let themeNode = this._box.get_theme_node();
|
2011-09-20 11:59:25 -04:00
|
|
|
let maxAllocation = new Clutter.ActorBox({ x1: 0, y1: 0,
|
|
|
|
x2: 42 /* whatever */,
|
|
|
|
y2: this._maxHeight });
|
|
|
|
let maxContent = themeNode.get_content_box(maxAllocation);
|
|
|
|
let availHeight = maxContent.y2 - maxContent.y1;
|
|
|
|
let spacing = themeNode.get_length('spacing');
|
2011-09-19 17:47:16 -04:00
|
|
|
|
2011-09-20 11:59:25 -04:00
|
|
|
|
|
|
|
let firstIcon = iconChildren[0]._delegate.child._delegate.icon;
|
|
|
|
|
2011-09-20 12:35:48 -04:00
|
|
|
let minHeight, natHeight;
|
2011-09-20 11:59:25 -04:00
|
|
|
|
2011-09-20 12:35:48 -04:00
|
|
|
// Enforce the current icon size during the size request if
|
|
|
|
// the icon is animating
|
|
|
|
if (firstIcon._animating) {
|
|
|
|
let [currentWidth, currentHeight] = firstIcon.icon.get_size();
|
2011-09-20 11:59:25 -04:00
|
|
|
|
2011-09-20 12:35:48 -04:00
|
|
|
firstIcon.icon.set_size(this.iconSize, this.iconSize);
|
|
|
|
[minHeight, natHeight] = iconChildren[0].get_preferred_height(-1);
|
|
|
|
|
|
|
|
firstIcon.icon.set_size(currentWidth, currentHeight);
|
|
|
|
} else {
|
|
|
|
[minHeight, natHeight] = iconChildren[0].get_preferred_height(-1);
|
|
|
|
}
|
2010-11-27 16:31:14 -05:00
|
|
|
|
2011-09-19 17:47:16 -04:00
|
|
|
|
2011-09-20 11:59:25 -04:00
|
|
|
// Subtract icon padding and box spacing from the available height
|
|
|
|
availHeight -= iconChildren.length * (natHeight - this.iconSize) +
|
|
|
|
(iconChildren.length - 1) * spacing;
|
2010-11-27 16:31:14 -05:00
|
|
|
|
2011-09-20 11:59:25 -04:00
|
|
|
let availSize = availHeight / iconChildren.length;
|
2011-09-19 17:47:16 -04:00
|
|
|
|
2011-02-09 17:40:48 -05:00
|
|
|
let iconSizes = [ 16, 22, 24, 32, 48, 64 ];
|
2010-11-27 16:31:14 -05:00
|
|
|
|
|
|
|
let newIconSize = 16;
|
|
|
|
for (let i = 0; i < iconSizes.length; i++) {
|
2011-09-20 11:59:25 -04:00
|
|
|
if (iconSizes[i] < availSize)
|
2010-11-27 16:31:14 -05:00
|
|
|
newIconSize = iconSizes[i];
|
|
|
|
}
|
|
|
|
|
2011-02-11 19:17:10 -05:00
|
|
|
if (newIconSize == this.iconSize)
|
2010-11-27 16:31:14 -05:00
|
|
|
return;
|
|
|
|
|
2011-02-11 19:17:10 -05:00
|
|
|
let oldIconSize = this.iconSize;
|
|
|
|
this.iconSize = newIconSize;
|
2011-08-28 09:35:13 -04:00
|
|
|
this.emit('icon-size-changed');
|
2010-11-27 16:31:14 -05:00
|
|
|
|
2011-01-21 06:06:13 -05:00
|
|
|
let scale = oldIconSize / newIconSize;
|
2010-11-27 16:31:14 -05:00
|
|
|
for (let i = 0; i < iconChildren.length; i++) {
|
2011-01-20 10:23:43 -05:00
|
|
|
let icon = iconChildren[i]._delegate.child._delegate.icon;
|
2011-01-21 06:06:13 -05:00
|
|
|
|
|
|
|
// Set the new size immediately, to keep the icons' sizes
|
2011-02-11 19:17:10 -05:00
|
|
|
// in sync with this.iconSize
|
|
|
|
icon.setIconSize(this.iconSize);
|
2011-02-09 17:55:50 -05:00
|
|
|
|
|
|
|
// Don't animate the icon size change when the overview
|
|
|
|
// is not visible or when initially filling the dash
|
|
|
|
if (!Main.overview.visible || !this._shownInitially)
|
|
|
|
continue;
|
|
|
|
|
2011-01-21 06:06:13 -05:00
|
|
|
let [targetWidth, targetHeight] = icon.icon.get_size();
|
|
|
|
|
|
|
|
// Scale the icon's texture to the previous size and
|
|
|
|
// tween to the new size
|
|
|
|
icon.icon.set_size(icon.icon.width * scale,
|
|
|
|
icon.icon.height * scale);
|
|
|
|
|
2011-09-20 12:35:48 -04:00
|
|
|
icon._animating = true;
|
2011-01-21 06:06:13 -05:00
|
|
|
Tweener.addTween(icon.icon,
|
|
|
|
{ width: targetWidth,
|
|
|
|
height: targetHeight,
|
|
|
|
time: DASH_ANIMATION_TIME,
|
2011-09-20 12:35:48 -04:00
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: function() {
|
|
|
|
icon._animating = false;
|
|
|
|
}
|
2011-01-21 06:06:13 -05:00
|
|
|
});
|
2010-11-27 16:31:14 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-07-21 19:29:02 -04:00
|
|
|
_redisplay: function () {
|
|
|
|
let favorites = AppFavorites.getAppFavorites().getFavoriteMap();
|
|
|
|
|
apps: Ensure running apps override new .desktop file data
This patch fixes the "apps vanish from alt-TAB bug".
If a "package system" rips away and possibly replaces .desktop files
at some random time, we have historically used inotify to detect this
and reread state (in a racy way, but...). In GNOME 2, this was
generally not too problematic because the menu widget was totally
separate from the list of windows - and the data they operate on was
disjoint as well.
In GNOME 3 we unify these, and this creates architectural problems
because the windows are tied to the app.
What this patch tries to do is, when rereading the application state,
if we have a running application, we keep that app around instead of
making a new instance. This ensures we preserve any state such as the
set of open windows.
This requires moving the running state into ShellAppSystem. Adjust
callers as necessary, and while we're at it drop the unused "contexts"
stuff.
This is just a somewhat quick band-aid; a REAL fix would require us
having low-level control over application installation. As long as
we're on top of random broken tar+wget wrappers, it will be gross.
A slight future improvement to this patch would add an explicit
"merge" between the old and new data. I think probably we always keep
around the ShellApp corresponding to a given ID, but replace its
GMenuTreeEntry.
https://bugzilla.gnome.org/show_bug.cgi?id=657990
2011-09-03 10:32:06 -04:00
|
|
|
let running = this._appSystem.get_running();
|
2010-07-21 19:29:02 -04:00
|
|
|
|
2011-01-13 07:44:40 -05:00
|
|
|
let children = this._box.get_children().filter(function(actor) {
|
2011-01-20 10:23:43 -05:00
|
|
|
return actor._delegate.child &&
|
|
|
|
actor._delegate.child._delegate &&
|
|
|
|
actor._delegate.child._delegate.app;
|
2011-01-13 07:44:40 -05:00
|
|
|
});
|
|
|
|
// Apps currently in the dash
|
|
|
|
let oldApps = children.map(function(actor) {
|
2011-01-20 10:23:43 -05:00
|
|
|
return actor._delegate.child._delegate.app;
|
2011-01-13 07:44:40 -05:00
|
|
|
});
|
|
|
|
// Apps supposed to be in the dash
|
|
|
|
let newApps = [];
|
|
|
|
|
|
|
|
for (let id in favorites)
|
|
|
|
newApps.push(favorites[id]);
|
2010-07-21 19:29:02 -04:00
|
|
|
|
|
|
|
for (let i = 0; i < running.length; i++) {
|
|
|
|
let app = running[i];
|
|
|
|
if (app.get_id() in favorites)
|
|
|
|
continue;
|
2011-01-13 07:44:40 -05:00
|
|
|
newApps.push(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Figure out the actual changes to the list of items; we iterate
|
|
|
|
// over both the list of items currently in the dash and the list
|
|
|
|
// of items expected there, and collect additions and removals.
|
|
|
|
// Moves are both an addition and a removal, where the order of
|
|
|
|
// the operations depends on whether we encounter the position
|
|
|
|
// where the item has been added first or the one from where it
|
|
|
|
// was removed.
|
|
|
|
// There is an assumption that only one item is moved at a given
|
|
|
|
// time; when moving several items at once, everything will still
|
|
|
|
// end up at the right position, but there might be additional
|
|
|
|
// additions/removals (e.g. it might remove all the launchers
|
|
|
|
// and add them back in the new order even if a smaller set of
|
|
|
|
// additions and removals is possible).
|
|
|
|
// If above assumptions turns out to be a problem, we might need
|
|
|
|
// to use a more sophisticated algorithm, e.g. Longest Common
|
|
|
|
// Subsequence as used by diff.
|
|
|
|
let addedItems = [];
|
|
|
|
let removedActors = [];
|
|
|
|
|
|
|
|
let newIndex = 0;
|
|
|
|
let oldIndex = 0;
|
|
|
|
while (newIndex < newApps.length || oldIndex < oldApps.length) {
|
|
|
|
// No change at oldIndex/newIndex
|
|
|
|
if (oldApps[oldIndex] == newApps[newIndex]) {
|
|
|
|
oldIndex++;
|
|
|
|
newIndex++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// App removed at oldIndex
|
|
|
|
if (oldApps[oldIndex] &&
|
|
|
|
newApps.indexOf(oldApps[oldIndex]) == -1) {
|
|
|
|
removedActors.push(children[oldIndex]);
|
|
|
|
oldIndex++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// App added at newIndex
|
|
|
|
if (newApps[newIndex] &&
|
|
|
|
oldApps.indexOf(newApps[newIndex]) == -1) {
|
|
|
|
addedItems.push({ app: newApps[newIndex],
|
2011-01-20 10:23:43 -05:00
|
|
|
item: this._createAppItem(newApps[newIndex]),
|
2011-01-13 07:44:40 -05:00
|
|
|
pos: newIndex });
|
|
|
|
newIndex++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// App moved
|
|
|
|
let insertHere = newApps[newIndex + 1] &&
|
|
|
|
newApps[newIndex + 1] == oldApps[oldIndex];
|
|
|
|
let alreadyRemoved = removedActors.reduce(function(result, actor) {
|
2011-01-20 10:23:43 -05:00
|
|
|
let removedApp = actor._delegate.child._delegate.app;
|
2011-01-13 07:44:40 -05:00
|
|
|
return result || removedApp == newApps[newIndex];
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
if (insertHere || alreadyRemoved) {
|
2011-01-20 10:23:43 -05:00
|
|
|
let newItem = this._createAppItem(newApps[newIndex]);
|
2011-01-13 07:44:40 -05:00
|
|
|
addedItems.push({ app: newApps[newIndex],
|
2011-01-20 10:23:43 -05:00
|
|
|
item: newItem,
|
2011-01-13 07:44:40 -05:00
|
|
|
pos: newIndex + removedActors.length });
|
|
|
|
newIndex++;
|
|
|
|
} else {
|
|
|
|
removedActors.push(children[oldIndex]);
|
|
|
|
oldIndex++;
|
|
|
|
}
|
2010-07-21 19:29:02 -04:00
|
|
|
}
|
|
|
|
|
2011-01-13 07:44:40 -05:00
|
|
|
for (let i = 0; i < addedItems.length; i++)
|
2012-02-13 15:27:16 -05:00
|
|
|
this._box.insert_child_at_index(addedItems[i].item.actor,
|
|
|
|
addedItems[i].pos);
|
2011-01-13 07:44:40 -05:00
|
|
|
|
2011-09-19 17:47:16 -04:00
|
|
|
for (let i = 0; i < removedActors.length; i++) {
|
|
|
|
let item = removedActors[i]._delegate;
|
2011-01-21 06:06:13 -05:00
|
|
|
|
2011-09-19 17:47:16 -04:00
|
|
|
// Don't animate item removal when the overview is hidden
|
|
|
|
if (Main.overview.visible)
|
|
|
|
item.animateOutAndDestroy();
|
|
|
|
else
|
|
|
|
item.actor.destroy();
|
|
|
|
}
|
2011-01-13 07:44:40 -05:00
|
|
|
|
2010-11-27 16:31:14 -05:00
|
|
|
this._adjustIconSize();
|
2011-01-21 06:06:13 -05:00
|
|
|
|
2011-02-02 10:44:07 -05:00
|
|
|
// Skip animations on first run when adding the initial set
|
|
|
|
// of items, to avoid all items zooming in at once
|
|
|
|
if (!this._shownInitially) {
|
|
|
|
this._shownInitially = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-06 11:46:12 -05:00
|
|
|
// Don't animate item addition when the overview is hidden
|
|
|
|
if (!Main.overview.visible)
|
|
|
|
return;
|
|
|
|
|
2011-01-21 06:06:13 -05:00
|
|
|
for (let i = 0; i < addedItems.length; i++)
|
|
|
|
addedItems[i].item.animateIn();
|
2010-07-21 19:29:02 -04:00
|
|
|
},
|
|
|
|
|
2010-11-07 20:51:02 -05:00
|
|
|
_clearDragPlaceholder: function() {
|
|
|
|
if (this._dragPlaceholder) {
|
2011-01-21 06:06:13 -05:00
|
|
|
this._dragPlaceholder.animateOutAndDestroy();
|
2010-11-07 20:51:02 -05:00
|
|
|
this._dragPlaceholder = null;
|
|
|
|
this._dragPlaceholderPos = -1;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-07-21 19:29:02 -04:00
|
|
|
handleDragOver : function(source, actor, x, y, time) {
|
|
|
|
let app = null;
|
|
|
|
if (source instanceof AppDisplay.AppWellIcon)
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 13:35:01 -04:00
|
|
|
app = this._appSystem.lookup_app(source.getId());
|
2011-01-30 20:25:00 -05:00
|
|
|
else if (source.metaWindow)
|
2010-07-21 19:29:02 -04:00
|
|
|
app = this._tracker.get_window_app(source.metaWindow);
|
|
|
|
|
|
|
|
// Don't allow favoriting of transient apps
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 13:35:01 -04:00
|
|
|
if (app == null || app.is_window_backed())
|
2010-07-21 19:29:02 -04:00
|
|
|
return DND.DragMotionResult.NO_DROP;
|
|
|
|
|
2011-01-06 08:19:44 -05:00
|
|
|
let favorites = AppFavorites.getAppFavorites().getFavorites();
|
|
|
|
let numFavorites = favorites.length;
|
|
|
|
|
|
|
|
let favPos = favorites.indexOf(app);
|
|
|
|
|
2011-01-21 06:06:13 -05:00
|
|
|
let children = this._box.get_children();
|
|
|
|
let numChildren = children.length;
|
2010-11-07 20:51:02 -05:00
|
|
|
let boxHeight = this._box.height;
|
|
|
|
|
|
|
|
// Keep the placeholder out of the index calculation; assuming that
|
|
|
|
// the remove target has the same size as "normal" items, we don't
|
|
|
|
// need to do the same adjustment there.
|
|
|
|
if (this._dragPlaceholder) {
|
2011-01-20 10:23:43 -05:00
|
|
|
boxHeight -= this._dragPlaceholder.actor.height;
|
2010-11-07 20:51:02 -05:00
|
|
|
numChildren--;
|
|
|
|
}
|
|
|
|
|
2012-01-26 09:35:31 -05:00
|
|
|
let pos = Math.floor(y * numChildren / boxHeight);
|
|
|
|
|
|
|
|
if (pos != this._dragPlaceholderPos && pos <= numFavorites && this._animatingPlaceholdersCount == 0) {
|
|
|
|
this._dragPlaceholderPos = pos;
|
2011-01-06 08:19:44 -05:00
|
|
|
|
|
|
|
// Don't allow positioning before or after self
|
2011-01-21 06:06:13 -05:00
|
|
|
if (favPos != -1 && (pos == favPos || pos == favPos + 1)) {
|
|
|
|
if (this._dragPlaceholder) {
|
|
|
|
this._dragPlaceholder.animateOutAndDestroy();
|
|
|
|
this._animatingPlaceholdersCount++;
|
|
|
|
this._dragPlaceholder.actor.connect('destroy',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
this._animatingPlaceholdersCount--;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
this._dragPlaceholder = null;
|
|
|
|
|
2011-01-06 08:19:44 -05:00
|
|
|
return DND.DragMotionResult.CONTINUE;
|
2011-01-21 06:06:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the placeholder already exists, we just move
|
|
|
|
// it, but if we are adding it, expand its size in
|
|
|
|
// an animation
|
|
|
|
let fadeIn;
|
|
|
|
if (this._dragPlaceholder) {
|
|
|
|
this._dragPlaceholder.actor.destroy();
|
|
|
|
fadeIn = false;
|
|
|
|
} else {
|
|
|
|
fadeIn = true;
|
|
|
|
}
|
2011-01-06 08:19:44 -05:00
|
|
|
|
2011-01-20 10:23:43 -05:00
|
|
|
this._dragPlaceholder = new DragPlaceholderItem();
|
2011-09-15 22:29:10 -04:00
|
|
|
this._dragPlaceholder.child.set_width (this.iconSize);
|
|
|
|
this._dragPlaceholder.child.set_height (this.iconSize / 2);
|
2012-02-13 15:27:16 -05:00
|
|
|
this._box.insert_child_at_index(this._dragPlaceholder.actor,
|
|
|
|
this._dragPlaceholderPos);
|
2011-01-21 06:06:13 -05:00
|
|
|
if (fadeIn)
|
|
|
|
this._dragPlaceholder.animateIn();
|
2010-11-07 20:51:02 -05:00
|
|
|
}
|
|
|
|
|
2012-01-26 04:20:03 -05:00
|
|
|
// Remove the drag placeholder if we are not in the
|
|
|
|
// "favorites zone"
|
|
|
|
if (pos > numFavorites && this._dragPlaceholder) {
|
|
|
|
this._clearDragPlaceholder();
|
|
|
|
}
|
|
|
|
if (!this._dragPlaceholder)
|
|
|
|
return DND.DragMotionResult.NO_DROP;
|
|
|
|
|
2011-01-06 08:19:44 -05:00
|
|
|
let srcIsFavorite = (favPos != -1);
|
2010-07-21 19:29:02 -04:00
|
|
|
|
|
|
|
if (srcIsFavorite)
|
2010-11-07 20:51:02 -05:00
|
|
|
return DND.DragMotionResult.MOVE_DROP;
|
2010-07-21 19:29:02 -04:00
|
|
|
|
|
|
|
return DND.DragMotionResult.COPY_DROP;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Draggable target interface
|
|
|
|
acceptDrop : function(source, actor, x, y, time) {
|
|
|
|
let app = null;
|
|
|
|
if (source instanceof AppDisplay.AppWellIcon) {
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 13:35:01 -04:00
|
|
|
app = this._appSystem.lookup_app(source.getId());
|
2011-01-30 20:25:00 -05:00
|
|
|
} else if (source.metaWindow) {
|
2010-07-21 19:29:02 -04:00
|
|
|
app = this._tracker.get_window_app(source.metaWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't allow favoriting of transient apps
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 13:35:01 -04:00
|
|
|
if (app == null || app.is_window_backed()) {
|
2010-07-21 19:29:02 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let id = app.get_id();
|
|
|
|
|
|
|
|
let favorites = AppFavorites.getAppFavorites().getFavoriteMap();
|
|
|
|
|
|
|
|
let srcIsFavorite = (id in favorites);
|
|
|
|
|
2010-11-07 20:51:02 -05:00
|
|
|
let favPos = 0;
|
|
|
|
let children = this._box.get_children();
|
|
|
|
for (let i = 0; i < this._dragPlaceholderPos; i++) {
|
2011-01-21 06:06:13 -05:00
|
|
|
if (this._dragPlaceholder &&
|
|
|
|
children[i] == this._dragPlaceholder.actor)
|
|
|
|
continue;
|
|
|
|
|
2011-01-20 10:23:43 -05:00
|
|
|
let childId = children[i]._delegate.child._delegate.app.get_id();
|
2010-11-07 20:51:02 -05:00
|
|
|
if (childId == id)
|
|
|
|
continue;
|
|
|
|
if (childId in favorites)
|
|
|
|
favPos++;
|
|
|
|
}
|
|
|
|
|
2012-01-26 04:20:03 -05:00
|
|
|
// No drag placeholder means we don't wan't to favorite the app
|
|
|
|
// and we are dragging it to its original position
|
|
|
|
if (!this._dragPlaceholder)
|
|
|
|
return true;
|
|
|
|
|
2010-11-07 20:51:02 -05:00
|
|
|
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this,
|
|
|
|
function () {
|
|
|
|
let appFavorites = AppFavorites.getAppFavorites();
|
|
|
|
if (srcIsFavorite)
|
|
|
|
appFavorites.moveFavoriteToPos(id, favPos);
|
|
|
|
else
|
|
|
|
appFavorites.addFavoriteAtPos(id, favPos);
|
2010-07-21 19:29:02 -04:00
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2010-07-21 19:29:02 -04:00
|
|
|
|
|
|
|
Signals.addSignalMethods(Dash.prototype);
|