2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-07-21 04:44:59 -04:00
|
|
|
|
2013-08-03 08:30:46 -04:00
|
|
|
const Clutter = imports.gi.Clutter;
|
2010-07-21 04:44:59 -04:00
|
|
|
const Gio = imports.gi.Gio;
|
2013-11-28 19:45:39 -05:00
|
|
|
const GLib = imports.gi.GLib;
|
2010-07-21 04:44:59 -04:00
|
|
|
const Lang = imports.lang;
|
2012-08-13 13:04:03 -04:00
|
|
|
const Mainloop = imports.mainloop;
|
2013-06-06 17:26:42 -04:00
|
|
|
const St = imports.gi.St;
|
2010-07-21 04:44:59 -04:00
|
|
|
|
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
|
2013-08-18 05:31:25 -04:00
|
|
|
const A11Y_SCHEMA = 'org.gnome.desktop.a11y';
|
|
|
|
const KEY_ALWAYS_SHOW = 'always-show-universal-access-status';
|
2013-08-13 12:39:07 -04:00
|
|
|
|
2013-08-18 05:31:25 -04:00
|
|
|
const A11Y_KEYBOARD_SCHEMA = 'org.gnome.desktop.a11y.keyboard';
|
|
|
|
const KEY_STICKY_KEYS_ENABLED = 'stickykeys-enable';
|
|
|
|
const KEY_BOUNCE_KEYS_ENABLED = 'bouncekeys-enable';
|
|
|
|
const KEY_SLOW_KEYS_ENABLED = 'slowkeys-enable';
|
|
|
|
const KEY_MOUSE_KEYS_ENABLED = 'mousekeys-enable';
|
2010-07-21 04:44:59 -04:00
|
|
|
|
2013-08-18 05:31:25 -04:00
|
|
|
const APPLICATIONS_SCHEMA = 'org.gnome.desktop.a11y.applications';
|
2010-07-21 04:44:59 -04:00
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var DPI_FACTOR_LARGE = 1.25;
|
2010-07-21 04:44:59 -04:00
|
|
|
|
2013-08-18 05:31:25 -04:00
|
|
|
const WM_SCHEMA = 'org.gnome.desktop.wm.preferences';
|
|
|
|
const KEY_VISUAL_BELL = 'visual-bell';
|
2010-07-21 04:44:59 -04:00
|
|
|
|
2013-08-18 05:31:25 -04:00
|
|
|
const DESKTOP_INTERFACE_SCHEMA = 'org.gnome.desktop.interface';
|
|
|
|
const KEY_GTK_THEME = 'gtk-theme';
|
|
|
|
const KEY_ICON_THEME = 'icon-theme';
|
|
|
|
const KEY_WM_THEME = 'theme';
|
|
|
|
const KEY_TEXT_SCALING_FACTOR = 'text-scaling-factor';
|
2010-07-21 04:44:59 -04:00
|
|
|
|
2013-08-18 05:31:25 -04:00
|
|
|
const HIGH_CONTRAST_THEME = 'HighContrast';
|
2010-07-21 04:44:59 -04:00
|
|
|
|
2017-07-18 13:41:25 -04:00
|
|
|
var ATIndicator = new Lang.Class({
|
2011-11-20 09:38:48 -05:00
|
|
|
Name: 'ATIndicator',
|
2013-06-06 17:26:42 -04:00
|
|
|
Extends: PanelMenu.Button,
|
2010-07-21 04:44:59 -04:00
|
|
|
|
|
|
|
_init: function() {
|
2013-06-06 17:26:42 -04:00
|
|
|
this.parent(0.0, _("Accessibility"));
|
|
|
|
|
|
|
|
this._hbox = new St.BoxLayout({ style_class: 'panel-status-menu-box' });
|
|
|
|
this._hbox.add_child(new St.Icon({ style_class: 'system-status-icon',
|
|
|
|
icon_name: 'preferences-desktop-accessibility-symbolic' }));
|
2014-02-18 07:45:26 -05:00
|
|
|
this._hbox.add_child(PopupMenu.arrowIcon(St.Side.BOTTOM));
|
2013-06-06 17:26:42 -04:00
|
|
|
|
|
|
|
this.actor.add_child(this._hbox);
|
2010-07-21 04:44:59 -04:00
|
|
|
|
2014-06-24 15:17:09 -04:00
|
|
|
this._a11ySettings = new Gio.Settings({ schema_id: A11Y_SCHEMA });
|
2013-08-13 12:39:07 -04:00
|
|
|
this._a11ySettings.connect('changed::' + KEY_ALWAYS_SHOW, Lang.bind(this, this._queueSyncMenuVisibility));
|
|
|
|
|
2010-07-21 04:44:59 -04:00
|
|
|
let highContrast = this._buildHCItem();
|
|
|
|
this.menu.addMenuItem(highContrast);
|
|
|
|
|
2011-02-17 10:05:22 -05:00
|
|
|
let magnifier = this._buildItem(_("Zoom"), APPLICATIONS_SCHEMA,
|
|
|
|
'screen-magnifier-enabled');
|
2010-07-21 04:44:59 -04:00
|
|
|
this.menu.addMenuItem(magnifier);
|
|
|
|
|
2010-11-12 13:37:51 -05:00
|
|
|
let textZoom = this._buildFontItem();
|
2010-07-21 04:44:59 -04:00
|
|
|
this.menu.addMenuItem(textZoom);
|
|
|
|
|
2012-06-15 17:54:04 -04:00
|
|
|
let screenReader = this._buildItem(_("Screen Reader"), APPLICATIONS_SCHEMA,
|
|
|
|
'screen-reader-enabled');
|
|
|
|
this.menu.addMenuItem(screenReader);
|
2010-07-21 04:44:59 -04:00
|
|
|
|
2011-08-29 13:02:42 -04:00
|
|
|
let screenKeyboard = this._buildItem(_("Screen Keyboard"), APPLICATIONS_SCHEMA,
|
|
|
|
'screen-keyboard-enabled');
|
|
|
|
this.menu.addMenuItem(screenKeyboard);
|
2010-07-21 04:44:59 -04:00
|
|
|
|
2011-11-14 09:34:42 -05:00
|
|
|
let visualBell = this._buildItem(_("Visual Alerts"), WM_SCHEMA, KEY_VISUAL_BELL);
|
2010-07-21 04:44:59 -04:00
|
|
|
this.menu.addMenuItem(visualBell);
|
|
|
|
|
2013-08-13 12:39:07 -04:00
|
|
|
let stickyKeys = this._buildItem(_("Sticky Keys"), A11Y_KEYBOARD_SCHEMA, KEY_STICKY_KEYS_ENABLED);
|
2010-07-21 04:44:59 -04:00
|
|
|
this.menu.addMenuItem(stickyKeys);
|
|
|
|
|
2013-08-13 12:39:07 -04:00
|
|
|
let slowKeys = this._buildItem(_("Slow Keys"), A11Y_KEYBOARD_SCHEMA, KEY_SLOW_KEYS_ENABLED);
|
2010-07-21 04:44:59 -04:00
|
|
|
this.menu.addMenuItem(slowKeys);
|
|
|
|
|
2013-08-13 12:39:07 -04:00
|
|
|
let bounceKeys = this._buildItem(_("Bounce Keys"), A11Y_KEYBOARD_SCHEMA, KEY_BOUNCE_KEYS_ENABLED);
|
2010-07-21 04:44:59 -04:00
|
|
|
this.menu.addMenuItem(bounceKeys);
|
|
|
|
|
2013-08-13 12:39:07 -04:00
|
|
|
let mouseKeys = this._buildItem(_("Mouse Keys"), A11Y_KEYBOARD_SCHEMA, KEY_MOUSE_KEYS_ENABLED);
|
2010-07-21 04:44:59 -04:00
|
|
|
this.menu.addMenuItem(mouseKeys);
|
|
|
|
|
2012-08-13 13:04:03 -04:00
|
|
|
this._syncMenuVisibility();
|
|
|
|
},
|
|
|
|
|
|
|
|
_syncMenuVisibility: function() {
|
|
|
|
this._syncMenuVisibilityIdle = 0;
|
|
|
|
|
2013-08-13 12:39:07 -04:00
|
|
|
let alwaysShow = this._a11ySettings.get_boolean(KEY_ALWAYS_SHOW);
|
2012-08-13 13:04:03 -04:00
|
|
|
let items = this.menu._getMenuItems();
|
|
|
|
|
2013-08-13 12:39:07 -04:00
|
|
|
this.actor.visible = alwaysShow || items.some(function(f) { return !!f.state; });
|
2012-08-13 13:04:03 -04:00
|
|
|
|
2013-11-28 19:45:39 -05:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2012-08-13 13:04:03 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_queueSyncMenuVisibility: function() {
|
|
|
|
if (this._syncMenuVisibilityIdle)
|
|
|
|
return;
|
|
|
|
|
2017-03-15 20:30:49 -04:00
|
|
|
this._syncMenuVisibilityIdle = Mainloop.idle_add(Lang.bind(this, this._syncMenuVisibility));
|
|
|
|
GLib.Source.set_name_by_id(this._syncMenuVisibilityIdle, '[gnome-shell] this._syncMenuVisibility');
|
2010-07-21 04:44:59 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_buildItemExtended: function(string, initial_value, writable, on_set) {
|
|
|
|
let widget = new PopupMenu.PopupSwitchMenuItem(string, initial_value);
|
|
|
|
if (!writable)
|
|
|
|
widget.actor.reactive = false;
|
|
|
|
else
|
|
|
|
widget.connect('toggled', function(item) {
|
|
|
|
on_set(item.state);
|
|
|
|
});
|
|
|
|
return widget;
|
|
|
|
},
|
|
|
|
|
|
|
|
_buildItem: function(string, schema, key) {
|
2014-06-24 15:17:09 -04:00
|
|
|
let settings = new Gio.Settings({ schema_id: schema });
|
2015-03-20 15:42:51 -04:00
|
|
|
settings.connect('changed::'+key, Lang.bind(this, function() {
|
|
|
|
widget.setToggleState(settings.get_boolean(key));
|
|
|
|
|
|
|
|
this._queueSyncMenuVisibility();
|
|
|
|
}));
|
|
|
|
|
2010-07-21 04:44:59 -04:00
|
|
|
let widget = this._buildItemExtended(string,
|
|
|
|
settings.get_boolean(key),
|
|
|
|
settings.is_writable(key),
|
|
|
|
function(enabled) {
|
|
|
|
return settings.set_boolean(key, enabled);
|
|
|
|
});
|
|
|
|
return widget;
|
|
|
|
},
|
|
|
|
|
|
|
|
_buildHCItem: function() {
|
2014-06-24 15:17:09 -04:00
|
|
|
let interfaceSettings = new Gio.Settings({ schema_id: DESKTOP_INTERFACE_SCHEMA });
|
|
|
|
let wmSettings = new Gio.Settings({ schema_id: WM_SCHEMA });
|
2015-03-20 15:42:51 -04:00
|
|
|
interfaceSettings.connect('changed::' + KEY_GTK_THEME, Lang.bind(this, function() {
|
|
|
|
let value = interfaceSettings.get_string(KEY_GTK_THEME);
|
|
|
|
if (value == HIGH_CONTRAST_THEME) {
|
|
|
|
highContrast.setToggleState(true);
|
|
|
|
} else {
|
|
|
|
highContrast.setToggleState(false);
|
|
|
|
gtkTheme = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._queueSyncMenuVisibility();
|
|
|
|
}));
|
|
|
|
interfaceSettings.connect('changed::' + KEY_ICON_THEME, function() {
|
|
|
|
let value = interfaceSettings.get_string(KEY_ICON_THEME);
|
|
|
|
if (value != HIGH_CONTRAST_THEME)
|
|
|
|
iconTheme = value;
|
|
|
|
});
|
|
|
|
wmSettings.connect('changed::' + KEY_WM_THEME, function() {
|
|
|
|
let value = wmSettings.get_string(KEY_WM_THEME);
|
|
|
|
if (value != HIGH_CONTRAST_THEME)
|
|
|
|
wmTheme = value;
|
|
|
|
});
|
|
|
|
|
2012-11-13 09:34:20 -05:00
|
|
|
let gtkTheme = interfaceSettings.get_string(KEY_GTK_THEME);
|
|
|
|
let iconTheme = interfaceSettings.get_string(KEY_ICON_THEME);
|
|
|
|
let wmTheme = wmSettings.get_string(KEY_WM_THEME);
|
2010-07-21 04:44:59 -04:00
|
|
|
let hasHC = (gtkTheme == HIGH_CONTRAST_THEME);
|
|
|
|
let highContrast = this._buildItemExtended(
|
|
|
|
_("High Contrast"),
|
|
|
|
hasHC,
|
2012-11-13 09:34:20 -05:00
|
|
|
interfaceSettings.is_writable(KEY_GTK_THEME) &&
|
|
|
|
interfaceSettings.is_writable(KEY_ICON_THEME) &&
|
|
|
|
wmSettings.is_writable(KEY_WM_THEME),
|
2010-07-21 04:44:59 -04:00
|
|
|
function (enabled) {
|
|
|
|
if (enabled) {
|
2012-11-13 09:34:20 -05:00
|
|
|
interfaceSettings.set_string(KEY_GTK_THEME, HIGH_CONTRAST_THEME);
|
|
|
|
interfaceSettings.set_string(KEY_ICON_THEME, HIGH_CONTRAST_THEME);
|
|
|
|
wmSettings.set_string(KEY_WM_THEME, HIGH_CONTRAST_THEME);
|
2011-02-18 10:15:35 -05:00
|
|
|
} else if(!hasHC) {
|
2012-11-13 09:34:20 -05:00
|
|
|
interfaceSettings.set_string(KEY_GTK_THEME, gtkTheme);
|
|
|
|
interfaceSettings.set_string(KEY_ICON_THEME, iconTheme);
|
|
|
|
wmSettings.set_string(KEY_WM_THEME, wmTheme);
|
2011-02-18 10:15:35 -05:00
|
|
|
} else {
|
2012-11-13 09:34:20 -05:00
|
|
|
interfaceSettings.reset(KEY_GTK_THEME);
|
|
|
|
interfaceSettings.reset(KEY_ICON_THEME);
|
|
|
|
wmSettings.reset(KEY_WM_THEME);
|
2010-07-21 04:44:59 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return highContrast;
|
|
|
|
},
|
|
|
|
|
2010-11-12 13:37:51 -05:00
|
|
|
_buildFontItem: function() {
|
2014-06-24 15:17:09 -04:00
|
|
|
let settings = new Gio.Settings({ schema_id: DESKTOP_INTERFACE_SCHEMA });
|
2015-03-20 15:42:51 -04:00
|
|
|
settings.connect('changed::' + KEY_TEXT_SCALING_FACTOR, Lang.bind(this, function() {
|
|
|
|
let factor = settings.get_double(KEY_TEXT_SCALING_FACTOR);
|
|
|
|
let active = (factor > 1.0);
|
|
|
|
widget.setToggleState(active);
|
|
|
|
|
|
|
|
this._queueSyncMenuVisibility();
|
|
|
|
}));
|
2010-11-12 11:36:41 -05:00
|
|
|
|
2011-03-03 11:01:19 -05:00
|
|
|
let factor = settings.get_double(KEY_TEXT_SCALING_FACTOR);
|
|
|
|
let initial_setting = (factor > 1.0);
|
2010-09-18 11:29:05 -04:00
|
|
|
let widget = this._buildItemExtended(_("Large Text"),
|
2010-07-21 04:44:59 -04:00
|
|
|
initial_setting,
|
2011-03-03 11:01:19 -05:00
|
|
|
settings.is_writable(KEY_TEXT_SCALING_FACTOR),
|
2010-07-21 04:44:59 -04:00
|
|
|
function (enabled) {
|
|
|
|
if (enabled)
|
2011-03-03 11:01:19 -05:00
|
|
|
settings.set_double(KEY_TEXT_SCALING_FACTOR,
|
|
|
|
DPI_FACTOR_LARGE);
|
2010-07-21 04:44:59 -04:00
|
|
|
else
|
2011-03-03 11:01:19 -05:00
|
|
|
settings.reset(KEY_TEXT_SCALING_FACTOR);
|
2010-07-21 04:44:59 -04:00
|
|
|
});
|
|
|
|
return widget;
|
|
|
|
}
|
2011-11-20 09:38:48 -05:00
|
|
|
});
|
2012-08-13 13:04:03 -04:00
|
|
|
|
2017-07-18 13:41:25 -04:00
|
|
|
var ATGreeterIndicator = new Lang.Class({
|
2012-08-13 13:04:03 -04:00
|
|
|
Name: 'ATGreeterIndicator',
|
|
|
|
Extends: ATIndicator,
|
|
|
|
|
|
|
|
// Override visibility handling to be always visible
|
|
|
|
_syncMenuVisibility: function() { },
|
|
|
|
_queueSyncMenuVisibility: function() { }
|
|
|
|
});
|