[gnome-shell] keyboard: Don't hide or show the keyboard immediately



commit 449575ceae6e3ee09a6bdd3d9e1f5965059d0963
Author: Rui Matos <tiagomatos gmail com>
Date:   Sun Nov 18 16:17:21 2012 +0100

    keyboard: Don't hide or show the keyboard immediately
    
    Acting on each Show/Hide DBus call immediately may cause a lot of
    jittery movement when Alt+Tabbing or even just switching tabs in
    e.g. gnome-terminal.
    
    To make the OSK feel sturdier, we wait a bit before actually showing
    or hiding it so that we can coalesce tight sequences of Show/Hide
    calls. I.e. the last call wins which means that we might end up not
    doing anything.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688646

 js/ui/keyboard.js |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js
index 2123d5c..7ce21d2 100644
--- a/js/ui/keyboard.js
+++ b/js/ui/keyboard.js
@@ -11,9 +11,12 @@ const Signals = imports.signals;
 const St = imports.gi.St;
 
 const BoxPointer = imports.ui.boxpointer;
+const Layout = imports.ui.layout;
 const Main = imports.ui.main;
 const MessageTray = imports.ui.messageTray;
 
+const KEYBOARD_REST_TIME = Layout.KEYBOARD_ANIMATION_TIME * 2 * 1000;
+
 const KEYBOARD_SCHEMA = 'org.gnome.shell.keyboard';
 const KEYBOARD_TYPE = 'keyboard-type';
 
@@ -151,6 +154,13 @@ const Keyboard = new Lang.Class({
         this._subkeysBoxPointer = null;
         this._capturedEventId = 0;
         this._capturedPress = false;
+
+        this._keyboardVisible = false;
+        Main.layoutManager.connect('keyboard-visible-changed', Lang.bind(this, function(o, visible) {
+            this._keyboardVisible = visible;
+        }));
+        this._keyboardRequested = false;
+        this._keyboardRestingId = 0;
     },
 
     init: function () {
@@ -461,7 +471,37 @@ const Keyboard = new Lang.Class({
                actor._extended_keys || actor.extended_key;
     },
 
+    _clearKeyboardRestTimer: function() {
+        if (!this._keyboardRestingId)
+            return;
+        GLib.source_remove(this._keyboardRestingId);
+        this._keyboardRestingId = 0;
+    },
+
     show: function (monitor) {
+        this._keyboardRequested = true;
+
+        if (this._keyboardVisible) {
+            if (monitor != Main.layoutManager.keyboardIndex) {
+                Main.layoutManager.keyboardIndex = monitor;
+                this._redraw();
+            }
+            return;
+        }
+
+        this._clearKeyboardRestTimer();
+        this._keyboardRestingId = GLib.timeout_add(GLib.PRIORITY_DEFAULT,
+                                                   KEYBOARD_REST_TIME,
+                                                   Lang.bind(this, function() {
+                                                       this._clearKeyboardRestTimer();
+                                                       this._show(monitor);
+                                                   }));
+    },
+
+    _show: function(monitor) {
+        if (!this._keyboardRequested)
+            return;
+
         Main.layoutManager.keyboardIndex = monitor;
         this._redraw();
         Main.layoutManager.showKeyboard();
@@ -469,6 +509,24 @@ const Keyboard = new Lang.Class({
     },
 
     hide: function () {
+        this._keyboardRequested = false;
+
+        if (!this._keyboardVisible)
+            return;
+
+        this._clearKeyboardRestTimer();
+        this._keyboardRestingId = GLib.timeout_add(GLib.PRIORITY_DEFAULT,
+                                                   KEYBOARD_REST_TIME,
+                                                   Lang.bind(this, function() {
+                                                       this._clearKeyboardRestTimer();
+                                                       this._hide();
+                                                   }));
+    },
+
+    _hide: function() {
+        if (this._keyboardRequested)
+            return;
+
         this._hideSubkeys();
         Main.layoutManager.hideKeyboard();
         this._createSource();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]