Skip to content

Commit db8e003

Browse files
JosephMccclefebvre
authored andcommitted
windowManger: Make the display change dialog a clutter dialog
1 parent 520b4db commit db8e003

File tree

3 files changed

+73
-169
lines changed

3 files changed

+73
-169
lines changed

files/usr/bin/cinnamon-display-changes-dialog

Lines changed: 0 additions & 117 deletions
This file was deleted.

js/ui/windowManager.js

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const Main = imports.ui.main;
1111
const WindowMenu = imports.ui.windowMenu;
1212
const GObject = imports.gi.GObject;
1313
const AppSwitcher = imports.ui.appSwitcher.appSwitcher;
14+
const Dialog = imports.ui.dialog;
1415
const ModalDialog = imports.ui.modalDialog;
1516
const WmGtkDialogs = imports.ui.wmGtkDialogs;
1617
const CloseDialog = imports.ui.closeDialog;
@@ -28,6 +29,7 @@ const WINDOW_ANIMATION_TIME_MULTIPLIERS = [
2829
]
2930

3031
const EASING_MULTIPLIER = 1000; // multiplier for tweening.time ---> easing.duration
32+
var ONE_SECOND = 1000; // in ms
3133

3234
const DIM_TIME = 0.500;
3335
const DIM_BRIGHTNESS = -0.2;
@@ -62,6 +64,75 @@ const ZONE_TR = 5;
6264
const ZONE_BR = 6;
6365
const ZONE_BL = 7;
6466

67+
var DisplayChangeDialog = GObject.registerClass(
68+
class DisplayChangeDialog extends ModalDialog.ModalDialog {
69+
_init(wm) {
70+
super._init();
71+
72+
this._wm = wm;
73+
74+
this._countDown = Meta.MonitorManager.get_display_configuration_timeout();
75+
76+
// Translators: This string should be shorter than 30 characters
77+
let title = _("Keep these display settings?");
78+
let description = this._formatCountDown();
79+
80+
this._content = new Dialog.MessageDialogContent({ title, description });
81+
this.contentLayout.add_child(this._content);
82+
83+
/* Translators: this and the following message should be limited in length,
84+
to avoid ellipsizing the labels.
85+
*/
86+
this._cancelButton = this.addButton({ label: _("Revert Settings"),
87+
action: this._onFailure.bind(this),
88+
key: Clutter.KEY_Escape });
89+
this._okButton = this.addButton({ label: _("Keep Changes"),
90+
action: this._onSuccess.bind(this),
91+
default: true });
92+
93+
this._timeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, ONE_SECOND, this._tick.bind(this));
94+
GLib.Source.set_name_by_id(this._timeoutId, '[cinnamon] this._tick');
95+
}
96+
97+
close(timestamp) {
98+
if (this._timeoutId > 0) {
99+
GLib.source_remove(this._timeoutId);
100+
this._timeoutId = 0;
101+
}
102+
103+
super.close(timestamp);
104+
}
105+
106+
_formatCountDown() {
107+
let fmt = ngettext("Settings changes will revert in %d second",
108+
"Settings changes will revert in %d seconds");
109+
return fmt.format(this._countDown);
110+
}
111+
112+
_tick() {
113+
this._countDown--;
114+
if (this._countDown == 0) {
115+
/* muffin already takes care of failing at timeout */
116+
this._timeoutId = 0;
117+
this.close();
118+
return GLib.SOURCE_REMOVE;
119+
}
120+
121+
this._content.description = this._formatCountDown();
122+
return GLib.SOURCE_CONTINUE;
123+
}
124+
125+
_onFailure() {
126+
this._wm.complete_display_change(false);
127+
this.close();
128+
}
129+
130+
_onSuccess() {
131+
this._wm.complete_display_change(true);
132+
this.close();
133+
}
134+
});
135+
65136
class WindowDimmer {
66137
constructor(actor) {
67138
this._brightnessEffect = new Clutter.BrightnessContrastEffect({
@@ -1398,7 +1469,7 @@ var WindowManager = class WindowManager {
13981469
}
13991470

14001471
_confirmDisplayChange() {
1401-
let dialog = new WmGtkDialogs.DisplayChangesDialog(this._cinnamonwm);
1472+
let dialog = new DisplayChangeDialog(this._cinnamonwm);
14021473
dialog.open();
14031474
}
14041475
};

js/ui/wmGtkDialogs.js

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,9 @@
11
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
22

3-
const { Clutter, Gio, GLib, GObject, Meta, St } = imports.gi;
3+
const Gio = imports.gi.Gio;
44

55
const SIGTERM = 15;
66

7-
var DisplayChangesDialog = class {
8-
constructor(wm) {
9-
this._wm = wm;
10-
this._countDown = Meta.MonitorManager.get_display_configuration_timeout();
11-
}
12-
13-
open() {
14-
try {
15-
this.proc = Gio.Subprocess.new(
16-
[
17-
"cinnamon-display-changes-dialog",
18-
this._countDown.toString()
19-
],
20-
0);
21-
22-
this.proc.wait_async(null, this._wait_finish.bind(this));
23-
} catch (e) {
24-
global.logWarning(`Could not spawn display dialog: ${e}`);
25-
26-
this.proc = null;
27-
this._revert();
28-
}
29-
}
30-
31-
_wait_finish(proc, result) {
32-
try {
33-
this.proc.wait_finish(result);
34-
} catch (e) {
35-
global.logWarning(`Something went wrong with display dialog: ${e}`);
36-
this._revert();
37-
}
38-
39-
if (this.proc.get_status() == 0) {
40-
this._keep();
41-
} else {
42-
this._revert()
43-
}
44-
}
45-
46-
_revert() {
47-
log("Reverting display changes");
48-
this._wm.complete_display_change(false);
49-
}
50-
51-
_keep() {
52-
log("Confirm display changes");
53-
this._wm.complete_display_change(true);
54-
}
55-
};
56-
577
var HoverClickHelper = class {
588
constructor(wm) {
599
this.proc = null;

0 commit comments

Comments
 (0)