2017-07-14 01:15:17 +00:00
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GObject = imports.gi.GObject;
|
|
|
|
const Gtk = imports.gi.Gtk;
|
|
|
|
const Meta = imports.gi.Meta;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
|
|
|
|
const Dialog = imports.ui.dialog;
|
|
|
|
const ModalDialog = imports.ui.modalDialog;
|
|
|
|
|
|
|
|
const WAYLAND_KEYBINDINGS_SCHEMA = 'org.gnome.mutter.wayland.keybindings';
|
|
|
|
|
2017-08-14 00:32:12 +00:00
|
|
|
const APP_WHITELIST = ['gnome-control-center.desktop'];
|
|
|
|
|
2017-07-14 01:15:17 +00:00
|
|
|
var DialogResponse = Meta.InhibitShortcutsDialogResponse;
|
|
|
|
|
2017-10-31 01:23:39 +00:00
|
|
|
var InhibitShortcutsDialog = GObject.registerClass({
|
2017-07-14 01:15:17 +00:00
|
|
|
Implements: [Meta.InhibitShortcutsDialog],
|
|
|
|
Properties: {
|
|
|
|
'window': GObject.ParamSpec.override('window', Meta.InhibitShortcutsDialog)
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
|
|
|
}, class InhibitShortcutsDialog extends GObject.Object {
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(window) {
|
2017-10-31 01:23:39 +00:00
|
|
|
super._init();
|
2017-07-14 01:15:17 +00:00
|
|
|
this._window = window;
|
|
|
|
|
|
|
|
this._dialog = new ModalDialog.ModalDialog();
|
|
|
|
this._buildLayout();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-07-14 01:15:17 +00:00
|
|
|
|
|
|
|
get window() {
|
|
|
|
return this._window;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-07-14 01:15:17 +00:00
|
|
|
|
|
|
|
set window(window) {
|
|
|
|
this._window = window;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-07-14 01:15:17 +00:00
|
|
|
|
2017-08-14 00:32:12 +00:00
|
|
|
get _app() {
|
|
|
|
let windowTracker = Shell.WindowTracker.get_default();
|
|
|
|
return windowTracker.get_window_app(this._window);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-08-14 00:32:12 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getRestoreAccel() {
|
2017-07-14 01:15:17 +00:00
|
|
|
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));
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-07-14 01:15:17 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_buildLayout() {
|
2017-08-14 00:32:12 +00:00
|
|
|
let name = this._app ? this._app.get_name() : this._window.title;
|
2017-07-14 01:15:17 +00: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 17:45:02 +00:00
|
|
|
/* Translators: %s is a keyboard shortcut like "Super+x" */
|
2017-07-14 01:15:17 +00: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 });
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-07-14 01:15:17 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_emitResponse(response) {
|
2017-07-14 01:15:17 +00:00
|
|
|
this.emit('response', response);
|
|
|
|
this._dialog.close();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-07-14 01:15:17 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
vfunc_show() {
|
2017-08-14 00:32:12 +00:00
|
|
|
if (this._app && APP_WHITELIST.indexOf(this._app.get_id()) != -1)
|
|
|
|
this._emitResponse(DialogResponse.ALLOW);
|
|
|
|
else
|
|
|
|
this._dialog.open();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-07-14 01:15:17 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
vfunc_hide() {
|
2017-07-14 01:15:17 +00:00
|
|
|
this._dialog.close();
|
|
|
|
}
|
|
|
|
});
|