Skip to content

Commit

Permalink
Fix window list previews position
Browse files Browse the repository at this point in the history
 * There was no margin the first time it showed up because the position
   was set before actually showing the actor.

 * Update position when window size changes, notably when bottom-positioned.
  • Loading branch information
germanfr authored and mtwebster committed May 5, 2018
1 parent 3e356de commit 4e17325
Showing 1 changed file with 37 additions and 32 deletions.
69 changes: 37 additions & 32 deletions files/usr/share/cinnamon/applets/window-list@cinnamon.org/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,38 +141,63 @@ class WindowPreview extends Tooltips.TooltipBase {
height: height
});

this._sizeChangedId = this.muffinWindow.connect('size-changed',
Lang.bind(this, function() {
let [width, height] = this._getScaledTextureSize(windowTexture);
this.thumbnail.set_size(width, height);
}));
this._sizeChangedId = this.muffinWindow.connect('size-changed', () => {
let [width, height] = this._getScaledTextureSize(windowTexture);
this.thumbnail.set_size(width, height);
this._set_position();
});

this.thumbnailBin.set_child(this.thumbnail);

this.actor.show();
this._set_position();

this.visible = true;
this._applet.cancelErodeTooltip();
this._applet._tooltipShowing = true;
}

hide() {
if (this._sizeChangedId != null) {
this.muffinWindow.disconnect(this._sizeChangedId);
this._sizeChangedId = null;
}
if (this.thumbnail) {
this.thumbnailBin.set_child(null);
this.thumbnail.destroy();
}
if (this.actor) {
this.actor.hide();
}
this.visible = false;
}

_set_position() {
let allocation = this.actor.get_allocation_box();
let previewHeight = allocation.y2 - allocation.y1;
let previewWidth = allocation.x2 - allocation.x1;

let monitor = Main.layoutManager.findMonitorForActor(this.item);
let previewTop;

if (this._applet.orientation == St.Side.BOTTOM) {
let previewTop;
if (this._applet.orientation === St.Side.BOTTOM) {
previewTop = this.item.get_transformed_position()[1] - previewHeight - 5;
} else if (this._applet.orientation == St.Side.TOP) {
} else if (this._applet.orientation === St.Side.TOP) {
previewTop = this.item.get_transformed_position()[1] + this.item.get_transformed_size()[1] + 5;
} else {
previewTop = this.item.get_transformed_position()[1];
}

let previewLeft;
if (this._applet.orientation == St.Side.BOTTOM || this._applet.orientation == St.Side.TOP) {
if (this._applet.orientation === St.Side.BOTTOM || this._applet.orientation === St.Side.TOP) {
// centre the applet on the window list item if window list is on the top or bottom panel
previewLeft = this.item.get_transformed_position()[0] + this.item.get_transformed_size()[0]/2 - previewWidth/2;
} else if (this._applet.orientation == St.Side.LEFT) {
} else if (this._applet.orientation === St.Side.LEFT) {
previewLeft = this.item.get_transformed_position()[0] + this.item.get_transformed_size()[0] + 5;
} else if (this._applet.orientation == St.Side.RIGHT) {
previewLeft = this.item.get_transformed_position()[0] - previewWidth -5;
} else {
previewLeft = this.item.get_transformed_position()[0] - previewWidth - 5;
}

previewLeft = Math.round(previewLeft);
previewLeft = Math.max(previewLeft, monitor.x);
previewLeft = Math.min(previewLeft, monitor.x + monitor.width - previewWidth);
Expand All @@ -181,26 +206,6 @@ class WindowPreview extends Tooltips.TooltipBase {
previewTop = Math.min(previewTop, monitor.y + monitor.height - previewHeight);

this.actor.set_position(previewLeft, previewTop);

this.actor.show();
this.visible = true;
this._applet.cancelErodeTooltip();
this._applet._tooltipShowing = true;
}

hide() {
if (this._sizeChangedId != null) {
this.muffinWindow.disconnect(this._sizeChangedId);
this._sizeChangedId = null;
}
if (this.thumbnail) {
this.thumbnailBin.set_child(null);
this.thumbnail.destroy();
}
if (this.actor) {
this.actor.hide();
}
this.visible = false;
}

set_text(text) {
Expand Down

0 comments on commit 4e17325

Please sign in to comment.