status/keyboard: Factor out a KeyboardManager class
This code will grow in a forthcoming patch so let's move it out. https://bugzilla.gnome.org/show_bug.cgi?id=736435
This commit is contained in:
parent
58aabfcf5b
commit
8e560f98d1
@ -18,6 +18,7 @@
|
||||
<file>misc/history.js</file>
|
||||
<file>misc/ibusManager.js</file>
|
||||
<file>misc/jsParse.js</file>
|
||||
<file>misc/keyboardManager.js</file>
|
||||
<file>misc/loginManager.js</file>
|
||||
<file>misc/modemManager.js</file>
|
||||
<file>misc/objectManager.js</file>
|
||||
|
71
js/misc/keyboardManager.js
Normal file
71
js/misc/keyboardManager.js
Normal file
@ -0,0 +1,71 @@
|
||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||
|
||||
const Gio = imports.gi.Gio;
|
||||
const GnomeDesktop = imports.gi.GnomeDesktop;
|
||||
const Lang = imports.lang;
|
||||
|
||||
const Main = imports.ui.main;
|
||||
|
||||
let _xkbInfo = null;
|
||||
|
||||
function getXkbInfo() {
|
||||
if (_xkbInfo == null)
|
||||
_xkbInfo = new GnomeDesktop.XkbInfo();
|
||||
return _xkbInfo;
|
||||
}
|
||||
|
||||
let _keyboardManager = null;
|
||||
|
||||
function getKeyboardManager() {
|
||||
if (_keyboardManager == null)
|
||||
_keyboardManager = new KeyboardManager();
|
||||
return _keyboardManager;
|
||||
}
|
||||
|
||||
function releaseKeyboard() {
|
||||
if (Main.modalCount > 0)
|
||||
global.display.unfreeze_keyboard(global.get_current_time());
|
||||
else
|
||||
global.display.ungrab_keyboard(global.get_current_time());
|
||||
}
|
||||
|
||||
function holdKeyboard() {
|
||||
global.freeze_keyboard(global.get_current_time());
|
||||
}
|
||||
|
||||
const KeyboardManager = new Lang.Class({
|
||||
Name: 'KeyboardManager',
|
||||
|
||||
// This is the longest we'll keep the keyboard frozen until an input
|
||||
// source is active.
|
||||
_MAX_INPUT_SOURCE_ACTIVATION_TIME: 4000, // ms
|
||||
|
||||
_BUS_NAME: 'org.gnome.SettingsDaemon.Keyboard',
|
||||
_OBJECT_PATH: '/org/gnome/SettingsDaemon/Keyboard',
|
||||
|
||||
_INTERFACE: '\
|
||||
<node> \
|
||||
<interface name="org.gnome.SettingsDaemon.Keyboard"> \
|
||||
<method name="SetInputSource"> \
|
||||
<arg type="u" direction="in" /> \
|
||||
</method> \
|
||||
</interface> \
|
||||
</node>',
|
||||
|
||||
_init: function() {
|
||||
let Proxy = Gio.DBusProxy.makeProxyWrapper(this._INTERFACE);
|
||||
this._proxy = new Proxy(Gio.DBus.session,
|
||||
this._BUS_NAME,
|
||||
this._OBJECT_PATH,
|
||||
function(proxy, error) {
|
||||
if (error)
|
||||
log(error.message);
|
||||
});
|
||||
this._proxy.g_default_timeout = this._MAX_INPUT_SOURCE_ACTIVATION_TIME;
|
||||
},
|
||||
|
||||
SetInputSource: function(is) {
|
||||
holdKeyboard();
|
||||
this._proxy.SetInputSourceRemote(is.index, releaseKeyboard);
|
||||
}
|
||||
});
|
@ -2,8 +2,6 @@
|
||||
|
||||
const Clutter = imports.gi.Clutter;
|
||||
const Gio = imports.gi.Gio;
|
||||
const GLib = imports.gi.GLib;
|
||||
const GnomeDesktop = imports.gi.GnomeDesktop;
|
||||
const Lang = imports.lang;
|
||||
const Meta = imports.gi.Meta;
|
||||
const Shell = imports.gi.Shell;
|
||||
@ -11,15 +9,15 @@ const Signals = imports.signals;
|
||||
const St = imports.gi.St;
|
||||
const Gettext = imports.gettext;
|
||||
|
||||
const IBus = imports.misc.ibusManager.IBus;
|
||||
const IBusManager = imports.misc.ibusManager;
|
||||
const KeyboardManager = imports.misc.keyboardManager;
|
||||
const Main = imports.ui.main;
|
||||
const PopupMenu = imports.ui.popupMenu;
|
||||
const PanelMenu = imports.ui.panelMenu;
|
||||
const SwitcherPopup = imports.ui.switcherPopup;
|
||||
const Util = imports.misc.util;
|
||||
|
||||
const IBus = imports.misc.ibusManager.IBus;
|
||||
const IBusManager = imports.misc.ibusManager;
|
||||
|
||||
const DESKTOP_INPUT_SOURCES_SCHEMA = 'org.gnome.desktop.input-sources';
|
||||
const KEY_CURRENT_INPUT_SOURCE = 'current';
|
||||
const KEY_INPUT_SOURCES = 'sources';
|
||||
@ -27,34 +25,6 @@ const KEY_INPUT_SOURCES = 'sources';
|
||||
const INPUT_SOURCE_TYPE_XKB = 'xkb';
|
||||
const INPUT_SOURCE_TYPE_IBUS = 'ibus';
|
||||
|
||||
// This is the longest we'll keep the keyboard frozen until an input
|
||||
// source is active.
|
||||
const MAX_INPUT_SOURCE_ACTIVATION_TIME = 4000; // ms
|
||||
|
||||
const BUS_NAME = 'org.gnome.SettingsDaemon.Keyboard';
|
||||
const OBJECT_PATH = '/org/gnome/SettingsDaemon/Keyboard';
|
||||
|
||||
const KeyboardManagerInterface = '<node> \
|
||||
<interface name="org.gnome.SettingsDaemon.Keyboard"> \
|
||||
<method name="SetInputSource"> \
|
||||
<arg type="u" direction="in" /> \
|
||||
</method> \
|
||||
</interface> \
|
||||
</node>';
|
||||
|
||||
const KeyboardManagerProxy = Gio.DBusProxy.makeProxyWrapper(KeyboardManagerInterface);
|
||||
|
||||
function releaseKeyboard() {
|
||||
if (Main.modalCount > 0)
|
||||
global.display.unfreeze_keyboard(global.get_current_time());
|
||||
else
|
||||
global.display.ungrab_keyboard(global.get_current_time());
|
||||
}
|
||||
|
||||
function holdKeyboard() {
|
||||
global.freeze_keyboard(global.get_current_time());
|
||||
}
|
||||
|
||||
const LayoutMenuItem = new Lang.Class({
|
||||
Name: 'LayoutMenuItem',
|
||||
Extends: PopupMenu.PopupBaseMenuItem,
|
||||
@ -225,7 +195,7 @@ const InputSourceIndicator = new Lang.Class({
|
||||
this._settings.connect('changed::' + KEY_CURRENT_INPUT_SOURCE, Lang.bind(this, this._currentInputSourceChanged));
|
||||
this._settings.connect('changed::' + KEY_INPUT_SOURCES, Lang.bind(this, this._inputSourcesChanged));
|
||||
|
||||
this._xkbInfo = new GnomeDesktop.XkbInfo();
|
||||
this._xkbInfo = KeyboardManager.getXkbInfo();
|
||||
|
||||
this._propSeparator = new PopupMenu.PopupSeparatorMenuItem();
|
||||
this.menu.addMenuItem(this._propSeparator);
|
||||
@ -240,12 +210,7 @@ const InputSourceIndicator = new Lang.Class({
|
||||
this._ibusManager.connect('property-updated', Lang.bind(this, this._ibusPropertyUpdated));
|
||||
this._inputSourcesChanged();
|
||||
|
||||
this._keyboardManager = new KeyboardManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
|
||||
function(proxy, error) {
|
||||
if (error)
|
||||
log(error.message);
|
||||
});
|
||||
this._keyboardManager.g_default_timeout = MAX_INPUT_SOURCE_ACTIVATION_TIME;
|
||||
this._keyboardManager = KeyboardManager.getKeyboardManager();
|
||||
|
||||
global.display.connect('modifiers-accelerator-activated', Lang.bind(this, this._modifiersSwitcher));
|
||||
|
||||
@ -283,7 +248,7 @@ const InputSourceIndicator = new Lang.Class({
|
||||
_modifiersSwitcher: function() {
|
||||
let sourceIndexes = Object.keys(this._inputSources);
|
||||
if (sourceIndexes.length == 0) {
|
||||
releaseKeyboard();
|
||||
KeyboardManager.releaseKeyboard();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -406,8 +371,7 @@ const InputSourceIndicator = new Lang.Class({
|
||||
let is = new InputSource(type, id, displayName, shortName, i);
|
||||
|
||||
is.connect('activate', Lang.bind(this, function() {
|
||||
holdKeyboard();
|
||||
this._keyboardManager.SetInputSourceRemote(is.index, releaseKeyboard);
|
||||
this._keyboardManager.SetInputSource(is);
|
||||
}));
|
||||
|
||||
if (!(is.shortName in inputSourcesByShortName))
|
||||
|
Loading…
Reference in New Issue
Block a user