2023-07-10 05:53:00 -04:00
|
|
|
import Clutter from 'gi://Clutter';
|
|
|
|
import Gio from 'gi://Gio';
|
|
|
|
import GObject from 'gi://GObject';
|
|
|
|
import Meta from 'gi://Meta';
|
2019-02-08 22:21:36 -05:00
|
|
|
|
2023-07-10 05:53:00 -04:00
|
|
|
import * as Dialog from './dialog.js';
|
|
|
|
import * as ModalDialog from './modalDialog.js';
|
2017-11-07 09:40:51 -05:00
|
|
|
|
|
|
|
const KEYBOARD_A11Y_SCHEMA = 'org.gnome.desktop.a11y.keyboard';
|
|
|
|
const KEY_STICKY_KEYS_ENABLED = 'stickykeys-enable';
|
|
|
|
const KEY_SLOW_KEYS_ENABLED = 'slowkeys-enable';
|
|
|
|
|
2023-07-10 05:53:00 -04:00
|
|
|
export const KbdA11yDialog = GObject.registerClass(
|
2017-10-30 21:23:39 -04:00
|
|
|
class KbdA11yDialog extends GObject.Object {
|
2017-10-30 20:03:21 -04:00
|
|
|
_init() {
|
2017-10-30 21:23:39 -04:00
|
|
|
super._init();
|
|
|
|
|
2023-08-06 18:40:20 -04:00
|
|
|
this._a11ySettings = new Gio.Settings({schema_id: KEYBOARD_A11Y_SCHEMA});
|
2017-11-07 09:40:51 -05:00
|
|
|
|
2019-10-05 06:35:21 -04:00
|
|
|
let seat = Clutter.get_default_backend().get_default_seat();
|
|
|
|
seat.connect('kbd-a11y-flags-changed',
|
2023-08-06 19:45:22 -04:00
|
|
|
this._showKbdA11yDialog.bind(this));
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-11-07 09:40:51 -05:00
|
|
|
|
2019-10-05 06:35:21 -04:00
|
|
|
_showKbdA11yDialog(seat, newFlags, whatChanged) {
|
2017-11-07 09:40:51 -05:00
|
|
|
let dialog = new ModalDialog.ModalDialog();
|
2020-01-13 08:04:40 -05:00
|
|
|
let title, description;
|
2017-11-07 09:40:51 -05:00
|
|
|
let key, enabled;
|
|
|
|
|
2022-06-14 10:38:27 -04:00
|
|
|
if (whatChanged & Meta.KeyboardA11yFlags.SLOW_KEYS_ENABLED) {
|
2017-11-07 09:40:51 -05:00
|
|
|
key = KEY_SLOW_KEYS_ENABLED;
|
2022-06-14 10:38:27 -04:00
|
|
|
enabled = (newFlags & Meta.KeyboardA11yFlags.SLOW_KEYS_ENABLED) > 0;
|
2019-09-12 18:27:56 -04:00
|
|
|
title = enabled
|
2023-08-06 18:34:20 -04:00
|
|
|
? _('Slow Keys Turned On')
|
|
|
|
: _('Slow Keys Turned Off');
|
2020-01-13 08:04:40 -05:00
|
|
|
description = _('You just held down the Shift key for 8 seconds. This is the shortcut ' +
|
|
|
|
'for the Slow Keys feature, which affects the way your keyboard works.');
|
2022-06-14 10:38:27 -04:00
|
|
|
} else if (whatChanged & Meta.KeyboardA11yFlags.STICKY_KEYS_ENABLED) {
|
2017-11-07 09:40:51 -05:00
|
|
|
key = KEY_STICKY_KEYS_ENABLED;
|
2022-06-14 10:38:27 -04:00
|
|
|
enabled = (newFlags & Meta.KeyboardA11yFlags.STICKY_KEYS_ENABLED) > 0;
|
2019-09-12 18:27:56 -04:00
|
|
|
title = enabled
|
2023-08-06 18:34:20 -04:00
|
|
|
? _('Sticky Keys Turned On')
|
|
|
|
: _('Sticky Keys Turned Off');
|
2020-01-13 08:04:40 -05:00
|
|
|
description = enabled
|
2023-08-06 18:34:20 -04:00
|
|
|
? _('You just pressed the Shift key 5 times in a row. This is the shortcut ' +
|
|
|
|
'for the Sticky Keys feature, which affects the way your keyboard works.')
|
|
|
|
: _('You just pressed two keys at once, or pressed the Shift key 5 times in a row. ' +
|
|
|
|
'This turns off the Sticky Keys feature, which affects the way your keyboard works.');
|
2017-11-07 09:40:51 -05:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-06 18:40:20 -04:00
|
|
|
let content = new Dialog.MessageDialogContent({title, description});
|
2020-01-27 16:19:31 -05:00
|
|
|
dialog.contentLayout.add_child(content);
|
2017-11-07 09:40:51 -05:00
|
|
|
|
2020-03-29 17:51:13 -04:00
|
|
|
dialog.addButton({
|
|
|
|
label: enabled ? _('Leave On') : _('Turn On'),
|
|
|
|
action: () => {
|
|
|
|
this._a11ySettings.set_boolean(key, true);
|
|
|
|
dialog.close();
|
|
|
|
},
|
|
|
|
default: enabled,
|
|
|
|
key: !enabled ? Clutter.KEY_Escape : null,
|
|
|
|
});
|
2017-11-07 09:40:51 -05:00
|
|
|
|
2020-03-29 17:51:13 -04:00
|
|
|
dialog.addButton({
|
|
|
|
label: enabled ? _('Turn Off') : _('Leave Off'),
|
|
|
|
action: () => {
|
|
|
|
this._a11ySettings.set_boolean(key, false);
|
|
|
|
dialog.close();
|
|
|
|
},
|
|
|
|
default: !enabled,
|
|
|
|
key: enabled ? Clutter.KEY_Escape : null,
|
|
|
|
});
|
2017-11-07 09:40:51 -05:00
|
|
|
|
|
|
|
dialog.open();
|
|
|
|
}
|
|
|
|
});
|