// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- const Gio = imports.gi.Gio; const Lang = imports.lang; const St = imports.gi.St; const Main = imports.ui.main; const A11Y_APPLICATIONS_SCHEMA = 'org.gnome.desktop.a11y.applications'; function OnScreenKeyboardButton() { this._init(); } OnScreenKeyboardButton.prototype = { _init: function() { this.actor = new St.Button ({ label: 'Show Keyboard' }); this.actor.connect("clicked", Lang.bind(this, this._toggleShowOnScreenKeyboard)); this._onScreenKeyboardShown = false; this._keyboardVisibleId = Main.layoutManager.connect('keyboard-visible-changed', Lang.bind(this, this._onKeyboardVisibleChanged)); }, _onKeyboardVisibleChanged: function (layoutManager, visible) { if (visible) { this.actor.set_label("Hide keyboard"); this._onScreenKeyboardShown = true; } else { this.actor.set_label("Show keyboard"); this._onScreenKeyboardShown = false; } }, _activateOnScreenKeyboard: function () { let settings = new Gio.Settings({ schema: A11Y_APPLICATIONS_SCHEMA }); let key = 'screen-keyboard-enabled'; if (!settings.get_boolean(key) && settings.is_writable(key)) { settings.set_boolean(key, true); } }, _toggleShowOnScreenKeyboard: function() { if (this._onScreenKeyboardShown) { Main.keyboard.hide(); } else { this._activateOnScreenKeyboard(); Main.keyboard.show(); } }, enable: function() { let _children = Main.panel._centerBox.get_children(); Main.panel._centerBox.insert_child_at_index(this.actor, _children.length - 1); Main.panel._centerBox.add(this.actor); }, disable: function() { Main.layoutManager.connect(this._keyboardVisibleId); Main.panel._centerBox.remove_actor(_button.actor); }, }; let _button; function init() { /* do nothing */ } function enable() { _button = new OnScreenKeyboardButton(); _button.enable(); } function disable() { _button.disable(); }