forked from rollcat/dewm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xbits.go
44 lines (39 loc) · 1.13 KB
/
xbits.go
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
package main
import (
"github.com/BurntSushi/xgb"
"github.com/BurntSushi/xgb/xproto"
)
// ICCCM related atoms
var (
atomWMProtocols xproto.Atom
atomWMDeleteWindow xproto.Atom
atomWMTakeFocus xproto.Atom
atomWMName xproto.Atom
atomNETActiveWindow xproto.Atom
atomNETWMName xproto.Atom
)
func (wm *WM) initAtoms() error {
atomWMProtocols = getAtom(wm.xc, "WM_PROTOCOLS")
atomWMDeleteWindow = getAtom(wm.xc, "WM_DELETE_WINDOW")
atomWMTakeFocus = getAtom(wm.xc, "WM_TAKE_FOCUS")
atomWMName = getAtom(wm.xc, "WM_NAME")
atomNETActiveWindow = getAtom(wm.xc, "_NET_ACTIVE_WINDOW")
atomNETWMName = getAtom(wm.xc, "_NET_WM_NAME")
return nil
}
func getAtom(xc *xgb.Conn, name string) xproto.Atom {
rply, err := xproto.InternAtom(xc, false, uint16(len(name)), name).Reply()
if err != nil {
panic(err)
}
if rply == nil {
return 0
}
return rply.Atom
}
// decodeAtom decodes an xproto.Atom from a property value (expressed
// as bytes). Note that v has to be at least 4 bytes long.
func decodeAtom(v []byte) xproto.Atom {
return xproto.Atom(uint32(v[0]) | uint32(v[1])<<8 |
uint32(v[2])<<16 | uint32(v[3])<<24)
}