2019-01-31 09:07:06 -05:00
|
|
|
/* exported InhibitShortcutsDialog */
|
2019-02-01 11:44:05 -05:00
|
|
|
const { Clutter, Gio, GLib, GObject, Gtk, Meta, Shell } = imports.gi;
|
2017-07-13 21:15:17 -04:00
|
|
|
|
|
|
|
const Dialog = imports.ui.dialog;
|
|
|
|
const ModalDialog = imports.ui.modalDialog;
|
2019-02-01 11:44:05 -05:00
|
|
|
const PermissionStore = imports.misc.permissionStore;
|
2017-07-13 21:15:17 -04:00
|
|
|
|
|
|
|
const WAYLAND_KEYBINDINGS_SCHEMA = 'org.gnome.mutter.wayland.keybindings';
|
|
|
|
|
2017-08-13 20:32:12 -04:00
|
|
|
const APP_WHITELIST = ['gnome-control-center.desktop'];
|
2019-02-01 11:44:05 -05:00
|
|
|
const APP_PERMISSIONS_TABLE = 'gnome';
|
|
|
|
const APP_PERMISSIONS_ID = 'shortcuts-inhibitor';
|
|
|
|
const GRANTED = 'GRANTED';
|
|
|
|
const DENIED = 'DENIED';
|
2017-08-13 20:32:12 -04:00
|
|
|
|
2017-07-13 21:15:17 -04:00
|
|
|
var DialogResponse = Meta.InhibitShortcutsDialogResponse;
|
|
|
|
|
2017-10-30 21:23:39 -04:00
|
|
|
var InhibitShortcutsDialog = GObject.registerClass({
|
2017-07-13 21:15:17 -04:00
|
|
|
Implements: [Meta.InhibitShortcutsDialog],
|
|
|
|
Properties: {
|
|
|
|
'window': GObject.ParamSpec.override('window', Meta.InhibitShortcutsDialog)
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
|
|
|
}, class InhibitShortcutsDialog extends GObject.Object {
|
2017-10-30 20:03:21 -04:00
|
|
|
_init(window) {
|
2017-10-30 21:23:39 -04:00
|
|
|
super._init();
|
2017-07-13 21:15:17 -04:00
|
|
|
this._window = window;
|
|
|
|
|
|
|
|
this._dialog = new ModalDialog.ModalDialog();
|
|
|
|
this._buildLayout();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-07-13 21:15:17 -04:00
|
|
|
|
|
|
|
get window() {
|
|
|
|
return this._window;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-07-13 21:15:17 -04:00
|
|
|
|
|
|
|
set window(window) {
|
|
|
|
this._window = window;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-07-13 21:15:17 -04:00
|
|
|
|
2017-08-13 20:32:12 -04:00
|
|
|
get _app() {
|
|
|
|
let windowTracker = Shell.WindowTracker.get_default();
|
|
|
|
return windowTracker.get_window_app(this._window);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-13 20:32:12 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_getRestoreAccel() {
|
2017-07-13 21:15:17 -04: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-30 21:23:39 -04:00
|
|
|
}
|
2017-07-13 21:15:17 -04:00
|
|
|
|
2019-02-01 11:44:05 -05:00
|
|
|
_shouldUsePermStore() {
|
|
|
|
return this._app && !this._app.is_window_backed();
|
|
|
|
}
|
|
|
|
|
|
|
|
_saveToPermissionStore(grant) {
|
|
|
|
if (!this._shouldUsePermStore() || this._permStore == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let permissions = {};
|
|
|
|
permissions[this._app.get_id()] = [grant];
|
|
|
|
let data = GLib.Variant.new('av', {});
|
|
|
|
|
|
|
|
this._permStore.SetRemote(APP_PERMISSIONS_TABLE,
|
|
|
|
true,
|
|
|
|
APP_PERMISSIONS_ID,
|
|
|
|
permissions,
|
|
|
|
data,
|
|
|
|
(result, error) => {
|
|
|
|
if (error != null)
|
|
|
|
log(error.message);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_buildLayout() {
|
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" */
|
2019-08-19 15:33:15 -04:00
|
|
|
let title = name
|
|
|
|
? _("%s wants to inhibit shortcuts").format(name)
|
|
|
|
: _("Application wants to inhibit shortcuts");
|
2017-07-13 21:15:17 -04:00
|
|
|
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: () => {
|
2019-02-01 11:44:05 -05:00
|
|
|
this._saveToPermissionStore(DENIED);
|
2017-07-13 21:15:17 -04:00
|
|
|
this._emitResponse(DialogResponse.DENY);
|
|
|
|
},
|
|
|
|
key: Clutter.KEY_Escape });
|
|
|
|
|
|
|
|
this._dialog.addButton({ label: _("Allow"),
|
|
|
|
action: () => {
|
2019-02-01 11:44:05 -05:00
|
|
|
this._saveToPermissionStore(GRANTED);
|
2017-07-13 21:15:17 -04:00
|
|
|
this._emitResponse(DialogResponse.ALLOW);
|
|
|
|
},
|
|
|
|
default: true });
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-07-13 21:15:17 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_emitResponse(response) {
|
2017-07-13 21:15:17 -04:00
|
|
|
this.emit('response', response);
|
|
|
|
this._dialog.close();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-07-13 21:15:17 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
vfunc_show() {
|
2018-07-14 16:56:22 -04:00
|
|
|
if (this._app && APP_WHITELIST.includes(this._app.get_id())) {
|
2017-08-13 20:32:12 -04:00
|
|
|
this._emitResponse(DialogResponse.ALLOW);
|
2019-02-01 11:44:05 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._shouldUsePermStore()) {
|
2017-08-13 20:32:12 -04:00
|
|
|
this._dialog.open();
|
2019-02-01 11:44:05 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check with the permission store */
|
|
|
|
let appId = this._app.get_id();
|
|
|
|
this._permStore = new PermissionStore.PermissionStore((proxy, error) => {
|
|
|
|
if (error) {
|
|
|
|
log(error.message);
|
|
|
|
this._dialog.open();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._permStore.LookupRemote(APP_PERMISSIONS_TABLE,
|
|
|
|
APP_PERMISSIONS_ID,
|
|
|
|
(res, error) => {
|
|
|
|
if (error) {
|
|
|
|
this._dialog.open();
|
|
|
|
log(error.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-01 08:41:55 -05:00
|
|
|
let [permissions] = res;
|
2019-02-01 11:44:05 -05:00
|
|
|
if (permissions[appId] === undefined) // Not found
|
|
|
|
this._dialog.open();
|
|
|
|
else if (permissions[appId] == GRANTED)
|
|
|
|
this._emitResponse(DialogResponse.ALLOW);
|
|
|
|
else
|
|
|
|
this._emitResponse(DialogResponse.DENY);
|
|
|
|
});
|
|
|
|
});
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-07-13 21:15:17 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
vfunc_hide() {
|
2017-07-13 21:15:17 -04:00
|
|
|
this._dialog.close();
|
|
|
|
}
|
|
|
|
});
|