Add close button

This commit is contained in:
Charles Gagnon
2019-05-19 10:42:22 -04:00
parent 2033f1b00c
commit aa87cb800d
5 changed files with 143 additions and 67 deletions

View File

@@ -864,7 +864,7 @@ var taskbarAppIcon = Utils.defineClass({
this.actor.add_style_class_name(className);
}
this._previewMenu.updateWindows(this, windows);
this._previewMenu.update(this, windows);
},
_getRunningIndicatorCount: function() {

View File

@@ -385,7 +385,7 @@ var dtpPanelManager = Utils.defineClass({
},
_newGetShowAppsButton: function() {
let focusedMonitorIndex = Taskbar.findIndex(this.allPanels, p => this.checkIfFocusedMonitor(p.monitor));
let focusedMonitorIndex = Utils.findIndex(this.allPanels, p => this.checkIfFocusedMonitor(p.monitor));
return this.allPanels[focusedMonitorIndex].taskbar.showAppsButton;
},

View File

@@ -84,21 +84,6 @@ function extendDashItemContainer(dashItemContainer) {
* - modified chldBox calculations for when 'show-apps-at-top' option is checked
* - handle horizontal dash
*/
function findIndex(array, predicate) {
if (Array.prototype.findIndex) {
return array.findIndex(predicate);
}
for (let i = 0, l = array.length; i < l; ++i) {
if (predicate(array[i])) {
return i;
}
}
return -1;
};
var taskbarActor = Utils.defineClass({
Name: 'DashToPanel-TaskbarActor',
Extends: St.Widget,
@@ -766,10 +751,6 @@ var taskbar = Utils.defineClass({
getAppStableSequence(appB, this._dtpSettings, this.panelWrapper.monitor);
},
sortWindowsCompareFunction: function(windowA, windowB) {
return getWindowStableSequence(windowA) - getWindowStableSequence(windowB);
},
_redisplay: function () {
if (!this._signalsHandler) {
return;
@@ -798,8 +779,8 @@ var taskbar = Utils.defineClass({
//remove the appIcons which are not in the expected apps list
for (let i = currentAppIcons.length - 1; i > -1; --i) {
let appIcon = currentAppIcons[i].child._delegate;
let appIndex = findIndex(expectedAppInfos, appInfo => appInfo.app == appIcon.app &&
appInfo.isLauncher == appIcon.isLauncher);
let appIndex = Utils.findIndex(expectedAppInfos, appInfo => appInfo.app == appIcon.app &&
appInfo.isLauncher == appIcon.isLauncher);
if (appIndex < 0 ||
(appIcon.window && (this.isGroupApps || expectedAppInfos[appIndex].windows.indexOf(appIcon.window) < 0)) ||
@@ -819,8 +800,8 @@ var taskbar = Utils.defineClass({
for (let j = 0, ll = neededAppIcons.length; j < ll; ++j) {
//check if the icon already exists
let matchingAppIconIndex = findIndex(currentAppIcons, appIcon => appIcon.child._delegate.app == neededAppIcons[j].app &&
appIcon.child._delegate.window == neededAppIcons[j].window);
let matchingAppIconIndex = Utils.findIndex(currentAppIcons, appIcon => appIcon.child._delegate.app == neededAppIcons[j].app &&
appIcon.child._delegate.window == neededAppIcons[j].window);
if (matchingAppIconIndex > 0 && matchingAppIconIndex != currentPosition) {
//moved icon, reposition it
@@ -885,7 +866,7 @@ var taskbar = Utils.defineClass({
app: app,
isLauncher: defaultIsLauncher || false,
windows: defaultWindows || AppIcons.getInterestingWindows(app, this._dtpSettings, this.panelWrapper.monitor)
.sort(this.sortWindowsCompareFunction)
.sort(sortWindowsCompareFunction)
}));
},
@@ -964,9 +945,9 @@ var taskbar = Utils.defineClass({
let currentAppIcons = this._getAppIcons();
let sourceIndex = currentAppIcons.indexOf(source);
let hoveredIndex = findIndex(currentAppIcons,
appIcon => x >= appIcon._dashItemContainer.x &&
x <= (appIcon._dashItemContainer.x + appIcon._dashItemContainer.width));
let hoveredIndex = Utils.findIndex(currentAppIcons,
appIcon => x >= appIcon._dashItemContainer.x &&
x <= (appIcon._dashItemContainer.x + appIcon._dashItemContainer.width));
if (!this._dragInfo) {
this._dragInfo = [sourceIndex, source];
@@ -1239,6 +1220,10 @@ function getAppStableSequence(app, settings, monitor) {
}, Infinity);
}
function sortWindowsCompareFunction(windowA, windowB) {
return getWindowStableSequence(windowA) - getWindowStableSequence(windowB);
}
function getWindowStableSequence(window) {
return ('_dtpPosition' in window ? window._dtpPosition : window.get_stable_sequence());
}

View File

@@ -270,6 +270,20 @@ var DisplayWrapper = {
}
};
var findIndex = function(array, predicate) {
if (Array.prototype.findIndex) {
return array.findIndex(predicate);
}
for (let i = 0, l = array.length; i < l; ++i) {
if (predicate(array[i])) {
return i;
}
}
return -1;
};
var mergeObjects = function(main, bck) {
for (var prop in bck) {
if (!main.hasOwnProperty(prop) && bck.hasOwnProperty(prop)) {

View File

@@ -16,12 +16,15 @@
*/
const Clutter = imports.gi.Clutter;
const Config = imports.misc.config;
const Gtk = imports.gi.Gtk;
const Main = imports.ui.main;
const Meta = imports.gi.Meta;
const Signals = imports.signals;
const Shell = imports.gi.Shell;
const St = imports.gi.St;
const Tweener = imports.ui.tweener;
const Workspace = imports.ui.workspace;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Taskbar = Me.imports.taskbar;
@@ -34,9 +37,12 @@ const T1 = 'openMenuTimeout';
const T2 = 'closeMenuTimeout';
const MAX_TRANSLATION = 40;
const HEADER_HEIGHT = 0;
const HEADER_HEIGHT = 40;
const DEFAULT_RATIO = { w: 160, h: 90 };
var headerHeight = 0;
var isLeftButtons = false;
var PreviewMenu = Utils.defineClass({
Name: 'DashToPanel.PreviewMenu',
Extends: St.Widget,
@@ -96,6 +102,7 @@ var PreviewMenu = Utils.defineClass({
Main.layoutManager.trackChrome(this.menu, { affectsInputRegion: true });
this._resetHiddenState();
this._refreshGlobals();
this._updateClip();
this._signalsHandler.add(
@@ -147,16 +154,18 @@ var PreviewMenu = Utils.defineClass({
if (this._currentAppIcon != appIcon) {
this._currentAppIcon = appIcon;
this.updateWindows(appIcon);
this._updatePosition();
if (!this.opened) {
this.menu.set_style('background: ' + this._panelWrapper.dynamicTransparency.currentBackgroundColor);
this.menu.show();
this.opened = true;
this._refreshGlobals();
}
this._mergeWindows(appIcon);
this._updatePosition();
this._animateOpenOrClose(true);
this.opened = true;
}
},
@@ -170,28 +179,60 @@ var PreviewMenu = Utils.defineClass({
}
},
updateWindows: function(appIcon, windows) {
update: function(appIcon, windows) {
if (this._currentAppIcon == appIcon) {
windows = windows || (appIcon.window ? [appIcon.window] : appIcon.getAppIconInterestingWindows());
let currentPreviews = this._box.get_children();
let l = Math.max(windows.length, currentPreviews.length);
for (let i = 0; i < l; ++i) {
if (currentPreviews[i] && windows[i] && windows[i] != currentPreviews[i].window) {
currentPreviews[i].assignWindow(windows[i], this.opened);
} else if (!currentPreviews[i]) {
let preview = new Preview(this._panelWrapper, this);
this._box.add_child(preview);
preview.assignWindow(windows[i], this.opened);
} else if (!windows[i]) {
currentPreviews[i][!this.opened ? 'destroy' : 'animateOut']();
}
if (windows && !windows.length) {
this.close();
} else {
this._addAndRemoveWindows(windows);
this._updatePosition();
}
}
},
_mergeWindows: function(appIcon, windows) {
windows = windows || (appIcon.window ? [appIcon.window] : appIcon.getAppIconInterestingWindows());
windows.sort(Taskbar.sortWindowsCompareFunction);
let currentPreviews = this._box.get_children();
let l = Math.max(windows.length, currentPreviews.length);
for (let i = 0; i < l; ++i) {
if (currentPreviews[i] && windows[i] && windows[i] != currentPreviews[i].window) {
currentPreviews[i].assignWindow(windows[i], this.opened);
} else if (!currentPreviews[i]) {
this._addNewPreview(windows[i]);
} else if (!windows[i]) {
currentPreviews[i][!this.opened ? 'destroy' : 'animateOut']();
}
}
},
_addAndRemoveWindows: function(windows) {
let currentPreviews = this._box.get_children();
windows.sort(Taskbar.sortWindowsCompareFunction);
for (let i = 0, l = windows.length; i < l; ++i) {
let currentIndex = Utils.findIndex(currentPreviews, c => c.window == windows[i]);
if (currentIndex < 0) {
this._addNewPreview(windows[i]);
} else {
currentPreviews.splice(currentIndex, 1);
}
}
currentPreviews.forEach(c => c.animateOut());
},
_addNewPreview: function(window) {
let preview = new Preview(this._panelWrapper, this);
this._box.add_child(preview);
preview.assignWindow(window, this.opened);
},
getCurrentAppIcon: function() {
return this._currentAppIcon;
},
@@ -237,6 +278,11 @@ var PreviewMenu = Utils.defineClass({
this._timeoutsHandler.remove(T2);
},
_refreshGlobals: function() {
headerHeight = this._dtpSettings.get_boolean('window-preview-show-title') ? HEADER_HEIGHT : 0;
isLeftButtons = Meta.prefs_get_button_layout().left_buttons.indexOf(Meta.ButtonFunction.CLOSE) >= 0;
},
_resetHiddenState: function() {
this.menu.hide();
this.opened = false;
@@ -258,7 +304,7 @@ var PreviewMenu = Utils.defineClass({
y = this._panelWrapper.monitor.y;
} else {
w = this._panelWrapper.monitor.width;
h = (previewSize + HEADER_HEIGHT) * scaleFactor;
h = (previewSize + headerHeight) * scaleFactor;
x = this._panelWrapper.monitor.x;
}
@@ -269,7 +315,7 @@ var PreviewMenu = Utils.defineClass({
} else if (this._position == St.Side.TOP) {
y = this._panelWrapper.monitor.y + panelSize * scaleFactor;
} else { //St.Side.BOTTOM
y = this._panelWrapper.monitor.y + this._panelWrapper.monitor.height - (panelSize + previewSize + HEADER_HEIGHT) * scaleFactor;
y = this._panelWrapper.monitor.y + this._panelWrapper.monitor.height - (panelSize + previewSize + headerHeight) * scaleFactor;
}
this.set_clip(0, 0, w, h);
@@ -357,9 +403,8 @@ var Preview = Utils.defineClass({
this.callParent('_init', {
style_class: 'preview-container',
reactive: true,
y_align: Clutter.ActorAlign.CENTER,
x_align: Clutter.ActorAlign.CENTER,
layout_manager: new Clutter.BoxLayout({ vertical: false })
track_hover: true,
layout_manager: new Clutter.BinLayout()
});
this._panelWrapper = panelWrapper;
@@ -368,25 +413,49 @@ var Preview = Utils.defineClass({
this._previewDimensions = this._getPreviewDimensions();
this.animatingOut = false;
this._titleBox = new St.BoxLayout({ height: HEADER_HEIGHT });
this._windowTitle = new St.Label({ y_align: Clutter.ActorAlign.CENTER, style_class: 'preview-label' });
this._titleBox.add_child(this._windowTitle);
this.add_actor(this._titleBox)
this._previewBin = new St.Widget({ layout_manager: new Clutter.BinLayout() });
this._previewBin.set_style('padding: ' + this._padding + 'px');
this._previewBin.set_style('padding: ' + this._padding + 'px;');
this._previewBin.set_size.apply(this._previewBin, this._getBinSize());
let closeButton = new St.Button({ style_class: 'window-close', accessible_name: 'Close window' });
this._closeButtonBin = new St.Widget({
layout_manager: new Clutter.BinLayout(),
opacity: 0,
x_expand: true, y_expand: true,
x_align: Clutter.ActorAlign[isLeftButtons ? 'START' : 'END'],
y_align: Clutter.ActorAlign.START,
style: 'padding: 4px; border-radius: 0 0 4px 4px;' +
'background-color:' + panelWrapper.dynamicTransparency.currentBackgroundColor
})
this._closeButtonBin.add_child(closeButton);
if (Config.PACKAGE_VERSION >= '3.31.9') {
closeButton.add_actor(new St.Icon({ icon_name: 'window-close-symbolic' }));
}
// if (headerHeight) {
// this._titleBox = new St.BoxLayout({ height: headerHeight });
// this._windowTitle = new St.Label({ y_align: Clutter.ActorAlign.CENTER, style_class: 'preview-label' });
// this._titleBox.add_child(this._windowTitle);
// this.add_actor(this._titleBox);
// }
//this.set_size
closeButton.connect('clicked', () => this._onCloseBtnClick());
this.connect('notify::hover', () => this._onHoverChanged());
this.add_actor(this._previewBin);
this.add_child(this._closeButtonBin);
},
assignWindow: function(window, animateSize) {
let clone = this._getWindowClone(window);
this.window = window;
this._resizeClone(clone);
this._addClone(clone, animateSize);
},
@@ -409,6 +478,14 @@ var Preview = Utils.defineClass({
return [binWidth, binHeight];
},
_onHoverChanged: function() {
Tweener.addTween(this._closeButtonBin, getTweenOpts({ opacity: this.hover ? 255 : 0 }));
},
_onCloseBtnClick: function() {
this.window.delete(global.get_current_time());
},
_addClone: function(newClone, animateSize) {
let currentClones = this._previewBin.get_children();
let newCloneOpts = getTweenOpts({ opacity: 255 });