2017-01-19 18:52:18 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2019-02-09 03:21:36 +00:00
|
|
|
const { Clutter, Gio, GLib, GObject, Meta, Shell } = imports.gi;
|
2017-01-19 18:52:18 +00:00
|
|
|
|
|
|
|
const Dialog = imports.ui.dialog;
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
const Tweener = imports.ui.tweener;
|
|
|
|
|
2019-01-29 01:18:52 +00:00
|
|
|
var FROZEN_WINDOW_BRIGHTNESS = -0.3;
|
|
|
|
var DIALOG_TRANSITION_TIME = 0.15;
|
2018-05-21 21:12:35 +00:00
|
|
|
var ALIVE_TIMEOUT = 5000;
|
2017-01-19 18:52:18 +00:00
|
|
|
|
2017-10-31 01:23:39 +00:00
|
|
|
var CloseDialog = GObject.registerClass({
|
2019-01-29 01:27:05 +00:00
|
|
|
Implements: [Meta.CloseDialog],
|
2017-01-19 18:52:18 +00:00
|
|
|
Properties: {
|
|
|
|
'window': GObject.ParamSpec.override('window', Meta.CloseDialog)
|
|
|
|
},
|
2017-10-31 01:23:39 +00:00
|
|
|
}, class CloseDialog extends GObject.Object {
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(window) {
|
2017-10-31 01:23:39 +00:00
|
|
|
super._init();
|
2017-01-19 18:52:18 +00:00
|
|
|
this._window = window;
|
|
|
|
this._dialog = null;
|
2018-09-04 11:53:24 +00:00
|
|
|
this._tracked = undefined;
|
2018-05-21 21:12:35 +00:00
|
|
|
this._timeoutId = 0;
|
2018-09-04 11:53:24 +00:00
|
|
|
this._windowFocusChangedId = 0;
|
|
|
|
this._keyFocusChangedId = 0;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-01-19 18:52:18 +00:00
|
|
|
|
|
|
|
get window() {
|
|
|
|
return this._window;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-01-19 18:52:18 +00:00
|
|
|
|
|
|
|
set window(window) {
|
|
|
|
this._window = window;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-01-19 18:52:18 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_createDialogContent() {
|
2017-01-19 18:52:18 +00:00
|
|
|
let tracker = Shell.WindowTracker.get_default();
|
|
|
|
let windowApp = tracker.get_window_app(this._window);
|
|
|
|
|
|
|
|
/* Translators: %s is an application name */
|
|
|
|
let title = _("“%s” is not responding.").format(windowApp.get_name());
|
|
|
|
let subtitle = _("You may choose to wait a short while for it to " +
|
|
|
|
"continue or force the application to quit entirely.");
|
|
|
|
let icon = new Gio.ThemedIcon({ name: 'dialog-warning-symbolic' });
|
|
|
|
return new Dialog.MessageDialogContent({ icon, title, subtitle });
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-01-19 18:52:18 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_initDialog() {
|
2017-01-19 18:52:18 +00:00
|
|
|
if (this._dialog)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let windowActor = this._window.get_compositor_private();
|
|
|
|
this._dialog = new Dialog.Dialog(windowActor, 'close-dialog');
|
|
|
|
this._dialog.width = windowActor.width;
|
|
|
|
this._dialog.height = windowActor.height;
|
|
|
|
|
|
|
|
this._dialog.addContent(this._createDialogContent());
|
2019-01-29 01:27:05 +00:00
|
|
|
this._dialog.addButton({ label: _('Force Quit'),
|
|
|
|
action: this._onClose.bind(this),
|
2017-01-19 18:52:18 +00:00
|
|
|
default: true });
|
2019-01-29 01:27:05 +00:00
|
|
|
this._dialog.addButton({ label: _('Wait'),
|
2017-12-02 00:27:35 +00:00
|
|
|
action: this._onWait.bind(this),
|
2019-01-29 01:27:05 +00:00
|
|
|
key: Clutter.Escape });
|
2017-01-19 18:52:18 +00:00
|
|
|
|
|
|
|
global.focus_manager.add_group(this._dialog);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-01-19 18:52:18 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_addWindowEffect() {
|
2017-01-19 18:52:18 +00:00
|
|
|
// We set the effect on the surface actor, so the dialog itself
|
|
|
|
// (which is a child of the MetaWindowActor) does not get the
|
|
|
|
// effect applied itself.
|
|
|
|
let windowActor = this._window.get_compositor_private();
|
|
|
|
let surfaceActor = windowActor.get_first_child();
|
|
|
|
let effect = new Clutter.BrightnessContrastEffect();
|
|
|
|
effect.set_brightness(FROZEN_WINDOW_BRIGHTNESS);
|
|
|
|
surfaceActor.add_effect_with_name("gnome-shell-frozen-window", effect);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-01-19 18:52:18 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_removeWindowEffect() {
|
2017-01-19 18:52:18 +00:00
|
|
|
let windowActor = this._window.get_compositor_private();
|
|
|
|
let surfaceActor = windowActor.get_first_child();
|
|
|
|
surfaceActor.remove_effect_by_name("gnome-shell-frozen-window");
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-01-19 18:52:18 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onWait() {
|
2017-01-19 18:52:18 +00:00
|
|
|
this.response(Meta.CloseDialogResponse.WAIT);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-01-19 18:52:18 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onClose() {
|
2017-01-19 18:52:18 +00:00
|
|
|
this.response(Meta.CloseDialogResponse.FORCE_CLOSE);
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-01-19 18:52:18 +00:00
|
|
|
|
2018-09-04 11:53:24 +00:00
|
|
|
_onFocusChanged() {
|
|
|
|
if (Meta.is_wayland_compositor())
|
|
|
|
return;
|
|
|
|
|
|
|
|
let focusWindow = global.display.focus_window;
|
|
|
|
let keyFocus = global.stage.key_focus;
|
|
|
|
|
|
|
|
let shouldTrack;
|
|
|
|
if (focusWindow != null)
|
|
|
|
shouldTrack = focusWindow == this._window;
|
|
|
|
else
|
|
|
|
shouldTrack = keyFocus && this._dialog.contains(keyFocus);
|
|
|
|
|
|
|
|
if (this._tracked === shouldTrack)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (shouldTrack)
|
|
|
|
Main.layoutManager.trackChrome(this._dialog,
|
|
|
|
{ affectsInputRegion: true });
|
|
|
|
else
|
|
|
|
Main.layoutManager.untrackChrome(this._dialog);
|
|
|
|
|
|
|
|
// The buttons are broken when they aren't added to the input region,
|
|
|
|
// so disable them properly in that case
|
|
|
|
this._dialog.buttonLayout.get_children().forEach(b => {
|
|
|
|
b.reactive = shouldTrack;
|
|
|
|
});
|
|
|
|
|
|
|
|
this._tracked = shouldTrack;
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2018-09-04 11:53:24 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
vfunc_show() {
|
2017-01-19 18:52:18 +00:00
|
|
|
if (this._dialog != null)
|
|
|
|
return;
|
|
|
|
|
2018-07-08 15:37:53 +00:00
|
|
|
Meta.disable_unredirect_for_display(global.display);
|
2018-05-21 19:21:05 +00:00
|
|
|
|
2018-05-21 21:12:35 +00:00
|
|
|
this._timeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, ALIVE_TIMEOUT,
|
|
|
|
() => {
|
|
|
|
this._window.check_alive(global.display.get_current_time_roundtrip());
|
|
|
|
return GLib.SOURCE_CONTINUE;
|
|
|
|
});
|
|
|
|
|
2018-09-04 11:53:24 +00:00
|
|
|
this._windowFocusChangedId =
|
|
|
|
global.display.connect('notify::focus-window',
|
|
|
|
this._onFocusChanged.bind(this));
|
|
|
|
|
|
|
|
this._keyFocusChangedId =
|
|
|
|
global.stage.connect('notify::key-focus',
|
|
|
|
this._onFocusChanged.bind(this));
|
|
|
|
|
2017-01-19 18:52:18 +00:00
|
|
|
this._addWindowEffect();
|
|
|
|
this._initDialog();
|
|
|
|
|
|
|
|
this._dialog.scale_y = 0;
|
|
|
|
this._dialog.set_pivot_point(0.5, 0.5);
|
|
|
|
|
|
|
|
Tweener.addTween(this._dialog,
|
|
|
|
{ scale_y: 1,
|
|
|
|
transition: 'linear',
|
|
|
|
time: DIALOG_TRANSITION_TIME,
|
2018-09-04 11:53:24 +00:00
|
|
|
onComplete: this._onFocusChanged.bind(this)
|
2017-01-19 18:52:18 +00:00
|
|
|
});
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-01-19 18:52:18 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
vfunc_hide() {
|
2017-01-19 18:52:18 +00:00
|
|
|
if (this._dialog == null)
|
|
|
|
return;
|
|
|
|
|
2018-07-08 15:37:53 +00:00
|
|
|
Meta.enable_unredirect_for_display(global.display);
|
2018-05-21 19:21:05 +00:00
|
|
|
|
2018-05-21 21:12:35 +00:00
|
|
|
GLib.source_remove(this._timeoutId);
|
|
|
|
this._timeoutId = 0;
|
|
|
|
|
2019-01-29 01:18:52 +00:00
|
|
|
global.display.disconnect(this._windowFocusChangedId);
|
2018-09-04 11:53:24 +00:00
|
|
|
this._windowFocusChangedId = 0;
|
|
|
|
|
|
|
|
global.stage.disconnect(this._keyFocusChangedId);
|
|
|
|
this._keyFocusChangedId = 0;
|
|
|
|
|
2017-01-19 18:52:18 +00:00
|
|
|
let dialog = this._dialog;
|
|
|
|
this._dialog = null;
|
|
|
|
this._removeWindowEffect();
|
|
|
|
|
|
|
|
Tweener.addTween(dialog,
|
|
|
|
{ scale_y: 0,
|
|
|
|
transition: 'linear',
|
|
|
|
time: DIALOG_TRANSITION_TIME,
|
2017-10-31 00:38:18 +00:00
|
|
|
onComplete: () => {
|
2017-01-19 18:52:18 +00:00
|
|
|
dialog.destroy();
|
2017-10-31 00:38:18 +00:00
|
|
|
}
|
2017-01-19 18:52:18 +00:00
|
|
|
});
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2017-01-19 18:52:18 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
vfunc_focus() {
|
2017-01-19 18:52:18 +00:00
|
|
|
if (this._dialog)
|
|
|
|
this._dialog.grab_key_focus();
|
|
|
|
}
|
|
|
|
});
|