aboutsummaryrefslogtreecommitdiff
path: root/config.go
blob: 8cab5d8282280fb239ec87021187effcb19f4f44 (plain)
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
package main

import (
	"github.com/BurntSushi/xgb"
	"github.com/BurntSushi/xgb/xproto"

	"github.com/crecheer/wm/keysym"
)

// appearance
var barHeight uint16 = 20
var gapSize int = 10
var barColor uint32 = 0x000000
var barFg uint32 = 0x888888
var selBg uint32 = 0x285577
var selFg uint32 = 0xEEEEEE
var fontName = "JetBrainsMono Nerd Font:size=16"
var tagCount = 9
var borderWidth int = 2
var borderColor uint32 = 0x444444
var borderFocus uint32 = 0x285577

// shows focused window title
var windowTitle = 0

// xproto.ModMask1 = Alt
// xproto.ModMask4 = Super / Win
var mod = uint16(xproto.ModMask4)

// commands that get executed on startup
var startup = []string{"notify-send hello world!"}

const shift = uint16(xproto.ModMaskShift)
const alt = uint16(xproto.ModMask1)

func bind(m uint16, sym uint32, fn func(*xgb.Conn)) Key {
	return Key{Mod: m, Sym: sym, Fn: fn}
}

func run(cmd string, args ...string) func(*xgb.Conn) {
	return func(*xgb.Conn) { spawn(cmd, args...) }
}

func setLayout(name string) func(*xgb.Conn) {
	return func(conn *xgb.Conn) {
		layout = name
		updateWindows(conn)
	}
}

var keys = []Key{
	bind(mod, keysym.XK_Return, run("st")),
	bind(mod, keysym.XK_w, run("qutebrowser")),
	bind(mod, keysym.XK_d, run("dmenu_run")),
	bind(mod|shift, keysym.XK_q, func(*xgb.Conn) { quit() }),
	bind(mod|shift, keysym.XK_r, func(*xgb.Conn) { restart() }),
	bind(mod, keysym.XK_q, func(conn *xgb.Conn) { killActiveWindow(conn, focused) }),
	bind(mod, keysym.XK_l, setLayout("tileHorizontal")),
	bind(mod|shift, keysym.XK_l, setLayout("tileVertical")),
	bind(mod, keysym.XK_m, setLayout("tileWithMaster")),
}

func init() {
	for i := 0; i < tagCount && i < 9; i++ {
		tags := BitMask(1) << i
		sym := keysym.XK_1 + uint32(i)
		keys = append(keys,
			bind(mod, sym, func(conn *xgb.Conn) { switchTags(conn, tags) }),
			bind(mod|shift, sym, func(conn *xgb.Conn) { moveToTag(conn, tags) }),
			bind(alt, sym, func(conn *xgb.Conn) { toggleView(conn, tags) }),
		)
	}
	all := BitMask(1)<<tagCount - 1
	keys = append(keys,
		bind(mod, keysym.XK_0, func(conn *xgb.Conn) { switchTags(conn, all) }),
		bind(mod|shift, keysym.XK_0, func(conn *xgb.Conn) { moveToTag(conn, all) }),
	)
}