/
configure.js
66 lines (57 loc) · 1.73 KB
/
configure.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
const {setupKeybindings} = require('./util')
const keys = require('../lib/keys')
const Workspace = require('./workspace')
const x11 = require('x11')
const ASYNC = 1
const NOPE = 0
function grabKeys (X, bindings) {
bindings.forEach(binding => {
X.GrabKey(global.root, true,
binding.buttons,
binding.keycode,
ASYNC,
ASYNC
)
})
}
// todo: make this key configurable
function grabButtons (X) {
X.GrabButton(
global.root, true, x11.eventMask.ButtonPress | x11.eventMask.ButtonRelease | x11.eventMask.PointerMotion,
ASYNC, ASYNC, NOPE, NOPE, 1, keys.buttons.M
)
X.GrabButton(
global.root, true, x11.eventMask.ButtonPress | x11.eventMask.ButtonRelease | x11.eventMask.PointerMotion,
ASYNC, ASYNC, NOPE, NOPE, 3, keys.buttons.M
)
}
function makeWorkspaces (size) {
const workspaces = []
for (let id = 0; id < size; id++) {
global.workspaces && global.workspaces[id]
? workspaces.push(global.workspaces[id])
: workspaces.push(Workspace.create(id))
}
return workspaces
}
module.exports = function () {
const configuration = require('../lib/configuration')
// todo: ungrab old keys
global.keybindings = setupKeybindings(configuration.keybindings)
grabKeys(global.X, global.keybindings)
grabButtons(global.X)
global.workspaces = makeWorkspaces(
configuration.settings && configuration.settings.workspaces
? configuration.settings.workspaces
: 5
)
global.X.ChangeWindowAttributes(global.root, {
eventMask: x11.eventMask.SubstructureNotify |
x11.eventMask.SubstructureRedirect |
x11.eventMask.ResizeRedirect |
x11.eventMask.Exposure |
x11.eventMask.MapRequest |
x11.eventMask.EnterWindow |
x11.eventMask.FocusChange
}, console.error)
}