-
Notifications
You must be signed in to change notification settings - Fork 1
/
piece.go
109 lines (92 loc) · 1.76 KB
/
piece.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright (c) 2018, Mark "Happy-Ferret" Bauermeister
//
// This software may be modified and distributed under the terms
// of the BSD license. See the LICENSE file for details.
package frame
import (
"github.com/BurntSushi/xgb/xproto"
"github.com/BurntSushi/xgbutil/xgraphics"
"github.com/BurntSushi/xgbutil/xwindow"
)
type piece struct {
*xwindow.Window
active, inactive xproto.Pixmap
}
func newPiece(w *xwindow.Window, active, inactive *xgraphics.Image) *piece {
p := &piece{Window: w}
p.Create(active, inactive)
return p
}
func newEmptyPiece() *piece {
return &piece{nil, 0, 0}
}
func (p *piece) empty() bool {
return p.Window == nil
}
func (p *piece) Create(act, inact *xgraphics.Image) {
if p.empty() {
return
}
if act != nil {
if p.active > 0 {
xgraphics.FreePixmap(p.X, p.active)
}
act.CreatePixmap()
act.XDraw()
p.active = act.Pixmap
}
if inact != nil {
if p.inactive > 0 {
xgraphics.FreePixmap(p.X, p.inactive)
}
inact.CreatePixmap()
inact.XDraw()
p.inactive = inact.Pixmap
}
}
func (p *piece) Destroy() {
if p.empty() {
return
}
p.Window.Destroy() // detaches all event handlers
xgraphics.FreePixmap(p.X, p.active)
xgraphics.FreePixmap(p.X, p.inactive)
}
func (p *piece) Active() {
if p.empty() {
return
}
p.Change(xproto.CwBackPixmap, uint32(p.active))
p.ClearAll()
}
func (p *piece) Inactive() {
if p.empty() {
return
}
p.Change(xproto.CwBackPixmap, uint32(p.inactive))
p.ClearAll()
}
func (p *piece) x() int {
if p.empty() {
return 0
}
return p.Geom.X()
}
func (p *piece) y() int {
if p.empty() {
return 0
}
return p.Geom.Y()
}
func (p *piece) w() int {
if p.empty() {
return 0
}
return p.Geom.Width()
}
func (p *piece) h() int {
if p.empty() {
return 0
}
return p.Geom.Height()
}