aboutsummaryrefslogtreecommitdiff
path: root/extension.js
blob: 1a457fdd0ac1980129d207d43dfbad814c0c7ba1 (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
// -*- 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: 'Keyboard' });
        this.actor.connect("clicked", Lang.bind(this, this._toggleShowOnScreenKeyboard));
        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) {
            this.actor.set_label("Show keyboard");
            Main.keyboard.hide();
        } else {
            this._activateOnScreenKeyboard();
            this.actor.set_label("Hide keyboard");
            Main.keyboard.show();
        }
        this._onScreenKeyboardShown = !this._onScreenKeyboardShown;
    },
};

let _button;

function init() {
    _button = new OnScreenKeyboardButton();
}

function enable() {
    let _children = Main.panel._centerBox.get_children();
    Main.panel._centerBox.insert_child_at_index(_button.actor, _children.length - 1);
    Main.panel._centerBox.add(_button.actor);
}

function disable() {
    Main.panel._centerBox.remove_actor(_button.actor);
}