1
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
3
const Gio = imports.gi.Gio;
4
const Lang = imports.lang;
6
const PanelMenu = imports.ui.panelMenu;
7
const PopupMenu = imports.ui.popupMenu;
9
const A11Y_SCHEMA = 'org.gnome.desktop.a11y.keyboard';
10
const KEY_STICKY_KEYS_ENABLED = 'stickykeys-enable';
11
const KEY_BOUNCE_KEYS_ENABLED = 'bouncekeys-enable';
12
const KEY_SLOW_KEYS_ENABLED = 'slowkeys-enable';
13
const KEY_MOUSE_KEYS_ENABLED = 'mousekeys-enable';
15
const APPLICATIONS_SCHEMA = 'org.gnome.desktop.a11y.applications';
17
const DPI_LOW_REASONABLE_VALUE = 50;
18
const DPI_HIGH_REASONABLE_VALUE = 500;
20
const DPI_FACTOR_LARGE = 1.25;
21
const DPI_FACTOR_LARGER = 1.5;
22
const DPI_FACTOR_LARGEST = 2.0;
24
const WM_SCHEMA = 'org.gnome.desktop.wm.preferences';
25
const KEY_VISUAL_BELL = 'visual-bell';
27
const DESKTOP_INTERFACE_SCHEMA = 'org.gnome.desktop.interface';
28
const KEY_GTK_THEME = 'gtk-theme';
29
const KEY_ICON_THEME = 'icon-theme';
30
const KEY_TEXT_SCALING_FACTOR = 'text-scaling-factor';
32
const HIGH_CONTRAST_THEME = 'HighContrast';
34
const ATIndicator = new Lang.Class({
36
Extends: PanelMenu.SystemStatusButton,
39
this.parent('preferences-desktop-accessibility-symbolic', _("Accessibility"));
41
let highContrast = this._buildHCItem();
42
this.menu.addMenuItem(highContrast);
44
let magnifier = this._buildItem(_("Zoom"), APPLICATIONS_SCHEMA,
45
'screen-magnifier-enabled');
46
this.menu.addMenuItem(magnifier);
48
let textZoom = this._buildFontItem();
49
this.menu.addMenuItem(textZoom);
51
let screenReader = this._buildItem(_("Screen Reader"), APPLICATIONS_SCHEMA,
52
'screen-reader-enabled');
53
this.menu.addMenuItem(screenReader);
55
let screenKeyboard = this._buildItem(_("Screen Keyboard"), APPLICATIONS_SCHEMA,
56
'screen-keyboard-enabled');
57
this.menu.addMenuItem(screenKeyboard);
59
let visualBell = this._buildItem(_("Visual Alerts"), WM_SCHEMA, KEY_VISUAL_BELL);
60
this.menu.addMenuItem(visualBell);
62
let stickyKeys = this._buildItem(_("Sticky Keys"), A11Y_SCHEMA, KEY_STICKY_KEYS_ENABLED);
63
this.menu.addMenuItem(stickyKeys);
65
let slowKeys = this._buildItem(_("Slow Keys"), A11Y_SCHEMA, KEY_SLOW_KEYS_ENABLED);
66
this.menu.addMenuItem(slowKeys);
68
let bounceKeys = this._buildItem(_("Bounce Keys"), A11Y_SCHEMA, KEY_BOUNCE_KEYS_ENABLED);
69
this.menu.addMenuItem(bounceKeys);
71
let mouseKeys = this._buildItem(_("Mouse Keys"), A11Y_SCHEMA, KEY_MOUSE_KEYS_ENABLED);
72
this.menu.addMenuItem(mouseKeys);
74
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
75
this.menu.addSettingsAction(_("Universal Access Settings"), 'gnome-universal-access-panel.desktop');
78
_buildItemExtended: function(string, initial_value, writable, on_set) {
79
let widget = new PopupMenu.PopupSwitchMenuItem(string, initial_value);
81
widget.actor.reactive = false;
83
widget.connect('toggled', function(item) {
89
_buildItem: function(string, schema, key) {
90
let settings = new Gio.Settings({ schema: schema });
91
let widget = this._buildItemExtended(string,
92
settings.get_boolean(key),
93
settings.is_writable(key),
95
return settings.set_boolean(key, enabled);
97
settings.connect('changed::'+key, function() {
98
widget.setToggleState(settings.get_boolean(key));
103
_buildHCItem: function() {
104
let settings = new Gio.Settings({ schema: DESKTOP_INTERFACE_SCHEMA });
105
let gtkTheme = settings.get_string(KEY_GTK_THEME);
106
let iconTheme = settings.get_string(KEY_ICON_THEME);
107
let hasHC = (gtkTheme == HIGH_CONTRAST_THEME);
108
let highContrast = this._buildItemExtended(
111
settings.is_writable(KEY_GTK_THEME) && settings.is_writable(KEY_ICON_THEME),
114
settings.set_string(KEY_GTK_THEME, HIGH_CONTRAST_THEME);
115
settings.set_string(KEY_ICON_THEME, HIGH_CONTRAST_THEME);
117
settings.set_string(KEY_GTK_THEME, gtkTheme);
118
settings.set_string(KEY_ICON_THEME, iconTheme);
120
settings.reset(KEY_GTK_THEME);
121
settings.reset(KEY_ICON_THEME);
124
settings.connect('changed::' + KEY_GTK_THEME, function() {
125
let value = settings.get_string(KEY_GTK_THEME);
126
if (value == HIGH_CONTRAST_THEME) {
127
highContrast.setToggleState(true);
129
highContrast.setToggleState(false);
133
settings.connect('changed::' + KEY_ICON_THEME, function() {
134
let value = settings.get_string(KEY_ICON_THEME);
135
if (value != HIGH_CONTRAST_THEME)
141
_buildFontItem: function() {
142
let settings = new Gio.Settings({ schema: DESKTOP_INTERFACE_SCHEMA });
144
let factor = settings.get_double(KEY_TEXT_SCALING_FACTOR);
145
let initial_setting = (factor > 1.0);
146
let widget = this._buildItemExtended(_("Large Text"),
148
settings.is_writable(KEY_TEXT_SCALING_FACTOR),
151
settings.set_double(KEY_TEXT_SCALING_FACTOR,
154
settings.reset(KEY_TEXT_SCALING_FACTOR);
156
settings.connect('changed::' + KEY_TEXT_SCALING_FACTOR, function() {
157
let factor = settings.get_double(KEY_TEXT_SCALING_FACTOR);
158
let active = (factor > 1.0);
159
widget.setToggleState(active);