appDisplay: Bring back drag overshoot region

This is a region where, if hovered while dragging, immediately goes
to the previous or next page. This behavior was lost during the
transition to the new app grid layout manager.

Bring back the drag overshoot region.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2335>
This commit is contained in:
Georges Basile Stavracas Neto 2022-08-09 19:39:41 -03:00 committed by Marge Bot
parent 692de0eb95
commit 4dcae8ddd2

View File

@ -43,6 +43,7 @@ const PAGE_PREVIEW_ANIMATION_TIME = 150;
const PAGE_INDICATOR_FADE_TIME = 200;
const PAGE_PREVIEW_RATIO = 0.20;
const OVERSHOOT_THRESHOLD = 20;
const OVERSHOOT_TIMEOUT = 300;
const DELAYED_MOVE_TIMEOUT = 200;
@ -843,6 +844,23 @@ var BaseAppView = GObject.registerClass({
this._overshootTimeoutId = 0;
}
_dragWithinOvershootRegion(dragEvent) {
const rtl = this.get_text_direction() === Clutter.TextDirection.RTL;
const {x, y, targetActor: indicator} = dragEvent;
const [indicatorX, indicatorY] = indicator.get_transformed_position();
const [indicatorWidth, indicatorHeight] = indicator.get_transformed_size();
let overshootX = indicatorX;
if (indicator === this._nextPageIndicator || rtl)
overshootX += indicatorWidth - OVERSHOOT_THRESHOLD;
const overshootBox = new Clutter.ActorBox();
overshootBox.set_origin(overshootX, indicatorY);
overshootBox.set_size(OVERSHOOT_THRESHOLD, indicatorHeight);
return overshootBox.contains(x, y);
}
_handleDragOvershoot(dragEvent) {
// Already animating
if (this._adjustment.get_transition('value') !== null)
@ -868,6 +886,13 @@ var BaseAppView = GObject.registerClass({
if (targetPage < 0 || targetPage >= this._grid.nPages)
return; // don't go beyond first/last page
// If dragging over the drag overshoot threshold region, immediately
// switch pages
if (this._dragWithinOvershootRegion(dragEvent)) {
this._resetOvershoot();
this.goToPage(targetPage);
}
this._overshootTimeoutId =
GLib.timeout_add(GLib.PRIORITY_DEFAULT, OVERSHOOT_TIMEOUT, () => {
this._resetOvershoot();