appDisplay: Special-case dropping over page indicators

This brings back the ability to drop an icon beyong the last page.
Because the acceptDrop() method does not have access to the target
drop actor, to avoid an extra pick or manually calculating it from
allocations, simply store it during DragMonitor.dragDrop(), and
use the target actor in acceptDrop().

This commit also removes the last usage of SidePages, so drop the
enum too.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2335>
This commit is contained in:
Georges Basile Stavracas Neto 2022-06-29 14:25:47 -03:00 committed by Marge Bot
parent 09b975fabf
commit 8f247971eb

View File

@ -79,13 +79,6 @@ const DEFAULT_FOLDERS = {
},
};
var SidePages = {
NONE: 0,
PREVIOUS: 1 << 0,
NEXT: 1 << 1,
DND: 1 << 2,
};
function _getCategories(info) {
let categoriesStr = info.get_categories();
if (!categoriesStr)
@ -884,6 +877,7 @@ var BaseAppView = GObject.registerClass({
_onDragBegin() {
this._dragMonitor = {
dragMotion: this._onDragMotion.bind(this),
dragDrop: this._onDragDrop.bind(this),
};
DND.addDragMonitor(this._dragMonitor);
this._appGridLayout.showPageIndicators();
@ -908,6 +902,13 @@ var BaseAppView = GObject.registerClass({
return DND.DragMotionResult.CONTINUE;
}
_onDragDrop(dropEvent) {
// Because acceptDrop() does not receive the target actor, store it
// here and use this value in the acceptDrop() implementation below.
this._dropTarget = dropEvent.targetActor;
return DND.DragMotionResult.CONTINUE;
}
_onDragEnd() {
if (this._dragMonitor) {
DND.removeDragMonitor(this._dragMonitor);
@ -939,11 +940,15 @@ var BaseAppView = GObject.registerClass({
}
acceptDrop(source) {
const dropTarget = this._dropTarget;
delete this._dropTarget;
if (!this._canAccept(source))
return false;
if (this._dropPage) {
const increment = this._dropPage === SidePages.NEXT ? 1 : -1;
if (dropTarget === this._prevPageIndicator ||
dropTarget === this._nextPageIndicator) {
const increment = dropTarget === this._prevPageIndicator ? -1 : 1;
const { currentPage, nPages } = this._grid;
const page = Math.min(currentPage + increment, nPages);
const position = page < nPages ? -1 : 0;