143 lines
5.8 KiB
Diff
143 lines
5.8 KiB
Diff
diff --git a/applet.js b/applet.js
|
|
--- 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 GnomeDesktop = imports.gi.GnomeDesktop;
|
|
const Main = imports.ui.main;
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
const Util = imports.misc.util;
|
|
@@ -15,11 +16,12 @@
|
|
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);
|
|
@@ -28,7 +30,7 @@
|
|
|
|
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));
|
|
}
|
|
};
|
|
|
|
@@ -54,18 +56,18 @@
|
|
this._layoutItems = [ ];
|
|
|
|
this._showFlags = global.settings.get_boolean("keyboard-applet-use-flags");
|
|
- 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 GnomeDesktop.XkbInfo();
|
|
+ this._ipsettings = new Gio.Settings({ schema: 'org.gnome.desktop.input-sources' });
|
|
+ this._ipsettings.connect('changed::sources', Lang.bind(this, this._syncConfig));
|
|
+ this._ipsettings.connect('changed::current', Lang.bind(this, this._syncGroup));
|
|
global.settings.connect('changed::keyboard-applet-use-flags', Lang.bind(this, this._reload_settings));
|
|
- 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();
|
|
@@ -98,7 +100,6 @@
|
|
},
|
|
|
|
_reload_settings: function() {
|
|
- this._showFlags = global.settings.get_boolean("keyboard-applet-use-flags");
|
|
this._syncConfig();
|
|
},
|
|
|
|
@@ -127,8 +128,8 @@
|
|
_syncConfig: function() {
|
|
this._showFlags = global.settings.get_boolean("keyboard-applet-use-flags");
|
|
|
|
- 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();
|
|
@@ -141,25 +142,29 @@
|
|
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);
|
|
}
|
|
|
|
@@ -167,17 +172,17 @@
|
|
},
|
|
|
|
_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);
|