2017-07-13 21:15:17 -04:00
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GObject = imports.gi.GObject;
|
|
|
|
const Gtk = imports.gi.Gtk;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Meta = imports.gi.Meta;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
|
|
|
|
const Dialog = imports.ui.dialog;
|
|
|
|
const ModalDialog = imports.ui.modalDialog;
|
|
|
|
|
|
|
|
const WAYLAND_KEYBINDINGS_SCHEMA = 'org.gnome.mutter.wayland.keybindings';
|
|
|
|
|
2017-08-13 20:32:12 -04:00
|
|
|
const APP_WHITELIST = ['gnome-control-center.desktop'];
|
|
|
|
|
2017-07-13 21:15:17 -04:00
|
|
|
var DialogResponse = Meta.InhibitShortcutsDialogResponse;
|
|
|
|
|
|
|
|
var InhibitShortcutsDialog = new Lang.Class({
|
|
|
|
Name: 'InhibitShortcutsDialog',
|
|
|
|
Extends: GObject.Object,
|
|
|
|
Implements: [Meta.InhibitShortcutsDialog],
|
|
|
|
Properties: {
|
|
|
|
'window': GObject.ParamSpec.override('window', Meta.InhibitShortcutsDialog)
|
|
|
|
},
|
|
|
|
|
|
|
|
_init: function(window) {
|
|
|
|
this.parent();
|
|
|
|
this._window = window;
|
|
|
|
|
|
|
|
this._dialog = new ModalDialog.ModalDialog();
|
|
|
|
this._buildLayout();
|
|
|
|
},
|
|
|
|
|
|
|
|
get window() {
|
|
|
|
return this._window;
|
|
|
|
},
|
|
|
|
|
|
|
|
set window(window) {
|
|
|
|
this._window = window;
|
|
|
|
},
|
|
|
|
|
2017-08-13 20:32:12 -04:00
|
|
|
get _app() {
|
|
|
|
let windowTracker = Shell.WindowTracker.get_default();
|
|
|
|
return windowTracker.get_window_app(this._window);
|
|
|
|
},
|
|
|
|
|
2017-07-13 21:15:17 -04:00
|
|
|
_getRestoreAccel: function() {
|
|
|
|
let settings = new Gio.Settings({ schema_id: WAYLAND_KEYBINDINGS_SCHEMA });
|
|
|
|
let accel = settings.get_strv('restore-shortcuts')[0] || '';
|
|
|
|
return Gtk.accelerator_get_label.apply(null,
|
|
|
|
Gtk.accelerator_parse(accel));
|
|
|
|
},
|
|
|
|
|
|
|
|
_buildLayout: function() {
|
2017-08-13 20:32:12 -04:00
|
|
|
let name = this._app ? this._app.get_name() : this._window.title;
|
2017-07-13 21:15:17 -04:00
|
|
|
|
|
|
|
/* Translators: %s is an application name like "Settings" */
|
|
|
|
let title = name ? _("%s wants to inhibit shortcuts").format(name)
|
|
|
|
: _("Application wants to inhibit shortcuts");
|
|
|
|
let icon = new Gio.ThemedIcon({ name: 'dialog-warning-symbolic' });
|
|
|
|
|
|
|
|
let contentParams = { icon, title };
|
|
|
|
|
|
|
|
let restoreAccel = this._getRestoreAccel();
|
|
|
|
if (restoreAccel)
|
|
|
|
contentParams.subtitle =
|
2017-08-11 13:45:02 -04:00
|
|
|
/* Translators: %s is a keyboard shortcut like "Super+x" */
|
2017-07-13 21:15:17 -04:00
|
|
|
_("You can restore shortcuts by pressing %s.").format(restoreAccel);
|
|
|
|
|
|
|
|
let content = new Dialog.MessageDialogContent(contentParams);
|
|
|
|
this._dialog.contentLayout.add_actor(content);
|
|
|
|
|
|
|
|
this._dialog.addButton({ label: _("Deny"),
|
|
|
|
action: () => {
|
|
|
|
this._emitResponse(DialogResponse.DENY);
|
|
|
|
},
|
|
|
|
key: Clutter.KEY_Escape });
|
|
|
|
|
|
|
|
this._dialog.addButton({ label: _("Allow"),
|
|
|
|
action: () => {
|
|
|
|
this._emitResponse(DialogResponse.ALLOW);
|
|
|
|
},
|
|
|
|
default: true });
|
|
|
|
},
|
|
|
|
|
|
|
|
_emitResponse: function(response) {
|
|
|
|
this.emit('response', response);
|
|
|
|
this._dialog.close();
|
|
|
|
},
|
|
|
|
|
|
|
|
vfunc_show: function() {
|
2017-08-13 20:32:12 -04:00
|
|
|
if (this._app && APP_WHITELIST.indexOf(this._app.get_id()) != -1)
|
|
|
|
this._emitResponse(DialogResponse.ALLOW);
|
|
|
|
else
|
|
|
|
this._dialog.open();
|
2017-07-13 21:15:17 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
vfunc_hide: function() {
|
|
|
|
this._dialog.close();
|
|
|
|
}
|
|
|
|
});
|