forked from golang/exp
/
x11.go
63 lines (51 loc) · 1.51 KB
/
x11.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package x11
import (
"fmt"
"github.com/BurntSushi/xgbutil/ewmh"
"github.com/BurntSushi/xgb"
"github.com/BurntSushi/xgb/xproto"
"github.com/BurntSushi/xgbutil"
"github.com/BurntSushi/xgbutil/motif"
)
func MoveWindow(xc *xgb.Conn, xw xproto.Window, x, y, width, height int32) (int32, int32, int32, int32) {
vals := []uint32{}
flags := xproto.ConfigWindowHeight |
xproto.ConfigWindowWidth |
xproto.ConfigWindowX |
xproto.ConfigWindowY
vals = append(vals, uint32(x))
vals = append(vals, uint32(y))
if int16(width) <= 0 {
width = 1
}
vals = append(vals, uint32(width))
if int16(height) <= 0 {
height = 1
}
vals = append(vals, uint32(height))
cook := xproto.ConfigureWindowChecked(xc, xw, uint16(flags), vals)
if err := cook.Check(); err != nil {
fmt.Println("X11 configure window failed: ", err)
}
return x, y, width, height
}
func ToggleFullScreen(xutil *xgbutil.XUtil, win xproto.Window) error {
return ewmh.WmStateReq(xutil, win, ewmh.StateToggle, "_NET_WM_STATE_FULLSCREEN")
}
func SetFullScreen(xutil *xgbutil.XUtil, win xproto.Window, fullscreen bool) error {
action := ewmh.StateRemove
if fullscreen {
action = ewmh.StateAdd
}
return ewmh.WmStateReq(xutil, win, action, "_NET_WM_STATE_FULLSCREEN")
}
func SetBorderless(xutil *xgbutil.XUtil, win xproto.Window, borderless bool) error {
hints := &motif.Hints{
Flags: motif.HintDecorations,
Decoration: motif.DecorationNone,
}
if !borderless {
hints.Decoration = motif.DecorationAll
}
return motif.WmHintsSet(xutil, win, hints)
}