Files
dash-to-panel/windowPreview.js

1100 lines
39 KiB
JavaScript
Raw Normal View History

2016-09-21 00:18:00 +00:00
/*
2016-12-23 11:08:39 -05:00
* This file is part of the Dash-To-Panel extension for Gnome 3
2016-09-21 00:18:00 +00:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-05-11 21:40:48 -04:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2016-09-21 00:18:00 +00:00
*/
2019-05-14 17:08:08 -04:00
const Clutter = imports.gi.Clutter;
2019-05-19 10:42:22 -04:00
const Config = imports.misc.config;
2019-05-14 17:08:08 -04:00
const Gtk = imports.gi.Gtk;
2016-09-21 00:18:00 +00:00
const Main = imports.ui.main;
const Mainloop = imports.mainloop;
2019-05-19 10:42:22 -04:00
const Meta = imports.gi.Meta;
2019-05-25 11:08:46 -04:00
const PopupMenu = imports.ui.popupMenu;
2016-09-21 00:18:00 +00:00
const Signals = imports.signals;
const Shell = imports.gi.Shell;
2016-09-21 00:18:00 +00:00
const St = imports.gi.St;
const Tweener = imports.ui.tweener;
2019-05-22 21:37:53 -04:00
const WindowManager = imports.ui.windowManager;
2019-05-19 10:42:22 -04:00
const Workspace = imports.ui.workspace;
2016-09-21 00:18:00 +00:00
const Me = imports.misc.extensionUtils.getCurrentExtension();
2019-09-04 21:55:26 -04:00
const Panel = Me.imports.panel;
2016-09-21 00:18:00 +00:00
const Taskbar = Me.imports.taskbar;
const Utils = Me.imports.utils;
2016-09-21 00:18:00 +00:00
2019-06-07 20:02:51 -04:00
//timeout intervals
const ENSURE_VISIBLE_MS = 200;
2019-05-11 21:40:48 -04:00
//timeout names
const T1 = 'openMenuTimeout';
const T2 = 'closeMenuTimeout';
const T3 = 'peekTimeout';
2019-06-07 20:02:51 -04:00
const T4 = 'ensureVisibleTimeout';
const MAX_TRANSLATION = 40;
2019-05-20 00:25:22 -04:00
const HEADER_HEIGHT = 38;
const MAX_CLOSE_BUTTON_SIZE = 30;
2019-05-27 23:57:25 -04:00
const MIN_DIMENSION = 100;
2019-05-20 00:25:22 -04:00
const FOCUSED_COLOR_OFFSET = 24;
const HEADER_COLOR_OFFSET = -12;
const FADE_SIZE = 36;
2019-05-22 21:37:53 -04:00
const PEEK_INDEX_PROP = '_dtpPeekInitialIndex';
2019-05-29 21:24:25 -04:00
let headerHeight = 0;
let alphaBg = 0;
2019-05-29 21:24:25 -04:00
let isLeftButtons = false;
let isTopHeader = true;
let scaleFactor = 1;
let animationTime = 0;
let aspectRatio = {};
2019-05-19 10:42:22 -04:00
2019-05-11 21:40:48 -04:00
var PreviewMenu = Utils.defineClass({
Name: 'DashToPanel-PreviewMenu',
2019-05-11 21:40:48 -04:00
Extends: St.Widget,
Signals: { 'open-state-changed': {} },
2016-09-21 00:18:00 +00:00
2019-08-31 15:50:53 -04:00
_init: function(panelWrapper) {
this.callParent('_init', { layout_manager: new Clutter.BinLayout() });
2019-09-04 21:55:26 -04:00
let geom = panelWrapper.geom;
this._panelWrapper = panelWrapper;
2019-05-20 00:25:22 -04:00
this.currentAppIcon = null;
2019-05-20 10:56:22 -04:00
this._focusedPreview = null;
this._peekedWindow = null;
2019-05-25 11:08:46 -04:00
this.peekInitialWorkspaceIndex = -1;
this.opened = false;
2019-09-04 21:55:26 -04:00
this.isVertical = geom.position == St.Side.LEFT || geom.position == St.Side.RIGHT;
this._translationProp = 'translation_' + (this.isVertical ? 'x' : 'y');
this._translationDirection = (geom.position == St.Side.TOP || geom.position == St.Side.LEFT ? -1 : 1);
this._translationOffset = Math.min(Panel.size, MAX_TRANSLATION) * this._translationDirection;
2019-05-14 17:08:08 -04:00
2019-05-26 13:43:42 -04:00
this.menu = new St.Widget({
name: 'preview-menu',
layout_manager: new Clutter.BinLayout(),
reactive: true,
track_hover: true,
2019-09-03 21:46:10 -04:00
x_expand: true,
2019-05-26 13:43:42 -04:00
y_expand: true,
2019-09-04 21:55:26 -04:00
x_align: Clutter.ActorAlign[geom.position != St.Side.RIGHT ? 'START' : 'END'],
y_align: Clutter.ActorAlign[geom.position != St.Side.BOTTOM ? 'START' : 'END']
2019-05-26 13:43:42 -04:00
});
2019-09-04 21:55:26 -04:00
this._box = new St.BoxLayout({ vertical: this.isVertical });
2019-05-14 17:08:08 -04:00
this._scrollView = new St.ScrollView({
name: 'dashtopanelPreviewScrollview',
hscrollbar_policy: Gtk.PolicyType.NEVER,
vscrollbar_policy: Gtk.PolicyType.NEVER,
enable_mouse_scrolling: true,
2019-09-04 21:55:26 -04:00
y_expand: !this.isVertical
2019-05-14 17:08:08 -04:00
});
this._scrollView.add_actor(this._box);
this.menu.add_child(this._scrollView);
this.add_child(this.menu);
},
2019-05-11 21:40:48 -04:00
enable: function() {
this._timeoutsHandler = new Utils.TimeoutsHandler();
2019-05-14 17:08:08 -04:00
this._signalsHandler = new Utils.GlobalSignalsHandler();
Main.layoutManager.addChrome(this, { affectsInputRegion: false });
Main.layoutManager.trackChrome(this.menu, { affectsInputRegion: true });
2019-05-14 17:08:08 -04:00
this._resetHiddenState();
2019-05-19 10:42:22 -04:00
this._refreshGlobals();
this._updateClip();
2019-05-20 10:56:22 -04:00
this.menu.set_position(1, 1);
2019-05-15 17:02:18 -04:00
2019-05-14 17:08:08 -04:00
this._signalsHandler.add(
[
this.menu,
2019-05-14 17:08:08 -04:00
'notify::hover',
() => this._onHoverChanged()
],
2019-05-15 17:02:18 -04:00
[
this._scrollView,
'scroll-event',
this._onScrollEvent.bind(this)
],
[
this._panelWrapper.panelBox,
'style-changed',
() => this._updateClip()
],
[
2019-08-31 15:50:53 -04:00
Me.settings,
[
'changed::panel-size',
'changed::window-preview-size',
2019-05-20 00:25:22 -04:00
'changed::window-preview-padding',
'changed::window-preview-show-title'
],
2019-05-20 00:25:22 -04:00
() => {
this._refreshGlobals();
this._updateClip();
}
2019-05-15 17:02:18 -04:00
]
2019-05-14 17:08:08 -04:00
);
},
2019-05-11 21:40:48 -04:00
disable: function() {
this._timeoutsHandler.destroy();
2019-05-14 17:08:08 -04:00
this._signalsHandler.destroy();
2017-01-09 17:54:03 -05:00
this.close(true);
2019-05-14 17:08:08 -04:00
2019-08-08 17:54:38 -04:00
Main.layoutManager.untrackChrome(this.menu);
Main.layoutManager.removeChrome(this);
2016-09-21 00:18:00 +00:00
},
requestOpen: function(appIcon) {
this._endOpenCloseTimeouts();
2019-08-31 15:50:53 -04:00
this._timeoutsHandler.add([T1, Me.settings.get_int('show-window-previews-timeout'), () => this.open(appIcon)]);
2016-09-21 00:18:00 +00:00
},
requestClose: function() {
this._endOpenCloseTimeouts();
2019-05-14 17:08:08 -04:00
this._addCloseTimeout();
},
open: function(appIcon) {
2019-05-20 00:25:22 -04:00
if (this.currentAppIcon != appIcon) {
this.currentAppIcon = appIcon;
if (!this.opened) {
2019-05-19 10:42:22 -04:00
this._refreshGlobals();
this.menu.set_style('background: ' + Utils.getrgbaColor(this._panelWrapper.dynamicTransparency.backgroundColorRgb, alphaBg));
this.show();
}
2019-05-19 10:42:22 -04:00
this._mergeWindows(appIcon);
this._updatePosition();
2019-05-15 17:02:18 -04:00
this._animateOpenOrClose(true);
2019-05-19 10:42:22 -04:00
this._setReactive(true);
this._setOpenedState(true);
2019-05-15 17:02:18 -04:00
}
},
2016-09-21 00:18:00 +00:00
close: function(immediate) {
2019-05-19 17:51:07 -04:00
this._endOpenCloseTimeouts();
2019-05-21 14:31:55 -04:00
this._removeFocus();
this._endPeek();
2019-05-14 17:08:08 -04:00
if (immediate) {
this._resetHiddenState();
} else {
this._animateOpenOrClose(false, () => this._resetHiddenState());
}
2019-05-21 14:31:55 -04:00
this._setReactive(false);
2019-05-21 14:31:55 -04:00
this.currentAppIcon = null;
2016-09-21 00:18:00 +00:00
},
2019-05-19 10:42:22 -04:00
update: function(appIcon, windows) {
2019-05-20 00:25:22 -04:00
if (this.currentAppIcon == appIcon) {
2019-05-19 10:42:22 -04:00
if (windows && !windows.length) {
this.close();
} else {
this._addAndRemoveWindows(windows);
this._updatePosition();
2019-05-14 17:08:08 -04:00
}
}
},
2016-09-21 00:18:00 +00:00
updatePosition: function() {
this._updatePosition();
},
2019-05-20 10:56:22 -04:00
focusNext: function() {
let previews = this._box.get_children();
let currentIndex = this._focusedPreview ? previews.indexOf(this._focusedPreview) : -1;
let nextIndex = currentIndex + 1;
nextIndex = previews[nextIndex] ? nextIndex : 0;
2019-05-21 14:31:55 -04:00
if (previews[nextIndex]) {
this._removeFocus();
previews[nextIndex].setFocus(true);
this._focusedPreview = previews[nextIndex];
}
2019-05-20 10:56:22 -04:00
return nextIndex;
},
activateFocused: function() {
if (this.opened && this._focusedPreview) {
this._focusedPreview.activate();
}
},
requestPeek: function(window) {
2019-05-21 14:31:55 -04:00
this._timeoutsHandler.remove(T3);
2019-08-31 15:50:53 -04:00
if (Me.settings.get_boolean('peek-mode')) {
2019-05-25 11:08:46 -04:00
if (this.peekInitialWorkspaceIndex < 0) {
2019-08-31 15:50:53 -04:00
this._timeoutsHandler.add([T3, Me.settings.get_int('enter-peek-mode-timeout'), () => this._peek(window)]);
2019-05-21 14:31:55 -04:00
} else {
this._peek(window);
}
}
},
endPeekHere: function() {
this._endPeek(true);
},
2019-06-07 20:02:51 -04:00
ensureVisible: function(preview) {
let [ , upper, pageSize] = this._getScrollAdjustmentValues();
2019-06-07 20:02:51 -04:00
if (upper > pageSize) {
this._timeoutsHandler.add([
T4,
ENSURE_VISIBLE_MS,
() => Utils.ensureActorVisibleInScrollView(this._scrollView, preview, MIN_DIMENSION, () => this._updateScrollFade())
2019-06-07 20:02:51 -04:00
]);
}
},
_setReactive: function(reactive) { 
this._box.get_children().forEach(c => c.reactive = reactive);
this.menu.reactive = reactive;
},
_setOpenedState: function(opened) {
this.opened = opened;
this.emit('open-state-changed');
},
2019-05-21 14:31:55 -04:00
_removeFocus: function() {
2019-05-20 10:56:22 -04:00
if (this._focusedPreview) {
this._focusedPreview.setFocus(false);
this._focusedPreview = null;
}
},
2019-05-19 10:42:22 -04:00
_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 {
2019-05-25 11:08:46 -04:00
currentPreviews[currentIndex].cancelAnimateOut();
currentPreviews[currentIndex].assignWindow(windows[i]);
2019-05-19 10:42:22 -04:00
currentPreviews.splice(currentIndex, 1);
2019-05-25 11:08:46 -04:00
if (this._peekedWindow && this._peekedWindow == windows[i]) {
this.requestPeek(windows[i]);
}
2019-05-19 10:42:22 -04:00
}
}
currentPreviews.forEach(c => c.animateOut());
},
_addNewPreview: function(window) {
let preview = new Preview(this);
2019-05-19 10:42:22 -04:00
this._box.add_child(preview);
2019-05-20 00:25:22 -04:00
preview.adjustOnStage();
2019-05-19 10:42:22 -04:00
preview.assignWindow(window, this.opened);
},
getCurrentAppIcon: function() {
2019-05-20 00:25:22 -04:00
return this.currentAppIcon;
2016-09-21 00:18:00 +00:00
},
2019-05-14 17:08:08 -04:00
_addCloseTimeout: function() {
2019-08-31 15:50:53 -04:00
this._timeoutsHandler.add([T2, Me.settings.get_int('leave-timeout'), () => this.close()]);
2019-05-14 17:08:08 -04:00
},
_onHoverChanged: function() {
this._endOpenCloseTimeouts();
2019-05-20 00:25:22 -04:00
if (this.currentAppIcon && !this.menu.hover) {
2019-05-14 17:08:08 -04:00
this._addCloseTimeout();
this._endPeek();
2019-05-14 17:08:08 -04:00
}
2016-09-21 00:18:00 +00:00
},
2019-05-15 17:02:18 -04:00
_onScrollEvent: function(actor, event) {
if (!event.is_pointer_emulated()) {
2019-09-04 21:55:26 -04:00
let vOrh = this.isVertical ? 'v' : 'h';
let adjustment = this._scrollView['get_' + vOrh + 'scroll_bar']().get_adjustment();
2019-05-15 17:02:18 -04:00
let increment = adjustment.step_increment;
let delta = increment;
2019-05-15 17:02:18 -04:00
switch (event.get_scroll_direction()) {
case Clutter.ScrollDirection.UP:
2019-05-19 11:39:15 -04:00
delta = -increment;
2019-05-15 17:02:18 -04:00
break;
case Clutter.ScrollDirection.SMOOTH:
2019-05-19 11:39:15 -04:00
let [dx, dy] = event.get_scroll_delta();
delta = dy * increment;
delta += dx * increment;
2019-05-15 17:02:18 -04:00
break;
}
adjustment.set_value(adjustment.get_value() + delta);
this._updateScrollFade();
2019-05-15 17:02:18 -04:00
}
return Clutter.EVENT_STOP;
},
_endOpenCloseTimeouts: function() {
this._timeoutsHandler.remove(T1);
this._timeoutsHandler.remove(T2);
2019-06-07 20:02:51 -04:00
this._timeoutsHandler.remove(T4);
2016-09-21 00:18:00 +00:00
},
2019-05-19 10:42:22 -04:00
_refreshGlobals: function() {
isLeftButtons = Meta.prefs_get_button_layout().left_buttons.indexOf(Meta.ButtonFunction.CLOSE) >= 0;
2019-08-31 15:50:53 -04:00
isTopHeader = Me.settings.get_string('window-preview-title-position') == 'TOP';
scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
2019-08-31 15:50:53 -04:00
headerHeight = Me.settings.get_boolean('window-preview-show-title') ? HEADER_HEIGHT * scaleFactor : 0;
animationTime = Me.settings.get_int('window-preview-animation-time') * .001;
2019-05-29 21:24:25 -04:00
aspectRatio.x = {
2019-08-31 15:50:53 -04:00
size: Me.settings.get_int('window-preview-aspect-ratio-x'),
fixed: Me.settings.get_boolean('window-preview-fixed-x')
2019-05-29 21:24:25 -04:00
};
aspectRatio.y = {
2019-08-31 15:50:53 -04:00
size: Me.settings.get_int('window-preview-aspect-ratio-y'),
fixed: Me.settings.get_boolean('window-preview-fixed-y')
2019-05-29 21:24:25 -04:00
};
if (this._panelWrapper.dynamicTransparency) {
2019-08-31 15:50:53 -04:00
alphaBg = Me.settings.get_boolean('preview-use-custom-opacity') ?
Me.settings.get_int('preview-custom-opacity') * .01 :
this._panelWrapper.dynamicTransparency.alpha;
}
2019-05-19 10:42:22 -04:00
},
2019-05-14 17:08:08 -04:00
_resetHiddenState: function() {
this.hide();
this._setOpenedState(false);
this.menu.opacity = 0;
this.menu[this._translationProp] = this._translationOffset;
2019-05-14 20:13:01 -04:00
this._box.get_children().forEach(c => c.destroy());
2019-05-14 17:08:08 -04:00
},
_updateClip: function() {
let x, y, w, h;
2019-09-04 21:55:26 -04:00
let geom = this._panelWrapper.geom;
let panelBoxTheme = this._panelWrapper.panelBox.get_theme_node();
2019-08-31 15:50:53 -04:00
let previewSize = (Me.settings.get_int('window-preview-size') +
Me.settings.get_int('window-preview-padding') * 2) * scaleFactor;
2019-09-04 21:55:26 -04:00
if (this.isVertical) {
w = previewSize;
h = this._panelWrapper.monitor.height;
y = this._panelWrapper.monitor.y;
} else {
w = this._panelWrapper.monitor.width;
h = (previewSize + headerHeight);
x = this._panelWrapper.monitor.x;
}
2019-09-04 21:55:26 -04:00
if (geom.position == St.Side.LEFT) {
x = this._panelWrapper.monitor.x + Panel.size + panelBoxTheme.get_padding(St.Side.LEFT);
2019-09-04 21:55:26 -04:00
} else if (geom.position == St.Side.RIGHT) {
x = this._panelWrapper.monitor.x + this._panelWrapper.monitor.width - (Panel.size + previewSize) - panelBoxTheme.get_padding(St.Side.RIGHT);
2019-09-04 21:55:26 -04:00
} else if (geom.position == St.Side.TOP) {
y = this._panelWrapper.monitor.y + Panel.size + panelBoxTheme.get_padding(St.Side.TOP);
} else { //St.Side.BOTTOM
y = this._panelWrapper.monitor.y + this._panelWrapper.monitor.height - (Panel.size + panelBoxTheme.get_padding(St.Side.BOTTOM) + previewSize + headerHeight);
}
2019-06-23 23:56:49 -04:00
Utils.setClip(this, x, y, w, h);
},
_updatePosition: function() {
2019-05-20 00:25:22 -04:00
let sourceNode = this.currentAppIcon.actor.get_theme_node();
let sourceContentBox = sourceNode.get_content_box(this.currentAppIcon.actor.get_allocation_box());
let sourceAllocation = Shell.util_get_transformed_allocation(this.currentAppIcon.actor);
let [previewsWidth, previewsHeight] = this._getPreviewsSize();
2019-08-31 15:50:53 -04:00
let appIconMargin = Me.settings.get_int('appicon-margin') / scaleFactor;
let x = 0, y = 0;
2016-09-21 00:18:00 +00:00
previewsWidth = Math.min(previewsWidth, this._panelWrapper.monitor.width);
previewsHeight = Math.min(previewsHeight, this._panelWrapper.monitor.height);
this._updateScrollFade(previewsWidth < this._panelWrapper.monitor.width && previewsHeight < this._panelWrapper.monitor.height);
2019-05-15 17:02:18 -04:00
2019-09-04 21:55:26 -04:00
if (this.isVertical) {
y = sourceAllocation.y1 + appIconMargin - this._panelWrapper.monitor.y + (sourceContentBox.y2 - sourceContentBox.y1 - previewsHeight) * .5;
y = Math.max(y, 0);
y = Math.min(y, this._panelWrapper.monitor.height - previewsHeight);
} else {
x = sourceAllocation.x1 + appIconMargin - this._panelWrapper.monitor.x + (sourceContentBox.x2 - sourceContentBox.x1 - previewsWidth) * .5;
x = Math.max(x, 0);
x = Math.min(x, this._panelWrapper.monitor.width - previewsWidth);
2016-09-21 00:18:00 +00:00
}
if (!this.opened) {
this.menu.set_position(x, y);
2019-05-26 13:43:42 -04:00
this.menu.set_size(previewsWidth, previewsHeight);
} else {
2019-05-26 13:43:42 -04:00
Tweener.addTween(this.menu, getTweenOpts({ x: x, y: y, width: previewsWidth, height: previewsHeight }));
}
2016-09-21 00:18:00 +00:00
},
_updateScrollFade: function(remove) {
let [value, upper, pageSize] = this._getScrollAdjustmentValues();
let needsFade = upper > pageSize;
let fadeWidgets = this.menu.get_children().filter(c => c != this._scrollView);
if (!remove && needsFade) {
if (!fadeWidgets.length) {
fadeWidgets.push(this._getFadeWidget());
fadeWidgets.push(this._getFadeWidget(true));
this.menu.add_child(fadeWidgets[0]);
this.menu.add_child(fadeWidgets[1]);
}
fadeWidgets[0].visible = value > 0;
fadeWidgets[1].visible = value + pageSize < upper;
} else if (remove || (!needsFade && fadeWidgets.length)) {
fadeWidgets.forEach(fw => fw.destroy());
}
},
_getScrollAdjustmentValues: function() {
2019-09-04 21:55:26 -04:00
let [value , , upper, , , pageSize] = this._scrollView[(this.isVertical ? 'v' : 'h') + 'scroll'].adjustment.get_values();
return [value, upper, pageSize];
},
_getFadeWidget: function(end) {
let rotation = 0;
let size = 0;
let x = 0, y = 0;
let startBg = Utils.getrgbaColor(this._panelWrapper.dynamicTransparency.backgroundColorRgb, Math.min(alphaBg + .1, 1));
let endBg = Utils.getrgbaColor(this._panelWrapper.dynamicTransparency.backgroundColorRgb, 0)
2019-08-31 16:37:16 -04:00
let fadeStyle = 'background-gradient-start:' + startBg +
'background-gradient-end:' + endBg +
2019-09-04 21:55:26 -04:00
'background-gradient-direction:' + Panel.getOrientation();
2019-09-04 21:55:26 -04:00
if (this.isVertical) {
rotation = end ? 270 : 90;
y = end ? this._panelWrapper.monitor.height - FADE_SIZE : 0;
size = this.width;
} else {
rotation = end ? 180 : 0;
x = end ? this._panelWrapper.monitor.width - FADE_SIZE : 0;
size = this.height;
}
let fadeWidget = new St.Widget({
reactive: false,
pivot_point: new Clutter.Point({ x: .5, y: .5 }),
rotation_angle_z: rotation,
style: fadeStyle,
x: x, y: y,
width: FADE_SIZE, height: size
});
return fadeWidget;
},
_getPreviewsSize: function() {
2019-05-15 17:02:18 -04:00
let previewsWidth = 0;
let previewsHeight = 0;
this._box.get_children().forEach(c => {
if (!c.animatingOut) {
let [width, height] = c.getSize();
2019-09-04 21:55:26 -04:00
if (this.isVertical) {
2019-05-17 01:25:39 -04:00
previewsWidth = Math.max(width, previewsWidth);
2019-05-15 17:02:18 -04:00
previewsHeight += height;
} else {
previewsWidth += width;
2019-05-17 01:25:39 -04:00
previewsHeight = Math.max(height, previewsHeight);
2019-05-15 17:02:18 -04:00
}
}
});
return [previewsWidth, previewsHeight];
},
2019-05-14 17:08:08 -04:00
_animateOpenOrClose: function(show, onComplete) {
let isTranslationAnimation = this.menu[this._translationProp] != 0;
2019-05-11 21:40:48 -04:00
let tweenOpts = {
opacity: show ? 255 : 0,
2019-05-14 17:08:08 -04:00
transition: show ? 'easeInOutQuad' : 'easeInCubic',
onComplete: () => {
if (isTranslationAnimation) {
Main.layoutManager._queueUpdateRegions();
}
(onComplete || (() => {}))();
}
2019-05-11 21:40:48 -04:00
};
tweenOpts[this._translationProp] = show ? this._translationDirection : this._translationOffset;
2019-05-14 17:08:08 -04:00
Tweener.addTween(this.menu, getTweenOpts(tweenOpts));
2019-05-14 17:08:08 -04:00
},
2019-05-21 14:31:55 -04:00
_peek: function(window) {
2019-05-25 11:08:46 -04:00
let currentWorkspace = Utils.getCurrentWorkspace();
2019-05-21 14:31:55 -04:00
let windowWorkspace = window.get_workspace();
2019-08-31 15:50:53 -04:00
let focusWindow = () => this._focusMetaWindow(Me.settings.get_int('peek-mode-opacity'), window);
this._restorePeekedWindowStack();
2019-05-25 11:08:46 -04:00
this._peekedWindow = window;
2019-05-22 21:37:53 -04:00
if (currentWorkspace != windowWorkspace) {
2019-05-25 11:08:46 -04:00
this._switchToWorkspaceImmediate(windowWorkspace.index());
this._timeoutsHandler.add([T3, 100, focusWindow]);
2019-05-22 21:37:53 -04:00
} else {
focusWindow();
2019-05-21 14:31:55 -04:00
}
2019-05-25 11:08:46 -04:00
if (this.peekInitialWorkspaceIndex < 0) {
this.peekInitialWorkspaceIndex = currentWorkspace.index();
2019-05-21 14:31:55 -04:00
}
},
_endPeek: function(stayHere) {
this._timeoutsHandler.remove(T3);
if (this._peekedWindow) {
this._restorePeekedWindowStack();
2019-05-21 14:31:55 -04:00
this._focusMetaWindow(255);
this._peekedWindow = null;
2019-05-25 23:38:09 -04:00
if (!stayHere) {
this._switchToWorkspaceImmediate(this.peekInitialWorkspaceIndex);
}
2019-05-26 00:01:22 -04:00
this.peekInitialWorkspaceIndex = -1;
2019-05-21 14:31:55 -04:00
}
},
2019-05-21 14:31:55 -04:00
2019-05-25 11:08:46 -04:00
_switchToWorkspaceImmediate: function(workspaceIndex) {
let workspace = Utils.getWorkspaceByIndex(workspaceIndex);
if (!workspace || (!workspace.list_windows().length &&
workspaceIndex < Utils.getWorkspaceCount() -1)) {
workspace = Utils.getCurrentWorkspace();
}
2019-05-25 11:08:46 -04:00
Main.wm._blockAnimations = true;
workspace.activate(global.display.get_current_time_roundtrip());
2019-05-25 11:08:46 -04:00
Main.wm._blockAnimations = false;
2019-05-21 14:31:55 -04:00
},
2019-05-25 11:08:46 -04:00
_focusMetaWindow: function(dimOpacity, window) {
2019-05-22 21:37:53 -04:00
if (Main.overview.visibleTarget) {
return;
}
global.get_window_actors().forEach(wa => {
let mw = wa.meta_window;
2019-05-25 11:08:46 -04:00
let isFocused = mw == window;
2019-05-22 21:37:53 -04:00
if (mw) {
if (isFocused) {
mw[PEEK_INDEX_PROP] = wa.get_parent().get_children().indexOf(wa);
wa.get_parent().set_child_above_sibling(wa, null);
}
2019-05-22 21:37:53 -04:00
if (isFocused && mw.minimized) {
wa.show();
2019-05-22 21:37:53 -04:00
}
Tweener.addTween(wa, getTweenOpts({ opacity: isFocused ? 255 : dimOpacity }));
2019-05-22 21:37:53 -04:00
}
});
},
_restorePeekedWindowStack: function() {
let windowActor = this._peekedWindow ? this._peekedWindow.get_compositor_private() : null;
2019-05-22 21:37:53 -04:00
if (windowActor) {
if (this._peekedWindow.hasOwnProperty(PEEK_INDEX_PROP)) {
windowActor.get_parent().set_child_at_index(windowActor, this._peekedWindow[PEEK_INDEX_PROP]);
delete this._peekedWindow[PEEK_INDEX_PROP];
2019-05-22 21:37:53 -04:00
}
if(this._peekedWindow.minimized) {
windowActor.hide();
2019-05-21 14:31:55 -04:00
}
}
2019-05-21 14:31:55 -04:00
},
2019-05-14 17:08:08 -04:00
});
var Preview = Utils.defineClass({
Name: 'DashToPanel-Preview',
2019-05-14 17:08:08 -04:00
Extends: St.Widget,
_init: function(previewMenu) {
2019-05-17 01:25:39 -04:00
this.callParent('_init', {
style_class: 'preview-container',
2019-05-17 01:25:39 -04:00
reactive: true,
2019-05-19 10:42:22 -04:00
track_hover: true,
layout_manager: new Clutter.BinLayout()
2019-05-17 01:25:39 -04:00
});
2019-05-14 17:08:08 -04:00
2019-05-25 11:08:46 -04:00
this.window = null;
this._needsCloseButton = true;
this.cloneWidth = this.cloneHeight = 0;
this._panelWrapper = previewMenu._panelWrapper;
2019-05-14 20:13:01 -04:00
this._previewMenu = previewMenu;
2019-08-31 15:50:53 -04:00
this._padding = Me.settings.get_int('window-preview-padding') * scaleFactor;
this._previewDimensions = this._getPreviewDimensions();
2019-05-14 20:13:01 -04:00
this.animatingOut = false;
2019-05-26 13:43:42 -04:00
let box = new St.Widget({ layout_manager: new Clutter.BoxLayout({ vertical: true }), y_expand: true });
2019-05-20 00:25:22 -04:00
let [previewBinWidth, previewBinHeight] = this._getBinSize();
2019-05-19 10:42:22 -04:00
let closeButton = new St.Button({ style_class: 'window-close', accessible_name: 'Close window' });
2019-05-20 00:25:22 -04:00
if (Config.PACKAGE_VERSION >= '3.31.9') {
closeButton.add_actor(new St.Icon({ icon_name: 'window-close-symbolic' }));
}
2019-05-19 10:42:22 -04:00
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[isTopHeader ? 'START' : 'END']
});
2019-05-19 10:42:22 -04:00
this._closeButtonBin.add_child(closeButton);
2019-05-26 13:43:42 -04:00
this._previewBin = new St.Widget({
layout_manager: new Clutter.BinLayout(),
x_expand: true, y_expand: true,
2019-05-27 23:57:25 -04:00
style: 'padding: ' + this._padding / scaleFactor + 'px;'
2019-05-26 13:43:42 -04:00
});
this._previewBin.set_size(previewBinWidth, previewBinHeight);
box.add_child(this._previewBin);
2019-05-20 00:25:22 -04:00
if (headerHeight) {
let headerBox = new St.Widget({
layout_manager: new Clutter.BoxLayout(),
2019-05-26 13:43:42 -04:00
x_expand: true,
y_align: Clutter.ActorAlign[isTopHeader ? 'START' : 'END'],
2019-05-26 21:19:41 -04:00
style: this._getBackgroundColor(HEADER_COLOR_OFFSET, 1)
2019-05-20 00:25:22 -04:00
});
this._workspaceIndicator = new St.Label({ y_align: Clutter.ActorAlign.CENTER });
2019-05-20 00:25:22 -04:00
this._windowTitle = new St.Label({ y_align: Clutter.ActorAlign.CENTER, x_expand: true });
2019-05-14 17:08:08 -04:00
2019-05-20 00:25:22 -04:00
this._iconBin = new St.Widget({ layout_manager: new Clutter.BinLayout() });
this._iconBin.set_size(headerHeight, headerHeight);
2019-05-19 10:42:22 -04:00
2019-05-20 00:25:22 -04:00
headerBox.add_child(this._iconBin);
headerBox.insert_child_at_index(this._workspaceIndicator, isLeftButtons ? 0 : 1);
headerBox.insert_child_at_index(this._windowTitle, isLeftButtons ? 1 : 2);
2019-05-14 17:08:08 -04:00
2019-05-26 13:43:42 -04:00
box.insert_child_at_index(headerBox, isTopHeader ? 0 : 1);
2019-05-20 00:25:22 -04:00
}
2019-05-19 10:42:22 -04:00
2019-05-26 13:43:42 -04:00
this.add_child(box);
this.add_child(this._closeButtonBin);
2019-05-19 10:42:22 -04:00
closeButton.connect('clicked', () => this._onCloseBtnClick());
this.connect('notify::hover', () => this._onHoverChanged());
2019-05-19 11:39:15 -04:00
this.connect('button-release-event', (actor, e) => this._onButtonReleaseEvent(e));
2019-05-20 00:25:22 -04:00
this.connect('destroy', () => this._onDestroy());
},
adjustOnStage: function() {
let closeButton = this._closeButtonBin.get_first_child();
let closeButtonHeight = closeButton.height;
let maxCloseButtonSize = MAX_CLOSE_BUTTON_SIZE * scaleFactor;
2019-05-20 10:56:22 -04:00
let closeButtonBorderRadius = '';
if (closeButtonHeight > maxCloseButtonSize) {
closeButtonHeight = maxCloseButtonSize;
closeButton.set_size(closeButtonHeight, closeButtonHeight);
}
2019-05-20 10:56:22 -04:00
if (!headerHeight) {
closeButtonBorderRadius = 'border-radius: ';
if (isTopHeader) {
closeButtonBorderRadius += (isLeftButtons ? '0 0 4px 0;' : '0 0 0 4px;');
} else {
closeButtonBorderRadius += (isLeftButtons ? '0 4px 0 0;' : '4px 0 0 0;');
}
2019-05-20 10:56:22 -04:00
}
2019-05-20 00:25:22 -04:00
this._closeButtonBin.set_style(
'padding: ' + (headerHeight ? Math.round((headerHeight - closeButtonHeight) * .5 / scaleFactor) : 4) + 'px;' +
this._getBackgroundColor(HEADER_COLOR_OFFSET, headerHeight ? 1 : .6) +
2019-05-20 10:56:22 -04:00
closeButtonBorderRadius
2019-05-20 00:25:22 -04:00
);
2019-05-15 17:02:18 -04:00
},
2019-05-14 20:13:01 -04:00
assignWindow: function(window, animateSize) {
2019-05-25 11:08:46 -04:00
if (this.window != window) {
let _assignWindowClone = () => {
if (window.get_compositor_private()) {
2019-05-27 23:57:25 -04:00
let cloneBin = this._getWindowCloneBin(window);
2019-05-25 11:08:46 -04:00
this._resizeClone(cloneBin, window);
2019-05-27 23:57:25 -04:00
this._addClone(cloneBin, animateSize);
2019-05-25 11:08:46 -04:00
this._previewMenu.updatePosition();
} else {
Mainloop.idle_add(() => _assignWindowClone());
}
};
_assignWindowClone();
}
2019-05-14 20:13:01 -04:00
2019-05-20 00:25:22 -04:00
this._removeWindowSignals();
2019-05-19 10:42:22 -04:00
this.window = window;
this._needsCloseButton = window.can_close() && !Utils.checkIfWindowHasTransient(window);
2019-05-25 11:08:46 -04:00
this._updateHeader();
2019-05-14 20:13:01 -04:00
},
animateOut: function() {
2019-05-25 11:08:46 -04:00
if (!this.animatingOut) {
2019-05-26 13:43:42 -04:00
let tweenOpts = getTweenOpts({ opacity: 0, width: 0, height: 0, onComplete: () => this.destroy() });
2019-05-14 20:13:01 -04:00
2019-05-25 11:08:46 -04:00
this.animatingOut = true;
2019-05-14 20:13:01 -04:00
2019-05-25 11:08:46 -04:00
Tweener.removeTweens(this);
Tweener.addTween(this, tweenOpts);
}
},
cancelAnimateOut: function() {
if (this.animatingOut) {
this.animatingOut = false;
Tweener.removeTweens(this);
Tweener.addTween(this, getTweenOpts({ opacity: 255 }));
}
2019-05-14 20:13:01 -04:00
},
2019-05-15 17:02:18 -04:00
getSize: function() {
let [binWidth, binHeight] = this._getBinSize();
2019-05-17 01:25:39 -04:00
binWidth = Math.max(binWidth, this.cloneWidth + this._padding * 2);
binHeight = Math.max(binHeight, this.cloneHeight + this._padding * 2) + headerHeight;
2019-05-15 17:02:18 -04:00
return [binWidth, binHeight];
},
2019-05-20 10:56:22 -04:00
setFocus: function(focused) {
this._hideOrShowCloseButton(!focused);
this.set_style(this._getBackgroundColor(FOCUSED_COLOR_OFFSET, focused ? '-' : 0));
2019-05-21 14:31:55 -04:00
if (focused) {
2019-06-07 20:02:51 -04:00
this._previewMenu.ensureVisible(this);
2019-05-21 14:31:55 -04:00
this._previewMenu.requestPeek(this.window);
}
2019-05-20 10:56:22 -04:00
},
activate: function() {
2019-05-21 14:31:55 -04:00
this._previewMenu.endPeekHere();
2019-05-20 10:56:22 -04:00
this._previewMenu.close();
2019-05-22 21:37:53 -04:00
Main.activateWindow(this.window);
2019-05-20 10:56:22 -04:00
},
2019-05-20 00:25:22 -04:00
_onDestroy: function() {
this._removeWindowSignals();
},
2019-05-19 10:42:22 -04:00
_onHoverChanged: function() {
2019-05-20 10:56:22 -04:00
this.setFocus(this.hover);
2019-05-19 10:42:22 -04:00
},
_onCloseBtnClick: function() {
this.window.delete(global.get_current_time());
2019-05-19 17:51:07 -04:00
this._hideOrShowCloseButton(true);
2019-05-22 21:37:53 -04:00
this.reactive = false;
2019-05-20 00:25:22 -04:00
2019-08-31 15:50:53 -04:00
if (!Me.settings.get_boolean('group-apps')) {
2019-05-20 00:25:22 -04:00
this._previewMenu.close();
}
2019-05-19 10:42:22 -04:00
},
2019-05-19 11:39:15 -04:00
_onButtonReleaseEvent: function(e) {
switch (e.get_button()) {
case 1: // Left click
2019-05-20 10:56:22 -04:00
this.activate();
2019-05-19 11:39:15 -04:00
break;
case 2: // Middle click
2019-08-31 15:50:53 -04:00
if (Me.settings.get_boolean('preview-middle-click-close')) {
2019-05-19 11:39:15 -04:00
this._onCloseBtnClick();
}
break;
2019-05-25 11:08:46 -04:00
case 3: // Right click
this._showContextMenu(e);
break;
2019-05-19 11:39:15 -04:00
}
return Clutter.EVENT_STOP;
},
2019-05-25 11:08:46 -04:00
_showContextMenu: function(e) {
let coords = e.get_coords();
let currentWorkspace = this._previewMenu.peekInitialWorkspaceIndex < 0 ?
Utils.getCurrentWorkspace() :
Utils.getWorkspaceByIndex(this._previewMenu.peekInitialWorkspaceIndex);
Main.wm._showWindowMenu(null, this.window, Meta.WindowMenuType.WM, {
x: coords[0],
y: coords[1],
width: 0,
height: 0
});
let ctxMenuData = Main.wm._windowMenuManager._manager._menus[0];
ctxMenuData.menu.connect('open-state-changed', () => this._previewMenu.menu.sync_hover());
if (this.window.get_workspace() != currentWorkspace) {
let menuItem = new PopupMenu.PopupMenuItem(_('Move to current Workspace') + ' [' + (currentWorkspace.index() + 1) + ']');
let menuItems = ctxMenuData.menu.box.get_children();
let insertIndex = Utils.findIndex(menuItems, c => c._delegate instanceof PopupMenu.PopupSeparatorMenuItem);
insertIndex = insertIndex >= 0 ? insertIndex : menuItems.length - 1;
ctxMenuData.menu.addMenuItem(menuItem, insertIndex);
menuItem.connect('activate', () => this.window.change_workspace(currentWorkspace));
}
},
2019-05-20 00:25:22 -04:00
_removeWindowSignals: function() {
if (this._titleWindowChangeId) {
this.window.disconnect(this._titleWindowChangeId);
this._titleWindowChangeId = 0;
}
},
_updateHeader: function() {
if (headerHeight) {
let iconTextureSize = headerHeight / scaleFactor * .6;
let icon = this._previewMenu.getCurrentAppIcon().app.create_icon_texture(iconTextureSize);
2019-05-23 20:08:49 -04:00
let workspaceIndex = '';
let workspaceStyle = null;
2019-08-31 15:50:53 -04:00
let commonTitleStyles = 'color: ' + Me.settings.get_string('window-preview-title-font-color') + ';' +
'font-size: ' + Me.settings.get_int('window-preview-title-font-size') + 'px;' +
'font-weight: ' + Me.settings.get_string('window-preview-title-font-weight') + ';';
2019-05-20 00:25:22 -04:00
this._iconBin.destroy_all_children();
this._iconBin.add_child(icon);
2019-08-31 15:50:53 -04:00
if (!Me.settings.get_boolean('isolate-workspaces')) {
2019-05-23 20:08:49 -04:00
workspaceIndex = (this.window.get_workspace().index() + 1).toString();
workspaceStyle = 'margin: 0 4px 0 ' + (isLeftButtons ? Math.round((headerHeight - icon.width) * .5) + 'px' : '0') + '; padding: 0 4px;' +
'border: 2px solid ' + this._getRgbaColor(FOCUSED_COLOR_OFFSET, .8) + 'border-radius: 2px;' + commonTitleStyles;
2019-05-20 00:25:22 -04:00
}
2019-05-23 20:08:49 -04:00
this._workspaceIndicator.text = workspaceIndex;
this._workspaceIndicator.set_style(workspaceStyle);
2019-05-20 00:25:22 -04:00
this._titleWindowChangeId = this.window.connect('notify::title', () => this._updateWindowTitle());
2019-05-23 20:08:49 -04:00
this._windowTitle.set_style('max-width: 0px; padding-right: 4px;' + commonTitleStyles);
2019-05-20 00:25:22 -04:00
this._updateWindowTitle();
}
},
_updateWindowTitle: function() {
this._windowTitle.text = this.window.title;
2019-05-20 00:25:22 -04:00
},
2019-05-19 17:51:07 -04:00
_hideOrShowCloseButton: function(hide) {
if (this._needsCloseButton) {
Tweener.addTween(this._closeButtonBin, getTweenOpts({ opacity: hide ? 0 : 255 }));
}
2019-05-19 17:51:07 -04:00
},
2019-05-20 00:25:22 -04:00
_getBackgroundColor: function(offset, alpha) {
return 'background-color: ' + this._getRgbaColor(offset, alpha) +
'transition-duration:' + this._panelWrapper.dynamicTransparency.animationDuration;
},
_getRgbaColor: function(offset, alpha) {
2019-05-20 00:25:22 -04:00
alpha = Math.abs(alpha);
if (isNaN(alpha)) {
alpha = alphaBg;
2019-05-20 00:25:22 -04:00
}
return Utils.getrgbaColor(this._panelWrapper.dynamicTransparency.backgroundColorRgb, alpha, offset);
2019-05-19 17:51:07 -04:00
},
2019-05-27 23:57:25 -04:00
_addClone: function(newCloneBin, animateSize) {
2019-05-17 01:25:39 -04:00
let currentClones = this._previewBin.get_children();
let newCloneOpts = getTweenOpts({ opacity: 255 });
2019-05-27 23:57:25 -04:00
this._previewBin.add_child(newCloneBin);
2019-05-17 01:25:39 -04:00
if (currentClones.length) {
2019-05-27 23:57:25 -04:00
let currentCloneBin = currentClones.pop();
let currentCloneOpts = getTweenOpts({ opacity: 0, onComplete: () => currentCloneBin.destroy() });
2019-05-17 01:25:39 -04:00
2019-05-27 23:57:25 -04:00
if (newCloneBin.width > currentCloneBin.width) {
newCloneOpts.width = newCloneBin.width;
newCloneBin.width = currentCloneBin.width;
2019-05-17 01:25:39 -04:00
} else {
2019-05-27 23:57:25 -04:00
currentCloneOpts.width = newCloneBin.width;
2019-05-17 01:25:39 -04:00
}
2019-05-27 23:57:25 -04:00
if (newCloneBin.height > currentCloneBin.height) {
newCloneOpts.height = newCloneBin.height;
newCloneBin.height = currentCloneBin.height;
2019-05-17 01:25:39 -04:00
} else {
2019-05-27 23:57:25 -04:00
currentCloneOpts.height = newCloneBin.height;
2019-05-17 01:25:39 -04:00
}
currentClones.forEach(c => c.destroy());
2019-05-27 23:57:25 -04:00
Tweener.addTween(currentCloneBin, currentCloneOpts);
} else if (animateSize) {
2019-05-27 23:57:25 -04:00
newCloneBin.width = 0;
newCloneBin.height = 0;
2019-05-26 13:43:42 -04:00
newCloneOpts.width = this.cloneWidth;
newCloneOpts.height = this.cloneHeight;
2019-05-17 01:25:39 -04:00
}
2019-05-27 23:57:25 -04:00
Tweener.addTween(newCloneBin, newCloneOpts);
2019-05-15 17:02:18 -04:00
},
2019-05-14 20:13:01 -04:00
2019-05-27 23:57:25 -04:00
_getWindowCloneBin: function(window) {
2019-06-10 06:40:47 -04:00
let frameRect = window.get_frame_rect();
let bufferRect = window.get_buffer_rect();
let clone = new Clutter.Clone({ source: window.get_compositor_private() });
let cloneBin = new St.Widget({
2019-05-27 23:57:25 -04:00
opacity: 0,
2019-06-10 06:40:47 -04:00
layout_manager: frameRect.width != bufferRect.width ||
frameRect.height != bufferRect.height ?
new WindowCloneLayout(frameRect, bufferRect) :
new Clutter.BinLayout()
2019-05-15 17:02:18 -04:00
});
cloneBin.add_child(clone);
return cloneBin;
2019-05-15 17:02:18 -04:00
},
_getBinSize: function() {
2019-05-29 21:24:25 -04:00
let [fixedWidth, fixedHeight] = this._previewDimensions;
2019-05-29 21:24:25 -04:00
return [
aspectRatio.x.fixed ? fixedWidth + this._padding * 2 : -1,
aspectRatio.y.fixed ? fixedHeight + this._padding * 2 : -1
];
2019-05-14 17:08:08 -04:00
},
_resizeClone: function(cloneBin, window) {
2019-06-10 06:40:47 -04:00
let frameRect = cloneBin.layout_manager.frameRect || window.get_frame_rect();
let [fixedWidth, fixedHeight] = this._previewDimensions;
let ratio = Math.min(fixedWidth / frameRect.width, fixedHeight / frameRect.height, 1);
let cloneWidth = frameRect.width * ratio;
let cloneHeight = frameRect.height * ratio;
2019-05-27 23:57:25 -04:00
let clonePaddingTB = cloneHeight < MIN_DIMENSION ? MIN_DIMENSION - cloneHeight : 0;
let clonePaddingLR = cloneWidth < MIN_DIMENSION ? MIN_DIMENSION - cloneWidth : 0;
let clonePaddingTop = clonePaddingTB * .5;
let clonePaddingLeft = clonePaddingLR * .5;
2019-05-15 17:02:18 -04:00
2019-05-27 23:57:25 -04:00
this.cloneWidth = cloneWidth + clonePaddingLR * scaleFactor;
this.cloneHeight = cloneHeight + clonePaddingTB * scaleFactor;
2019-05-17 01:25:39 -04:00
cloneBin.set_style('padding: ' + clonePaddingTop + 'px ' + clonePaddingLeft + 'px;');
cloneBin.layout_manager.ratio = ratio;
cloneBin.layout_manager.padding = [clonePaddingLeft * scaleFactor, clonePaddingTop * scaleFactor];
cloneBin.get_first_child().set_size(cloneWidth, cloneHeight);
},
2019-05-15 17:02:18 -04:00
_getPreviewDimensions: function() {
2019-08-31 15:50:53 -04:00
let size = Me.settings.get_int('window-preview-size') * scaleFactor;
let w, h;
2019-09-04 21:55:26 -04:00
if (this._previewMenu.isVertical) {
w = size;
2019-05-29 21:24:25 -04:00
h = w * aspectRatio.y.size / aspectRatio.x.size;
} else {
h = size;
2019-05-29 21:24:25 -04:00
w = h * aspectRatio.x.size / aspectRatio.y.size;
}
return [w, h];
2019-05-15 17:02:18 -04:00
}
2019-05-14 20:13:01 -04:00
});
var WindowCloneLayout = Utils.defineClass({
Name: 'DashToPanel-WindowCloneLayout',
Extends: Clutter.BinLayout,
2019-06-10 06:40:47 -04:00
_init: function(frameRect, bufferRect) {
this.callParent('_init');
2019-06-10 06:40:47 -04:00
//the buffer_rect contains the transparent padding that must be removed
this.frameRect = frameRect;
this.bufferRect = bufferRect;
},
vfunc_allocate: function(actor, box, flags) {
let [width, height] = box.get_size();
box.set_origin(
(this.bufferRect.x - this.frameRect.x) * this.ratio + this.padding[0],
(this.bufferRect.y - this.frameRect.y) * this.ratio + this.padding[1]
);
box.set_size(
width + (this.bufferRect.width - this.frameRect.width) * this.ratio,
height + (this.bufferRect.height - this.frameRect.height) * this.ratio
);
actor.get_first_child().allocate(box, flags);
}
});
2019-05-14 20:13:01 -04:00
function getTweenOpts(opts) {
let defaults = {
time: animationTime,
2019-05-14 20:13:01 -04:00
transition: 'easeInOutQuad'
};
return Utils.mergeObjects(opts || {}, defaults);
}