unlockDialog: Add swipe gesture

Clicking or typing to reveal the auth prompt are good options for
mouse/keyboard workflows, but awkward on touch devices. Now that
we have SwipeTracker, adding corresponding gestures support is
easy, so do just that.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/972
This commit is contained in:
Florian Müllner 2020-02-02 12:23:32 +01:00 committed by Georges Basile Stavracas Neto
parent 55bfc4d820
commit 9e5071849c

View File

@ -8,6 +8,7 @@ const Background = imports.ui.background;
const Layout = imports.ui.layout; const Layout = imports.ui.layout;
const Main = imports.ui.main; const Main = imports.ui.main;
const MessageTray = imports.ui.messageTray; const MessageTray = imports.ui.messageTray;
const SwipeTracker = imports.ui.swipeTracker;
const AuthPrompt = imports.gdm.authPrompt; const AuthPrompt = imports.gdm.authPrompt;
@ -436,6 +437,12 @@ var UnlockDialog = GObject.registerClass({
this._setTransitionProgress(this._adjustment.value); this._setTransitionProgress(this._adjustment.value);
}); });
this._swipeTracker = new SwipeTracker.SwipeTracker(
this, Shell.ActionMode.UNLOCK_SCREEN);
this._swipeTracker.connect('begin', this._swipeBegin.bind(this));
this._swipeTracker.connect('update', this._swipeUpdate.bind(this));
this._swipeTracker.connect('end', this._swipeEnd.bind(this));
this._activePage = null; this._activePage = null;
let tapAction = new Clutter.TapAction(); let tapAction = new Clutter.TapAction();
@ -457,16 +464,16 @@ var UnlockDialog = GObject.registerClass({
this._user = this._userManager.get_user(this._userName); this._user = this._userManager.get_user(this._userName);
// Authentication & Clock stack // Authentication & Clock stack
let stack = new Shell.Stack(); this._stack = new Shell.Stack();
this._promptBox = new St.BoxLayout({ vertical: true }); this._promptBox = new St.BoxLayout({ vertical: true });
this._promptBox.set_pivot_point(0.5, 0.5); this._promptBox.set_pivot_point(0.5, 0.5);
this._promptBox.hide(); this._promptBox.hide();
stack.add_child(this._promptBox); this._stack.add_child(this._promptBox);
this._clock = new Clock(); this._clock = new Clock();
this._clock.set_pivot_point(0.5, 0.5); this._clock.set_pivot_point(0.5, 0.5);
stack.add_child(this._clock); this._stack.add_child(this._clock);
this._showClock(); this._showClock();
this.allowCancel = false; this.allowCancel = false;
@ -480,10 +487,10 @@ var UnlockDialog = GObject.registerClass({
// Main Box // Main Box
let mainBox = new Clutter.Actor(); let mainBox = new Clutter.Actor();
mainBox.add_constraint(new Layout.MonitorConstraint({ primary: true })); mainBox.add_constraint(new Layout.MonitorConstraint({ primary: true }));
mainBox.add_child(stack); mainBox.add_child(this._stack);
mainBox.add_child(this._notificationsBox); mainBox.add_child(this._notificationsBox);
mainBox.layout_manager = new UnlockDialogLayout( mainBox.layout_manager = new UnlockDialogLayout(
stack, this._stack,
this._notificationsBox); this._notificationsBox);
this.add_child(mainBox); this.add_child(mainBox);
@ -656,6 +663,40 @@ var UnlockDialog = GObject.registerClass({
this._authPrompt.cancel(); this._authPrompt.cancel();
} }
_swipeBegin(tracker, monitor) {
if (monitor !== Main.layoutManager.primaryIndex)
return;
this._adjustment.remove_transition('value');
this._ensureAuthPrompt();
let progress = this._adjustment.value;
tracker.confirmSwipe(this._stack.height,
[0, 1],
progress,
Math.round(progress));
}
_swipeUpdate(tracker, progress) {
this._adjustment.value = progress;
}
_swipeEnd(tracker, duration, endProgress) {
this._activePage = endProgress
? this._promptBox
: this._clock;
this._adjustment.ease(endProgress, {
mode: Clutter.AnimationMode.EASE_OUT_CUBIC,
duration,
onComplete: () => {
if (this._activePage === this._clock)
this._maybeDestroyAuthPrompt();
},
});
}
_onDestroy() { _onDestroy() {
this.popModal(); this.popModal();