-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmanage.js
More file actions
121 lines (109 loc) · 3.16 KB
/
manage.js
File metadata and controls
121 lines (109 loc) · 3.16 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var xcb = require ('./xcb')
new xcb.Connection(function(display) {
var X = this
, wins = []
, width = 800
, height = 600
, curGroup = 0
, groups = [[]]
, root = X.getScreen()
//console.log('root: ', root)
function mod(x, by) {
return (x > 0) ? x % by
: (by - (Math.abs(x) % by)) % by
}
function nextGroup(x) {
var t = curGroup + x
t = mod(t, groups.length)
changeGroup(t)
}
function sizeWindows() {
var group = groups[curGroup]
, len = group.length
, winWidth = Math.floor(width / len)
group.forEach(function(window, i) {
console.log("\t*resizing window : ", window)
X.ConfigureWindow({ window: window, value_mask: 15, value_list: [i * winWidth, 0, winWidth, 600] })
})
X.flush();
}
X.QueryTree({ window: root.root }, function(qtree) {
console.log("Query Tree Response")
console.log(qtree)
qtree.children.forEach(function(child) {
X.GetWindowAttributes({ window: child }, function(attrs) {
console.log('wid', child, attrs)
if (!(attrs.override_redirect || attrs.map_state == xcb.MapState.Unmapped)) {
console.log('managing', child)
manage(child)
}
})
})
})
//console.log(X.getSetup());
function changeGroup(num) {
if (num === curGroup) return
console.log('switching groups to', num)
groups[curGroup].forEach(function(window) {
X.UnmapWindow({ window: window })
})
curGroup = num
groups[curGroup].forEach(function(window) {
X.MapWindow({ window: window })
})
sizeWindows()
}
X.manageWindows();
xcb.onCreate = function(ev) {
console.log("Window being created, indexing", ev.window)
console.log('\tParent -> ', ev.parent)
X.GetWindowAttributes({ window: ev.window }, function(reply) {
console.log('Response from window ', ev.window, ' configuration!', reply)
})
if (!ev.override_redirect) manage(ev.window)
}
function manage(wid) {
wins.push(wid);
if (groups[curGroup].length == 2) groups.push([])
, changeGroup(groups.length - 1)
groups[curGroup].push(wid)
sizeWindows()
}
xcb.onDestroy = function(ev) {
var win = ev.window
, index = wins.indexOf(win)
if (index != -1) {
console.log('window destroyed, removing from index', win)
wins.splice(index, 1)
groups.forEach(function(group, i) {
var index = group.indexOf(win)
if (index != -1) {
group.splice(index, 1)
if (i === curGroup) sizeWindows()
}
})
}
else console.log('we werent watching the window', win)
}
xcb.onMapRequest = function(ev) {
console.log('\tmapping win', ev.window)
X.MapWindow({ window: ev.window })
X.flush();
}
xcb.onUnmap = function(ev) {
console.log('\t*unmapping win', ev.window)
}
xcb.onKeyPress = function(event) {
console.log('Keypress')
console.log(event)
if (event.state & 8) {
switch (event.detail) {
case 113: return nextGroup(-1)
case 114: return nextGroup(1)
case 10: return changeGroup(0)
case 11: return changeGroup(1)
case 12: return changeGroup(2)
}
}
}
})