2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 09:07:06 -05:00
|
|
|
/* exported ATIndicator */
|
2010-07-21 04:44:59 -04:00
|
|
|
|
2019-02-08 22:21:36 -05:00
|
|
|
const { Gio, GLib, GObject, St } = imports.gi;
|
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_TEXT_SCALING_FACTOR = 'text-scaling-factor';
|
2010-07-21 04:44:59 -04:00
|
|
|
|
2021-12-19 11:30:00 -05:00
|
|
|
const A11Y_INTERFACE_SCHEMA = 'org.gnome.desktop.a11y.interface';
|
|
|
|
const KEY_HIGH_CONTRAST = 'high-contrast';
|
2010-07-21 04:44:59 -04:00
|
|
|
|
2017-10-30 21:23:39 -04:00
|
|
|
var ATIndicator = GObject.registerClass(
|
|
|
|
class ATIndicator extends PanelMenu.Button {
|
2017-10-30 20:03:21 -04:00
|
|
|
_init() {
|
2019-06-14 14:58:50 -04:00
|
|
|
super._init(0.5, _("Accessibility"));
|
2013-06-06 17:26:42 -04:00
|
|
|
|
2021-01-24 15:39:43 -05:00
|
|
|
this.add_child(new St.Icon({
|
2021-02-01 19:51:15 -05:00
|
|
|
style_class: 'system-status-icon',
|
2022-02-03 14:14:52 -05:00
|
|
|
icon_name: 'org.gnome.Settings-accessibility-symbolic',
|
2021-01-24 15:39:43 -05:00
|
|
|
}));
|
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 });
|
2022-02-07 09:14:06 -05:00
|
|
|
this._a11ySettings.connect(`changed::${KEY_ALWAYS_SHOW}`, this._queueSyncMenuVisibility.bind(this));
|
2013-08-13 12:39:07 -04:00
|
|
|
|
2021-12-19 11:30:00 -05:00
|
|
|
let highContrast = this._buildItem(_('High Contrast'), A11Y_INTERFACE_SCHEMA, KEY_HIGH_CONTRAST);
|
2010-07-21 04:44:59 -04:00
|
|
|
this.menu.addMenuItem(highContrast);
|
|
|
|
|
2011-02-17 10:05:22 -05:00
|
|
|
let magnifier = this._buildItem(_("Zoom"), APPLICATIONS_SCHEMA,
|
2019-01-29 14:36:54 -05:00
|
|
|
'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,
|
2019-01-29 14:36:54 -05:00
|
|
|
'screen-reader-enabled');
|
2012-06-15 17:54:04 -04:00
|
|
|
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,
|
2019-01-29 14:36:54 -05:00
|
|
|
'screen-keyboard-enabled');
|
2011-08-29 13:02:42 -04:00
|
|
|
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);
|
|
|
|
|
2023-01-13 12:29:13 -05:00
|
|
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
|
|
|
this.menu.addSettingsAction(_('Accessibility Settings'),
|
|
|
|
'gnome-universal-access-panel.desktop');
|
|
|
|
|
2012-08-13 13:04:03 -04:00
|
|
|
this._syncMenuVisibility();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2012-08-13 13:04:03 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_syncMenuVisibility() {
|
2012-08-13 13:04:03 -04:00
|
|
|
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();
|
|
|
|
|
2019-04-09 19:17:51 -04:00
|
|
|
this.visible = alwaysShow || items.some(f => !!f.state);
|
2012-08-13 13:04:03 -04:00
|
|
|
|
2013-11-28 19:45:39 -05:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2012-08-13 13:04:03 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_queueSyncMenuVisibility() {
|
2012-08-13 13:04:03 -04:00
|
|
|
if (this._syncMenuVisibilityIdle)
|
|
|
|
return;
|
|
|
|
|
2019-08-19 14:50:33 -04:00
|
|
|
this._syncMenuVisibilityIdle = GLib.idle_add(GLib.PRIORITY_DEFAULT, this._syncMenuVisibility.bind(this));
|
2017-03-15 20:30:49 -04:00
|
|
|
GLib.Source.set_name_by_id(this._syncMenuVisibilityIdle, '[gnome-shell] this._syncMenuVisibility');
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2010-07-21 04:44:59 -04:00
|
|
|
|
2019-01-31 08:43:52 -05:00
|
|
|
_buildItemExtended(string, initialValue, writable, onSet) {
|
|
|
|
let widget = new PopupMenu.PopupSwitchMenuItem(string, initialValue);
|
2019-08-19 20:51:42 -04:00
|
|
|
if (!writable) {
|
2019-07-16 05:24:13 -04:00
|
|
|
widget.reactive = false;
|
2019-08-19 20:51:42 -04:00
|
|
|
} else {
|
2017-10-30 20:38:18 -04:00
|
|
|
widget.connect('toggled', item => {
|
2019-01-31 08:43:52 -05:00
|
|
|
onSet(item.state);
|
2010-07-21 04:44:59 -04:00
|
|
|
});
|
2019-08-19 20:51:42 -04:00
|
|
|
}
|
2010-07-21 04:44:59 -04:00
|
|
|
return widget;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2010-07-21 04:44:59 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_buildItem(string, schema, key) {
|
2014-06-24 15:17:09 -04:00
|
|
|
let settings = new Gio.Settings({ schema_id: schema });
|
2019-04-26 04:56:07 -04:00
|
|
|
let widget = this._buildItemExtended(string,
|
|
|
|
settings.get_boolean(key),
|
|
|
|
settings.is_writable(key),
|
|
|
|
enabled => settings.set_boolean(key, enabled));
|
|
|
|
|
2022-02-07 09:14:06 -05:00
|
|
|
settings.connect(`changed::${key}`, () => {
|
2015-03-20 15:42:51 -04:00
|
|
|
widget.setToggleState(settings.get_boolean(key));
|
|
|
|
|
|
|
|
this._queueSyncMenuVisibility();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2015-03-20 15:42:51 -04:00
|
|
|
|
2010-07-21 04:44:59 -04:00
|
|
|
return widget;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2010-07-21 04:44:59 -04:00
|
|
|
|
2019-04-26 04:56:07 -04:00
|
|
|
_buildFontItem() {
|
|
|
|
let settings = new Gio.Settings({ schema_id: DESKTOP_INTERFACE_SCHEMA });
|
2011-03-03 11:01:19 -05:00
|
|
|
let factor = settings.get_double(KEY_TEXT_SCALING_FACTOR);
|
2019-08-19 15:38:51 -04:00
|
|
|
let initialSetting = factor > 1.0;
|
2010-09-18 11:29:05 -04:00
|
|
|
let widget = this._buildItemExtended(_("Large Text"),
|
2019-01-31 08:43:52 -05:00
|
|
|
initialSetting,
|
2011-03-03 11:01:19 -05:00
|
|
|
settings.is_writable(KEY_TEXT_SCALING_FACTOR),
|
2017-10-30 20:38:18 -04:00
|
|
|
enabled => {
|
2019-08-19 20:51:42 -04:00
|
|
|
if (enabled) {
|
2019-09-12 18:41:47 -04:00
|
|
|
settings.set_double(
|
|
|
|
KEY_TEXT_SCALING_FACTOR, DPI_FACTOR_LARGE);
|
2019-08-19 20:51:42 -04:00
|
|
|
} else {
|
2011-03-03 11:01:19 -05:00
|
|
|
settings.reset(KEY_TEXT_SCALING_FACTOR);
|
2019-08-19 20:51:42 -04:00
|
|
|
}
|
2010-07-21 04:44:59 -04:00
|
|
|
});
|
2019-04-26 04:56:07 -04:00
|
|
|
|
2022-02-07 09:14:06 -05:00
|
|
|
settings.connect(`changed::${KEY_TEXT_SCALING_FACTOR}`, () => {
|
2019-08-19 20:20:08 -04:00
|
|
|
factor = settings.get_double(KEY_TEXT_SCALING_FACTOR);
|
2019-08-19 15:38:51 -04:00
|
|
|
let active = factor > 1.0;
|
2019-04-26 04:56:07 -04:00
|
|
|
widget.setToggleState(active);
|
|
|
|
|
|
|
|
this._queueSyncMenuVisibility();
|
|
|
|
});
|
|
|
|
|
2010-07-21 04:44:59 -04:00
|
|
|
return widget;
|
|
|
|
}
|
2011-11-20 09:38:48 -05:00
|
|
|
});
|