iconGrid: Return page and position for drop targets instead of items
Returning a page and a position for the drop target seems more straightforward than returning an actual grid item in getDropTarget(). With the next commit, this will allow us to throw away drop targets that are not on the current page. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2348>
This commit is contained in:
parent
b781b3e9fd
commit
2e6fd8b730
@ -1172,14 +1172,8 @@ var BaseAppView = GObject.registerClass({
|
||||
}
|
||||
|
||||
_getDropTarget(x, y, source) {
|
||||
const { currentPage } = this._grid;
|
||||
|
||||
let [item, dragLocation] = this._grid.getDropTarget(x, y);
|
||||
|
||||
const [sourcePage, sourcePosition] = this._grid.getItemPosition(source);
|
||||
const targetPage = currentPage;
|
||||
let targetPosition = item
|
||||
? this._grid.getItemPosition(item)[1] : -1;
|
||||
let [targetPage, targetPosition, dragLocation] = this._grid.getDropTarget(x, y);
|
||||
|
||||
// In case we're hovering over the edge of an item but the
|
||||
// reflow will happen in the opposite direction (the drag
|
||||
@ -1212,14 +1206,6 @@ var BaseAppView = GObject.registerClass({
|
||||
}
|
||||
}
|
||||
|
||||
// Append to the page if dragging over empty area
|
||||
if (dragLocation === IconGrid.DragLocation.EMPTY_SPACE) {
|
||||
const pageItems =
|
||||
this._grid.getItemsAtPage(currentPage).filter(c => c.visible);
|
||||
|
||||
targetPosition = pageItems.length;
|
||||
}
|
||||
|
||||
return [targetPage, targetPosition, dragLocation];
|
||||
}
|
||||
|
||||
|
@ -1008,19 +1008,21 @@ var IconGridLayout = GObject.registerClass({
|
||||
|
||||
// Out of bounds
|
||||
if (page >= this._pages.length)
|
||||
return [null, DragLocation.INVALID];
|
||||
return [0, 0, DragLocation.INVALID];
|
||||
|
||||
if (isRtl && this._orientation === Clutter.Orientation.HORIZONTAL)
|
||||
page = swap(page, this._pages.length);
|
||||
|
||||
// Page-relative coordinates from now on
|
||||
// Get page-relative coordinates
|
||||
let adjX = x;
|
||||
let adjY = y;
|
||||
if (this._orientation === Clutter.Orientation.HORIZONTAL)
|
||||
x %= this._pageWidth;
|
||||
adjX %= this._pageWidth;
|
||||
else
|
||||
y %= this._pageHeight;
|
||||
adjY %= this._pageHeight;
|
||||
|
||||
if (x < leftEmptySpace || y < topEmptySpace)
|
||||
return [null, DragLocation.INVALID];
|
||||
if (adjX < leftEmptySpace || adjY < topEmptySpace)
|
||||
return [0, 0, DragLocation.INVALID];
|
||||
|
||||
const gridWidth =
|
||||
childSize * this.columnsPerPage +
|
||||
@ -1029,25 +1031,16 @@ var IconGridLayout = GObject.registerClass({
|
||||
childSize * this.rowsPerPage +
|
||||
vSpacing * (this.rowsPerPage - 1);
|
||||
|
||||
if (x > leftEmptySpace + gridWidth || y > topEmptySpace + gridHeight)
|
||||
return [null, DragLocation.INVALID];
|
||||
if (adjX > leftEmptySpace + gridWidth || adjY > topEmptySpace + gridHeight)
|
||||
return [0, 0, DragLocation.INVALID];
|
||||
|
||||
const halfHSpacing = hSpacing / 2;
|
||||
const halfVSpacing = vSpacing / 2;
|
||||
const visibleItems = this._pages[page].visibleChildren;
|
||||
|
||||
for (const item of visibleItems) {
|
||||
const childBox = item.allocation.copy();
|
||||
|
||||
// Page offset
|
||||
switch (this._orientation) {
|
||||
case Clutter.Orientation.HORIZONTAL:
|
||||
childBox.set_origin(childBox.x1 % this._pageWidth, childBox.y1);
|
||||
break;
|
||||
case Clutter.Orientation.VERTICAL:
|
||||
childBox.set_origin(childBox.x1, childBox.y1 % this._pageHeight);
|
||||
break;
|
||||
}
|
||||
for (let i = 0; i < visibleItems.length; i++) {
|
||||
const item = visibleItems[i];
|
||||
const childBox = item.allocation;
|
||||
|
||||
// Outside the icon boundaries
|
||||
if (x < childBox.x1 - halfHSpacing ||
|
||||
@ -1072,10 +1065,10 @@ var IconGridLayout = GObject.registerClass({
|
||||
dragLocation = DragLocation.START_EDGE;
|
||||
}
|
||||
|
||||
return [item, dragLocation];
|
||||
return [page, i, dragLocation];
|
||||
}
|
||||
|
||||
return [null, DragLocation.EMPTY_SPACE];
|
||||
return [page, -1, DragLocation.EMPTY_SPACE];
|
||||
}
|
||||
|
||||
get iconSize() {
|
||||
|
Loading…
Reference in New Issue
Block a user