summaryrefslogtreecommitdiff
path: root/community/cinnamon/keyboard_applet.patch
blob: 29ea489ce3cdf6a4ce5f41c5d9c4fc7dfaf48850 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
--- a/files/usr/share/cinnamon/applets/keyboard@cinnamon.org/applet.js
+++ b/files/usr/share/cinnamon/applets/keyboard@cinnamon.org/applet.js
@@ -1,9 +1,10 @@
 const Applet = imports.ui.applet;
-const Gkbd = imports.gi.Gkbd;
 const Lang = imports.lang;
-const Cinnamon = imports.gi.Cinnamon;
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
 const St = imports.gi.St;
 const Gtk = imports.gi.Gtk;
+const CinnamonDesktop = imports.gi.CinnamonDesktop;
 const Main = imports.ui.main;
 const PopupMenu = imports.ui.popupMenu;
 const Util = imports.misc.util;
@@ -16,11 +17,12 @@ function LayoutMenuItem() {
 LayoutMenuItem.prototype = {
     __proto__: PopupMenu.PopupBaseMenuItem.prototype,
 
-    _init: function(config, id, indicator, long_name) {
+    _init: function(ipsettings, id, index, indicator, long_name) {
         PopupMenu.PopupBaseMenuItem.prototype._init.call(this);
 
-        this._config = config;
+        this._ipsettings = ipsettings;
         this._id = id;
+        this._index = index;
         this.label = new St.Label({ text: long_name });
         this.indicator = indicator;
         this.addActor(this.label);
@@ -29,7 +31,7 @@ LayoutMenuItem.prototype = {
 
     activate: function(event) {
         PopupMenu.PopupBaseMenuItem.prototype.activate.call(this);
-        this._config.lock_group(this._id);
+        this._ipsettings.set_value('current', GLib.Variant.new_uint32(this._index));
     }
 };
 
@@ -62,18 +64,18 @@ MyApplet.prototype = {
                                        this._syncConfig,
                                        null);
 
-            this._config = Gkbd.Configuration.get();
-            this._config.connect('changed', Lang.bind(this, this._syncConfig));
-            this._config.connect('group-changed', Lang.bind(this, this._syncGroup));
+            this._xkbInfo = new CinnamonDesktop.XkbInfo();
+            this._ipsettings = new Gio.Settings({ schema: 'org.cinnamon.desktop.input-sources' });
+            this._ipsettings.connect('changed::sources', Lang.bind(this, this._syncConfig));
+            this._ipsettings.connect('changed::current', Lang.bind(this, this._syncGroup));
 
-            this._config.start_listen();
 
             this._syncConfig();
 
             this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
             this.menu.addAction(_("Show Keyboard Layout"), Lang.bind(this, function() {
                 Main.overview.hide();
-                Util.spawn(['gkbd-keyboard-display', '-g', String(this._config.get_current_group() + 1)]);
+                Util.spawn(['gkbd-keyboard-display', '-l', this._selectedLayout._id]);
             }));                                
             this.menu.addAction(_("Show Character Table"), Lang.bind(this, function() {
                 Main.overview.hide();
@@ -113,8 +115,8 @@ MyApplet.prototype = {
     },
 
     _syncConfig: function() {
-        let groups = this._config.get_group_names();
-        if (groups.length > 1) {
+        let sources = this._ipsettings.get_value('sources');
+        if (sources.n_children() > 1) {
             this.actor.show();
         } else {
             this.menu.close();
@@ -127,25 +129,30 @@ MyApplet.prototype = {
         for (let i = 0; i < this._labelActors.length; i++)
             this._labelActors[i].destroy();
 
-        let short_names = this._adjustGroupNames(this._config.get_short_group_names());
 
         this._selectedLayout = null;
         this._layoutItems = [ ];
         this._labelActors = [ ];
-        for (let i = 0; i < groups.length; i++) {
-            let icon_name = this._config.get_group_name(i);
+        for (let i = 0; i < sources.n_children(); i++) {
+            let [type, id] = sources.get_child_value(i).deep_unpack();
+            let displayName = id;
+            let shortName = id;
+            let xkbLayout = id;
+            if (type == 'xkb') {
+                [_exists, displayName, shortName, xkbLayout, _xkbVariant] = this._xkbInfo.get_layout_info(id);
+            } // TODO: errorhandling, handle 'ibus'
+            let icon_name = xkbLayout; // FIXME: Really?
             let actor;
             if (this._showFlags)
                 actor = new St.Icon({ icon_name: icon_name, icon_type: St.IconType.FULLCOLOR, style_class: 'popup-menu-icon' });
             else
-                actor = new St.Label({ text: short_names[i] });
-            let item = new LayoutMenuItem(this._config, i, actor, groups[i]);
-            item._short_group_name = short_names[i];
+                actor = new St.Label({ text: shortName });
+            let item = new LayoutMenuItem(this._ipsettings, id, i, actor, displayName);
             item._icon_name = icon_name;
             this._layoutItems.push(item);
             this.menu.addMenuItem(item, i);
 
-            let shortLabel = new St.Label({ text: short_names[i] });
+            let shortLabel = new St.Label({ text: shortName });
             this._labelActors.push(shortLabel);
         }
 
@@ -153,17 +160,17 @@ MyApplet.prototype = {
     },
 
     _syncGroup: function() {
-        let selected = this._config.get_current_group();
+        let current = this._ipsettings.get_uint('current');
 
         if (this._selectedLayout) {
             this._selectedLayout.setShowDot(false);
             this._selectedLayout = null;
         }
 
-        let item = this._layoutItems[selected];
+        let item = this._layoutItems[current];
         item.setShowDot(true);
 
-        let selectedLabel = this._labelActors[selected];
+        let selectedLabel = this._labelActors[current];
 
         if (this._showFlags) {
             this.set_applet_icon_name(item._icon_name);