-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestcmd.js
More file actions
55 lines (45 loc) · 1.39 KB
/
testcmd.js
File metadata and controls
55 lines (45 loc) · 1.39 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
const GLib = imports.gi.GLib;
function directoryOfThisScript() {
const re = /@(.+?)(:\d+)+$/;
const stack = new Error().stack.split('\n');
for (const l of stack) {
if (l.indexOf("directoryOfThisScript@") >= 0) {
const m = re.exec(l);
if (m) {
return GLib.path_get_dirname(m[1]);
}
}
}
return null;
}
imports.searchPath.push(directoryOfThisScript());
const DispConf = imports.dispconf;
const Model = imports.model;
const {logObject} = imports.util;
let model = null;
function showState(state) {
log(`New MonitorsState with serial ${state.serial}`);
for (const m of state.monitors) {
log(`Monitor ${m.connector} mode ${m.currentMode}`);
}
model = Model.getStateModel(state);
log(Model.describeModel(model));
}
DispConf.onMonitorsChanged = showState;
DispConf.enable();
DispConf.updateMonitorsState().then(showState, error => {
log("Error from updateMonitorsState():");
log(error);
});
const mainLoop = GLib.MainLoop.new(null, false);
function changeMode(group) {
const mon = model.monitors[0];
const con = mon.connector;
const mode = mon.modeGroups[group].modes[0].id;
log(`Changing mode: ${con}, ${mode}`);
DispConf.changeMode(con, mode);
return false;
}
GLib.timeout_add(0, 2000, () => changeMode(2));
GLib.timeout_add(0, 5000, () => changeMode(0));
mainLoop.run();