From f52cafeb4a92b81b391d999771ef1feab2981189 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Thu, 11 Feb 2021 13:08:47 +0100 Subject: [PATCH] layout: Move keyboard slide animation to keyboard The animation handling is kinda split between layout (for the keyboard slide), and keyboard (for the focus window slide). It would be nice to have more fine grained control on those, so move the animation handling altogether to keyboard.js as a start. This is roughly similar, except that transformations apply to the Keyboard actor, instead of the keyboardBox (its parent). We now queue a relayout after the animation in order to update the chrome tracking. The only layering break now is that we emit layoutManager::keyboard-visible-changed in keyboard.js, its purpose will be dropped in future commits, so leave it there for now. Part-of: --- js/ui/keyboard.js | 62 +++++++++++++++++++++++++++++++++++++++++------ js/ui/layout.js | 48 ------------------------------------ 2 files changed, 54 insertions(+), 56 deletions(-) diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js index a579495ad..ef655e3e0 100644 --- a/js/ui/keyboard.js +++ b/js/ui/keyboard.js @@ -8,12 +8,12 @@ const Signals = imports.signals; const InputSourceManager = imports.ui.status.keyboard; const IBusManager = imports.misc.ibusManager; const BoxPointer = imports.ui.boxpointer; -const Layout = imports.ui.layout; const Main = imports.ui.main; const PageIndicators = imports.ui.pageIndicators; const PopupMenu = imports.ui.popupMenu; -var KEYBOARD_REST_TIME = Layout.KEYBOARD_ANIMATION_TIME * 2; +var KEYBOARD_ANIMATION_TIME = 150; +var KEYBOARD_REST_TIME = KEYBOARD_ANIMATION_TIME * 2; 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 */ @@ -1168,7 +1168,6 @@ var KeyboardManager = class KeyBoardManager { this._keyboard.setCursorLocation(null); this._keyboard.destroy(); this._keyboard = null; - Main.layoutManager.hideKeyboard(true); } } @@ -1213,7 +1212,7 @@ var KeyboardManager = class KeyBoardManager { var Keyboard = GObject.registerClass( class Keyboard extends St.BoxLayout { _init() { - super._init({ name: 'keyboard', vertical: true }); + super._init({ name: 'keyboard', reactive: true, vertical: true }); this._focusInExtendedKeys = false; this._emojiActive = false; @@ -1294,6 +1293,7 @@ class Keyboard extends St.BoxLayout { Main.layoutManager.untrackChrome(this); Main.layoutManager.keyboardBox.remove_actor(this); + Main.layoutManager.keyboardBox.hide(); if (this._languagePopup) { this._languagePopup.destroy(); @@ -1742,7 +1742,7 @@ class Keyboard extends St.BoxLayout { Main.layoutManager.keyboardIndex = monitor; this._relayout(); - Main.layoutManager.showKeyboard(); + this.animateShow(); this._setEmojiActive(false); @@ -1774,10 +1774,56 @@ class Keyboard extends St.BoxLayout { if (this._keyboardRequested) return; - Main.layoutManager.hideKeyboard(); + this.animateHide(); this.setCursorLocation(null); } + animateShow() { + Main.layoutManager.keyboardBox.show(); + this.ease({ + translation_y: -this.height, + opacity: 255, + duration: KEYBOARD_ANIMATION_TIME, + mode: Clutter.AnimationMode.EASE_OUT_QUAD, + onComplete: () => { + this._animateShowComplete(); + }, + }); + Main.layoutManager.emit('keyboard-visible-changed', true); + } + + _animateShowComplete() { + let keyboardBox = Main.layoutManager.keyboardBox; + this._keyboardHeightNotifyId = keyboardBox.connect('notify::height', () => { + this.translation_y = -this.height; + }); + + // Queue a relayout so the keyboardBox can update its chrome region. + keyboardBox.queue_relayout(); + } + + animateHide(immediate) { + if (this._keyboardHeightNotifyId) { + Main.layoutManager.keyboardBox.disconnect(this._keyboardHeightNotifyId); + this._keyboardHeightNotifyId = 0; + } + this.ease({ + translation_y: 0, + opacity: 0, + duration: immediate ? 0 : KEYBOARD_ANIMATION_TIME, + mode: Clutter.AnimationMode.EASE_IN_QUAD, + onComplete: () => { + this._animateHideComplete(); + }, + }); + + Main.layoutManager.emit('keyboard-visible-changed', false); + } + + _animateHideComplete() { + Main.layoutManager.keyboardBox.hide(); + } + resetSuggestions() { if (this._suggestions) this._suggestions.clear(); @@ -1813,7 +1859,7 @@ class Keyboard extends St.BoxLayout { if (show) { windowActor.ease({ y: windowActor.y - deltaY, - duration: Layout.KEYBOARD_ANIMATION_TIME, + duration: KEYBOARD_ANIMATION_TIME, mode: Clutter.AnimationMode.EASE_OUT_QUAD, onComplete: () => { this._windowSlideAnimationComplete(window, -deltaY); @@ -1822,7 +1868,7 @@ class Keyboard extends St.BoxLayout { } else { windowActor.ease({ y: windowActor.y + deltaY, - duration: Layout.KEYBOARD_ANIMATION_TIME, + duration: KEYBOARD_ANIMATION_TIME, mode: Clutter.AnimationMode.EASE_IN_QUAD, onComplete: () => { this._windowSlideAnimationComplete(window, deltaY); diff --git a/js/ui/layout.js b/js/ui/layout.js index 1a41a34be..0c844bc49 100644 --- a/js/ui/layout.js +++ b/js/ui/layout.js @@ -13,7 +13,6 @@ const Params = imports.misc.params; const Ripples = imports.ui.ripples; var STARTUP_ANIMATION_TIME = 500; -var KEYBOARD_ANIMATION_TIME = 150; var BACKGROUND_FADE_ANIMATION_TIME = 1000; var HOT_CORNER_PRESSURE_THRESHOLD = 100; // pixels @@ -731,53 +730,6 @@ var LayoutManager = GObject.registerClass({ this.emit('startup-complete'); } - showKeyboard() { - this.keyboardBox.show(); - this.keyboardBox.ease({ - translation_y: -this.keyboardBox.height, - opacity: 255, - duration: KEYBOARD_ANIMATION_TIME, - mode: Clutter.AnimationMode.EASE_OUT_QUAD, - onComplete: () => { - this._showKeyboardComplete(); - }, - }); - this.emit('keyboard-visible-changed', true); - } - - _showKeyboardComplete() { - // Poke Chrome to update the input shape; it doesn't notice - // anchor point changes - this._updateRegions(); - - this._keyboardHeightNotifyId = this.keyboardBox.connect('notify::height', () => { - this.keyboardBox.translation_y = -this.keyboardBox.height; - }); - } - - hideKeyboard(immediate) { - if (this._keyboardHeightNotifyId) { - this.keyboardBox.disconnect(this._keyboardHeightNotifyId); - this._keyboardHeightNotifyId = 0; - } - this.keyboardBox.ease({ - translation_y: 0, - opacity: 0, - duration: immediate ? 0 : KEYBOARD_ANIMATION_TIME, - mode: Clutter.AnimationMode.EASE_IN_QUAD, - onComplete: () => { - this._hideKeyboardComplete(); - }, - }); - - this.emit('keyboard-visible-changed', false); - } - - _hideKeyboardComplete() { - this.keyboardBox.hide(); - this._updateRegions(); - } - // setDummyCursorGeometry: // // The cursor dummy is a standard widget commonly used for popup