-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidgets.js
More file actions
93 lines (90 loc) · 3.49 KB
/
widgets.js
File metadata and controls
93 lines (90 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const {Gio, GLib, GObject, Gtk} = imports.gi;
const [DispConf, logError, logObject] = (function() {
try {
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Util = Me.imports.util;
return [Me.imports.dispconf, Util.logError, Util.logObject];
} catch (error) {
const Util = imports.util;
return [imports.dispconf, Util.logError, Util.logObject];
}
})();
// For model see model.js
// callback is called with (Gtk.CheckButton, Monitor, Mode)
// Returns [Gtk.Grid,
// Map<"monitor.connector,mode.id,underscan:bool", Gtk.CheckButton>]
function buildGrid(model, callback) {
if (!model.monitors.length)
return [Gtk.Label.new("No suitable monitors"), null];
const SPACING = 4;
const gridWidget = new Gtk.Grid({
column_homogeneous: false,
row_homogeneous: false,
column_spacing: SPACING,
row_spacing: SPACING});
// First work out how many columns are in the grid for spanning labels
let numColumns = 1;
for (const mon of model.monitors) {
for (const group of mon.modeGroups) {
numColumns = Math.max(numColumns, group.modes.length);
if (numColumns == 4)
break;
}
if (numColumns == 4)
break;
}
let radios = new Map();
let row = 0;
// Use of const is important below to prevent closures inadvertently
// sharing the same values
for (let mon = 0; mon < model.monitors.length; ++mon) {
const monitor = model.monitors[mon];
gridWidget.attach(Gtk.Label.new(`${monitor.connector}`),
0, row, numColumns, 1);
++row;
let radGroup = null;
for (let mgn = 0; mgn < monitor.modeGroups.length; ++mgn) {
const group = monitor.modeGroups[mgn];
for (let mdn = 0; mdn < group.modes.length; ++mdn) {
const mode = group.modes[mdn];
let label;
if (mdn == 0) {
label = `${group.refresh}Hz`;
if (mode.interlaced && !mode.underscan)
label += " (i)";
else if (!mode.interlaced && mode.underscan)
label += " (u)";
else if (mode.interlaced && mode.underscan)
label += " (iu)";
} else {
if (mode.interlaced && ! mode.underscan)
label = "Interlaced";
else if (!mode.interlaced && mode.underscan)
label = "Underscan";
else if (mode.interlaced && mode.underscan)
label += "I + U";
else // Shouldn't happen
label = "-";
}
const radio = Gtk.CheckButton.new_with_label(label);
if (radGroup) {
radio.set_group(radGroup);
} else {
radGroup = radio;
}
radios.set(`${monitor.connector},${mode.id},${mode.underscan}`,
radio);
radio.set_active(mode.current);
radio.connect("toggled", r => {
if (r.get_active()) {
callback(r, monitor, mode);
}
});
gridWidget.attach(radio, mdn, row, 1, 1);
}
++row;
}
}
return [gridWidget, radios];
}