aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.go190
1 files changed, 44 insertions, 146 deletions
diff --git a/config.go b/config.go
index e05855e..8cab5d8 100644
--- a/config.go
+++ b/config.go
@@ -30,151 +30,49 @@ 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{
- {
- Mod: mod,
- Sym: keysym.XK_Return,
- Fn: func(conn *xgb.Conn) {
- spawn("st")
- },
- },
- {
- Mod: mod,
- Sym: keysym.XK_w,
- Fn: func(conn *xgb.Conn) {
- spawn("qutebrowser")
- },
- },
- {
- Mod: mod | xproto.ModMaskShift,
- Sym: keysym.XK_q,
- Fn: func(conn *xgb.Conn) {
- quit()
- },
- },
- {
- Mod: mod | xproto.ModMaskShift,
- Sym: keysym.XK_r,
- Fn: func(conn *xgb.Conn) {
- restart()
- },
- },
- {
- Mod: mod,
- Sym: keysym.XK_q,
- Fn: func(conn *xgb.Conn) {
- killActiveWindow(conn, focused)
- },
- },
- {
- Mod: mod,
- Sym: keysym.XK_d,
- Fn: func(conn *xgb.Conn) {
- spawn("dmenu_run")
- },
- },
- {
- Mod: mod,
- Sym: keysym.XK_l,
- Fn: func(conn *xgb.Conn) {
- layout = "tileHorizontal"
- updateWindows(conn)
- },
- },
- {
- Mod: mod | xproto.ModMaskShift,
- Sym: keysym.XK_l,
- Fn: func(conn *xgb.Conn) {
- layout = "tileVertical"
- updateWindows(conn)
- },
- },
- {
- Mod: mod,
- Sym: keysym.XK_m,
- Fn: func(conn *xgb.Conn) {
- layout = "tileWithMaster"
- updateWindows(conn)
- },
- },
- {
- Mod: mod,
- Sym: keysym.XK_0,
- Fn: func(conn *xgb.Conn) {
- var tags BitMask = 1<<tagCount - 1
- switchTags(conn, tags)
- },
- },
- {
- Mod: mod,
- Sym: keysym.XK_1,
- Fn: func(conn *xgb.Conn) {
- var tags BitMask = 1
- switchTags(conn, tags)
- },
- },
- {
- Mod: mod,
- Sym: keysym.XK_2,
- Fn: func(conn *xgb.Conn) {
- var tags BitMask = 2
- switchTags(conn, tags)
- },
- },
- {
- Mod: mod,
- Sym: keysym.XK_3,
- Fn: func(conn *xgb.Conn) {
- var tags BitMask = 4
- switchTags(conn, tags)
- },
- },
- {
- Mod: mod,
- Sym: keysym.XK_4,
- Fn: func(conn *xgb.Conn) {
- var tags BitMask = 8
- switchTags(conn, tags)
- },
- },
- {
- Mod: mod,
- Sym: keysym.XK_5,
- Fn: func(conn *xgb.Conn) {
- var tags BitMask = 16
- switchTags(conn, tags)
- },
- },
- {
- Mod: mod,
- Sym: keysym.XK_6,
- Fn: func(conn *xgb.Conn) {
- var tags BitMask = 32
- switchTags(conn, tags)
- },
- },
- {
- Mod: mod,
- Sym: keysym.XK_7,
- Fn: func(conn *xgb.Conn) {
- var tags BitMask = 64
- switchTags(conn, tags)
- },
- },
- {
- Mod: mod,
- Sym: keysym.XK_8,
- Fn: func(conn *xgb.Conn) {
- var tags BitMask = 128
- switchTags(conn, tags)
- },
- },
- {
- Mod: mod,
- Sym: keysym.XK_9,
- Fn: func(conn *xgb.Conn) {
- var tags BitMask = 256
- switchTags(conn, tags)
- },
- },
+ 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) }),
+ )
}