2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 09:07:06 -05:00
|
|
|
/* exported AppDisplay, AppSearchProvider */
|
2008-11-20 19:53:11 -05:00
|
|
|
|
2019-02-08 22:21:36 -05:00
|
|
|
const { Clutter, Gio, GLib, GObject, Meta, Shell, St } = imports.gi;
|
2009-02-02 18:02:16 -05:00
|
|
|
const Signals = imports.signals;
|
2008-11-20 19:53:11 -05:00
|
|
|
|
2009-10-15 19:28:29 -04:00
|
|
|
const AppFavorites = imports.ui.appFavorites;
|
2013-01-31 11:13:37 -05:00
|
|
|
const BoxPointer = imports.ui.boxpointer;
|
2009-06-30 16:35:39 -04:00
|
|
|
const DND = imports.ui.dnd;
|
2014-06-11 07:13:12 -04:00
|
|
|
const GrabHelper = imports.ui.grabHelper;
|
2010-07-20 22:22:19 -04:00
|
|
|
const IconGrid = imports.ui.iconGrid;
|
2009-07-31 17:20:26 -04:00
|
|
|
const Main = imports.ui.main;
|
2019-01-22 06:10:51 -05:00
|
|
|
const PageIndicators = imports.ui.pageIndicators;
|
2010-05-20 11:18:46 -04:00
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
2017-08-21 09:20:25 -04:00
|
|
|
const Search = imports.ui.search;
|
2010-06-22 12:39:14 -04:00
|
|
|
const Params = imports.misc.params;
|
2012-06-11 13:53:32 -04:00
|
|
|
const Util = imports.misc.util;
|
2017-08-21 09:20:25 -04:00
|
|
|
const SystemActions = imports.misc.systemActions;
|
2009-04-01 15:51:17 -04:00
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const { loadInterfaceXML } = imports.misc.fileUtils;
|
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var MENU_POPUP_TIMEOUT = 600;
|
|
|
|
var MAX_COLUMNS = 6;
|
|
|
|
var MIN_COLUMNS = 4;
|
|
|
|
var MIN_ROWS = 4;
|
2009-04-23 10:41:24 -04:00
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var INACTIVE_GRID_OPACITY = 77;
|
2014-06-17 13:10:54 -04:00
|
|
|
// This time needs to be less than IconGrid.EXTRA_SPACE_ANIMATION_TIME
|
|
|
|
// to not clash with other animations
|
2019-08-01 19:13:10 -04:00
|
|
|
var INACTIVE_GRID_OPACITY_ANIMATION_TIME = 240;
|
2017-07-18 13:47:27 -04:00
|
|
|
var FOLDER_SUBICON_FRACTION = .4;
|
2013-01-31 11:13:37 -05:00
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var MIN_FREQUENT_APPS_COUNT = 3;
|
2013-05-03 12:20:21 -04:00
|
|
|
|
2019-08-01 19:13:10 -04:00
|
|
|
var VIEWS_SWITCH_TIME = 400;
|
|
|
|
var VIEWS_SWITCH_ANIMATION_DELAY = 100;
|
2017-07-18 13:23:12 -04:00
|
|
|
|
2019-08-01 19:13:10 -04:00
|
|
|
var PAGE_SWITCH_TIME = 300;
|
2013-01-31 11:13:37 -05:00
|
|
|
|
2019-06-29 13:09:32 -04:00
|
|
|
var APP_ICON_SCALE_IN_TIME = 500;
|
|
|
|
var APP_ICON_SCALE_IN_DELAY = 700;
|
|
|
|
|
2016-10-19 09:58:16 -04:00
|
|
|
const SWITCHEROO_BUS_NAME = 'net.hadess.SwitcherooControl';
|
|
|
|
const SWITCHEROO_OBJECT_PATH = '/net/hadess/SwitcherooControl';
|
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const SwitcherooProxyInterface = loadInterfaceXML('net.hadess.SwitcherooControl');
|
2016-10-19 09:58:16 -04:00
|
|
|
const SwitcherooProxy = Gio.DBusProxy.makeProxyWrapper(SwitcherooProxyInterface);
|
|
|
|
let discreteGpuAvailable = false;
|
|
|
|
|
2014-02-14 08:00:17 -05:00
|
|
|
function _getCategories(info) {
|
|
|
|
let categoriesStr = info.get_categories();
|
|
|
|
if (!categoriesStr)
|
|
|
|
return [];
|
|
|
|
return categoriesStr.split(';');
|
|
|
|
}
|
|
|
|
|
2014-01-28 12:06:11 -05:00
|
|
|
function _listsIntersect(a, b) {
|
|
|
|
for (let itemA of a)
|
2018-07-14 16:56:22 -04:00
|
|
|
if (b.includes(itemA))
|
2014-01-28 12:06:11 -05:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-15 22:24:25 -05:00
|
|
|
function _getFolderName(folder) {
|
|
|
|
let name = folder.get_string('name');
|
|
|
|
|
|
|
|
if (folder.get_boolean('translate')) {
|
|
|
|
let keyfile = new GLib.KeyFile();
|
|
|
|
let path = 'desktop-directories/' + name;
|
|
|
|
|
|
|
|
try {
|
|
|
|
keyfile.load_from_data_dirs(path, GLib.KeyFileFlags.NONE);
|
|
|
|
name = keyfile.get_locale_string('Desktop Entry', 'Name', null);
|
2019-01-28 20:26:39 -05:00
|
|
|
} catch (e) {
|
2013-12-15 22:24:25 -05:00
|
|
|
return name;
|
2013-01-31 09:16:25 -05:00
|
|
|
}
|
|
|
|
}
|
2013-12-15 22:24:25 -05:00
|
|
|
|
|
|
|
return name;
|
2014-01-13 11:39:30 -05:00
|
|
|
}
|
2013-01-31 09:16:25 -05:00
|
|
|
|
2014-04-27 11:05:10 -04:00
|
|
|
function clamp(value, min, max) {
|
|
|
|
return Math.max(min, Math.min(max, value));
|
|
|
|
}
|
|
|
|
|
2019-06-28 18:47:32 -04:00
|
|
|
function _getViewFromIcon(icon) {
|
|
|
|
let parent = icon.actor.get_parent();
|
|
|
|
if (!parent._delegate || !(parent._delegate instanceof BaseAppView))
|
|
|
|
return null;
|
|
|
|
return parent._delegate;
|
|
|
|
}
|
|
|
|
|
2019-07-16 16:51:25 -04:00
|
|
|
function _findBestFolderName(apps) {
|
|
|
|
let appInfos = apps.map(app => app.get_app_info());
|
|
|
|
|
|
|
|
let categoryCounter = {};
|
|
|
|
let commonCategories = [];
|
|
|
|
|
|
|
|
appInfos.reduce((categories, appInfo) => {
|
|
|
|
for (let category of appInfo.get_categories().split(';')) {
|
|
|
|
if (!(category in categoryCounter))
|
|
|
|
categoryCounter[category] = 0;
|
|
|
|
|
|
|
|
categoryCounter[category] += 1;
|
|
|
|
|
|
|
|
// If a category is present in all apps, its counter will
|
|
|
|
// reach appInfos.length
|
|
|
|
if (category.length > 0 &&
|
|
|
|
categoryCounter[category] == appInfos.length) {
|
|
|
|
categories.push(category);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return categories;
|
|
|
|
}, commonCategories);
|
|
|
|
|
|
|
|
for (let category of commonCategories) {
|
|
|
|
let keyfile = new GLib.KeyFile();
|
|
|
|
let path = 'desktop-directories/%s.directory'.format(category);
|
|
|
|
|
|
|
|
try {
|
|
|
|
keyfile.load_from_data_dirs(path, GLib.KeyFileFlags.NONE);
|
|
|
|
return keyfile.get_locale_string('Desktop Entry', 'Name', null);
|
|
|
|
} catch (e) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
class BaseAppView {
|
|
|
|
constructor(params, gridParams) {
|
2019-04-18 16:55:34 -04:00
|
|
|
if (this.constructor === BaseAppView)
|
|
|
|
throw new TypeError(`Cannot instantiate abstract class ${this.constructor.name}`);
|
2008-11-20 19:53:11 -05:00
|
|
|
|
2013-08-27 15:22:16 -04:00
|
|
|
gridParams = Params.parse(gridParams, { xAlign: St.Align.MIDDLE,
|
|
|
|
columnLimit: MAX_COLUMNS,
|
2013-08-27 15:23:13 -04:00
|
|
|
minRows: MIN_ROWS,
|
|
|
|
minColumns: MIN_COLUMNS,
|
2013-08-23 05:14:21 -04:00
|
|
|
fillParent: false,
|
|
|
|
padWithSpacing: true });
|
2013-08-27 15:22:16 -04:00
|
|
|
params = Params.parse(params, { usePagination: false });
|
|
|
|
|
2019-01-28 20:27:05 -05:00
|
|
|
if (params.usePagination)
|
2013-08-27 15:22:16 -04:00
|
|
|
this._grid = new IconGrid.PaginatedIconGrid(gridParams);
|
|
|
|
else
|
|
|
|
this._grid = new IconGrid.IconGrid(gridParams);
|
2010-12-18 14:18:10 -05:00
|
|
|
|
2018-08-21 05:21:26 -04:00
|
|
|
this._grid.connect('child-focused', (grid, actor) => {
|
|
|
|
this._childFocused(actor);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2013-02-19 18:38:11 -05:00
|
|
|
// Standard hack for ClutterBinLayout
|
2018-07-02 10:03:07 -04:00
|
|
|
this._grid.x_expand = true;
|
2013-02-19 18:38:11 -05:00
|
|
|
|
2013-02-19 17:23:41 -05:00
|
|
|
this._items = {};
|
|
|
|
this._allItems = [];
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-02-19 17:23:41 -05:00
|
|
|
|
2019-01-31 09:08:10 -05:00
|
|
|
_childFocused(_actor) {
|
2014-03-20 09:54:04 -04:00
|
|
|
// Nothing by default
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-03-20 09:54:04 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_redisplay() {
|
2019-07-01 22:13:07 -04:00
|
|
|
let oldApps = this._allItems.slice();
|
|
|
|
let oldAppIds = oldApps.map(icon => icon.id);
|
|
|
|
|
|
|
|
let newApps = this._loadApps().sort(this._compareItems);
|
|
|
|
let newAppIds = newApps.map(icon => icon.id);
|
|
|
|
|
|
|
|
let addedApps = newApps.filter(icon => !oldAppIds.includes(icon.id));
|
|
|
|
let removedApps = oldApps.filter(icon => !newAppIds.includes(icon.id));
|
|
|
|
|
|
|
|
// Remove old app icons
|
|
|
|
removedApps.forEach(icon => {
|
|
|
|
let iconIndex = this._allItems.indexOf(icon);
|
|
|
|
|
|
|
|
this._allItems.splice(iconIndex, 1);
|
|
|
|
this._grid.removeItem(icon);
|
|
|
|
delete this._items[icon.id];
|
|
|
|
});
|
|
|
|
|
|
|
|
// Add new app icons
|
|
|
|
addedApps.forEach(icon => {
|
|
|
|
let iconIndex = newApps.indexOf(icon);
|
|
|
|
|
|
|
|
this._allItems.splice(iconIndex, 0, icon);
|
|
|
|
this._grid.addItem(icon, iconIndex);
|
|
|
|
this._items[icon.id] = icon;
|
|
|
|
});
|
2019-07-01 22:01:59 -04:00
|
|
|
|
|
|
|
this.emit('view-loaded');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-01-28 11:11:10 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getAllItems() {
|
2014-01-28 11:36:57 -05:00
|
|
|
return this._allItems;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-01-28 11:36:57 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_compareItems(a, b) {
|
2014-01-28 11:36:57 -05:00
|
|
|
return a.name.localeCompare(b.name);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-01-28 11:36:57 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_selectAppInternal(id) {
|
2011-07-09 09:30:42 -04:00
|
|
|
if (this._items[id])
|
2018-11-27 07:58:25 -05:00
|
|
|
this._items[id].actor.navigate_focus(null, St.DirectionType.TAB_FORWARD, false);
|
2011-07-09 09:30:42 -04:00
|
|
|
else
|
2019-01-29 19:18:24 -05:00
|
|
|
log(`No such application ${id}`);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-07-09 09:30:42 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
selectApp(id) {
|
2011-07-09 09:30:42 -04:00
|
|
|
if (this._items[id] && this._items[id].actor.mapped) {
|
|
|
|
this._selectAppInternal(id);
|
|
|
|
} else if (this._items[id]) {
|
|
|
|
// Need to wait until the view is mapped
|
2017-10-30 20:38:18 -04:00
|
|
|
let signalId = this._items[id].actor.connect('notify::mapped',
|
|
|
|
actor => {
|
|
|
|
if (actor.mapped) {
|
|
|
|
actor.disconnect(signalId);
|
|
|
|
this._selectAppInternal(id);
|
|
|
|
}
|
|
|
|
});
|
2011-07-09 09:30:42 -04:00
|
|
|
} else {
|
|
|
|
// Need to wait until the view is built
|
2017-10-30 20:38:18 -04:00
|
|
|
let signalId = this.connect('view-loaded', () => {
|
2011-07-09 09:30:42 -04:00
|
|
|
this.disconnect(signalId);
|
|
|
|
this.selectApp(id);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2011-07-09 09:30:42 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-06-17 13:10:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_doSpringAnimation(animationDirection) {
|
2018-07-02 10:03:07 -04:00
|
|
|
this._grid.opacity = 255;
|
2014-06-17 13:10:54 -04:00
|
|
|
this._grid.animateSpring(animationDirection,
|
|
|
|
Main.overview.getShowAppsButton());
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-06-17 13:10:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
animate(animationDirection, onComplete) {
|
2016-11-18 03:00:01 -05:00
|
|
|
if (onComplete) {
|
2017-10-30 20:38:18 -04:00
|
|
|
let animationDoneId = this._grid.connect('animation-done', () => {
|
|
|
|
this._grid.disconnect(animationDoneId);
|
|
|
|
onComplete();
|
|
|
|
});
|
2016-11-18 03:00:01 -05:00
|
|
|
}
|
|
|
|
|
2014-06-17 13:10:54 -04:00
|
|
|
if (animationDirection == IconGrid.AnimationDirection.IN) {
|
2018-07-02 10:03:07 -04:00
|
|
|
let id = this._grid.connect('paint', () => {
|
|
|
|
this._grid.disconnect(id);
|
2017-06-01 22:22:36 -04:00
|
|
|
this._doSpringAnimation(animationDirection);
|
|
|
|
});
|
2014-06-17 13:10:54 -04:00
|
|
|
} else {
|
|
|
|
this._doSpringAnimation(animationDirection);
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-06-17 15:31:53 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
animateSwitch(animationDirection) {
|
2018-07-20 15:46:19 -04:00
|
|
|
this.actor.remove_all_transitions();
|
|
|
|
this._grid.remove_all_transitions();
|
2014-06-17 15:31:53 -04:00
|
|
|
|
2018-07-20 15:46:19 -04:00
|
|
|
let params = {
|
|
|
|
duration: VIEWS_SWITCH_TIME,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD
|
|
|
|
};
|
2014-06-17 15:31:53 -04:00
|
|
|
if (animationDirection == IconGrid.AnimationDirection.IN) {
|
|
|
|
this.actor.show();
|
|
|
|
params.opacity = 255;
|
2018-07-20 15:46:19 -04:00
|
|
|
params.delay = VIEWS_SWITCH_ANIMATION_DELAY;
|
2014-06-17 15:31:53 -04:00
|
|
|
} else {
|
|
|
|
params.opacity = 0;
|
|
|
|
params.delay = 0;
|
2019-01-27 19:42:00 -05:00
|
|
|
params.onComplete = () => this.actor.hide();
|
2014-06-17 15:31:53 -04:00
|
|
|
}
|
|
|
|
|
2018-07-20 15:46:19 -04:00
|
|
|
this._grid.ease(params);
|
2013-02-19 17:23:41 -05:00
|
|
|
}
|
2019-01-28 20:18:52 -05:00
|
|
|
}
|
2013-08-28 13:26:21 -04:00
|
|
|
Signals.addSignalMethods(BaseAppView.prototype);
|
2013-02-19 17:23:41 -05:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var AllView = class AllView extends BaseAppView {
|
|
|
|
constructor() {
|
|
|
|
super({ usePagination: true }, null);
|
2013-09-03 12:59:06 -04:00
|
|
|
this._scrollView = new St.ScrollView({ style_class: 'all-apps',
|
|
|
|
x_expand: true,
|
|
|
|
y_expand: true,
|
|
|
|
x_fill: true,
|
|
|
|
y_fill: false,
|
|
|
|
reactive: true,
|
|
|
|
y_align: St.Align.START });
|
2013-08-27 15:22:16 -04:00
|
|
|
this.actor = new St.Widget({ layout_manager: new Clutter.BinLayout(),
|
2019-01-28 20:27:05 -05:00
|
|
|
x_expand: true, y_expand: true });
|
2013-09-03 12:59:06 -04:00
|
|
|
this.actor.add_actor(this._scrollView);
|
2019-06-28 18:47:32 -04:00
|
|
|
this._grid._delegate = this;
|
2013-09-03 12:59:06 -04:00
|
|
|
|
2018-11-27 07:45:36 -05:00
|
|
|
this._scrollView.set_policy(St.PolicyType.NEVER,
|
|
|
|
St.PolicyType.EXTERNAL);
|
2013-09-03 12:59:06 -04:00
|
|
|
this._adjustment = this._scrollView.vscroll.adjustment;
|
2013-08-27 15:22:16 -04:00
|
|
|
|
2019-01-22 06:10:51 -05:00
|
|
|
this._pageIndicators = new PageIndicators.AnimatedPageIndicators();
|
2017-10-30 20:38:18 -04:00
|
|
|
this._pageIndicators.connect('page-activated',
|
|
|
|
(indicators, pageIndex) => {
|
2013-08-12 13:09:43 -04:00
|
|
|
this.goToPage(pageIndex);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2019-01-22 06:10:51 -05:00
|
|
|
this._pageIndicators.connect('scroll-event', this._onScroll.bind(this));
|
|
|
|
this.actor.add_actor(this._pageIndicators);
|
2013-08-12 13:09:43 -04:00
|
|
|
|
2013-12-15 22:24:25 -05:00
|
|
|
this.folderIcons = [];
|
2013-08-30 12:50:35 -04:00
|
|
|
|
2013-08-27 15:22:16 -04:00
|
|
|
this._stack = new St.Widget({ layout_manager: new Clutter.BinLayout() });
|
2010-12-18 14:18:10 -05:00
|
|
|
let box = new St.BoxLayout({ vertical: true });
|
2013-08-27 15:22:16 -04:00
|
|
|
|
2014-06-17 13:10:54 -04:00
|
|
|
this._grid.currentPage = 0;
|
2018-07-02 10:03:07 -04:00
|
|
|
this._stack.add_actor(this._grid);
|
2013-02-18 15:04:51 -05:00
|
|
|
this._eventBlocker = new St.Widget({ x_expand: true, y_expand: true });
|
|
|
|
this._stack.add_actor(this._eventBlocker);
|
2013-08-27 15:22:16 -04:00
|
|
|
|
|
|
|
box.add_actor(this._stack);
|
2013-09-03 12:59:06 -04:00
|
|
|
this._scrollView.add_actor(box);
|
2013-08-27 15:22:16 -04:00
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
this._scrollView.connect('scroll-event', this._onScroll.bind(this));
|
2013-02-18 15:04:51 -05:00
|
|
|
|
2013-08-12 10:36:45 -04:00
|
|
|
let panAction = new Clutter.PanAction({ interpolate: false });
|
2017-12-01 19:27:35 -05:00
|
|
|
panAction.connect('pan', this._onPan.bind(this));
|
|
|
|
panAction.connect('gesture-cancel', this._onPanEnd.bind(this));
|
|
|
|
panAction.connect('gesture-end', this._onPanEnd.bind(this));
|
2013-08-12 10:36:45 -04:00
|
|
|
this._panAction = panAction;
|
2013-09-03 12:59:06 -04:00
|
|
|
this._scrollView.add_action(panAction);
|
2013-08-12 10:36:45 -04:00
|
|
|
this._panning = false;
|
2013-02-18 15:04:51 -05:00
|
|
|
this._clickAction = new Clutter.ClickAction();
|
2017-10-30 20:38:18 -04:00
|
|
|
this._clickAction.connect('clicked', () => {
|
2013-02-18 15:04:51 -05:00
|
|
|
if (!this._currentPopup)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let [x, y] = this._clickAction.get_coords();
|
|
|
|
let actor = global.stage.get_actor_at_pos(Clutter.PickMode.ALL, x, y);
|
|
|
|
if (!this._currentPopup.actor.contains(actor))
|
|
|
|
this._currentPopup.popdown();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2013-02-18 15:04:51 -05:00
|
|
|
this._eventBlocker.add_action(this._clickAction);
|
2013-08-27 15:22:16 -04:00
|
|
|
|
2013-07-09 09:11:03 -04:00
|
|
|
this._displayingPopup = false;
|
2019-07-18 10:06:38 -04:00
|
|
|
this._currentPopupDestroyId = 0;
|
2013-07-09 09:11:03 -04:00
|
|
|
|
2013-08-27 15:22:16 -04:00
|
|
|
this._availWidth = 0;
|
|
|
|
this._availHeight = 0;
|
2013-08-19 08:02:02 -04:00
|
|
|
|
2019-01-27 19:42:00 -05:00
|
|
|
Main.overview.connect('hidden', () => this.goToPage(0));
|
2017-10-30 20:38:18 -04:00
|
|
|
this._grid.connect('space-opened', () => {
|
|
|
|
let fadeEffect = this._scrollView.get_effect('fade');
|
|
|
|
if (fadeEffect)
|
|
|
|
fadeEffect.enabled = false;
|
|
|
|
|
|
|
|
this.emit('space-ready');
|
|
|
|
});
|
|
|
|
this._grid.connect('space-closed', () => {
|
|
|
|
this._displayingPopup = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.actor.connect('notify::mapped', () => {
|
|
|
|
if (this.actor.mapped) {
|
|
|
|
this._keyPressEventId =
|
|
|
|
global.stage.connect('key-press-event',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onKeyPressEvent.bind(this));
|
2017-10-30 20:38:18 -04:00
|
|
|
} else {
|
|
|
|
if (this._keyPressEventId)
|
|
|
|
global.stage.disconnect(this._keyPressEventId);
|
|
|
|
this._keyPressEventId = 0;
|
|
|
|
}
|
|
|
|
});
|
2014-01-28 11:11:10 -05:00
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
this._redisplayWorkId = Main.initializeDeferredWork(this.actor, this._redisplay.bind(this));
|
2014-01-28 11:11:10 -05:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
Shell.AppSystem.get_default().connect('installed-changed', () => {
|
2014-01-28 11:11:10 -05:00
|
|
|
Main.queueDeferredWork(this._redisplayWorkId);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2014-06-24 15:17:09 -04:00
|
|
|
this._folderSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.app-folders' });
|
2017-10-30 20:38:18 -04:00
|
|
|
this._folderSettings.connect('changed::folder-children', () => {
|
2014-01-28 11:11:10 -05:00
|
|
|
Main.queueDeferredWork(this._redisplayWorkId);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2019-06-28 18:44:20 -04:00
|
|
|
|
2019-06-28 19:48:22 -04:00
|
|
|
Main.overview.connect('item-drag-begin', this._onDragBegin.bind(this));
|
|
|
|
Main.overview.connect('item-drag-end', this._onDragEnd.bind(this));
|
|
|
|
|
2019-06-28 18:44:20 -04:00
|
|
|
this._nEventBlockerInhibits = 0;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-01-28 11:11:10 -05:00
|
|
|
|
2019-07-18 11:13:27 -04:00
|
|
|
_redisplay() {
|
|
|
|
super._redisplay();
|
2019-07-01 22:01:59 -04:00
|
|
|
this._refilterApps();
|
2019-07-18 11:13:27 -04:00
|
|
|
}
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_itemNameChanged(item) {
|
2014-01-28 11:36:57 -05:00
|
|
|
// If an item's name changed, we can pluck it out of where it's
|
|
|
|
// supposed to be and reinsert it where it's sorted.
|
|
|
|
let oldIdx = this._allItems.indexOf(item);
|
|
|
|
this._allItems.splice(oldIdx, 1);
|
|
|
|
let newIdx = Util.insertSorted(this._allItems, item, this._compareItems);
|
|
|
|
|
|
|
|
this._grid.removeItem(item);
|
|
|
|
this._grid.addItem(item, newIdx);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-01-28 11:36:57 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_refilterApps() {
|
2019-06-29 13:09:32 -04:00
|
|
|
let filteredApps = this._allItems.filter(icon => !icon.actor.visible);
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
this._allItems.forEach(icon => {
|
2014-01-28 11:36:57 -05:00
|
|
|
if (icon instanceof AppIcon)
|
|
|
|
icon.actor.visible = true;
|
|
|
|
});
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
this.folderIcons.forEach(folder => {
|
2014-01-28 11:36:57 -05:00
|
|
|
let folderApps = folder.getAppIds();
|
2017-10-30 20:38:18 -04:00
|
|
|
folderApps.forEach(appId => {
|
2014-01-28 11:36:57 -05:00
|
|
|
let appIcon = this._items[appId];
|
|
|
|
appIcon.actor.visible = false;
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
|
|
|
});
|
2019-06-29 13:09:32 -04:00
|
|
|
|
|
|
|
// Scale in app icons that weren't visible, but now are
|
|
|
|
filteredApps.filter(icon => icon.actor.visible).forEach(icon => {
|
|
|
|
if (icon instanceof AppIcon)
|
|
|
|
icon.scaleIn();
|
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-01-28 11:36:57 -05:00
|
|
|
|
2018-12-03 07:18:19 -05:00
|
|
|
getAppInfos() {
|
|
|
|
return this._appInfoList;
|
|
|
|
}
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_loadApps() {
|
2019-07-01 22:13:07 -04:00
|
|
|
let newApps = [];
|
2018-12-19 07:26:54 -05:00
|
|
|
this._appInfoList = Shell.AppSystem.get_default().get_installed().filter(appInfo => {
|
2015-07-30 13:55:19 -04:00
|
|
|
try {
|
2019-01-31 09:04:56 -05:00
|
|
|
(appInfo.get_id()); // catch invalid file encodings
|
2019-01-28 20:26:39 -05:00
|
|
|
} catch (e) {
|
2015-07-30 13:55:19 -04:00
|
|
|
return false;
|
|
|
|
}
|
2014-01-28 11:11:10 -05:00
|
|
|
return appInfo.should_show();
|
2018-12-03 07:18:19 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
let apps = this._appInfoList.map(app => app.get_id());
|
2014-01-28 11:11:10 -05:00
|
|
|
|
|
|
|
let appSys = Shell.AppSystem.get_default();
|
|
|
|
|
2019-07-01 22:13:07 -04:00
|
|
|
this.folderIcons = [];
|
|
|
|
|
2014-01-28 11:11:10 -05:00
|
|
|
let folders = this._folderSettings.get_strv('folder-children');
|
2017-10-30 20:38:18 -04:00
|
|
|
folders.forEach(id => {
|
2014-01-28 11:36:57 -05:00
|
|
|
let path = this._folderSettings.path + 'folders/' + id + '/';
|
2019-07-30 11:15:51 -04:00
|
|
|
let icon = this._items[id];
|
|
|
|
if (!icon) {
|
|
|
|
icon = new FolderIcon(id, path, this);
|
|
|
|
icon.connect('name-changed', this._itemNameChanged.bind(this));
|
2019-07-02 12:33:07 -04:00
|
|
|
icon.connect('apps-changed', this._redisplay.bind(this));
|
2019-07-30 11:15:51 -04:00
|
|
|
}
|
2019-07-01 22:13:07 -04:00
|
|
|
newApps.push(icon);
|
2014-01-28 11:11:10 -05:00
|
|
|
this.folderIcons.push(icon);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2014-01-28 11:11:10 -05:00
|
|
|
|
2015-01-27 16:10:45 -05:00
|
|
|
// Allow dragging of the icon only if the Dash would accept a drop to
|
|
|
|
// change favorite-apps. There are no other possible drop targets from
|
|
|
|
// the app picker, so there's no other need for a drag to start,
|
|
|
|
// at least on single-monitor setups.
|
|
|
|
// This also disables drag-to-launch on multi-monitor setups,
|
|
|
|
// but we hope that is not used much.
|
2015-03-20 15:30:57 -04:00
|
|
|
let favoritesWritable = global.settings.is_writable('favorite-apps');
|
2015-01-27 16:10:45 -05:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
apps.forEach(appId => {
|
2014-01-28 11:11:10 -05:00
|
|
|
let app = appSys.lookup_app(appId);
|
2015-01-27 16:10:45 -05:00
|
|
|
|
|
|
|
let icon = new AppIcon(app,
|
|
|
|
{ isDraggable: favoritesWritable });
|
2019-07-01 22:13:07 -04:00
|
|
|
newApps.push(icon);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2019-07-01 22:13:07 -04:00
|
|
|
|
|
|
|
return newApps;
|
2019-06-29 12:22:08 -04:00
|
|
|
}
|
2014-01-28 11:11:10 -05:00
|
|
|
|
2019-05-15 15:32:29 -04:00
|
|
|
// Overridden from BaseAppView
|
2017-10-30 20:03:21 -04:00
|
|
|
animate(animationDirection, onComplete) {
|
2015-03-04 04:29:22 -05:00
|
|
|
this._scrollView.reactive = false;
|
2017-10-30 20:38:18 -04:00
|
|
|
let completionFunc = () => {
|
2015-03-04 04:29:22 -05:00
|
|
|
this._scrollView.reactive = true;
|
2015-03-04 12:58:14 -05:00
|
|
|
if (onComplete)
|
|
|
|
onComplete();
|
2017-10-30 20:38:18 -04:00
|
|
|
};
|
2015-03-04 04:29:22 -05:00
|
|
|
|
2014-06-17 13:10:54 -04:00
|
|
|
if (animationDirection == IconGrid.AnimationDirection.OUT &&
|
|
|
|
this._displayingPopup && this._currentPopup) {
|
|
|
|
this._currentPopup.popdown();
|
2017-10-30 20:38:18 -04:00
|
|
|
let spaceClosedId = this._grid.connect('space-closed', () => {
|
|
|
|
this._grid.disconnect(spaceClosedId);
|
2017-10-30 21:19:44 -04:00
|
|
|
super.animate(animationDirection, completionFunc);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2014-06-17 13:10:54 -04:00
|
|
|
} else {
|
2017-10-30 21:19:44 -04:00
|
|
|
super.animate(animationDirection, completionFunc);
|
2014-06-17 15:31:53 -04:00
|
|
|
if (animationDirection == IconGrid.AnimationDirection.OUT)
|
|
|
|
this._pageIndicators.animateIndicators(animationDirection);
|
2014-06-17 13:10:54 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-06-17 13:10:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
animateSwitch(animationDirection) {
|
2017-10-30 21:19:44 -04:00
|
|
|
super.animateSwitch(animationDirection);
|
2014-06-17 15:31:53 -04:00
|
|
|
|
|
|
|
if (this._currentPopup && this._displayingPopup &&
|
|
|
|
animationDirection == IconGrid.AnimationDirection.OUT)
|
2018-07-20 15:46:19 -04:00
|
|
|
this._currentPopup.actor.ease({
|
|
|
|
opacity: 0,
|
|
|
|
duration: VIEWS_SWITCH_TIME,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
2019-08-19 16:20:35 -04:00
|
|
|
onComplete: () => (this.opacity = 255)
|
2018-07-20 15:46:19 -04:00
|
|
|
});
|
2014-06-17 15:31:53 -04:00
|
|
|
|
|
|
|
if (animationDirection == IconGrid.AnimationDirection.OUT)
|
|
|
|
this._pageIndicators.animateIndicators(animationDirection);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-06-17 15:31:53 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getCurrentPageY() {
|
2014-06-17 13:10:54 -04:00
|
|
|
return this._grid.getPageY(this._grid.currentPage);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-30 12:50:35 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
goToPage(pageNumber) {
|
2014-04-27 11:05:10 -04:00
|
|
|
pageNumber = clamp(pageNumber, 0, this._grid.nPages() - 1);
|
|
|
|
|
2014-06-17 13:10:54 -04:00
|
|
|
if (this._grid.currentPage == pageNumber && this._displayingPopup && this._currentPopup)
|
2013-07-09 09:11:03 -04:00
|
|
|
return;
|
|
|
|
if (this._displayingPopup && this._currentPopup)
|
|
|
|
this._currentPopup.popdown();
|
|
|
|
|
2019-07-25 21:04:38 -04:00
|
|
|
if (!this.actor.mapped) {
|
|
|
|
this._adjustment.value = this._grid.getPageY(pageNumber);
|
|
|
|
this._pageIndicators.setCurrentPage(pageNumber);
|
2019-08-06 18:41:54 -04:00
|
|
|
this._grid.currentPage = pageNumber;
|
2019-07-25 21:04:38 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-12 10:36:45 -04:00
|
|
|
let velocity;
|
|
|
|
if (!this._panning)
|
|
|
|
velocity = 0;
|
|
|
|
else
|
|
|
|
velocity = Math.abs(this._panAction.get_velocity(0)[2]);
|
|
|
|
// Tween the change between pages.
|
|
|
|
// If velocity is not specified (i.e. scrolling with mouse wheel),
|
|
|
|
// use the same speed regardless of original position
|
|
|
|
// if velocity is specified, it's in pixels per milliseconds
|
|
|
|
let diffToPage = this._diffToPage(pageNumber);
|
2013-09-03 12:59:06 -04:00
|
|
|
let childBox = this._scrollView.get_allocation_box();
|
2013-08-12 10:36:45 -04:00
|
|
|
let totalHeight = childBox.y2 - childBox.y1;
|
|
|
|
let time;
|
|
|
|
// Only take the velocity into account on page changes, otherwise
|
|
|
|
// return smoothly to the current page using the default velocity
|
2014-06-17 13:10:54 -04:00
|
|
|
if (this._grid.currentPage != pageNumber) {
|
2019-08-01 19:13:10 -04:00
|
|
|
let minVelocity = totalHeight / PAGE_SWITCH_TIME;
|
2013-08-12 10:36:45 -04:00
|
|
|
velocity = Math.max(minVelocity, velocity);
|
2019-08-01 19:13:10 -04:00
|
|
|
time = diffToPage / velocity;
|
2013-08-12 10:36:45 -04:00
|
|
|
} else {
|
|
|
|
time = PAGE_SWITCH_TIME * diffToPage / totalHeight;
|
|
|
|
}
|
|
|
|
// When changing more than one page, make sure to not take
|
|
|
|
// longer than PAGE_SWITCH_TIME
|
|
|
|
time = Math.min(time, PAGE_SWITCH_TIME);
|
|
|
|
|
2014-06-17 13:10:54 -04:00
|
|
|
this._grid.currentPage = pageNumber;
|
2019-07-24 15:03:17 -04:00
|
|
|
this._adjustment.ease(this._grid.getPageY(pageNumber), {
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
|
|
|
duration: time
|
|
|
|
});
|
|
|
|
|
2014-04-27 11:02:45 -04:00
|
|
|
this._pageIndicators.setCurrentPage(pageNumber);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-12 10:36:45 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_diffToPage(pageNumber) {
|
2013-09-03 12:59:06 -04:00
|
|
|
let currentScrollPosition = this._adjustment.value;
|
2013-08-12 10:36:45 -04:00
|
|
|
return Math.abs(currentScrollPosition - this._grid.getPageY(pageNumber));
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-02-18 15:04:51 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
openSpaceForPopup(item, side, nRows) {
|
2013-07-09 09:11:03 -04:00
|
|
|
this._updateIconOpacities(true);
|
|
|
|
this._displayingPopup = true;
|
|
|
|
this._grid.openExtraSpace(item, side, nRows);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-07-09 09:11:03 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_closeSpaceForPopup() {
|
2013-07-09 09:11:03 -04:00
|
|
|
this._updateIconOpacities(false);
|
2017-06-15 07:43:58 -04:00
|
|
|
|
|
|
|
let fadeEffect = this._scrollView.get_effect('fade');
|
|
|
|
if (fadeEffect)
|
|
|
|
fadeEffect.enabled = true;
|
|
|
|
|
2013-07-09 09:11:03 -04:00
|
|
|
this._grid.closeExtraSpace();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-07-09 09:11:03 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onScroll(actor, event) {
|
2015-03-04 04:29:22 -05:00
|
|
|
if (this._displayingPopup || !this._scrollView.reactive)
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_STOP;
|
2013-09-13 12:53:02 -04:00
|
|
|
|
2013-08-27 15:22:16 -04:00
|
|
|
let direction = event.get_scroll_direction();
|
2013-09-13 12:53:02 -04:00
|
|
|
if (direction == Clutter.ScrollDirection.UP)
|
2014-06-17 13:10:54 -04:00
|
|
|
this.goToPage(this._grid.currentPage - 1);
|
2013-09-13 12:53:02 -04:00
|
|
|
else if (direction == Clutter.ScrollDirection.DOWN)
|
2014-06-17 13:10:54 -04:00
|
|
|
this.goToPage(this._grid.currentPage + 1);
|
2013-09-13 12:53:02 -04:00
|
|
|
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_STOP;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2008-12-19 23:27:57 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onPan(action) {
|
2013-07-09 09:11:03 -04:00
|
|
|
if (this._displayingPopup)
|
|
|
|
return false;
|
2013-08-12 10:36:45 -04:00
|
|
|
this._panning = true;
|
|
|
|
this._clickAction.release();
|
2019-01-31 09:08:00 -05:00
|
|
|
let [dist_, dx_, dy] = action.get_motion_delta(0);
|
2013-09-03 12:59:06 -04:00
|
|
|
let adjustment = this._adjustment;
|
|
|
|
adjustment.value -= (dy / this._scrollView.height) * adjustment.page_size;
|
2013-08-12 10:36:45 -04:00
|
|
|
return false;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-12 10:36:45 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onPanEnd(action) {
|
2019-01-29 14:36:54 -05:00
|
|
|
if (this._displayingPopup)
|
2013-07-09 09:11:03 -04:00
|
|
|
return;
|
appDisplay: Make page panning smoother on touch
Currently, our logic for page panning isn't great. If the user starts a
pan upwards and hesitates over a new page, we'll go to the *next* page
on release, since the difference is greater, but the velocity wound down
to 0.
Instead of trying to treat it like page down or scrolls, simply do the
math to find the page where the user scrolled to.
This is unfortunately broken for fast swipes, since the user doesn't get
far enough into the new page to make a difference. I'm getting the
impression we'll need a gesture recognizer for this, though, however
crude. Simple hacks I tried, like a velocity multiplier, didn't work
properly.
https://bugzilla.gnome.org/show_bug.cgi?id=729064
2014-04-27 11:18:04 -04:00
|
|
|
|
|
|
|
let pageHeight = this._grid.getPageHeight();
|
|
|
|
|
|
|
|
// Calculate the scroll value we'd be at, which is our current
|
|
|
|
// scroll plus any velocity the user had when they released
|
|
|
|
// their finger.
|
|
|
|
|
|
|
|
let velocity = -action.get_velocity(0)[2];
|
|
|
|
let endPanValue = this._adjustment.value + velocity;
|
|
|
|
|
|
|
|
let closestPage = Math.round(endPanValue / pageHeight);
|
|
|
|
this.goToPage(closestPage);
|
|
|
|
|
2013-08-12 10:36:45 -04:00
|
|
|
this._panning = false;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-12 10:36:45 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onKeyPressEvent(actor, event) {
|
2013-09-12 11:20:07 -04:00
|
|
|
if (this._displayingPopup)
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_STOP;
|
2013-09-12 11:20:07 -04:00
|
|
|
|
|
|
|
if (event.get_key_symbol() == Clutter.Page_Up) {
|
2014-06-17 13:10:54 -04:00
|
|
|
this.goToPage(this._grid.currentPage - 1);
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_STOP;
|
2013-09-12 11:20:07 -04:00
|
|
|
} else if (event.get_key_symbol() == Clutter.Page_Down) {
|
2014-06-17 13:10:54 -04:00
|
|
|
this.goToPage(this._grid.currentPage + 1);
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_STOP;
|
2013-09-12 11:20:07 -04:00
|
|
|
}
|
|
|
|
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-09-12 11:20:07 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
addFolderPopup(popup) {
|
2013-02-18 14:19:18 -05:00
|
|
|
this._stack.add_actor(popup.actor);
|
2017-10-30 20:38:18 -04:00
|
|
|
popup.connect('open-state-changed', (popup, isOpen) => {
|
|
|
|
this._eventBlocker.reactive = isOpen;
|
2019-07-18 10:06:38 -04:00
|
|
|
|
|
|
|
if (this._currentPopup) {
|
|
|
|
this._currentPopup.actor.disconnect(this._currentPopupDestroyId);
|
|
|
|
this._currentPopupDestroyId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._currentPopup = null;
|
|
|
|
|
|
|
|
if (isOpen) {
|
|
|
|
this._currentPopup = popup;
|
|
|
|
this._currentPopupDestroyId = popup.actor.connect('destroy', () => {
|
|
|
|
this._currentPopup = null;
|
|
|
|
this._currentPopupDestroyId = 0;
|
|
|
|
this._eventBlocker.reactive = false;
|
|
|
|
});
|
|
|
|
}
|
2017-10-30 20:38:18 -04:00
|
|
|
this._updateIconOpacities(isOpen);
|
2019-01-28 20:27:05 -05:00
|
|
|
if (!isOpen)
|
2017-10-30 20:38:18 -04:00
|
|
|
this._closeSpaceForPopup();
|
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-02-18 14:19:18 -05:00
|
|
|
|
2018-08-21 05:21:26 -04:00
|
|
|
_childFocused(icon) {
|
2013-08-27 15:22:16 -04:00
|
|
|
let itemPage = this._grid.getItemPage(icon);
|
|
|
|
this.goToPage(itemPage);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-27 15:22:16 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateIconOpacities(folderOpen) {
|
2013-02-18 15:04:51 -05:00
|
|
|
for (let id in this._items) {
|
2018-07-20 15:46:19 -04:00
|
|
|
let opacity;
|
2013-02-18 15:04:51 -05:00
|
|
|
if (folderOpen && !this._items[id].actor.checked)
|
2013-08-22 11:31:41 -04:00
|
|
|
opacity = INACTIVE_GRID_OPACITY;
|
2013-02-18 15:04:51 -05:00
|
|
|
else
|
2013-08-22 11:31:41 -04:00
|
|
|
opacity = 255;
|
2018-07-20 15:46:19 -04:00
|
|
|
this._items[id].actor.ease({
|
|
|
|
opacity: opacity,
|
|
|
|
duration: INACTIVE_GRID_OPACITY_ANIMATION_TIME,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD
|
|
|
|
});
|
2013-02-18 15:04:51 -05:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-27 15:22:16 -04:00
|
|
|
|
|
|
|
// Called before allocation to calculate dynamic spacing
|
2017-10-30 20:03:21 -04:00
|
|
|
adaptToSize(width, height) {
|
2013-08-27 15:22:16 -04:00
|
|
|
let box = new Clutter.ActorBox();
|
|
|
|
box.x1 = 0;
|
|
|
|
box.x2 = width;
|
|
|
|
box.y1 = 0;
|
|
|
|
box.y2 = height;
|
|
|
|
box = this.actor.get_theme_node().get_content_box(box);
|
2013-09-03 12:59:06 -04:00
|
|
|
box = this._scrollView.get_theme_node().get_content_box(box);
|
2018-07-02 10:03:07 -04:00
|
|
|
box = this._grid.get_theme_node().get_content_box(box);
|
2013-08-27 15:22:16 -04:00
|
|
|
let availWidth = box.x2 - box.x1;
|
|
|
|
let availHeight = box.y2 - box.y1;
|
|
|
|
let oldNPages = this._grid.nPages();
|
|
|
|
|
2013-08-15 04:38:17 -04:00
|
|
|
this._grid.adaptToSize(availWidth, availHeight);
|
|
|
|
|
2013-09-03 12:59:06 -04:00
|
|
|
let fadeOffset = Math.min(this._grid.topPadding,
|
|
|
|
this._grid.bottomPadding);
|
|
|
|
this._scrollView.update_fade_effect(fadeOffset, 0);
|
2015-06-10 10:05:41 -04:00
|
|
|
if (fadeOffset > 0)
|
|
|
|
this._scrollView.get_effect('fade').fade_edges = true;
|
2013-09-03 12:59:06 -04:00
|
|
|
|
2013-08-12 13:09:43 -04:00
|
|
|
if (this._availWidth != availWidth || this._availHeight != availHeight || oldNPages != this._grid.nPages()) {
|
2017-10-30 20:38:18 -04:00
|
|
|
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => {
|
2019-06-17 06:59:01 -04:00
|
|
|
this._adjustment.value = 0;
|
|
|
|
this._grid.currentPage = 0;
|
2017-10-30 20:38:18 -04:00
|
|
|
this._pageIndicators.setNPages(this._grid.nPages());
|
|
|
|
this._pageIndicators.setCurrentPage(0);
|
2019-07-22 14:37:33 -04:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2013-08-12 13:09:43 -04:00
|
|
|
}
|
2013-08-27 15:22:16 -04:00
|
|
|
|
|
|
|
this._availWidth = availWidth;
|
|
|
|
this._availHeight = availHeight;
|
2013-08-30 12:50:35 -04:00
|
|
|
// Update folder views
|
2013-12-15 22:24:25 -05:00
|
|
|
for (let i = 0; i < this.folderIcons.length; i++)
|
|
|
|
this.folderIcons[i].adaptToSize(availWidth, availHeight);
|
2009-03-20 12:06:34 -04:00
|
|
|
}
|
2019-06-28 18:44:20 -04:00
|
|
|
|
2019-06-28 19:48:22 -04:00
|
|
|
_handleDragOvershoot(dragEvent) {
|
|
|
|
let [, gridY] = this.actor.get_transformed_position();
|
|
|
|
let [, gridHeight] = this.actor.get_transformed_size();
|
|
|
|
let gridBottom = gridY + gridHeight;
|
|
|
|
|
|
|
|
// Within the grid boundaries, or already animating
|
|
|
|
if (dragEvent.y > gridY && dragEvent.y < gridBottom ||
|
|
|
|
this._adjustment.get_transition('value') != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Moving above the grid
|
|
|
|
let currentY = this._adjustment.value;
|
|
|
|
if (dragEvent.y <= gridY && currentY > 0) {
|
|
|
|
this.goToPage(this._grid.currentPage - 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Moving below the grid
|
|
|
|
let maxY = this._adjustment.upper - this._adjustment.page_size;
|
|
|
|
if (dragEvent.y >= gridBottom && currentY < maxY) {
|
|
|
|
this.goToPage(this._grid.currentPage + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_onDragBegin() {
|
|
|
|
this._dragMonitor = {
|
|
|
|
dragMotion: this._onDragMotion.bind(this)
|
|
|
|
};
|
|
|
|
DND.addDragMonitor(this._dragMonitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onDragMotion(dragEvent) {
|
|
|
|
if (!(dragEvent.source instanceof AppIcon))
|
|
|
|
return DND.DragMotionResult.CONTINUE;
|
|
|
|
|
|
|
|
let appIcon = dragEvent.source;
|
|
|
|
|
|
|
|
// Handle the drag overshoot. When dragging to above the
|
|
|
|
// icon grid, move to the page above; when dragging below,
|
|
|
|
// move to the page below.
|
|
|
|
if (this._grid.contains(appIcon.actor))
|
|
|
|
this._handleDragOvershoot(dragEvent);
|
|
|
|
|
|
|
|
return DND.DragMotionResult.CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
_onDragEnd() {
|
|
|
|
if (this._dragMonitor) {
|
|
|
|
DND.removeDragMonitor(this._dragMonitor);
|
|
|
|
this._dragMonitor = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-29 00:26:08 -04:00
|
|
|
_canAccept(source) {
|
|
|
|
if (!(source instanceof AppIcon))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
let view = _getViewFromIcon(source);
|
|
|
|
if (!(view instanceof FolderView))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
handleDragOver(source) {
|
|
|
|
if (!this._canAccept(source))
|
|
|
|
return DND.DragMotionResult.NO_DROP;
|
|
|
|
|
|
|
|
return DND.DragMotionResult.MOVE_DROP;
|
|
|
|
}
|
|
|
|
|
|
|
|
acceptDrop(source) {
|
|
|
|
if (!this._canAccept(source))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
let view = _getViewFromIcon(source);
|
|
|
|
view.removeApp(source.app);
|
|
|
|
|
|
|
|
if (this._currentPopup)
|
|
|
|
this._currentPopup.popdown();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-28 18:44:20 -04:00
|
|
|
inhibitEventBlocker() {
|
|
|
|
this._nEventBlockerInhibits++;
|
|
|
|
this._eventBlocker.visible = this._nEventBlockerInhibits == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uninhibitEventBlocker() {
|
|
|
|
if (this._nEventBlockerInhibits === 0)
|
|
|
|
throw new Error('Not inhibited');
|
|
|
|
|
|
|
|
this._nEventBlockerInhibits--;
|
|
|
|
this._eventBlocker.visible = this._nEventBlockerInhibits == 0;
|
|
|
|
}
|
2019-07-16 16:51:25 -04:00
|
|
|
|
|
|
|
createFolder(apps) {
|
|
|
|
let newFolderId = GLib.uuid_string_random();
|
|
|
|
|
|
|
|
let folders = this._folderSettings.get_strv('folder-children');
|
|
|
|
folders.push(newFolderId);
|
|
|
|
this._folderSettings.set_strv('folder-children', folders);
|
|
|
|
|
|
|
|
// Create the new folder
|
|
|
|
let newFolderPath = this._folderSettings.path.concat('folders/', newFolderId, '/');
|
|
|
|
let newFolderSettings = new Gio.Settings({
|
|
|
|
schema_id: 'org.gnome.desktop.app-folders.folder',
|
|
|
|
path: newFolderPath
|
|
|
|
});
|
|
|
|
if (!newFolderSettings) {
|
|
|
|
log('Error creating new folder');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let appItems = apps.map(id => this._items[id].app);
|
|
|
|
let folderName = _findBestFolderName(appItems);
|
|
|
|
if (!folderName)
|
|
|
|
folderName = _("Unnamed Folder");
|
|
|
|
|
|
|
|
newFolderSettings.delay();
|
|
|
|
newFolderSettings.set_string('name', folderName);
|
|
|
|
newFolderSettings.set_strv('apps', apps);
|
|
|
|
newFolderSettings.apply();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2013-07-09 09:11:03 -04:00
|
|
|
Signals.addSignalMethods(AllView.prototype);
|
2008-11-20 19:53:11 -05:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var FrequentView = class FrequentView extends BaseAppView {
|
|
|
|
constructor() {
|
|
|
|
super(null, { fillParent: true });
|
2015-01-27 16:10:45 -05:00
|
|
|
|
2013-02-21 22:29:57 -05:00
|
|
|
this.actor = new St.Widget({ style_class: 'frequent-apps',
|
2013-05-03 12:20:21 -04:00
|
|
|
layout_manager: new Clutter.BinLayout(),
|
2013-02-21 22:29:57 -05:00
|
|
|
x_expand: true, y_expand: true });
|
2013-05-03 12:20:21 -04:00
|
|
|
|
|
|
|
this._noFrequentAppsLabel = new St.Label({ text: _("Frequently used applications will appear here"),
|
|
|
|
style_class: 'no-frequent-applications-label',
|
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
x_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
|
|
y_expand: true });
|
|
|
|
|
2018-07-02 10:03:07 -04:00
|
|
|
this._grid.y_expand = true;
|
2013-05-03 12:20:21 -04:00
|
|
|
|
2018-07-02 10:03:07 -04:00
|
|
|
this.actor.add_actor(this._grid);
|
2013-05-03 12:20:21 -04:00
|
|
|
this.actor.add_actor(this._noFrequentAppsLabel);
|
|
|
|
this._noFrequentAppsLabel.hide();
|
2013-02-18 14:18:08 -05:00
|
|
|
|
|
|
|
this._usage = Shell.AppUsage.get_default();
|
2014-01-28 11:06:21 -05:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
this.actor.connect('notify::mapped', () => {
|
2014-01-28 11:06:21 -05:00
|
|
|
if (this.actor.mapped)
|
|
|
|
this._redisplay();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-02-18 14:18:08 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
hasUsefulData() {
|
2012-04-09 02:27:47 -04:00
|
|
|
return this._usage.get_most_used().length >= MIN_FREQUENT_APPS_COUNT;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-30 14:25:19 -04:00
|
|
|
|
2019-06-29 12:15:20 -04:00
|
|
|
_compareItems() {
|
|
|
|
// The FrequentView does not need to be sorted alphabetically
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_loadApps() {
|
2019-07-01 22:13:07 -04:00
|
|
|
let apps = [];
|
2012-04-09 02:27:47 -04:00
|
|
|
let mostUsed = this._usage.get_most_used();
|
2013-08-30 14:25:19 -04:00
|
|
|
let hasUsefulData = this.hasUsefulData();
|
2013-05-03 12:20:21 -04:00
|
|
|
this._noFrequentAppsLabel.visible = !hasUsefulData;
|
2019-01-28 20:27:05 -05:00
|
|
|
if (!hasUsefulData)
|
2019-07-01 22:13:07 -04:00
|
|
|
return [];
|
2013-05-03 12:20:21 -04:00
|
|
|
|
2015-01-27 16:10:45 -05:00
|
|
|
// Allow dragging of the icon only if the Dash would accept a drop to
|
|
|
|
// change favorite-apps. There are no other possible drop targets from
|
|
|
|
// the app picker, so there's no other need for a drag to start,
|
|
|
|
// at least on single-monitor setups.
|
|
|
|
// This also disables drag-to-launch on multi-monitor setups,
|
|
|
|
// but we hope that is not used much.
|
2015-03-20 15:30:57 -04:00
|
|
|
let favoritesWritable = global.settings.is_writable('favorite-apps');
|
2015-01-27 16:10:45 -05:00
|
|
|
|
2013-02-18 14:18:08 -05:00
|
|
|
for (let i = 0; i < mostUsed.length; i++) {
|
2013-03-31 14:05:49 -04:00
|
|
|
if (!mostUsed[i].get_app_info().should_show())
|
|
|
|
continue;
|
2015-01-27 16:10:45 -05:00
|
|
|
let appIcon = new AppIcon(mostUsed[i],
|
|
|
|
{ isDraggable: favoritesWritable });
|
2019-07-01 22:13:07 -04:00
|
|
|
apps.push(appIcon);
|
2013-02-18 14:18:08 -05:00
|
|
|
}
|
2019-07-01 22:13:07 -04:00
|
|
|
|
|
|
|
return apps;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-27 15:22:16 -04:00
|
|
|
|
|
|
|
// Called before allocation to calculate dynamic spacing
|
2017-10-30 20:03:21 -04:00
|
|
|
adaptToSize(width, height) {
|
2013-08-27 15:22:16 -04:00
|
|
|
let box = new Clutter.ActorBox();
|
|
|
|
box.x1 = box.y1 = 0;
|
|
|
|
box.x2 = width;
|
|
|
|
box.y2 = height;
|
|
|
|
box = this.actor.get_theme_node().get_content_box(box);
|
2018-07-02 10:03:07 -04:00
|
|
|
box = this._grid.get_theme_node().get_content_box(box);
|
2013-08-27 15:22:16 -04:00
|
|
|
let availWidth = box.x2 - box.x1;
|
|
|
|
let availHeight = box.y2 - box.y1;
|
2013-08-15 04:38:17 -04:00
|
|
|
this._grid.adaptToSize(availWidth, availHeight);
|
2013-02-18 14:18:08 -05:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2013-02-18 14:18:08 -05:00
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var Views = {
|
2013-02-18 14:18:08 -05:00
|
|
|
FREQUENT: 0,
|
|
|
|
ALL: 1
|
|
|
|
};
|
|
|
|
|
2017-10-30 21:23:39 -04:00
|
|
|
var ControlsBoxLayout = GObject.registerClass(
|
|
|
|
class ControlsBoxLayout extends Clutter.BoxLayout {
|
2013-05-24 06:03:00 -04:00
|
|
|
/**
|
|
|
|
* Override the BoxLayout behavior to use the maximum preferred width of all
|
|
|
|
* buttons for each child
|
|
|
|
*/
|
2017-10-30 20:03:21 -04:00
|
|
|
vfunc_get_preferred_width(container, forHeight) {
|
2013-05-24 06:03:00 -04:00
|
|
|
let maxMinWidth = 0;
|
|
|
|
let maxNaturalWidth = 0;
|
|
|
|
for (let child = container.get_first_child();
|
2019-01-29 14:36:54 -05:00
|
|
|
child;
|
|
|
|
child = child.get_next_sibling()) {
|
|
|
|
let [minWidth, natWidth] = child.get_preferred_width(forHeight);
|
|
|
|
maxMinWidth = Math.max(maxMinWidth, minWidth);
|
|
|
|
maxNaturalWidth = Math.max(maxNaturalWidth, natWidth);
|
2013-05-24 06:03:00 -04:00
|
|
|
}
|
|
|
|
let childrenCount = container.get_n_children();
|
|
|
|
let totalSpacing = this.spacing * (childrenCount - 1);
|
|
|
|
return [maxMinWidth * childrenCount + totalSpacing,
|
|
|
|
maxNaturalWidth * childrenCount + totalSpacing];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-30 21:23:39 -04:00
|
|
|
var ViewStackLayout = GObject.registerClass({
|
2017-02-14 12:24:50 -05:00
|
|
|
Signals: { 'allocated-size-changed': { param_types: [GObject.TYPE_INT,
|
|
|
|
GObject.TYPE_INT] } },
|
2017-10-30 21:23:39 -04:00
|
|
|
}, class ViewStackLayout extends Clutter.BinLayout {
|
2017-10-30 20:03:21 -04:00
|
|
|
vfunc_allocate(actor, box, flags) {
|
2013-08-27 15:22:16 -04:00
|
|
|
let availWidth = box.x2 - box.x1;
|
|
|
|
let availHeight = box.y2 - box.y1;
|
|
|
|
// Prepare children of all views for the upcoming allocation, calculate all
|
|
|
|
// the needed values to adapt available size
|
|
|
|
this.emit('allocated-size-changed', availWidth, availHeight);
|
2017-10-30 21:23:39 -04:00
|
|
|
super.vfunc_allocate(actor, box, flags);
|
2013-08-27 15:22:16 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var AppDisplay = class AppDisplay {
|
|
|
|
constructor() {
|
2014-06-24 15:17:09 -04:00
|
|
|
this._privacySettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.privacy' });
|
2013-03-01 18:56:18 -05:00
|
|
|
this._privacySettings.connect('changed::remember-app-usage',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._updateFrequentVisibility.bind(this));
|
2013-01-30 17:58:42 -05:00
|
|
|
|
2013-02-18 14:18:08 -05:00
|
|
|
this._views = [];
|
|
|
|
|
|
|
|
let view, button;
|
|
|
|
view = new FrequentView();
|
|
|
|
button = new St.Button({ label: _("Frequent"),
|
2015-01-16 09:33:56 -05:00
|
|
|
style_class: 'app-view-control button',
|
2013-02-18 14:18:08 -05:00
|
|
|
can_focus: true,
|
|
|
|
x_expand: true });
|
|
|
|
this._views[Views.FREQUENT] = { 'view': view, 'control': button };
|
|
|
|
|
|
|
|
view = new AllView();
|
|
|
|
button = new St.Button({ label: _("All"),
|
2015-01-16 09:33:56 -05:00
|
|
|
style_class: 'app-view-control button',
|
2013-02-18 14:18:08 -05:00
|
|
|
can_focus: true,
|
|
|
|
x_expand: true });
|
|
|
|
this._views[Views.ALL] = { 'view': view, 'control': button };
|
|
|
|
|
2013-08-27 15:22:16 -04:00
|
|
|
this.actor = new St.BoxLayout ({ style_class: 'app-display',
|
|
|
|
x_expand: true, y_expand: true,
|
|
|
|
vertical: true });
|
|
|
|
this._viewStackLayout = new ViewStackLayout();
|
|
|
|
this._viewStack = new St.Widget({ x_expand: true, y_expand: true,
|
|
|
|
layout_manager: this._viewStackLayout });
|
2017-12-01 19:27:35 -05:00
|
|
|
this._viewStackLayout.connect('allocated-size-changed', this._onAllocatedSizeChanged.bind(this));
|
2014-04-15 16:21:33 -04:00
|
|
|
this.actor.add_actor(this._viewStack);
|
2013-05-24 06:03:00 -04:00
|
|
|
let layout = new ControlsBoxLayout({ homogeneous: true });
|
2013-07-09 17:15:02 -04:00
|
|
|
this._controls = new St.Widget({ style_class: 'app-view-controls',
|
|
|
|
layout_manager: layout });
|
2017-10-30 20:38:18 -04:00
|
|
|
this._controls.connect('notify::mapped', () => {
|
|
|
|
// controls are faded either with their parent or
|
|
|
|
// explicitly in animate(); we can't know how they'll be
|
|
|
|
// shown next, so make sure to restore their opacity
|
|
|
|
// when they are hidden
|
|
|
|
if (this._controls.mapped)
|
2019-01-29 14:36:54 -05:00
|
|
|
return;
|
2017-10-30 20:38:18 -04:00
|
|
|
|
2018-07-20 15:46:19 -04:00
|
|
|
this._controls.remove_all_transitions();
|
2017-10-30 20:38:18 -04:00
|
|
|
this._controls.opacity = 255;
|
|
|
|
});
|
2014-06-17 13:10:54 -04:00
|
|
|
|
2013-07-09 17:15:02 -04:00
|
|
|
layout.hookup_style(this._controls);
|
2013-08-27 15:22:16 -04:00
|
|
|
this.actor.add_actor(new St.Bin({ child: this._controls }));
|
2013-02-18 14:18:08 -05:00
|
|
|
|
|
|
|
for (let i = 0; i < this._views.length; i++) {
|
|
|
|
this._viewStack.add_actor(this._views[i].view.actor);
|
|
|
|
this._controls.add_actor(this._views[i].control);
|
|
|
|
|
|
|
|
let viewIndex = i;
|
2019-02-04 06:30:53 -05:00
|
|
|
this._views[i].control.connect('clicked', () => {
|
2017-10-30 20:38:18 -04:00
|
|
|
this._showView(viewIndex);
|
|
|
|
global.settings.set_uint('app-picker-view', viewIndex);
|
|
|
|
});
|
2013-02-18 14:18:08 -05:00
|
|
|
}
|
2013-10-13 10:48:12 -04:00
|
|
|
let initialView = Math.min(global.settings.get_uint('app-picker-view'),
|
|
|
|
this._views.length - 1);
|
2013-08-30 14:25:19 -04:00
|
|
|
let frequentUseful = this._views[Views.FREQUENT].view.hasUsefulData();
|
2013-10-13 10:48:12 -04:00
|
|
|
if (initialView == Views.FREQUENT && !frequentUseful)
|
|
|
|
initialView = Views.ALL;
|
|
|
|
this._showView(initialView);
|
2013-03-01 18:46:34 -05:00
|
|
|
this._updateFrequentVisibility();
|
2016-10-19 09:58:16 -04:00
|
|
|
|
|
|
|
Gio.DBus.system.watch_name(SWITCHEROO_BUS_NAME,
|
|
|
|
Gio.BusNameWatcherFlags.NONE,
|
2017-12-01 19:27:35 -05:00
|
|
|
this._switcherooProxyAppeared.bind(this),
|
2017-10-30 20:38:18 -04:00
|
|
|
() => {
|
2016-10-19 09:58:16 -04:00
|
|
|
this._switcherooProxy = null;
|
|
|
|
this._updateDiscreteGpuAvailable();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-10-19 09:58:16 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateDiscreteGpuAvailable() {
|
2016-10-19 09:58:16 -04:00
|
|
|
if (!this._switcherooProxy)
|
|
|
|
discreteGpuAvailable = false;
|
|
|
|
else
|
|
|
|
discreteGpuAvailable = this._switcherooProxy.HasDualGpu;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2016-10-19 09:58:16 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_switcherooProxyAppeared() {
|
2016-10-19 09:58:16 -04:00
|
|
|
this._switcherooProxy = new SwitcherooProxy(Gio.DBus.system, SWITCHEROO_BUS_NAME, SWITCHEROO_OBJECT_PATH,
|
2017-10-30 20:38:18 -04:00
|
|
|
(proxy, error) => {
|
2016-10-19 09:58:16 -04:00
|
|
|
if (error) {
|
|
|
|
log(error.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._updateDiscreteGpuAvailable();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-06-04 18:01:32 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
animate(animationDirection, onComplete) {
|
2016-11-17 10:24:44 -05:00
|
|
|
let currentView = this._views.filter(v => v.control.has_style_pseudo_class('checked')).pop().view;
|
2014-06-17 13:10:54 -04:00
|
|
|
|
|
|
|
// Animate controls opacity using iconGrid animation time, since
|
|
|
|
// it will be the time the AllView or FrequentView takes to show
|
|
|
|
// it entirely.
|
|
|
|
let finalOpacity;
|
|
|
|
if (animationDirection == IconGrid.AnimationDirection.IN) {
|
|
|
|
this._controls.opacity = 0;
|
|
|
|
finalOpacity = 255;
|
|
|
|
} else {
|
2019-01-28 20:18:52 -05:00
|
|
|
finalOpacity = 0;
|
2014-06-17 13:10:54 -04:00
|
|
|
}
|
|
|
|
|
2018-07-20 15:46:19 -04:00
|
|
|
this._controls.ease({
|
|
|
|
opacity: finalOpacity,
|
|
|
|
duration: IconGrid.ANIMATION_TIME_IN,
|
|
|
|
mode: Clutter.AnimationMode.EASE_IN_OUT_QUAD
|
|
|
|
});
|
2014-06-17 13:10:54 -04:00
|
|
|
|
|
|
|
currentView.animate(animationDirection, onComplete);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-06-17 13:10:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_showView(activeIndex) {
|
2013-02-18 14:18:08 -05:00
|
|
|
for (let i = 0; i < this._views.length; i++) {
|
|
|
|
if (i == activeIndex)
|
|
|
|
this._views[i].control.add_style_pseudo_class('checked');
|
|
|
|
else
|
|
|
|
this._views[i].control.remove_style_pseudo_class('checked');
|
2014-06-17 15:31:53 -04:00
|
|
|
|
2019-08-19 15:33:15 -04:00
|
|
|
let animationDirection = i == activeIndex
|
|
|
|
? IconGrid.AnimationDirection.IN
|
|
|
|
: IconGrid.AnimationDirection.OUT;
|
2014-06-17 15:31:53 -04:00
|
|
|
this._views[i].view.animateSwitch(animationDirection);
|
2013-02-18 14:18:08 -05:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-06-04 18:01:32 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateFrequentVisibility() {
|
2013-03-01 18:56:18 -05:00
|
|
|
let enabled = this._privacySettings.get_boolean('remember-app-usage');
|
2013-03-01 18:46:34 -05:00
|
|
|
this._views[Views.FREQUENT].control.visible = enabled;
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
let visibleViews = this._views.filter(v => v.control.visible);
|
2013-03-01 18:46:34 -05:00
|
|
|
this._controls.visible = visibleViews.length > 1;
|
|
|
|
|
|
|
|
if (!enabled && this._views[Views.FREQUENT].view.actor.visible)
|
|
|
|
this._showView(Views.ALL);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-03-01 18:46:34 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
selectApp(id) {
|
2011-07-09 09:30:42 -04:00
|
|
|
this._showView(Views.ALL);
|
|
|
|
this._views[Views.ALL].view.selectApp(id);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-27 15:22:16 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onAllocatedSizeChanged(actor, width, height) {
|
2013-08-27 15:22:16 -04:00
|
|
|
let box = new Clutter.ActorBox();
|
2019-01-28 20:27:05 -05:00
|
|
|
box.x1 = box.y1 = 0;
|
2013-08-27 15:22:16 -04:00
|
|
|
box.x2 = width;
|
|
|
|
box.y2 = height;
|
|
|
|
box = this._viewStack.get_theme_node().get_content_box(box);
|
|
|
|
let availWidth = box.x2 - box.x1;
|
|
|
|
let availHeight = box.y2 - box.y1;
|
|
|
|
for (let i = 0; i < this._views.length; i++)
|
|
|
|
this._views[i].view.adaptToSize(availWidth, availHeight);
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2009-11-29 17:45:30 -05:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var AppSearchProvider = class AppSearchProvider {
|
|
|
|
constructor() {
|
2009-11-29 17:45:30 -05:00
|
|
|
this._appSys = Shell.AppSystem.get_default();
|
2012-08-09 17:52:36 -04:00
|
|
|
this.id = 'applications';
|
2017-06-12 22:24:12 -04:00
|
|
|
this.isRemoteProvider = false;
|
|
|
|
this.canLaunchSearch = false;
|
2017-08-21 09:20:25 -04:00
|
|
|
|
|
|
|
this._systemActions = new SystemActions.getDefault();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-11-29 17:45:30 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getResultMetas(apps, callback) {
|
2012-02-17 10:39:27 -05:00
|
|
|
let metas = [];
|
2017-08-21 09:20:25 -04:00
|
|
|
for (let id of apps) {
|
|
|
|
if (id.endsWith('.desktop')) {
|
|
|
|
let app = this._appSys.lookup_app(id);
|
|
|
|
|
2019-02-12 09:02:09 -05:00
|
|
|
metas.push({
|
|
|
|
id: app.get_id(),
|
|
|
|
name: app.get_name(),
|
|
|
|
createIcon: size => app.create_icon_texture(size),
|
2017-08-21 09:20:25 -04:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
let name = this._systemActions.getName(id);
|
|
|
|
let iconName = this._systemActions.getIconName(id);
|
|
|
|
|
|
|
|
let createIcon = size => new St.Icon({ icon_name: iconName,
|
|
|
|
width: size,
|
|
|
|
height: size,
|
|
|
|
style_class: 'system-action-icon' });
|
|
|
|
|
|
|
|
metas.push({ id, name, createIcon });
|
|
|
|
}
|
2012-02-17 10:39:27 -05:00
|
|
|
}
|
2017-08-21 09:20:25 -04:00
|
|
|
|
2012-05-02 15:45:37 -04:00
|
|
|
callback(metas);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-11-29 17:45:30 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
filterResults(results, maxNumber) {
|
2013-05-29 16:48:30 -04:00
|
|
|
return results.slice(0, maxNumber);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-05-29 16:48:30 -04:00
|
|
|
|
2019-01-31 09:08:10 -05:00
|
|
|
getInitialResultSet(terms, callback, _cancellable) {
|
2013-11-02 20:13:42 -04:00
|
|
|
let query = terms.join(' ');
|
2015-07-30 13:55:19 -04:00
|
|
|
let groups = Shell.AppSystem.search(query);
|
2013-11-02 20:13:42 -04:00
|
|
|
let usage = Shell.AppUsage.get_default();
|
|
|
|
let results = [];
|
2017-10-30 20:38:18 -04:00
|
|
|
groups.forEach(group => {
|
|
|
|
group = group.filter(appID => {
|
2013-11-02 20:13:42 -04:00
|
|
|
let app = Gio.DesktopAppInfo.new(appID);
|
|
|
|
return app && app.should_show();
|
|
|
|
});
|
2017-10-30 20:38:18 -04:00
|
|
|
results = results.concat(group.sort(
|
2012-04-09 02:27:47 -04:00
|
|
|
(a, b) => usage.compare(a, b)
|
2017-10-30 20:38:18 -04:00
|
|
|
));
|
2013-11-02 20:13:42 -04:00
|
|
|
});
|
2017-08-21 09:20:25 -04:00
|
|
|
|
|
|
|
results = results.concat(this._systemActions.getMatchingActions(terms));
|
|
|
|
|
2013-11-02 20:13:42 -04:00
|
|
|
callback(results);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
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
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getSubsearchResultSet(previousResults, terms, callback, cancellable) {
|
2013-11-02 20:13:42 -04:00
|
|
|
this.getInitialResultSet(terms, callback, cancellable);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
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
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
createResultObject(resultMeta) {
|
2017-08-21 09:20:25 -04:00
|
|
|
if (resultMeta.id.endsWith('.desktop'))
|
|
|
|
return new AppIcon(this._appSys.lookup_app(resultMeta['id']));
|
|
|
|
else
|
|
|
|
return new SystemActionIcon(this, resultMeta);
|
2009-11-29 17:45:30 -05:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2013-08-20 04:49:02 -04:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var FolderView = class FolderView extends BaseAppView {
|
2019-07-16 16:51:25 -04:00
|
|
|
constructor(folder, id, parentView) {
|
2017-10-30 21:19:44 -04:00
|
|
|
super(null, null);
|
2013-08-30 12:50:35 -04:00
|
|
|
// If it not expand, the parent doesn't take into account its preferred_width when allocating
|
|
|
|
// the second time it allocates, so we apply the "Standard hack for ClutterBinLayout"
|
2018-07-02 10:03:07 -04:00
|
|
|
this._grid.x_expand = true;
|
2019-07-16 16:51:25 -04:00
|
|
|
this._id = id;
|
2019-06-29 11:58:26 -04:00
|
|
|
this._folder = folder;
|
|
|
|
this._parentView = parentView;
|
2019-06-28 18:47:32 -04:00
|
|
|
this._grid._delegate = this;
|
2013-08-30 12:50:35 -04:00
|
|
|
|
|
|
|
this.actor = new St.ScrollView({ overlay_scrollbars: true });
|
2018-11-27 07:45:36 -05:00
|
|
|
this.actor.set_policy(St.PolicyType.NEVER, St.PolicyType.AUTOMATIC);
|
2013-08-30 12:50:35 -04:00
|
|
|
let scrollableContainer = new St.BoxLayout({ vertical: true, reactive: true });
|
2018-07-02 10:03:07 -04:00
|
|
|
scrollableContainer.add_actor(this._grid);
|
2013-08-30 12:50:35 -04:00
|
|
|
this.actor.add_actor(scrollableContainer);
|
2013-08-23 14:49:27 -04:00
|
|
|
|
|
|
|
let action = new Clutter.PanAction({ interpolate: true });
|
2017-12-01 19:27:35 -05:00
|
|
|
action.connect('pan', this._onPan.bind(this));
|
2013-08-23 14:49:27 -04:00
|
|
|
this.actor.add_action(action);
|
2019-06-29 11:58:26 -04:00
|
|
|
|
|
|
|
this._folder.connect('changed', this._redisplay.bind(this));
|
|
|
|
this._redisplay();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-20 04:49:02 -04:00
|
|
|
|
2018-08-21 05:21:26 -04:00
|
|
|
_childFocused(actor) {
|
2014-03-20 09:54:04 -04:00
|
|
|
Util.ensureActorVisibleInScrollView(this.actor, actor);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-03-20 09:54:04 -04:00
|
|
|
|
2019-05-15 15:32:29 -04:00
|
|
|
// Overridden from BaseAppView
|
2017-10-30 20:03:21 -04:00
|
|
|
animate(animationDirection) {
|
2014-06-17 06:47:00 -04:00
|
|
|
this._grid.animatePulse(animationDirection);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-06-17 06:47:00 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
createFolderIcon(size) {
|
2014-08-05 17:26:45 -04:00
|
|
|
let layout = new Clutter.GridLayout();
|
2014-02-16 01:06:53 -05:00
|
|
|
let icon = new St.Widget({ layout_manager: layout,
|
|
|
|
style_class: 'app-folder-icon' });
|
2014-03-14 12:03:10 -04:00
|
|
|
layout.hookup_style(icon);
|
2013-08-20 04:49:02 -04:00
|
|
|
let subSize = Math.floor(FOLDER_SUBICON_FRACTION * size);
|
2018-01-05 18:54:33 -05:00
|
|
|
let scale = St.ThemeContext.get_for_stage(global.stage).scale_factor;
|
2013-08-20 04:49:02 -04:00
|
|
|
|
2014-03-14 10:50:18 -04:00
|
|
|
let numItems = this._allItems.length;
|
2014-06-20 11:46:22 -04:00
|
|
|
let rtl = icon.get_text_direction() == Clutter.TextDirection.RTL;
|
2014-03-14 10:50:18 -04:00
|
|
|
for (let i = 0; i < 4; i++) {
|
2018-01-05 18:54:33 -05:00
|
|
|
let bin = new St.Bin({ width: subSize * scale, height: subSize * scale });
|
2017-08-11 05:04:37 -04:00
|
|
|
if (i < numItems)
|
|
|
|
bin.child = this._allItems[i].app.create_icon_texture(subSize);
|
2014-08-05 17:26:45 -04:00
|
|
|
layout.attach(bin, rtl ? (i + 1) % 2 : i % 2, Math.floor(i / 2), 1, 1);
|
2013-08-20 04:49:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return icon;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-30 12:50:35 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onPan(action) {
|
2019-01-31 09:08:00 -05:00
|
|
|
let [dist_, dx_, dy] = action.get_motion_delta(0);
|
2013-08-23 14:49:27 -04:00
|
|
|
let adjustment = this.actor.vscroll.adjustment;
|
|
|
|
adjustment.value -= (dy / this.actor.height) * adjustment.page_size;
|
|
|
|
return false;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-23 14:49:27 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
adaptToSize(width, height) {
|
2013-08-30 12:50:35 -04:00
|
|
|
this._parentAvailableWidth = width;
|
|
|
|
this._parentAvailableHeight = height;
|
|
|
|
|
2013-08-15 04:38:17 -04:00
|
|
|
this._grid.adaptToSize(width, height);
|
2013-08-30 12:50:35 -04:00
|
|
|
|
2013-09-05 21:12:28 -04:00
|
|
|
// To avoid the fade effect being applied to the unscrolled grid,
|
|
|
|
// the offset would need to be applied after adjusting the padding;
|
|
|
|
// however the final padding is expected to be too small for the
|
|
|
|
// effect to look good, so use the unadjusted padding
|
|
|
|
let fadeOffset = Math.min(this._grid.topPadding,
|
|
|
|
this._grid.bottomPadding);
|
|
|
|
this.actor.update_fade_effect(fadeOffset, 0);
|
|
|
|
|
2013-08-30 12:50:35 -04:00
|
|
|
// Set extra padding to avoid popup or close button being cut off
|
|
|
|
this._grid.topPadding = Math.max(this._grid.topPadding - this._offsetForEachSide, 0);
|
2013-09-05 20:50:09 -04:00
|
|
|
this._grid.bottomPadding = Math.max(this._grid.bottomPadding - this._offsetForEachSide, 0);
|
|
|
|
this._grid.leftPadding = Math.max(this._grid.leftPadding - this._offsetForEachSide, 0);
|
|
|
|
this._grid.rightPadding = Math.max(this._grid.rightPadding - this._offsetForEachSide, 0);
|
2013-08-30 12:50:35 -04:00
|
|
|
|
|
|
|
this.actor.set_width(this.usedWidth());
|
|
|
|
this.actor.set_height(this.usedHeight());
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-30 12:50:35 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getPageAvailableSize() {
|
2013-08-30 12:50:35 -04:00
|
|
|
let pageBox = new Clutter.ActorBox();
|
|
|
|
pageBox.x1 = pageBox.y1 = 0;
|
|
|
|
pageBox.x2 = this._parentAvailableWidth;
|
|
|
|
pageBox.y2 = this._parentAvailableHeight;
|
|
|
|
|
|
|
|
let contentBox = this.actor.get_theme_node().get_content_box(pageBox);
|
|
|
|
// We only can show icons inside the collection view boxPointer
|
2019-05-15 15:32:29 -04:00
|
|
|
// so we have to subtract the required padding etc of the boxpointer
|
2013-08-30 12:50:35 -04:00
|
|
|
return [(contentBox.x2 - contentBox.x1) - 2 * this._offsetForEachSide, (contentBox.y2 - contentBox.y1) - 2 * this._offsetForEachSide];
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-30 12:50:35 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
usedWidth() {
|
2019-02-01 08:41:55 -05:00
|
|
|
let [availWidthPerPage] = this._getPageAvailableSize();
|
2013-08-30 12:50:35 -04:00
|
|
|
return this._grid.usedWidth(availWidthPerPage);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-30 12:50:35 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
usedHeight() {
|
2013-08-30 12:50:35 -04:00
|
|
|
return this._grid.usedHeightForNRows(this.nRowsDisplayedAtOnce());
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-30 12:50:35 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
nRowsDisplayedAtOnce() {
|
2013-08-30 12:50:35 -04:00
|
|
|
let [availWidthPerPage, availHeightPerPage] = this._getPageAvailableSize();
|
|
|
|
let maxRows = this._grid.rowsForHeight(availHeightPerPage) - 1;
|
|
|
|
return Math.min(this._grid.nRows(availWidthPerPage), maxRows);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-30 12:50:35 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
setPaddingOffsets(offset) {
|
2013-08-30 12:50:35 -04:00
|
|
|
this._offsetForEachSide = offset;
|
2013-08-20 04:49:02 -04:00
|
|
|
}
|
2019-06-29 11:58:26 -04:00
|
|
|
|
|
|
|
_loadApps() {
|
2019-07-01 22:13:07 -04:00
|
|
|
let apps = [];
|
2019-06-29 11:58:26 -04:00
|
|
|
let excludedApps = this._folder.get_strv('excluded-apps');
|
|
|
|
let appSys = Shell.AppSystem.get_default();
|
|
|
|
let addAppId = appId => {
|
|
|
|
if (excludedApps.includes(appId))
|
|
|
|
return;
|
|
|
|
|
|
|
|
let app = appSys.lookup_app(appId);
|
|
|
|
if (!app)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!app.get_app_info().should_show())
|
|
|
|
return;
|
|
|
|
|
2019-07-30 11:15:51 -04:00
|
|
|
if (apps.some(appIcon => appIcon.id == appId))
|
|
|
|
return;
|
|
|
|
|
2019-06-29 11:58:26 -04:00
|
|
|
let icon = new AppIcon(app);
|
2019-07-01 22:13:07 -04:00
|
|
|
apps.push(icon);
|
2019-06-29 11:58:26 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
let folderApps = this._folder.get_strv('apps');
|
|
|
|
folderApps.forEach(addAppId);
|
|
|
|
|
|
|
|
let folderCategories = this._folder.get_strv('categories');
|
|
|
|
let appInfos = this._parentView.getAppInfos();
|
|
|
|
appInfos.forEach(appInfo => {
|
|
|
|
let appCategories = _getCategories(appInfo);
|
|
|
|
if (!_listsIntersect(folderCategories, appCategories))
|
|
|
|
return;
|
|
|
|
|
|
|
|
addAppId(appInfo.get_id());
|
|
|
|
});
|
2019-07-01 22:13:07 -04:00
|
|
|
|
|
|
|
return apps;
|
2019-06-29 11:58:26 -04:00
|
|
|
}
|
2019-06-29 00:26:08 -04:00
|
|
|
|
|
|
|
removeApp(app) {
|
|
|
|
let folderApps = this._folder.get_strv('apps');
|
|
|
|
let index = folderApps.indexOf(app.id);
|
2019-07-16 16:51:25 -04:00
|
|
|
if (index >= 0)
|
2019-06-29 00:26:08 -04:00
|
|
|
folderApps.splice(index, 1);
|
|
|
|
|
|
|
|
// If this is a categories-based folder, also add it to
|
|
|
|
// the list of excluded apps
|
|
|
|
let categories = this._folder.get_strv('categories');
|
|
|
|
if (categories.length > 0) {
|
|
|
|
let excludedApps = this._folder.get_strv('excluded-apps');
|
|
|
|
excludedApps.push(app.id);
|
|
|
|
this._folder.set_strv('excluded-apps', excludedApps);
|
|
|
|
}
|
|
|
|
|
2019-07-16 16:51:25 -04:00
|
|
|
// Remove the folder if this is the last app icon; otherwise,
|
|
|
|
// just remove the icon
|
|
|
|
if (folderApps.length == 0) {
|
|
|
|
let settings = new Gio.Settings({ schema_id: 'org.gnome.desktop.app-folders' });
|
|
|
|
let folders = settings.get_strv('folder-children');
|
|
|
|
folders.splice(folders.indexOf(this._id), 1);
|
|
|
|
settings.set_strv('folder-children', folders);
|
|
|
|
|
|
|
|
// Resetting all keys deletes the relocatable schema
|
|
|
|
let keys = this._folder.settings_schema.list_keys();
|
|
|
|
for (let key of keys)
|
|
|
|
this._folder.reset(key);
|
|
|
|
} else {
|
|
|
|
this._folder.set_strv('apps', folderApps);
|
|
|
|
}
|
|
|
|
|
2019-06-29 00:26:08 -04:00
|
|
|
return true;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2013-01-31 11:13:37 -05:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var FolderIcon = class FolderIcon {
|
|
|
|
constructor(id, path, parentView) {
|
2013-12-15 22:24:25 -05:00
|
|
|
this.id = id;
|
2017-06-12 22:24:12 -04:00
|
|
|
this.name = '';
|
2013-01-31 11:13:37 -05:00
|
|
|
this._parentView = parentView;
|
|
|
|
|
2014-01-28 11:36:57 -05:00
|
|
|
this._folder = new Gio.Settings({ schema_id: 'org.gnome.desktop.app-folders.folder',
|
|
|
|
path: path });
|
2013-01-31 11:13:37 -05:00
|
|
|
this.actor = new St.Button({ style_class: 'app-well-app app-folder',
|
|
|
|
button_mask: St.ButtonMask.ONE,
|
|
|
|
toggle_mode: true,
|
|
|
|
can_focus: true,
|
|
|
|
x_fill: true,
|
|
|
|
y_fill: true });
|
|
|
|
this.actor._delegate = this;
|
2013-08-30 12:50:35 -04:00
|
|
|
// whether we need to update arrow side, position etc.
|
|
|
|
this._popupInvalidated = false;
|
2013-01-31 11:13:37 -05:00
|
|
|
|
2019-06-28 22:46:16 -04:00
|
|
|
this.icon = new IconGrid.BaseIcon('', {
|
|
|
|
createIcon: this._createIcon.bind(this),
|
|
|
|
setSizeManually: true
|
|
|
|
});
|
2018-06-30 14:00:08 -04:00
|
|
|
this.actor.set_child(this.icon);
|
2013-01-31 11:13:37 -05:00
|
|
|
this.actor.label_actor = this.icon.label;
|
|
|
|
|
2019-07-16 16:51:25 -04:00
|
|
|
this.view = new FolderView(this._folder, id, parentView);
|
2013-01-31 11:13:37 -05:00
|
|
|
|
2019-08-09 17:27:57 -04:00
|
|
|
this._itemDragBeginId = Main.overview.connect(
|
|
|
|
'item-drag-begin', this._onDragBegin.bind(this));
|
|
|
|
this._itemDragEndId = Main.overview.connect(
|
|
|
|
'item-drag-end', this._onDragEnd.bind(this));
|
2019-06-28 18:47:32 -04:00
|
|
|
|
2019-09-01 13:12:42 -04:00
|
|
|
this._popupTimeoutId = 0;
|
|
|
|
|
|
|
|
this.actor.connect('leave-event', this._onLeaveEvent.bind(this));
|
|
|
|
this.actor.connect('button-press-event', this._onButtonPress.bind(this));
|
|
|
|
this.actor.connect('touch-event', this._onTouchEvent.bind(this));
|
|
|
|
this.actor.connect('popup-menu', this._popupRenamePopup.bind(this));
|
|
|
|
|
2019-07-18 10:19:13 -04:00
|
|
|
this.actor.connect('clicked', this.open.bind(this));
|
2019-07-22 10:57:57 -04:00
|
|
|
this.actor.connect('destroy', this.onDestroy.bind(this));
|
2017-10-30 20:38:18 -04:00
|
|
|
this.actor.connect('notify::mapped', () => {
|
|
|
|
if (!this.actor.mapped && this._popup)
|
|
|
|
this._popup.popdown();
|
|
|
|
});
|
2014-01-28 11:36:57 -05:00
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
this._folder.connect('changed', this._redisplay.bind(this));
|
2014-01-28 11:36:57 -05:00
|
|
|
this._redisplay();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-01-28 11:36:57 -05:00
|
|
|
|
2019-07-22 10:57:57 -04:00
|
|
|
onDestroy() {
|
2019-08-09 17:27:57 -04:00
|
|
|
Main.overview.disconnect(this._itemDragBeginId);
|
|
|
|
Main.overview.disconnect(this._itemDragEndId);
|
|
|
|
|
2019-07-22 10:57:57 -04:00
|
|
|
this.view.actor.destroy();
|
|
|
|
|
2019-07-18 14:49:30 -04:00
|
|
|
if (this._spaceReadySignalId) {
|
|
|
|
this._parentView.disconnect(this._spaceReadySignalId);
|
|
|
|
this._spaceReadySignalId = 0;
|
|
|
|
}
|
|
|
|
|
2019-07-22 10:57:57 -04:00
|
|
|
if (this._popup)
|
|
|
|
this._popup.actor.destroy();
|
2019-09-01 13:12:42 -04:00
|
|
|
|
|
|
|
this._removeMenuTimeout();
|
2019-07-22 10:57:57 -04:00
|
|
|
}
|
|
|
|
|
2019-07-18 10:19:13 -04:00
|
|
|
open() {
|
2019-09-01 13:12:42 -04:00
|
|
|
this._removeMenuTimeout();
|
2019-07-18 10:19:13 -04:00
|
|
|
this._ensurePopup();
|
|
|
|
this.view.actor.vscroll.adjustment.value = 0;
|
|
|
|
this._openSpaceForPopup();
|
|
|
|
}
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getAppIds() {
|
2017-10-30 20:38:18 -04:00
|
|
|
return this.view.getAllItems().map(item => item.id);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-01-28 11:36:57 -05:00
|
|
|
|
2019-06-28 18:47:32 -04:00
|
|
|
_onDragBegin() {
|
2019-07-01 20:37:35 -04:00
|
|
|
this._dragMonitor = {
|
|
|
|
dragMotion: this._onDragMotion.bind(this),
|
|
|
|
};
|
|
|
|
DND.addDragMonitor(this._dragMonitor);
|
|
|
|
|
2019-06-28 18:47:32 -04:00
|
|
|
this._parentView.inhibitEventBlocker();
|
|
|
|
}
|
|
|
|
|
2019-07-01 20:37:35 -04:00
|
|
|
_onDragMotion(dragEvent) {
|
|
|
|
let target = dragEvent.targetActor;
|
|
|
|
|
|
|
|
if (!this.actor.contains(target) || !this._canAccept(dragEvent.source))
|
|
|
|
this.actor.remove_style_pseudo_class('drop');
|
|
|
|
else
|
|
|
|
this.actor.add_style_pseudo_class('drop');
|
|
|
|
|
|
|
|
return DND.DragMotionResult.CONTINUE;
|
|
|
|
}
|
|
|
|
|
2019-06-28 18:47:32 -04:00
|
|
|
_onDragEnd() {
|
2019-07-01 20:37:35 -04:00
|
|
|
this.actor.remove_style_pseudo_class('drop');
|
2019-06-28 18:47:32 -04:00
|
|
|
this._parentView.uninhibitEventBlocker();
|
2019-07-01 20:37:35 -04:00
|
|
|
DND.removeDragMonitor(this._dragMonitor);
|
2019-06-28 18:47:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_canAccept(source) {
|
|
|
|
if (!(source instanceof AppIcon))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
let view = _getViewFromIcon(source);
|
|
|
|
if (!view || !(view instanceof AllView))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (this._folder.get_strv('apps').includes(source.id))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
handleDragOver(source) {
|
|
|
|
if (!this._canAccept(source))
|
|
|
|
return DND.DragMotionResult.NO_DROP;
|
|
|
|
|
|
|
|
return DND.DragMotionResult.MOVE_DROP;
|
|
|
|
}
|
|
|
|
|
|
|
|
acceptDrop(source) {
|
|
|
|
if (!this._canAccept(source))
|
2019-08-09 09:56:37 -04:00
|
|
|
return false;
|
2019-06-28 18:47:32 -04:00
|
|
|
|
|
|
|
let app = source.app;
|
|
|
|
let folderApps = this._folder.get_strv('apps');
|
|
|
|
folderApps.push(app.id);
|
|
|
|
|
|
|
|
this._folder.set_strv('apps', folderApps);
|
|
|
|
|
|
|
|
// Also remove from 'excluded-apps' if the app id is listed
|
|
|
|
// there. This is only possible on categories-based folders.
|
|
|
|
let excludedApps = this._folder.get_strv('excluded-apps');
|
|
|
|
let index = excludedApps.indexOf(app.id);
|
|
|
|
if (index >= 0) {
|
|
|
|
excludedApps.splice(index, 1);
|
|
|
|
this._folder.set_strv('excluded-apps', excludedApps);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateName() {
|
2014-01-28 11:36:57 -05:00
|
|
|
let name = _getFolderName(this._folder);
|
|
|
|
if (this.name == name)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.name = name;
|
|
|
|
this.icon.label.text = this.name;
|
|
|
|
this.emit('name-changed');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-01-28 11:36:57 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_redisplay() {
|
2014-01-28 11:36:57 -05:00
|
|
|
this._updateName();
|
2014-09-18 10:33:13 -04:00
|
|
|
this.actor.visible = this.view.getAllItems().length > 0;
|
2019-06-28 18:49:18 -04:00
|
|
|
this.icon.update();
|
2014-01-28 11:36:57 -05:00
|
|
|
this.emit('apps-changed');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-01-31 11:13:37 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_createIcon(iconSize) {
|
2013-08-15 04:38:17 -04:00
|
|
|
return this.view.createFolderIcon(iconSize, this);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-01-31 11:13:37 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_popupHeight() {
|
2013-08-30 12:50:35 -04:00
|
|
|
let usedHeight = this.view.usedHeight() + this._popup.getOffset(St.Side.TOP) + this._popup.getOffset(St.Side.BOTTOM);
|
|
|
|
return usedHeight;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-30 12:50:35 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_openSpaceForPopup() {
|
2019-07-18 14:49:30 -04:00
|
|
|
this._spaceReadySignalId = this._parentView.connect('space-ready', () => {
|
|
|
|
this._parentView.disconnect(this._spaceReadySignalId);
|
|
|
|
this._spaceReadySignalId = 0;
|
2017-10-30 20:38:18 -04:00
|
|
|
this._popup.popup();
|
|
|
|
this._updatePopupPosition();
|
|
|
|
});
|
2013-07-09 09:11:03 -04:00
|
|
|
this._parentView.openSpaceForPopup(this, this._boxPointerArrowside, this.view.nRowsDisplayedAtOnce());
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-07-09 09:11:03 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_calculateBoxPointerArrowSide() {
|
2013-08-30 12:50:35 -04:00
|
|
|
let spaceTop = this.actor.y - this._parentView.getCurrentPageY();
|
|
|
|
let spaceBottom = this._parentView.actor.height - (spaceTop + this.actor.height);
|
|
|
|
|
|
|
|
return spaceTop > spaceBottom ? St.Side.BOTTOM : St.Side.TOP;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-30 12:50:35 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updatePopupSize() {
|
2013-08-30 12:50:35 -04:00
|
|
|
// StWidget delays style calculation until needed, make sure we use the correct values
|
2018-07-02 10:03:07 -04:00
|
|
|
this.view._grid.ensure_style();
|
2013-08-30 12:50:35 -04:00
|
|
|
|
2013-09-06 17:31:03 -04:00
|
|
|
let offsetForEachSide = Math.ceil((this._popup.getOffset(St.Side.TOP) +
|
|
|
|
this._popup.getOffset(St.Side.BOTTOM) -
|
|
|
|
this._popup.getCloseButtonOverlap()) / 2);
|
2013-08-30 12:50:35 -04:00
|
|
|
// Add extra padding to prevent boxpointer decorations and close button being cut off
|
|
|
|
this.view.setPaddingOffsets(offsetForEachSide);
|
|
|
|
this.view.adaptToSize(this._parentAvailableWidth, this._parentAvailableHeight);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-30 12:50:35 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updatePopupPosition() {
|
2013-08-30 12:50:35 -04:00
|
|
|
if (!this._popup)
|
2013-01-31 11:13:37 -05:00
|
|
|
return;
|
|
|
|
|
2013-08-30 12:50:35 -04:00
|
|
|
if (this._boxPointerArrowside == St.Side.BOTTOM)
|
2013-07-09 09:11:03 -04:00
|
|
|
this._popup.actor.y = this.actor.allocation.y1 + this.actor.translation_y - this._popupHeight();
|
2013-08-30 12:50:35 -04:00
|
|
|
else
|
2013-07-09 09:11:03 -04:00
|
|
|
this._popup.actor.y = this.actor.allocation.y1 + this.actor.translation_y + this.actor.height;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-30 12:50:35 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_ensurePopup() {
|
2013-08-30 12:50:35 -04:00
|
|
|
if (this._popup && !this._popupInvalidated)
|
|
|
|
return;
|
|
|
|
this._boxPointerArrowside = this._calculateBoxPointerArrowSide();
|
|
|
|
if (!this._popup) {
|
|
|
|
this._popup = new AppFolderPopup(this, this._boxPointerArrowside);
|
|
|
|
this._parentView.addFolderPopup(this._popup);
|
2017-10-30 20:38:18 -04:00
|
|
|
this._popup.connect('open-state-changed', (popup, isOpen) => {
|
|
|
|
if (!isOpen)
|
|
|
|
this.actor.checked = false;
|
|
|
|
});
|
2013-08-30 12:50:35 -04:00
|
|
|
} else {
|
|
|
|
this._popup.updateArrowSide(this._boxPointerArrowside);
|
2013-01-31 11:13:37 -05:00
|
|
|
}
|
2013-08-30 12:50:35 -04:00
|
|
|
this._updatePopupSize();
|
|
|
|
this._updatePopupPosition();
|
|
|
|
this._popupInvalidated = false;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-01-31 11:13:37 -05:00
|
|
|
|
2019-09-01 13:12:42 -04:00
|
|
|
_removeMenuTimeout() {
|
|
|
|
if (this._popupTimeoutId > 0) {
|
2019-08-19 14:50:33 -04:00
|
|
|
GLib.source_remove(this._popupTimeoutId);
|
2019-09-01 13:12:42 -04:00
|
|
|
this._popupTimeoutId = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_setPopupTimeout() {
|
|
|
|
this._removeMenuTimeout();
|
2019-08-19 14:50:33 -04:00
|
|
|
this._popupTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, MENU_POPUP_TIMEOUT, () => {
|
2019-09-01 13:12:42 -04:00
|
|
|
this._popupTimeoutId = 0;
|
|
|
|
this._popupRenamePopup();
|
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
});
|
|
|
|
GLib.Source.set_name_by_id(this._popupTimeoutId,
|
|
|
|
'[gnome-shell] this._popupRenamePopup');
|
|
|
|
}
|
|
|
|
|
|
|
|
_onLeaveEvent(_actor, _event) {
|
|
|
|
this.actor.fake_release();
|
|
|
|
this._removeMenuTimeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
_onButtonPress(_actor, event) {
|
|
|
|
let button = event.get_button();
|
|
|
|
if (button == 1) {
|
|
|
|
this._setPopupTimeout();
|
|
|
|
} else if (button == 3) {
|
|
|
|
this._popupRenamePopup();
|
|
|
|
return Clutter.EVENT_STOP;
|
|
|
|
}
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
_onTouchEvent(actor, event) {
|
|
|
|
if (event.type() == Clutter.EventType.TOUCH_BEGIN)
|
|
|
|
this._setPopupTimeout();
|
|
|
|
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
_popupRenamePopup() {
|
|
|
|
this._removeMenuTimeout();
|
|
|
|
this.actor.fake_release();
|
|
|
|
|
|
|
|
if (!this._menu) {
|
|
|
|
this._menuManager = new PopupMenu.PopupMenuManager(this.actor);
|
|
|
|
|
|
|
|
this._menu = new RenameFolderMenu(this, this._folder);
|
|
|
|
this._menuManager.addMenu(this._menu);
|
|
|
|
|
|
|
|
this._menu.connect('open-state-changed', (menu, isPoppedUp) => {
|
|
|
|
if (!isPoppedUp)
|
|
|
|
this.actor.sync_hover();
|
|
|
|
});
|
|
|
|
let id = Main.overview.connect('hiding', () => {
|
|
|
|
this._menu.close();
|
|
|
|
});
|
|
|
|
this.actor.connect('destroy', () => {
|
|
|
|
Main.overview.disconnect(id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.actor.set_hover(true);
|
2019-09-13 21:03:15 -04:00
|
|
|
this._menu.open();
|
2019-09-01 13:12:42 -04:00
|
|
|
this._menuManager.ignoreRelease();
|
|
|
|
}
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
adaptToSize(width, height) {
|
2013-08-30 12:50:35 -04:00
|
|
|
this._parentAvailableWidth = width;
|
|
|
|
this._parentAvailableHeight = height;
|
2019-01-28 20:27:05 -05:00
|
|
|
if (this._popup)
|
2013-08-30 12:50:35 -04:00
|
|
|
this.view.adaptToSize(width, height);
|
|
|
|
this._popupInvalidated = true;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
|
|
|
};
|
2014-01-28 11:36:57 -05:00
|
|
|
Signals.addSignalMethods(FolderIcon.prototype);
|
2013-01-31 11:13:37 -05:00
|
|
|
|
2019-09-13 21:03:15 -04:00
|
|
|
var RenameFolderMenuItem = GObject.registerClass(
|
|
|
|
class RenameFolderMenuItem extends PopupMenu.PopupBaseMenuItem {
|
|
|
|
_init(folder) {
|
|
|
|
super._init({
|
|
|
|
style_class: 'rename-folder-popup-item',
|
|
|
|
reactive: false,
|
|
|
|
});
|
|
|
|
this.setOrnament(PopupMenu.Ornament.HIDDEN);
|
2019-09-01 13:12:42 -04:00
|
|
|
|
|
|
|
this._folder = folder;
|
|
|
|
|
|
|
|
// Entry
|
|
|
|
this._entry = new St.Entry({
|
|
|
|
x_expand: true,
|
|
|
|
width: 200,
|
|
|
|
});
|
2019-09-13 21:03:15 -04:00
|
|
|
this.add_child(this._entry);
|
2019-09-11 14:09:08 -04:00
|
|
|
|
2019-09-12 23:19:02 -04:00
|
|
|
this._entry.clutter_text.connect(
|
|
|
|
'notify::text', this._validate.bind(this));
|
|
|
|
this._entry.clutter_text.connect(
|
|
|
|
'activate', this._updateFolderName.bind(this));
|
2019-09-01 13:12:42 -04:00
|
|
|
|
|
|
|
// Rename button
|
|
|
|
this._button = new St.Button({
|
|
|
|
style_class: 'button',
|
|
|
|
reactive: true,
|
|
|
|
button_mask: St.ButtonMask.ONE | St.ButtonMask.TWO,
|
|
|
|
can_focus: true,
|
2019-09-12 23:19:02 -04:00
|
|
|
label: _('Rename'),
|
2019-09-01 13:12:42 -04:00
|
|
|
});
|
2019-09-13 21:03:15 -04:00
|
|
|
this.add_child(this._button);
|
2019-09-01 13:12:42 -04:00
|
|
|
|
|
|
|
this._button.connect('clicked', this._updateFolderName.bind(this));
|
|
|
|
}
|
|
|
|
|
2019-09-13 21:03:15 -04:00
|
|
|
vfunc_map() {
|
|
|
|
this._entry.text = _getFolderName(this._folder);
|
|
|
|
this._entry.clutter_text.set_selection(0, -1);
|
|
|
|
super.vfunc_map();
|
|
|
|
}
|
2019-09-01 13:12:42 -04:00
|
|
|
|
2019-09-13 21:03:15 -04:00
|
|
|
vfunc_key_focus_in() {
|
|
|
|
super.vfunc_key_focus_in();
|
|
|
|
this._entry.clutter_text.grab_key_focus();
|
2019-09-01 13:12:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_isValidFolderName() {
|
|
|
|
let folderName = _getFolderName(this._folder);
|
|
|
|
let newFolderName = this._entry.text.trim();
|
|
|
|
|
|
|
|
return newFolderName.length > 0 && newFolderName != folderName;
|
|
|
|
}
|
|
|
|
|
|
|
|
_validate() {
|
|
|
|
let isValid = this._isValidFolderName();
|
|
|
|
|
|
|
|
this._button.reactive = isValid;
|
|
|
|
}
|
|
|
|
|
|
|
|
_updateFolderName() {
|
|
|
|
if (!this._isValidFolderName())
|
|
|
|
return;
|
|
|
|
|
|
|
|
let newFolderName = this._entry.text.trim();
|
|
|
|
this._folder.set_string('name', newFolderName);
|
|
|
|
this._folder.set_boolean('translate', false);
|
2019-09-13 21:03:15 -04:00
|
|
|
this.activate(Clutter.get_current_event());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var RenameFolderMenu = class RenameFolderMenu extends PopupMenu.PopupMenu {
|
|
|
|
constructor(source, folder) {
|
|
|
|
super(source.actor, 0.5, St.Side.BOTTOM);
|
|
|
|
this.actor.add_style_class_name('rename-folder-popup');
|
|
|
|
|
|
|
|
// We want to keep the item hovered while the menu is up
|
|
|
|
this.blockSourceEvents = true;
|
|
|
|
|
|
|
|
let menuItem = new RenameFolderMenuItem(folder);
|
|
|
|
this.addMenuItem(menuItem);
|
|
|
|
|
|
|
|
// Focus the text entry on menu pop-up
|
|
|
|
this.focusActor = menuItem;
|
|
|
|
|
|
|
|
// Chain our visibility and lifecycle to that of the source
|
|
|
|
this._sourceMappedId = source.actor.connect('notify::mapped', () => {
|
|
|
|
if (!source.actor.mapped)
|
|
|
|
this.close();
|
|
|
|
});
|
|
|
|
source.actor.connect('destroy', () => {
|
|
|
|
source.actor.disconnect(this._sourceMappedId);
|
|
|
|
this.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
Main.uiGroup.add_actor(this.actor);
|
2019-09-01 13:12:42 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
Signals.addSignalMethods(RenameFolderMenu.prototype);
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var AppFolderPopup = class AppFolderPopup {
|
|
|
|
constructor(source, side) {
|
2013-01-31 11:13:37 -05:00
|
|
|
this._source = source;
|
|
|
|
this._view = source.view;
|
|
|
|
this._arrowSide = side;
|
|
|
|
|
|
|
|
this._isOpen = false;
|
2013-05-16 11:20:32 -04:00
|
|
|
this.parentOffset = 0;
|
2013-01-31 11:13:37 -05:00
|
|
|
|
|
|
|
this.actor = new St.Widget({ layout_manager: new Clutter.BinLayout(),
|
2013-02-20 11:20:46 -05:00
|
|
|
visible: false,
|
|
|
|
// We don't want to expand really, but look
|
|
|
|
// at the layout manager of our parent...
|
|
|
|
//
|
|
|
|
// DOUBLE HACK: if you set one, you automatically
|
|
|
|
// get the effect for the other direction too, so
|
|
|
|
// we need to set the y_align
|
|
|
|
x_expand: true,
|
|
|
|
y_expand: true,
|
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
y_align: Clutter.ActorAlign.START });
|
2013-01-31 11:13:37 -05:00
|
|
|
this._boxPointer = new BoxPointer.BoxPointer(this._arrowSide,
|
|
|
|
{ style_class: 'app-folder-popup-bin',
|
|
|
|
x_fill: true,
|
|
|
|
y_fill: true,
|
2013-08-30 12:50:35 -04:00
|
|
|
x_expand: true,
|
2013-01-31 11:13:37 -05:00
|
|
|
x_align: St.Align.START });
|
|
|
|
|
2019-04-09 16:21:15 -04:00
|
|
|
this._boxPointer.style_class = 'app-folder-popup';
|
|
|
|
this.actor.add_actor(this._boxPointer);
|
2013-01-31 11:13:37 -05:00
|
|
|
this._boxPointer.bin.set_child(this._view.actor);
|
|
|
|
|
2013-09-10 05:48:55 -04:00
|
|
|
this.closeButton = Util.makeCloseButton(this._boxPointer);
|
2017-12-01 19:27:35 -05:00
|
|
|
this.closeButton.connect('clicked', this.popdown.bind(this));
|
2013-05-16 13:35:12 -04:00
|
|
|
this.actor.add_actor(this.closeButton);
|
2013-01-31 11:13:37 -05:00
|
|
|
|
2019-04-09 16:21:15 -04:00
|
|
|
this._boxPointer.bind_property('opacity', this.closeButton, 'opacity',
|
|
|
|
GObject.BindingFlags.SYNC_CREATE);
|
2013-01-31 11:13:37 -05:00
|
|
|
|
2013-03-06 15:42:36 -05:00
|
|
|
global.focus_manager.add_group(this.actor);
|
|
|
|
|
2018-10-11 14:12:54 -04:00
|
|
|
this._grabHelper = new GrabHelper.GrabHelper(this.actor, {
|
|
|
|
actionMode: Shell.ActionMode.POPUP
|
|
|
|
});
|
2014-06-16 04:24:39 -04:00
|
|
|
this._grabHelper.addActor(Main.layoutManager.overviewGroup);
|
2017-12-01 19:27:35 -05:00
|
|
|
this.actor.connect('key-press-event', this._onKeyPress.bind(this));
|
2019-07-22 11:02:10 -04:00
|
|
|
this.actor.connect('destroy', this._onDestroy.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
_onDestroy() {
|
|
|
|
if (this._isOpen) {
|
|
|
|
this._isOpen = false;
|
|
|
|
this._grabHelper.ungrab({ actor: this.actor });
|
|
|
|
this._grabHelper = null;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-06-11 09:27:40 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onKeyPress(actor, event) {
|
2014-06-11 09:27:40 -04:00
|
|
|
if (global.stage.get_key_focus() != actor)
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
// Since we need to only grab focus on one item child when the user
|
|
|
|
// actually press a key we don't use navigate_focus when opening
|
|
|
|
// the popup.
|
|
|
|
// Instead of that, grab the focus on the AppFolderPopup actor
|
|
|
|
// and actually moves the focus to a child only when the user
|
|
|
|
// actually press a key.
|
|
|
|
// It should work with just grab_key_focus on the AppFolderPopup
|
|
|
|
// actor, but since the arrow keys are not wrapping_around the focus
|
|
|
|
// is not grabbed by a child when the widget that has the current focus
|
|
|
|
// is the same that is requesting focus, so to make it works with arrow
|
|
|
|
// keys we need to connect to the key-press-event and navigate_focus
|
|
|
|
// when that happens using TAB_FORWARD or TAB_BACKWARD instead of arrow
|
|
|
|
// keys
|
|
|
|
|
|
|
|
// Use TAB_FORWARD for down key and right key
|
|
|
|
// and TAB_BACKWARD for up key and left key on ltr
|
|
|
|
// languages
|
|
|
|
let direction;
|
|
|
|
let isLtr = Clutter.get_default_text_direction() == Clutter.TextDirection.LTR;
|
|
|
|
switch (event.get_key_symbol()) {
|
2019-02-01 07:21:00 -05:00
|
|
|
case Clutter.Down:
|
|
|
|
direction = St.DirectionType.TAB_FORWARD;
|
|
|
|
break;
|
|
|
|
case Clutter.Right:
|
2019-09-12 18:27:56 -04:00
|
|
|
direction = isLtr
|
|
|
|
? St.DirectionType.TAB_FORWARD
|
|
|
|
: St.DirectionType.TAB_BACKWARD;
|
2019-02-01 07:21:00 -05:00
|
|
|
break;
|
|
|
|
case Clutter.Up:
|
|
|
|
direction = St.DirectionType.TAB_BACKWARD;
|
|
|
|
break;
|
|
|
|
case Clutter.Left:
|
2019-09-12 18:27:56 -04:00
|
|
|
direction = isLtr
|
|
|
|
? St.DirectionType.TAB_BACKWARD
|
|
|
|
: St.DirectionType.TAB_FORWARD;
|
2019-02-01 07:21:00 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2014-06-11 09:27:40 -04:00
|
|
|
}
|
|
|
|
return actor.navigate_focus(null, direction, false);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-01-31 11:13:37 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
toggle() {
|
2013-01-31 11:13:37 -05:00
|
|
|
if (this._isOpen)
|
|
|
|
this.popdown();
|
|
|
|
else
|
|
|
|
this.popup();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-01-31 11:13:37 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
popup() {
|
2013-01-31 11:13:37 -05:00
|
|
|
if (this._isOpen)
|
|
|
|
return;
|
|
|
|
|
2014-06-11 07:13:12 -04:00
|
|
|
this._isOpen = this._grabHelper.grab({ actor: this.actor,
|
2017-12-01 19:27:35 -05:00
|
|
|
onUngrab: this.popdown.bind(this) });
|
2014-06-11 07:13:12 -04:00
|
|
|
|
|
|
|
if (!this._isOpen)
|
|
|
|
return;
|
|
|
|
|
2013-01-31 11:13:37 -05:00
|
|
|
this.actor.show();
|
2013-02-20 08:13:46 -05:00
|
|
|
|
|
|
|
this._boxPointer.setArrowActor(this._source.actor);
|
2014-06-17 06:47:00 -04:00
|
|
|
// We need to hide the icons of the view until the boxpointer animation
|
|
|
|
// is completed so we can animate the icons after as we like without
|
|
|
|
// showing them while boxpointer is animating.
|
|
|
|
this._view.actor.opacity = 0;
|
2018-08-21 06:29:44 -04:00
|
|
|
this._boxPointer.open(BoxPointer.PopupAnimation.FADE |
|
2014-06-17 06:47:00 -04:00
|
|
|
BoxPointer.PopupAnimation.SLIDE,
|
2017-10-30 20:38:18 -04:00
|
|
|
() => {
|
2019-01-29 14:36:54 -05:00
|
|
|
this._view.actor.opacity = 255;
|
|
|
|
this._view.animate(IconGrid.AnimationDirection.IN);
|
|
|
|
});
|
2013-01-31 11:13:37 -05:00
|
|
|
|
|
|
|
this.emit('open-state-changed', true);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-01-31 11:13:37 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
popdown() {
|
2013-01-31 11:13:37 -05:00
|
|
|
if (!this._isOpen)
|
|
|
|
return;
|
|
|
|
|
2014-06-11 07:13:12 -04:00
|
|
|
this._grabHelper.ungrab({ actor: this.actor });
|
|
|
|
|
2018-08-21 06:29:44 -04:00
|
|
|
this._boxPointer.close(BoxPointer.PopupAnimation.FADE |
|
|
|
|
BoxPointer.PopupAnimation.SLIDE);
|
2013-01-31 11:13:37 -05:00
|
|
|
this._isOpen = false;
|
|
|
|
this.emit('open-state-changed', false);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-30 12:50:35 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getCloseButtonOverlap() {
|
2013-08-30 12:50:35 -04:00
|
|
|
return this.closeButton.get_theme_node().get_length('-shell-close-overlap-y');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-30 12:50:35 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getOffset(side) {
|
2013-08-30 12:50:35 -04:00
|
|
|
let offset = this._boxPointer.getPadding(side);
|
|
|
|
if (this._arrowSide == side)
|
|
|
|
offset += this._boxPointer.getArrowHeight();
|
|
|
|
return offset;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-30 12:50:35 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
updateArrowSide(side) {
|
2013-08-30 12:50:35 -04:00
|
|
|
this._arrowSide = side;
|
|
|
|
this._boxPointer.updateArrowSide(side);
|
2013-01-31 11:13:37 -05:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2013-01-31 11:13:37 -05:00
|
|
|
Signals.addSignalMethods(AppFolderPopup.prototype);
|
2013-01-30 17:51:43 -05:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var AppIcon = class AppIcon {
|
2019-07-11 19:31:38 -04:00
|
|
|
constructor(app, iconParams = {}) {
|
2009-12-08 12:51:05 -05:00
|
|
|
this.app = app;
|
2013-12-15 22:18:17 -05:00
|
|
|
this.id = app.get_id();
|
|
|
|
this.name = app.get_name();
|
|
|
|
|
2011-01-25 16:22:00 -05:00
|
|
|
this.actor = new St.Button({ style_class: 'app-well-app',
|
2019-06-29 13:09:32 -04:00
|
|
|
pivot_point: new Clutter.Point({ x: 0.5, y: 0.5 }),
|
2011-01-25 16:22:00 -05:00
|
|
|
reactive: true,
|
|
|
|
button_mask: St.ButtonMask.ONE | St.ButtonMask.TWO,
|
2011-02-03 12:38:03 -05:00
|
|
|
can_focus: true,
|
2011-01-25 16:22:00 -05:00
|
|
|
x_fill: true,
|
|
|
|
y_fill: true });
|
2015-02-17 12:33:37 -05:00
|
|
|
|
|
|
|
this._dot = new St.Widget({ style_class: 'app-well-app-running-dot',
|
|
|
|
layout_manager: new Clutter.BinLayout(),
|
|
|
|
x_expand: true, y_expand: true,
|
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
y_align: Clutter.ActorAlign.END });
|
|
|
|
|
|
|
|
this._iconContainer = new St.Widget({ layout_manager: new Clutter.BinLayout(),
|
|
|
|
x_expand: true, y_expand: true });
|
|
|
|
|
|
|
|
this.actor.set_child(this._iconContainer);
|
|
|
|
this._iconContainer.add_child(this._dot);
|
|
|
|
|
2009-12-08 12:51:05 -05:00
|
|
|
this.actor._delegate = this;
|
|
|
|
|
2019-07-12 18:32:54 -04:00
|
|
|
this._hasDndHover = false;
|
|
|
|
this._folderPreviewId = 0;
|
|
|
|
|
2015-01-27 16:10:45 -05:00
|
|
|
// Get the isDraggable property without passing it on to the BaseIcon:
|
|
|
|
let appIconParams = Params.parse(iconParams, { isDraggable: true }, true);
|
|
|
|
let isDraggable = appIconParams['isDraggable'];
|
|
|
|
delete iconParams['isDraggable'];
|
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
iconParams['createIcon'] = this._createIcon.bind(this);
|
2013-08-15 04:38:17 -04:00
|
|
|
iconParams['setSizeManually'] = true;
|
2013-01-30 17:51:43 -05:00
|
|
|
this.icon = new IconGrid.BaseIcon(app.get_name(), iconParams);
|
2018-06-30 14:00:08 -04:00
|
|
|
this._iconContainer.add_child(this.icon);
|
2009-12-08 12:51:05 -05:00
|
|
|
|
2011-03-08 13:33:57 -05:00
|
|
|
this.actor.label_actor = this.icon.label;
|
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
this.actor.connect('leave-event', this._onLeaveEvent.bind(this));
|
|
|
|
this.actor.connect('button-press-event', this._onButtonPress.bind(this));
|
|
|
|
this.actor.connect('touch-event', this._onTouchEvent.bind(this));
|
|
|
|
this.actor.connect('clicked', this._onClicked.bind(this));
|
|
|
|
this.actor.connect('popup-menu', this._onKeyboardPopupMenu.bind(this));
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2009-12-08 12:51:05 -05:00
|
|
|
this._menu = null;
|
2019-04-09 19:23:59 -04:00
|
|
|
this._menuManager = new PopupMenu.PopupMenuManager(this.actor);
|
2009-12-08 12:51:05 -05:00
|
|
|
|
2015-01-27 16:10:45 -05:00
|
|
|
if (isDraggable) {
|
|
|
|
this._draggable = DND.makeDraggable(this.actor);
|
2017-10-30 20:38:18 -04:00
|
|
|
this._draggable.connect('drag-begin', () => {
|
2019-06-29 00:32:40 -04:00
|
|
|
this._dragging = true;
|
2019-07-04 17:39:13 -04:00
|
|
|
this.scaleAndFade();
|
2017-10-30 20:38:18 -04:00
|
|
|
this._removeMenuTimeout();
|
|
|
|
Main.overview.beginItemDrag(this);
|
|
|
|
});
|
|
|
|
this._draggable.connect('drag-cancelled', () => {
|
2019-06-29 00:32:40 -04:00
|
|
|
this._dragging = false;
|
2017-10-30 20:38:18 -04:00
|
|
|
Main.overview.cancelledItemDrag(this);
|
|
|
|
});
|
|
|
|
this._draggable.connect('drag-end', () => {
|
2019-06-29 00:32:40 -04:00
|
|
|
this._dragging = false;
|
2019-07-04 17:39:13 -04:00
|
|
|
this.undoScaleAndFade();
|
2019-01-29 14:36:54 -05:00
|
|
|
Main.overview.endItemDrag(this);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2015-01-27 16:10:45 -05:00
|
|
|
}
|
2009-12-08 12:51:05 -05:00
|
|
|
|
2019-08-09 17:27:57 -04:00
|
|
|
this._itemDragBeginId = Main.overview.connect(
|
|
|
|
'item-drag-begin', this._onDragBegin.bind(this));
|
|
|
|
this._itemDragEndId = Main.overview.connect(
|
|
|
|
'item-drag-end', this._onDragEnd.bind(this));
|
2019-07-12 18:32:54 -04:00
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
this.actor.connect('destroy', this._onDestroy.bind(this));
|
2010-01-07 00:40:21 -05:00
|
|
|
|
2010-03-10 08:52:28 -05:00
|
|
|
this._menuTimeoutId = 0;
|
2017-10-30 20:38:18 -04:00
|
|
|
this._stateChangedId = this.app.connect('notify::state', () => {
|
|
|
|
this._updateRunningStyle();
|
|
|
|
});
|
2014-11-01 10:24:03 -04:00
|
|
|
this._updateRunningStyle();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-01-07 00:40:21 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onDestroy() {
|
2019-08-09 17:27:57 -04:00
|
|
|
Main.overview.disconnect(this._itemDragBeginId);
|
|
|
|
Main.overview.disconnect(this._itemDragEndId);
|
|
|
|
|
2019-07-12 18:32:54 -04:00
|
|
|
if (this._folderPreviewId > 0) {
|
|
|
|
GLib.source_remove(this._folderPreviewId);
|
|
|
|
this._folderPreviewId = 0;
|
|
|
|
}
|
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);
|
2019-08-09 17:30:44 -04:00
|
|
|
if (this._draggable) {
|
|
|
|
if (this._dragging)
|
|
|
|
Main.overview.endItemDrag(this);
|
|
|
|
this._draggable = null;
|
2019-06-29 00:32:40 -04:00
|
|
|
}
|
2010-06-05 18:35:26 -04:00
|
|
|
this._stateChangedId = 0;
|
2010-03-10 08:52:28 -05:00
|
|
|
this._removeMenuTimeout();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-03-10 08:52:28 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_createIcon(iconSize) {
|
2013-01-30 17:51:43 -05:00
|
|
|
return this.app.create_icon_texture(iconSize);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-01-30 17:51:43 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_removeMenuTimeout() {
|
2010-03-10 08:52:28 -05:00
|
|
|
if (this._menuTimeoutId > 0) {
|
2019-08-19 14:50:33 -04:00
|
|
|
GLib.source_remove(this._menuTimeoutId);
|
2010-03-10 08:52:28 -05:00
|
|
|
this._menuTimeoutId = 0;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-01-07 00:40:21 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateRunningStyle() {
|
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.app.state != Shell.AppState.STOPPED)
|
2015-02-17 12:33:37 -05:00
|
|
|
this._dot.show();
|
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
|
2015-02-17 12:33:37 -05:00
|
|
|
this._dot.hide();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-11-12 17:46:59 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_setPopupTimeout() {
|
2014-07-22 06:40:54 -04:00
|
|
|
this._removeMenuTimeout();
|
2019-08-19 14:50:33 -04:00
|
|
|
this._menuTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, MENU_POPUP_TIMEOUT, () => {
|
2017-10-30 20:38:18 -04:00
|
|
|
this._menuTimeoutId = 0;
|
|
|
|
this.popupMenu();
|
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
});
|
2014-07-22 06:40:54 -04:00
|
|
|
GLib.Source.set_name_by_id(this._menuTimeoutId, '[gnome-shell] this.popupMenu');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-07-22 06:40:54 -04:00
|
|
|
|
2019-02-04 06:30:53 -05:00
|
|
|
_onLeaveEvent(_actor, _event) {
|
2014-07-22 06:40:54 -04:00
|
|
|
this.actor.fake_release();
|
|
|
|
this._removeMenuTimeout();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-07-22 06:40:54 -04:00
|
|
|
|
2019-02-04 06:30:53 -05:00
|
|
|
_onButtonPress(_actor, event) {
|
2010-03-10 08:52:28 -05:00
|
|
|
let button = event.get_button();
|
|
|
|
if (button == 1) {
|
2014-07-22 06:40:54 -04:00
|
|
|
this._setPopupTimeout();
|
2011-01-26 11:15:41 -05:00
|
|
|
} else if (button == 3) {
|
|
|
|
this.popupMenu();
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_STOP;
|
2010-03-10 08:52:28 -05:00
|
|
|
}
|
2013-11-29 13:17:34 -05:00
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-11-12 17:46:59 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onTouchEvent(actor, event) {
|
2014-07-22 06:40:54 -04:00
|
|
|
if (event.type() == Clutter.EventType.TOUCH_BEGIN)
|
|
|
|
this._setPopupTimeout();
|
|
|
|
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-07-22 06:40:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onClicked(actor, button) {
|
2010-03-10 08:52:28 -05:00
|
|
|
this._removeMenuTimeout();
|
2014-08-20 12:39:02 -04:00
|
|
|
this.activate(button);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-11-12 17:46:59 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onKeyboardPopupMenu() {
|
2011-02-03 12:38:03 -05:00
|
|
|
this.popupMenu();
|
2018-11-27 07:58:25 -05:00
|
|
|
this._menu.actor.navigate_focus(null, St.DirectionType.TAB_FORWARD, false);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-02-03 12:38:03 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getId() {
|
2010-02-15 19:50:36 -05:00
|
|
|
return this.app.get_id();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-02-15 19:50:36 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
popupMenu() {
|
2010-03-10 08:52:28 -05:00
|
|
|
this._removeMenuTimeout();
|
|
|
|
this.actor.fake_release();
|
2015-01-27 16:10:45 -05:00
|
|
|
|
|
|
|
if (this._draggable)
|
|
|
|
this._draggable.fakeRelease();
|
2010-03-10 08:52:28 -05:00
|
|
|
|
2009-11-12 17:46:59 -05:00
|
|
|
if (!this._menu) {
|
|
|
|
this._menu = new AppIconMenu(this);
|
2017-10-30 20:38:18 -04:00
|
|
|
this._menu.connect('activate-window', (menu, window) => {
|
2009-11-12 17:46:59 -05:00
|
|
|
this.activateWindow(window);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
|
|
|
this._menu.connect('open-state-changed', (menu, isPoppedUp) => {
|
2011-02-12 14:03:44 -05:00
|
|
|
if (!isPoppedUp)
|
2009-11-12 17:46:59 -05:00
|
|
|
this._onMenuPoppedDown();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
|
|
|
let id = Main.overview.connect('hiding', () => {
|
|
|
|
this._menu.close();
|
|
|
|
});
|
|
|
|
this.actor.connect('destroy', () => {
|
2015-03-03 19:51:19 -05:00
|
|
|
Main.overview.disconnect(id);
|
|
|
|
});
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2010-10-07 14:15:51 -04:00
|
|
|
this._menuManager.addMenu(this._menu);
|
2009-11-12 17:46:59 -05:00
|
|
|
}
|
|
|
|
|
2012-11-03 16:03:33 -04:00
|
|
|
this.emit('menu-state-changed', true);
|
|
|
|
|
2011-03-22 10:43:27 -04:00
|
|
|
this.actor.set_hover(true);
|
2010-05-20 11:18:46 -04:00
|
|
|
this._menu.popup();
|
2012-02-29 19:09:41 -05:00
|
|
|
this._menuManager.ignoreRelease();
|
2013-08-18 10:20:22 -04:00
|
|
|
this.emit('sync-tooltip');
|
2009-11-12 17:46:59 -05:00
|
|
|
|
|
|
|
return false;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-11-12 17:46:59 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
activateWindow(metaWindow) {
|
2009-12-08 12:51:05 -05:00
|
|
|
if (metaWindow) {
|
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
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-12-08 12:51:05 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onMenuPoppedDown() {
|
2010-03-19 13:47:34 -04:00
|
|
|
this.actor.sync_hover();
|
2012-11-03 16:03:33 -04:00
|
|
|
this.emit('menu-state-changed', false);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-12-08 12:51:05 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
activate(button) {
|
2014-08-20 12:39:02 -04:00
|
|
|
let event = Clutter.get_current_event();
|
|
|
|
let modifiers = event ? event.get_state() : 0;
|
2018-05-29 00:27:22 -04:00
|
|
|
let isMiddleButton = button && button == Clutter.BUTTON_MIDDLE;
|
|
|
|
let isCtrlPressed = (modifiers & Clutter.ModifierType.CONTROL_MASK) != 0;
|
|
|
|
let openNewWindow = this.app.can_open_new_window() &&
|
|
|
|
this.app.state == Shell.AppState.RUNNING &&
|
|
|
|
(isCtrlPressed || isMiddleButton);
|
2009-12-08 12:51:05 -05:00
|
|
|
|
2014-06-17 15:31:53 -04:00
|
|
|
if (this.app.state == Shell.AppState.STOPPED || openNewWindow)
|
|
|
|
this.animateLaunch();
|
|
|
|
|
2014-08-20 12:39:02 -04:00
|
|
|
if (openNewWindow)
|
2013-02-17 23:08:41 -05:00
|
|
|
this.app.open_new_window(-1);
|
2014-08-20 12:39:02 -04:00
|
|
|
else
|
2013-02-17 23:08:41 -05:00
|
|
|
this.app.activate();
|
|
|
|
|
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();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-09-01 14:15:29 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
animateLaunch() {
|
2014-06-17 15:31:53 -04:00
|
|
|
this.icon.animateZoomOut();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-06-17 15:31:53 -04:00
|
|
|
|
2019-09-15 05:40:27 -04:00
|
|
|
animateLaunchAtPos(x, y) {
|
|
|
|
this.icon.animateZoomOutAtPos(x, y);
|
|
|
|
}
|
|
|
|
|
2019-06-29 13:09:32 -04:00
|
|
|
scaleIn() {
|
|
|
|
this.actor.scale_x = 0;
|
|
|
|
this.actor.scale_y = 0;
|
|
|
|
|
|
|
|
this.actor.ease({
|
|
|
|
scale_x: 1,
|
|
|
|
scale_y: 1,
|
|
|
|
time: APP_ICON_SCALE_IN_TIME,
|
|
|
|
delay: APP_ICON_SCALE_IN_DELAY,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUINT
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
shellWorkspaceLaunch(params) {
|
2019-08-02 06:58:34 -04:00
|
|
|
let { stack } = new Error();
|
|
|
|
log(`shellWorkspaceLaunch is deprecated, use app.open_new_window() instead\n${stack}`);
|
|
|
|
|
2011-08-11 05:35:23 -04:00
|
|
|
params = Params.parse(params, { workspace: -1,
|
|
|
|
timestamp: 0 });
|
2011-01-30 16:09:58 -05:00
|
|
|
|
2011-08-11 05:35:23 -04:00
|
|
|
this.app.open_new_window(params.workspace);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-08-17 20:29:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getDragActor() {
|
2011-08-28 09:35:13 -04:00
|
|
|
return this.app.create_icon_texture(Main.overview.dashIconSize);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
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.
|
2017-10-30 20:03:21 -04:00
|
|
|
getDragActorSource() {
|
2010-07-21 19:29:02 -04:00
|
|
|
return this.icon.icon;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-08-18 10:20:22 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
shouldShowTooltip() {
|
2013-08-18 10:20:22 -04:00
|
|
|
return this.actor.hover && (!this._menu || !this._menu.isOpen);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2019-07-04 17:39:13 -04:00
|
|
|
|
|
|
|
scaleAndFade() {
|
|
|
|
this.actor.reactive = false;
|
|
|
|
this.actor.ease({
|
|
|
|
scale_x: 0.75,
|
|
|
|
scale_y: 0.75,
|
|
|
|
opacity: 128
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
undoScaleAndFade() {
|
|
|
|
this.actor.reactive = true;
|
|
|
|
this.actor.ease({
|
|
|
|
scale_x: 1.0,
|
|
|
|
scale_y: 1.0,
|
|
|
|
opacity: 255
|
|
|
|
});
|
|
|
|
}
|
2019-07-12 18:32:54 -04:00
|
|
|
|
|
|
|
_showFolderPreview() {
|
|
|
|
this.icon.label.opacity = 0;
|
|
|
|
this.icon.icon.ease({
|
|
|
|
scale_x: FOLDER_SUBICON_FRACTION,
|
|
|
|
scale_y: FOLDER_SUBICON_FRACTION
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_hideFolderPreview() {
|
|
|
|
this.icon.label.opacity = 255;
|
|
|
|
this.icon.icon.ease({
|
|
|
|
scale_x: 1.0,
|
|
|
|
scale_y: 1.0
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_canAccept(source) {
|
|
|
|
let view = _getViewFromIcon(source);
|
|
|
|
|
|
|
|
return source != this &&
|
|
|
|
(source instanceof AppIcon) &&
|
|
|
|
(view instanceof AllView);
|
|
|
|
}
|
|
|
|
|
|
|
|
_setHoveringByDnd(hovering) {
|
|
|
|
if (hovering) {
|
|
|
|
if (this._folderPreviewId > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._folderPreviewId =
|
|
|
|
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 500, () => {
|
|
|
|
this.actor.add_style_pseudo_class('drop');
|
|
|
|
this._showFolderPreview();
|
|
|
|
this._folderPreviewId = 0;
|
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (this._folderPreviewId > 0) {
|
|
|
|
GLib.source_remove(this._folderPreviewId);
|
|
|
|
this._folderPreviewId = 0;
|
|
|
|
}
|
|
|
|
this._hideFolderPreview();
|
|
|
|
this.actor.remove_style_pseudo_class('drop');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_onDragBegin() {
|
|
|
|
this._dragMonitor = {
|
|
|
|
dragMotion: this._onDragMotion.bind(this),
|
|
|
|
};
|
|
|
|
DND.addDragMonitor(this._dragMonitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onDragMotion(dragEvent) {
|
|
|
|
let target = dragEvent.targetActor;
|
|
|
|
let isHovering = target == this.actor || this.actor.contains(target);
|
|
|
|
let canDrop = this._canAccept(dragEvent.source);
|
|
|
|
let hasDndHover = isHovering && canDrop;
|
|
|
|
|
|
|
|
if (this._hasDndHover != hasDndHover) {
|
|
|
|
this._setHoveringByDnd(hasDndHover);
|
|
|
|
this._hasDndHover = hasDndHover;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DND.DragMotionResult.CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
_onDragEnd() {
|
|
|
|
this.actor.remove_style_pseudo_class('drop');
|
|
|
|
DND.removeDragMonitor(this._dragMonitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleDragOver(source) {
|
|
|
|
if (source == this)
|
|
|
|
return DND.DragMotionResult.NO_DROP;
|
|
|
|
|
|
|
|
if (!this._canAccept(source))
|
|
|
|
return DND.DragMotionResult.CONTINUE;
|
|
|
|
|
|
|
|
return DND.DragMotionResult.MOVE_DROP;
|
|
|
|
}
|
|
|
|
|
|
|
|
acceptDrop(source) {
|
|
|
|
this._setHoveringByDnd(false);
|
|
|
|
|
|
|
|
if (!this._canAccept(source))
|
|
|
|
return false;
|
|
|
|
|
2019-07-16 16:51:25 -04:00
|
|
|
let view = _getViewFromIcon(this);
|
|
|
|
let apps = [this.id, source.id];
|
|
|
|
|
|
|
|
return view.createFolder(apps);
|
2019-07-12 18:32:54 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2013-01-30 17:51:43 -05:00
|
|
|
Signals.addSignalMethods(AppIcon.prototype);
|
2009-11-12 17:46:59 -05:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var AppIconMenu = class AppIconMenu extends PopupMenu.PopupMenu {
|
|
|
|
constructor(source) {
|
2010-11-29 16:07:10 -05:00
|
|
|
let side = St.Side.LEFT;
|
2012-02-13 20:37:28 -05:00
|
|
|
if (Clutter.get_default_text_direction() == Clutter.TextDirection.RTL)
|
2010-11-29 16:07:10 -05:00
|
|
|
side = St.Side.RIGHT;
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
super(source.actor, 0.5, side);
|
2010-05-20 11:18:46 -04:00
|
|
|
|
2011-03-22 10:43:27 -04:00
|
|
|
// We want to keep the item hovered while the menu is up
|
|
|
|
this.blockSourceEvents = true;
|
|
|
|
|
2009-11-12 17:46:59 -05:00
|
|
|
this._source = source;
|
|
|
|
|
2010-05-20 11:18:46 -04:00
|
|
|
this.actor.add_style_class_name('app-well-menu');
|
2009-11-12 17:46:59 -05:00
|
|
|
|
|
|
|
// Chain our visibility and lifecycle to that of the source
|
2017-12-06 00:55:37 -05:00
|
|
|
this._sourceMappedId = source.actor.connect('notify::mapped', () => {
|
2009-11-12 17:46:59 -05:00
|
|
|
if (!source.actor.mapped)
|
2010-05-20 11:18:46 -04:00
|
|
|
this.close();
|
2017-12-06 00:55:37 -05:00
|
|
|
});
|
|
|
|
source.actor.connect('destroy', () => {
|
|
|
|
source.actor.disconnect(this._sourceMappedId);
|
|
|
|
this.destroy();
|
|
|
|
});
|
2009-11-12 17:46:59 -05:00
|
|
|
|
2010-05-06 17:18:10 -04:00
|
|
|
Main.uiGroup.add_actor(this.actor);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-11-12 17:46:59 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_redisplay() {
|
2010-05-20 11:18:46 -04:00
|
|
|
this.removeAll();
|
2009-11-12 17:46:59 -05:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
let windows = this._source.app.get_windows().filter(
|
|
|
|
w => !w.skip_taskbar
|
|
|
|
);
|
2009-11-12 17:46:59 -05:00
|
|
|
|
2019-02-12 07:37:39 -05:00
|
|
|
if (windows.length > 0)
|
|
|
|
this.addMenuItem(
|
|
|
|
/* Translators: This is the heading of a list of open windows */
|
|
|
|
new PopupMenu.PopupSeparatorMenuItem(_("Open Windows"))
|
|
|
|
);
|
|
|
|
|
|
|
|
windows.forEach(window => {
|
2019-08-19 15:33:15 -04:00
|
|
|
let title = window.title
|
|
|
|
? window.title : this._source.app.get_name();
|
2018-02-20 12:16:52 -05:00
|
|
|
let item = this._appendMenuItem(title);
|
2017-10-30 20:38:18 -04:00
|
|
|
item.connect('activate', () => {
|
2011-11-21 13:01:05 -05:00
|
|
|
this.emit('activate-window', window);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2019-02-12 07:37:39 -05:00
|
|
|
});
|
2009-11-12 17:46:59 -05:00
|
|
|
|
2011-08-11 06:06:38 -04:00
|
|
|
if (!this._source.app.is_window_backed()) {
|
2011-11-21 13:01:05 -05:00
|
|
|
this._appendSeparator();
|
2009-11-12 17:46:59 -05:00
|
|
|
|
2015-02-12 20:03:33 -05:00
|
|
|
let appInfo = this._source.app.get_app_info();
|
|
|
|
let actions = appInfo.list_actions();
|
|
|
|
if (this._source.app.can_open_new_window() &&
|
2019-07-10 16:52:09 -04:00
|
|
|
!actions.includes('new-window')) {
|
2014-01-19 12:05:16 -05:00
|
|
|
this._newWindowMenuItem = this._appendMenuItem(_("New Window"));
|
2017-10-30 20:38:18 -04:00
|
|
|
this._newWindowMenuItem.connect('activate', () => {
|
2019-08-08 11:27:40 -04:00
|
|
|
this._source.animateLaunch();
|
2014-01-19 12:05:16 -05:00
|
|
|
this._source.app.open_new_window(-1);
|
|
|
|
this.emit('activate-window', null);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2014-01-19 12:05:16 -05:00
|
|
|
this._appendSeparator();
|
|
|
|
}
|
2011-11-21 13:01:05 -05:00
|
|
|
|
2016-10-19 09:58:16 -04:00
|
|
|
if (discreteGpuAvailable &&
|
|
|
|
this._source.app.state == Shell.AppState.STOPPED &&
|
2019-07-10 16:52:09 -04:00
|
|
|
!actions.includes('activate-discrete-gpu')) {
|
2016-10-19 09:58:16 -04:00
|
|
|
this._onDiscreteGpuMenuItem = this._appendMenuItem(_("Launch using Dedicated Graphics Card"));
|
2017-10-30 20:38:18 -04:00
|
|
|
this._onDiscreteGpuMenuItem.connect('activate', () => {
|
2019-08-08 11:27:40 -04:00
|
|
|
this._source.animateLaunch();
|
2016-10-19 09:58:16 -04:00
|
|
|
this._source.app.launch(0, -1, true);
|
|
|
|
this.emit('activate-window', null);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2016-10-19 09:58:16 -04:00
|
|
|
}
|
|
|
|
|
2014-01-19 12:46:36 -05:00
|
|
|
for (let i = 0; i < actions.length; i++) {
|
|
|
|
let action = actions[i];
|
|
|
|
let item = this._appendMenuItem(appInfo.get_action_name(action));
|
2017-10-30 20:38:18 -04:00
|
|
|
item.connect('activate', (emitter, event) => {
|
2019-08-08 12:15:32 -04:00
|
|
|
if (action == 'new-window' ||
|
|
|
|
action == 'activate-discrete-gpu')
|
2019-08-02 08:23:13 -04:00
|
|
|
this._source.animateLaunch();
|
|
|
|
|
2014-01-19 12:46:36 -05:00
|
|
|
this._source.app.launch_action(action, event.get_time(), -1);
|
|
|
|
this.emit('activate-window', null);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2014-01-19 12:46:36 -05:00
|
|
|
}
|
2009-11-12 17:46:59 -05:00
|
|
|
|
2015-03-20 15:30:57 -04:00
|
|
|
let canFavorite = global.settings.is_writable('favorite-apps');
|
2011-11-21 13:01:05 -05:00
|
|
|
|
2014-12-11 10:22:19 -05:00
|
|
|
if (canFavorite) {
|
|
|
|
this._appendSeparator();
|
|
|
|
|
|
|
|
let isFavorite = AppFavorites.getAppFavorites().isFavorite(this._source.app.get_id());
|
|
|
|
|
|
|
|
if (isFavorite) {
|
|
|
|
let item = this._appendMenuItem(_("Remove from Favorites"));
|
2017-10-30 20:38:18 -04:00
|
|
|
item.connect('activate', () => {
|
2014-12-11 10:22:19 -05:00
|
|
|
let favs = AppFavorites.getAppFavorites();
|
|
|
|
favs.removeFavorite(this._source.app.get_id());
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2014-12-11 10:22:19 -05:00
|
|
|
} else {
|
|
|
|
let item = this._appendMenuItem(_("Add to Favorites"));
|
2017-10-30 20:38:18 -04:00
|
|
|
item.connect('activate', () => {
|
2014-12-11 10:22:19 -05:00
|
|
|
let favs = AppFavorites.getAppFavorites();
|
|
|
|
favs.addFavorite(this._source.app.get_id());
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2014-12-11 10:22:19 -05:00
|
|
|
}
|
2011-11-21 13:01:05 -05:00
|
|
|
}
|
2013-11-02 15:36:34 -04:00
|
|
|
|
|
|
|
if (Shell.AppSystem.get_default().lookup_app('org.gnome.Software.desktop')) {
|
|
|
|
this._appendSeparator();
|
|
|
|
let item = this._appendMenuItem(_("Show Details"));
|
2017-10-30 20:38:18 -04:00
|
|
|
item.connect('activate', () => {
|
2013-11-02 15:36:34 -04:00
|
|
|
let id = this._source.app.get_id();
|
|
|
|
let args = GLib.Variant.new('(ss)', [id, '']);
|
2017-10-30 20:38:18 -04:00
|
|
|
Gio.DBus.get(Gio.BusType.SESSION, null, (o, res) => {
|
|
|
|
let bus = Gio.DBus.get_finish(res);
|
|
|
|
bus.call('org.gnome.Software',
|
|
|
|
'/org/gnome/Software',
|
|
|
|
'org.gtk.Actions', 'Activate',
|
|
|
|
GLib.Variant.new('(sava{sv})',
|
|
|
|
['details', [args], null]),
|
|
|
|
null, 0, -1, null, null);
|
|
|
|
Main.overview.hide();
|
|
|
|
});
|
|
|
|
});
|
2013-11-02 15:36:34 -04:00
|
|
|
}
|
2011-08-11 06:06:38 -04:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-11-12 17:46:59 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_appendSeparator() {
|
2010-05-20 11:18:46 -04:00
|
|
|
let separator = new PopupMenu.PopupSeparatorMenuItem();
|
|
|
|
this.addMenuItem(separator);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-11-12 17:46:59 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_appendMenuItem(labelText) {
|
2010-05-20 11:18:46 -04:00
|
|
|
// FIXME: app-well-menu-item style
|
|
|
|
let item = new PopupMenu.PopupMenuItem(labelText);
|
|
|
|
this.addMenuItem(item);
|
|
|
|
return item;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-11-12 17:46:59 -05:00
|
|
|
|
2019-01-31 09:08:10 -05:00
|
|
|
popup(_activatingButton) {
|
2009-11-12 17:46:59 -05:00
|
|
|
this._redisplay();
|
2010-05-20 11:18:46 -04:00
|
|
|
this.open();
|
2009-11-12 17:46:59 -05:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2009-11-12 17:46:59 -05:00
|
|
|
Signals.addSignalMethods(AppIconMenu.prototype);
|
2017-08-21 09:20:25 -04:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var SystemActionIcon = class SystemActionIcon extends Search.GridSearchResult {
|
2017-10-30 20:03:21 -04:00
|
|
|
activate() {
|
2017-08-21 09:20:25 -04:00
|
|
|
SystemActions.getDefault().activateAction(this.metaInfo['id']);
|
|
|
|
Main.overview.hide();
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|