keyboard: Use SwipeTracker for emoji panel page switching

This allows handling scroll events, in addition to 1fg and pointer
gestures. 3fg gestures are less relevant here.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2278>
This commit is contained in:
Carlos Garnacho 2022-06-28 23:47:04 +02:00 committed by Florian Müllner
parent d843136247
commit 2b81355fa1

View File

@ -11,12 +11,11 @@ const BoxPointer = imports.ui.boxpointer;
const Main = imports.ui.main; const Main = imports.ui.main;
const PageIndicators = imports.ui.pageIndicators; const PageIndicators = imports.ui.pageIndicators;
const PopupMenu = imports.ui.popupMenu; const PopupMenu = imports.ui.popupMenu;
const SwipeTracker = imports.ui.swipeTracker;
var KEYBOARD_ANIMATION_TIME = 150; var KEYBOARD_ANIMATION_TIME = 150;
var KEYBOARD_REST_TIME = KEYBOARD_ANIMATION_TIME * 2; var KEYBOARD_REST_TIME = KEYBOARD_ANIMATION_TIME * 2;
var KEY_LONG_PRESS_TIME = 250; var KEY_LONG_PRESS_TIME = 250;
var PANEL_SWITCH_ANIMATION_TIME = 500;
var PANEL_SWITCH_RELATIVE_DISTANCE = 1 / 3; /* A third of the actor width */
const A11Y_APPLICATIONS_SCHEMA = 'org.gnome.desktop.a11y.applications'; const A11Y_APPLICATIONS_SCHEMA = 'org.gnome.desktop.a11y.applications';
const SHOW_KEYBOARD = 'screen-keyboard-enabled'; const SHOW_KEYBOARD = 'screen-keyboard-enabled';
@ -677,13 +676,14 @@ var EmojiPager = GObject.registerClass({
this._delta = 0; this._delta = 0;
this._width = null; this._width = null;
let panAction = new Clutter.PanAction({ interpolate: false }); const swipeTracker = new SwipeTracker.SwipeTracker(this,
panAction.connect('pan', this._onPan.bind(this)); Clutter.Orientation.HORIZONTAL,
panAction.connect('gesture-begin', this._onPanBegin.bind(this)); Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW,
panAction.connect('gesture-cancel', this._onPanCancel.bind(this)); {allowDrag: true, allowScroll: true});
panAction.connect('gesture-end', this._onPanEnd.bind(this)); swipeTracker.connect('begin', this._onSwipeBegin.bind(this));
this._panAction = panAction; swipeTracker.connect('update', this._onSwipeUpdate.bind(this));
this.add_action_full('pan', Clutter.EventPhase.CAPTURE, panAction); swipeTracker.connect('end', this._onSwipeEnd.bind(this));
this._swipeTracker = swipeTracker;
} }
get delta() { get delta() {
@ -702,9 +702,6 @@ var EmojiPager = GObject.registerClass({
this._delta = value; this._delta = value;
this.notify('delta'); this.notify('delta');
if (value == 0)
return;
let relValue = Math.abs(value / this._width); let relValue = Math.abs(value / this._width);
let followingPage = this.getFollowingPage(); let followingPage = this.getFollowingPage();
@ -753,9 +750,8 @@ var EmojiPager = GObject.registerClass({
return this._prevPage(this._curPage); return this._prevPage(this._curPage);
} }
_onPan(action) { _onSwipeUpdate(tracker, progress) {
let [dist_, dx, dy_] = action.get_motion_delta(0); this.delta = -progress * this._width;
this.delta += dx;
if (this._currentKey != null) { if (this._currentKey != null) {
this._currentKey.cancel(); this._currentKey.cancel();
@ -765,27 +761,20 @@ var EmojiPager = GObject.registerClass({
return false; return false;
} }
_onPanBegin() { _onSwipeBegin(tracker) {
this._width = this.width; this._width = this.width;
return true; const points = [-1, 0, 1];
tracker.confirmSwipe(this._width, points, 0, 0);
} }
_onPanEnd() { _onSwipeEnd(tracker, duration, endProgress) {
if (Math.abs(this._delta) < this.width * PANEL_SWITCH_RELATIVE_DISTANCE) {
this._onPanCancel();
} else {
let value;
if (this._delta > 0)
value = this._width;
else if (this._delta < 0)
value = -this._width;
let relDelta = Math.abs(this._delta - value) / this._width;
let time = PANEL_SWITCH_ANIMATION_TIME * Math.abs(relDelta);
this.remove_all_transitions(); this.remove_all_transitions();
if (endProgress === 0) {
this.ease_property('delta', 0, {duration});
} else {
const value = endProgress < 0 ? this._width : -this._width;
this.ease_property('delta', value, { this.ease_property('delta', value, {
duration: time, duration,
onComplete: () => { onComplete: () => {
this.setCurrentPage(this.getFollowingPage()); this.setCurrentPage(this.getFollowingPage());
}, },
@ -793,16 +782,6 @@ var EmojiPager = GObject.registerClass({
} }
} }
_onPanCancel() {
let relDelta = Math.abs(this._delta) / this.width;
let time = PANEL_SWITCH_ANIMATION_TIME * Math.abs(relDelta);
this.remove_all_transitions();
this.ease_property('delta', 0, {
duration: time,
});
}
_initPagingInfo() { _initPagingInfo() {
this._pages = []; this._pages = [];
@ -868,9 +847,6 @@ var EmojiPager = GObject.registerClass({
key.connect('pressed', () => { key.connect('pressed', () => {
this._currentKey = key; this._currentKey = key;
}); });
key.connect('long-press', () => {
this._panAction.cancel();
});
key.connect('commit', (actor, keyval, str) => { key.connect('commit', (actor, keyval, str) => {
if (this._currentKey != key) if (this._currentKey != key)
return; return;