Skip to content

Commit

Permalink
Window previews: set max size based on monitor dimensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
franglais125 committed Aug 21, 2017
1 parent 0858dc8 commit 949018a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
9 changes: 5 additions & 4 deletions appIcons.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,17 +380,18 @@ const MyAppIcon = new Lang.Class({
else {
// Setting the max-height is s useful if part of the menu is
// scrollable so the minimum height is smaller than the natural height.
let monitor_index = Main.layoutManager.findIndexForActor(this.actor);
let workArea = Main.layoutManager.getWorkAreaForMonitor(monitor_index);
let workArea = Main.layoutManager.getWorkAreaForMonitor(this.monitorIndex);
let position = Utils.getPosition(this._dtdSettings);
this._isHorizontal = ( position == St.Side.TOP ||
position == St.Side.BOTTOM);
// If horizontal also remove the height of the dash
let additional_margin = this._isHorizontal && !this._dtdSettings.get_boolean('dock-fixed') ? Main.overview._dash.actor.height : 0;
let verticalMargins = this._menu.actor.margin_top + this._menu.actor.margin_bottom;
// Also set a max width to the menu, so long labels (long windows title) get truncated
let monitor = Main.layoutManager.monitors[this.monitorIndex];
let max_width = Math.round(monitor.width / 3);
this._menu.actor.style = ('max-height: ' + Math.round(workArea.height - additional_margin - verticalMargins) + 'px;' +
'max-width: 400px');
'max-width: ' + max_width + 'px');
}

// Close the window previews
Expand Down Expand Up @@ -1391,7 +1392,7 @@ const MyAppIconMenu = new Lang.Class({
separatorShown = true;
}

let item = new WindowPreview.WindowPreviewMenuItem(window);
let item = new WindowPreview.WindowPreviewMenuItem(window, this._source);
this._allWindowsMenuItem.menu.addMenuItem(item);
item.connect('activate', Lang.bind(this, function() {
this.emit('activate-window', window);
Expand Down
18 changes: 10 additions & 8 deletions windowPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ const Workspace = imports.ui.workspace;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Utils = Me.imports.utils;

const PREVIEW_MAX_WIDTH = 250;
const PREVIEW_MAX_HEIGHT = 150;

/*
* Timeouts for the hovering events
*/
Expand Down Expand Up @@ -306,7 +303,7 @@ const WindowPreviewList = new Lang.Class({
},

_createPreviewItem: function(window) {
let preview = new WindowPreviewMenuItem(window);
let preview = new WindowPreviewMenuItem(window, this._source);
return preview;
},

Expand Down Expand Up @@ -455,15 +452,20 @@ const WindowPreviewMenuItem = new Lang.Class({
Name: 'WindowPreviewMenuItem',
Extends: PopupMenu.PopupBaseMenuItem,

_init: function(window, params) {
_init: function(window, source, params) {
this._window = window;
this._destroyId = 0;
this._windowAddedId = 0;
params = Params.parse(params, { style_class: 'app-well-preview-menu-item' });
this.parent(params);

let monitorIndex = source.monitorIndex;
let monitor = Main.layoutManager.monitors[monitorIndex];
this._preview_max_width = Math.round(monitor.width / 5);
this._preview_max_height = Math.round(monitor.height / 5);

this._cloneBin = new St.Bin();
this._cloneBin.set_size(PREVIEW_MAX_WIDTH, PREVIEW_MAX_HEIGHT);
this._cloneBin.set_size(this._preview_max_width, this._preview_max_height);

// TODO: improve the way the closebutton is layout. Just use some padding
// for the moment.
Expand All @@ -485,7 +487,7 @@ const WindowPreviewMenuItem = new Lang.Class({
overlayGroup.add_actor(this.closeButton);

let label = new St.Label({ text: window.get_title()});
label.set_style('max-width: '+PREVIEW_MAX_WIDTH +'px');
label.set_style('max-width: ' + this._preview_max_width + 'px');
let labelBin = new St.Bin({ child: label,
x_align: St.Align.MIDDLE});

Expand Down Expand Up @@ -536,7 +538,7 @@ const WindowPreviewMenuItem = new Lang.Class({
let windowTexture = mutterWindow.get_texture();
let [width, height] = windowTexture.get_size();

let scale = Math.min(1.0, PREVIEW_MAX_WIDTH/width, PREVIEW_MAX_HEIGHT/height);
let scale = Math.min(1.0, this._preview_max_width / width, this._preview_max_height / height);

let clone = new Clutter.Clone ({ source: windowTexture,
reactive: true,
Expand Down

0 comments on commit 949018a

Please sign in to comment.