iconGrid: Also consider left/right empty space as drop targets

Make it a bit easier to drag items to the start of pages by also taking
the left and right empty space into account, instead of considering it
an invalid target.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2348>
This commit is contained in:
Jonas Dreßler 2022-06-24 13:50:42 +02:00 committed by Marge Bot
parent 40bd48068f
commit 4cf372b890

View File

@ -1021,9 +1021,6 @@ var IconGridLayout = GObject.registerClass({
else else
adjY %= this._pageHeight; adjY %= this._pageHeight;
if (adjX < leftEmptySpace || adjY < topEmptySpace)
return [0, 0, DragLocation.INVALID];
const gridWidth = const gridWidth =
childSize * this.columnsPerPage + childSize * this.columnsPerPage +
hSpacing * (this.columnsPerPage - 1); hSpacing * (this.columnsPerPage - 1);
@ -1031,7 +1028,12 @@ var IconGridLayout = GObject.registerClass({
childSize * this.rowsPerPage + childSize * this.rowsPerPage +
vSpacing * (this.rowsPerPage - 1); vSpacing * (this.rowsPerPage - 1);
if (adjX > leftEmptySpace + gridWidth || adjY > topEmptySpace + gridHeight) const inTopEmptySpace = adjY < topEmptySpace;
const inLeftEmptySpace = adjX < leftEmptySpace;
const inRightEmptySpace = adjX > leftEmptySpace + gridWidth;
const inBottomEmptySpace = adjY > topEmptySpace + gridHeight;
if (inTopEmptySpace || inBottomEmptySpace)
return [0, 0, DragLocation.INVALID]; return [0, 0, DragLocation.INVALID];
const halfHSpacing = hSpacing / 2; const halfHSpacing = hSpacing / 2;
@ -1042,12 +1044,23 @@ var IconGridLayout = GObject.registerClass({
const item = visibleItems[i]; const item = visibleItems[i];
const childBox = item.allocation; const childBox = item.allocation;
// Outside the icon boundaries const firstInRow = i % this.columnsPerPage === 0;
const lastInRow = i % this.columnsPerPage === this.columnsPerPage - 1;
// Check icon boundaries
if ((inLeftEmptySpace && firstInRow) ||
(inRightEmptySpace && lastInRow)) {
if (y < childBox.y1 - halfVSpacing ||
y > childBox.y2 + halfVSpacing)
continue;
} else {
// eslint-disable-next-line no-lonely-if
if (x < childBox.x1 - halfHSpacing || if (x < childBox.x1 - halfHSpacing ||
x > childBox.x2 + halfHSpacing || x > childBox.x2 + halfHSpacing ||
y < childBox.y1 - halfVSpacing || y < childBox.y1 - halfVSpacing ||
y > childBox.y2 + halfVSpacing) y > childBox.y2 + halfVSpacing)
continue; continue;
}
let dragLocation; let dragLocation;