diff --git a/js/ui/main.js b/js/ui/main.js index b5589978d..47dadef3b 100644 --- a/js/ui/main.js +++ b/js/ui/main.js @@ -480,28 +480,67 @@ function _getAndClearErrorStack() { function _relayout() { let monitors = global.get_monitors(); - if (monitors.length != hotCorners.length) { - // destroy old corners - for (let i = 0; i < hotCorners.length; i++) - hotCorners[i].destroy(); - hotCorners = []; - for (let i = 0; i < monitors.length; i++) - hotCorners[i] = new Panel.HotCorner(); - } + // destroy old corners + for (let i = 0; i < hotCorners.length; i++) + hotCorners[i].destroy(); + hotCorners = []; let primary = global.get_primary_monitor(); for (let i = 0; i < monitors.length; i++) { let monitor = monitors[i]; - let corner = hotCorners[i]; let isPrimary = (monitor.x == primary.x && monitor.y == primary.y && monitor.width == primary.width && monitor.height == primary.height); + + let cornerX = monitor.x; + let cornerY = monitor.y; if (St.Widget.get_default_direction() == St.TextDirection.RTL) - corner.actor.set_position(monitor.x + monitor.width, monitor.y); + cornerX += monitor.width; + + + let haveTopLeftCorner = true; + + /* Check if we have a top left (right for RTL) corner. + * I.e. if there is no monitor directly above or to the left(right) */ + let besideX; + if (St.Widget.get_default_direction() == St.TextDirection.RTL) + besideX = monitor.x + 1; else - corner.actor.set_position(monitor.x, monitor.y); + besideX = cornerX - 1; + let besideY = cornerY; + let aboveX = cornerX; + let aboveY = cornerY - 1; + + for (let j = 0; j < monitors.length; j++) { + if (i == j) + continue; + let otherMonitor = monitors[j]; + if (besideX >= otherMonitor.x && + besideX < otherMonitor.x + otherMonitor.width && + besideY >= otherMonitor.y && + besideY < otherMonitor.y + otherMonitor.height) { + haveTopLeftCorner = false; + break; + } + if (aboveX >= otherMonitor.x && + aboveX < otherMonitor.x + otherMonitor.width && + aboveY >= otherMonitor.y && + aboveY < otherMonitor.y + otherMonitor.height) { + haveTopLeftCorner = false; + break; + } + } + + /* We only want hot corners where there is a natural top-left + * corner, and on the primary monitor */ + if (!isPrimary && !haveTopLeftCorner) + continue; + + let corner = new Panel.HotCorner(); + hotCorners.push(corner); + corner.actor.set_position(cornerX, cornerY); if (isPrimary) panel.setHotCorner(corner); }