[gnome-shell] status/keyboard: Ensure we always have at least one input source



commit 72c6f0025d659466f00e54e4a6a6315d806cb1f3
Author: Rui Matos <tiagomatos gmail com>
Date:   Fri Oct 10 15:54:30 2014 +0200

    status/keyboard: Ensure we always have at least one input source
    
    Most of the code handles the sources setting being empty and
    InputSourceManager.currentSource being null because previously the
    "model" (i.e. the sources list) was kept in gnome-settings-daemon.
    
    But this is fragile and since we're now the canonical place where the
    list lives we can force it to never be empty even if the gsetting is
    empty or contains only invalid entries.  Adding the default keyboard
    layout in that case is the safest thing to do.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=738303

 js/ui/status/keyboard.js |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)
---
diff --git a/js/ui/status/keyboard.js b/js/ui/status/keyboard.js
index 0c84541..8cb8cc9 100644
--- a/js/ui/status/keyboard.js
+++ b/js/ui/status/keyboard.js
@@ -298,8 +298,7 @@ const InputSourceManager = new Lang.Class({
         this._inputSources = {};
         this._ibusSources = {};
 
-        let inputSourcesByShortName = {};
-
+        let infosList = [];
         for (let i = 0; i < nSources; i++) {
             let displayName;
             let shortName;
@@ -323,11 +322,24 @@ const InputSourceManager = new Lang.Class({
                 }
             }
 
-            if (!exists)
-                continue;
+            if (exists)
+                infosList.push({ type: type, id: id, displayName: displayName, shortName: shortName });
+        }
 
-            let is = new InputSource(type, id, displayName, shortName, i);
+        if (infosList.length == 0) {
+            let type = INPUT_SOURCE_TYPE_XKB;
+            let id = KeyboardManager.DEFAULT_LAYOUT;
+            let [ , displayName, shortName, , ] = this._xkbInfo.get_layout_info(id);
+            infosList.push({ type: type, id: id, displayName: displayName, shortName: shortName });
+        }
 
+        let inputSourcesByShortName = {};
+        for (let i = 0; i < infosList.length; i++) {
+            let is = new InputSource(infosList[i].type,
+                                     infosList[i].id,
+                                     infosList[i].displayName,
+                                     infosList[i].shortName,
+                                     i);
             is.connect('activate', Lang.bind(this, this._activateInputSource));
 
             if (!(is.shortName in inputSourcesByShortName))


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