diff --git a/js/js-resources.gresource.xml b/js/js-resources.gresource.xml index 7a5c8ca6f..ba0d2f483 100644 --- a/js/js-resources.gresource.xml +++ b/js/js-resources.gresource.xml @@ -61,6 +61,7 @@ ui/ibusCandidatePopup.js ui/iconGrid.js ui/inhibitShortcutsDialog.js + ui/kbdA11yDialog.js ui/keyboard.js ui/layout.js ui/lightbox.js diff --git a/js/ui/kbdA11yDialog.js b/js/ui/kbdA11yDialog.js new file mode 100644 index 000000000..995cc7694 --- /dev/null +++ b/js/ui/kbdA11yDialog.js @@ -0,0 +1,77 @@ +const Clutter = imports.gi.Clutter; +const Gio = imports.gi.Gio; +const GObject = imports.gi.GObject; +const Lang = imports.lang; +const Dialog = imports.ui.dialog; +const ModalDialog = imports.ui.modalDialog; + +const KEYBOARD_A11Y_SCHEMA = 'org.gnome.desktop.a11y.keyboard'; +const KEY_STICKY_KEYS_ENABLED = 'stickykeys-enable'; +const KEY_SLOW_KEYS_ENABLED = 'slowkeys-enable'; + +var KbdA11yDialog = new Lang.Class({ + Name: 'KbdA11yDialog', + Extends: GObject.Object, + + _init: function() { + this._a11ySettings = new Gio.Settings({ schema_id: KEYBOARD_A11Y_SCHEMA }); + + let deviceManager = Clutter.DeviceManager.get_default(); + deviceManager.connect('kbd-a11y-flags-changed', + Lang.bind(this, this._showKbdA11yDialog)); + }, + + _showKbdA11yDialog: function(deviceManager, newFlags, whatChanged) { + let dialog = new ModalDialog.ModalDialog(); + let title, body; + let key, enabled; + + if (whatChanged & Clutter.KeyboardA11yFlags.SLOW_KEYS_ENABLED) { + key = KEY_SLOW_KEYS_ENABLED; + enabled = (newFlags & Clutter.KeyboardA11yFlags.SLOW_KEYS_ENABLED) ? true : false; + title = enabled ? + _("Slow Keys Turned On") : + _("Slow Keys Turned Off"); + body = _("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."); + + } else if (whatChanged & Clutter.KeyboardA11yFlags.STICKY_KEYS_ENABLED) { + key = KEY_STICKY_KEYS_ENABLED; + enabled = (newFlags & Clutter.KeyboardA11yFlags.STICKY_KEYS_ENABLED) ? true : false; + title = enabled ? + _("Sticky Keys Turned On") : + _("Sticky Keys Turned Off"); + body = enabled ? + _("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."); + } else { + return; + } + + let icon = new Gio.ThemedIcon({ name: 'preferences-desktop-accessibility-symbolic' }); + let contentParams = { icon, title, body, styleClass: 'access-dialog' }; + let content = new Dialog.MessageDialogContent(contentParams); + + dialog.contentLayout.add_actor(content); + + dialog.addButton({ label: enabled ? _("Leave On") : _("Turn On"), + action: () => { + this._a11ySettings.set_boolean(key, true); + dialog.close(); + }, + default: enabled, + key: !enabled ? Clutter.Escape : null }); + + dialog.addButton({ label: enabled ? _("Turn Off") : _("Leave Off"), + action: () => { + this._a11ySettings.set_boolean(key, false); + dialog.close(); + }, + default: !enabled, + key: enabled ? Clutter.Escape : null }); + + dialog.open(); + } +}); diff --git a/js/ui/main.js b/js/ui/main.js index e981db94a..d581fd481 100644 --- a/js/ui/main.js +++ b/js/ui/main.js @@ -44,6 +44,7 @@ const WindowManager = imports.ui.windowManager; const Magnifier = imports.ui.magnifier; const XdndHandler = imports.ui.xdndHandler; const Util = imports.misc.util; +const KbdA11yDialog = imports.ui.kbdA11yDialog; const A11Y_SCHEMA = 'org.gnome.desktop.a11y.keyboard'; const STICKY_KEYS_ENABLE = 'stickykeys-enable'; @@ -78,6 +79,7 @@ var magnifier = null; var xdndHandler = null; var keyboard = null; var layoutManager = null; +var kbdA11yDialog = null; let _startDate; let _defaultCssStylesheet = null; let _cssStylesheet = null; @@ -163,6 +165,7 @@ function _initializeUI() { osdWindowManager = new OsdWindow.OsdWindowManager(); osdMonitorLabeler = new OsdMonitorLabeler.OsdMonitorLabeler(); overview = new Overview.Overview(); + kbdA11yDialog = new KbdA11yDialog.KbdA11yDialog(); wm = new WindowManager.WindowManager(); magnifier = new Magnifier.Magnifier(); if (LoginManager.canLock()) diff --git a/po/POTFILES.in b/po/POTFILES.in index 03ff3a552..e65dc2fa3 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -32,6 +32,7 @@ js/ui/endSessionDialog.js js/ui/extensionDownloader.js js/ui/extensionSystem.js js/ui/inhibitShortcutsDialog.js +js/ui/kbdA11yDialog.js js/ui/keyboard.js js/ui/lookingGlass.js js/ui/main.js