-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtracker.go
131 lines (101 loc) · 2.17 KB
/
tracker.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package main
import (
"image"
"image/draw"
"time"
"github.com/BurntSushi/xgbutil"
"github.com/BurntSushi/xgbutil/xgraphics"
"github.com/BurntSushi/xgbutil/xwindow"
"github.com/AmandaCameron/gobar/images"
"github.com/AmandaCameron/gobar/utils"
"github.com/AmandaCameron/gobar/utils/startup"
"github.com/AmandaCameron/gobar/utils/xdg"
)
type Tracker struct {
Background xgraphics.BGRA
Position int
Parent *xwindow.Window
X *xgbutil.XUtil
Size int
img *xgraphics.Image
window *xwindow.Window
stopMe bool
pos int
launchId string
}
func (t *Tracker) Init() {
var err error
t.img = xgraphics.New(t.X, image.Rect(0, 0, t.Size, t.Size))
t.window, err = xwindow.Create(t.X, t.Parent.Id)
utils.FailMeMaybe(err)
t.window.Resize(t.Size, t.Size)
t.window.Move(t.Position, 0)
t.img.XSurfaceSet(t.window.Id)
t.window.Map()
t.stopMe = true
l := startup.Listener{
X: t.X,
Callbacks: t,
}
l.Initialize()
t.Draw()
}
// Sastify the commandtray.AppTracker interface
func (t *Tracker) NewApp(app *xdg.Application, launchId string) {
t.start(launchId)
go func() {
time.Sleep(5 * time.Second)
t.stop()
}()
}
// Sastify the startup.Contract interface
func (t *Tracker) Add(props map[string]string) {
t.start(props["ID"])
}
func (t *Tracker) Remove(props map[string]string) {
if t.launchId == props["ID"] {
t.stop()
}
}
func (t *Tracker) Change(props map[string]string) {
// Do Nothing.
}
// Internal Functions
func (t *Tracker) start(lId string) {
if !t.stopMe {
// Refuse to track two apps at once.
return
}
t.launchId = lId
t.stopMe = false
go func() {
for !t.stopMe {
t.Draw()
time.Sleep(250 * time.Millisecond)
}
t.Draw()
}()
}
func (t *Tracker) stop() {
t.stopMe = true
}
func (t *Tracker) Draw() {
t.img.For(func(x, y int) xgraphics.BGRA {
return t.Background
})
img := images.Tracker_1
if t.pos == 1 {
img = images.Tracker_2
} else if t.pos == 2 {
img = images.Tracker_3
} else if t.pos == 3 {
img = images.Tracker_4
}
t.pos++
t.pos %= 4
if !t.stopMe {
draw.Draw(t.img, image.Rect(4, 4, 20, 20), img, image.Point{0, 0}, draw.Over)
}
t.img.XDraw()
t.img.XPaint(t.window.Id)
}