boxpointer: Calculate position using workarea

Take the workarea into consideration when calculating the position and the size
of box pointer and of its arrow.

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/issues/1102
This commit is contained in:
Andrea Azzarone 2019-03-22 12:31:48 +00:00
parent 611605a67f
commit 2f3f3fbcdb

View File

@ -24,7 +24,7 @@ var POPUP_ANIMATION_TIME = 0.15;
* placed. The arrow position may be controlled via * placed. The arrow position may be controlled via
* setArrowOrigin(). The arrow side might be temporarily flipped * setArrowOrigin(). The arrow side might be temporarily flipped
* depending on the box size and source position to keep the box * depending on the box size and source position to keep the box
* totally inside the monitor if possible. * totally inside the monitor workarea if possible.
* *
*/ */
var BoxPointer = GObject.registerClass({ var BoxPointer = GObject.registerClass({
@ -489,7 +489,8 @@ var BoxPointer = GObject.registerClass({
// We also want to keep it onscreen, and separated from the // We also want to keep it onscreen, and separated from the
// edge by the same distance as the main part of the box is // edge by the same distance as the main part of the box is
// separated from its sourceActor // separated from its sourceActor
let monitor = Main.layoutManager.findMonitorForActor(sourceActor); let monitorIndex = Main.layoutManager.findIndexForActor(sourceActor);
let workarea = Main.layoutManager.getWorkAreaForMonitor(monitorIndex);
let themeNode = this.get_theme_node(); let themeNode = this.get_theme_node();
let borderWidth = themeNode.get_length('-arrow-border-width'); let borderWidth = themeNode.get_length('-arrow-border-width');
let arrowBase = themeNode.get_length('-arrow-base'); let arrowBase = themeNode.get_length('-arrow-base');
@ -539,8 +540,8 @@ var BoxPointer = GObject.registerClass({
case St.Side.BOTTOM: case St.Side.BOTTOM:
resX = sourceCenterX - (halfMargin + (natWidth - margin) * alignment); resX = sourceCenterX - (halfMargin + (natWidth - margin) * alignment);
resX = Math.max(resX, monitor.x + padding); resX = Math.max(resX, workarea.x + padding);
resX = Math.min(resX, monitor.x + monitor.width - (padding + natWidth)); resX = Math.min(resX, workarea.x + workarea.width - (padding + natWidth));
arrowOrigin = sourceCenterX - resX; arrowOrigin = sourceCenterX - resX;
if (arrowOrigin <= (x1 + (borderRadius + halfBase))) { if (arrowOrigin <= (x1 + (borderRadius + halfBase))) {
@ -558,8 +559,8 @@ var BoxPointer = GObject.registerClass({
case St.Side.RIGHT: case St.Side.RIGHT:
resY = sourceCenterY - (halfMargin + (natHeight - margin) * alignment); resY = sourceCenterY - (halfMargin + (natHeight - margin) * alignment);
resY = Math.max(resY, monitor.y + padding); resY = Math.max(resY, workarea.y + padding);
resY = Math.min(resY, monitor.y + monitor.height - (padding + natHeight)); resY = Math.min(resY, workarea.y + workarea.height - (padding + natHeight));
arrowOrigin = sourceCenterY - resY; arrowOrigin = sourceCenterY - resY;
if (arrowOrigin <= (y1 + (borderRadius + halfBase))) { if (arrowOrigin <= (y1 + (borderRadius + halfBase))) {
@ -625,27 +626,28 @@ var BoxPointer = GObject.registerClass({
let monitorActor = this.sourceActor; let monitorActor = this.sourceActor;
if (!monitorActor) if (!monitorActor)
monitorActor = this; monitorActor = this;
let monitor = Main.layoutManager.findMonitorForActor(monitorActor); let monitorIndex = Main.layoutManager.findIndexForActor(monitorActor);
let workarea = Main.layoutManager.getWorkAreaForMonitor(monitorIndex);
switch (arrowSide) { switch (arrowSide) {
case St.Side.TOP: case St.Side.TOP:
if (sourceAllocation.y2 + boxHeight > monitor.y + monitor.height && if (sourceAllocation.y2 + boxHeight > workarea.y + workarea.height &&
boxHeight < sourceAllocation.y1 - monitor.y) boxHeight < sourceAllocation.y1 - workarea.y)
return St.Side.BOTTOM; return St.Side.BOTTOM;
break; break;
case St.Side.BOTTOM: case St.Side.BOTTOM:
if (sourceAllocation.y1 - boxHeight < monitor.y && if (sourceAllocation.y1 - boxHeight < workarea.y &&
boxHeight < monitor.y + monitor.height - sourceAllocation.y2) boxHeight < workarea.y + workarea.height - sourceAllocation.y2)
return St.Side.TOP; return St.Side.TOP;
break; break;
case St.Side.LEFT: case St.Side.LEFT:
if (sourceAllocation.x2 + boxWidth > monitor.x + monitor.width && if (sourceAllocation.x2 + boxWidth > workarea.x + workarea.width &&
boxWidth < sourceAllocation.x1 - monitor.x) boxWidth < sourceAllocation.x1 - workarea.x)
return St.Side.RIGHT; return St.Side.RIGHT;
break; break;
case St.Side.RIGHT: case St.Side.RIGHT:
if (sourceAllocation.x1 - boxWidth < monitor.x && if (sourceAllocation.x1 - boxWidth < workarea.x &&
boxWidth < monitor.x + monitor.width - sourceAllocation.x2) boxWidth < workarea.x + workarea.width - sourceAllocation.x2)
return St.Side.LEFT; return St.Side.LEFT;
break; break;
} }