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
/
windowStore.js
102 lines (72 loc) · 1.94 KB
/
windowStore.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
95
96
97
98
99
100
101
102
var windowMapping = {};
var windowLayers = [];
exports.registerWindow = function(window_id, alias, position) {
if(!alias) {
alias = window_id;
}
if(!position) {
position = { x: 0, y: 0 };
}
windowMapping[alias] = { wid: window_id, position: position };
return true;
};
exports.unregisterWindow = function (window_id) {
console.log("try to unregister " + window_id);
};
exports.getWidget = function(wid, widget_type) {
var targetWindow = exports.getAliasByID(wid);
if(typeof windowMapping[targetWindow].widgets === "undefined") {
windowMapping[targetWindow].widgets = {};
}
return windowMapping[targetWindow].widgets[widget_type];
}
exports.addWidget = function(wid, widget_type, xid) {
var targetWindow = exports.getAliasByID(wid);
if(typeof windowMapping[targetWindow].widgets === "undefined") {
windowMapping[targetWindow].widgets = {};
}
windowMapping[targetWindow].widgets[widget_type] = xid;
return true;
}
exports.updateLayers = function(X) {
var wm_root = exports.callWindow("OdieRoot");
X.QueryTree(wm_root, function(err, tree) {
if(err) {
return console.log(err);
}
exports.storeLayers(tree.children);
});
};
exports.storeLayers = function(layers) {
windowLayers = layers;
return true;
};
exports.callWindow = function(alias) {
var targetWindow = windowMapping[alias];
if(typeof targetWindow === "undefined") {
return undefined;
}
return windowMapping[alias].wid;
};
exports.expose = function() {
return windowMapping;
};
exports.getPosition = function(wid) {
var alias = exports.getAliasByID(wid);
return windowMapping[alias].position;
};
exports.updatePosition = function(wid, position) {
var alias = exports.getAliasByID(wid);
if(typeof windowMapping[alias] !== "undefined") {
windowMapping[alias].position = position;
}
return true;
};
exports.getAliasByID = function(wid) {
for(var key in windowMapping) {
if(windowMapping[key].wid === wid) {
return key;
}
}
return false;
}