This repository has been archived by the owner on Mar 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
94 lines (72 loc) · 2.62 KB
/
index.js
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
94
// Odie - a window manager
//
// author: Buwei Chiu <[email protected]>
var x11 = require("x11"),
fs = require("fs"),
path = require("path");
// odie processor
var Odie_Events = require("./events/"),
Odie_WindowStore = require("./windowStore"),
Odie_AtomStore = require("./atomStore");
x11.createClient(function(err, display) {
// X client
var X = display.client;
Odie_AtomStore.delegate(display);
Odie_AtomStore.scanAtoms();
// Root window
var root = display.screen[0].root;
Odie_WindowStore.registerWindow(root, "ScreenRoot");
// We make these event redirect to root
X.ChangeWindowAttributes(root, {
eventMask: x11.eventMask.SubstructureRedirect | x11.eventMask.SubstructureNotify | x11.eventMask.ProperityChange
}, function(err) {
if(err.error === 10) {
console.log("Error: maybe another window manager had already ran?");
process.exit(1);
}
});
// Create a window under all windows but root (window manager window)
var wm_root = X.AllocID();
X.CreateWindow(wm_root, root, 0, 0, display.screen[0].pixel_width, display.screen[0].pixel_height, 0, 0, 0, 0, { backgroundPixel: 0x000000, eventMask: x11.eventMask.Exposure | x11.eventMask.Button1Motion | x11.eventMask.ButtonPress | x11.eventMask.ButtonRelease });
X.MapWindow(wm_root);
Odie_WindowStore.registerWindow(wm_root, "OdieRoot");
Odie_Events.setXClient(X);
// TODO: grab all exising window
//X.QueryTree()
X.on("event", Odie_Events.Emitter);
X.on("error", Odie_Events.Error);
var repl = require('repl')
var net = require('net')
net.createServer(function (socket) {
var r = repl.start({
prompt: 'socket '+socket.remoteAddress+':'+socket.remotePort+'> ',
input: socket,
output: socket,
terminal: true,
useGlobal: true
});
r.on('exit', function () {
socket.end()
});
r.context.socket = socket
r.context.atom = Odie_AtomStore;
r.context.window = Odie_WindowStore;
}).listen(1337);
fs.watch( path.join(__dirname, "events") , function(event, filename) {
if(event == "change") {
Odie_Events = null;
X.removeAllListeners("event");
X.removeAllListeners("error");
delete require.cache[ path.join(__dirname, "events", "index.js") ];
delete require.cache[ path.join(__dirname, "events", "mouse_actions.js") ];
delete require.cache[ path.join(__dirname, "events", "configure_request.js") ];
delete require.cache[ path.join(__dirname, "events", "atom_processor.js") ];
Odie_Events = require("./events/");
Odie_Events.setXClient(X);
Odie_AtomStore.scanAtoms();
X.on("event", Odie_Events.Emitter);
X.on("error", Odie_Events.Error);
console.log("***** Events reloaded, due to " + filename);
}
});
});