-
Notifications
You must be signed in to change notification settings - Fork 18
/
workspace.go
98 lines (82 loc) · 1.93 KB
/
workspace.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
package main
import (
"fmt"
"github.com/blrsn/zentile/state"
)
type Workspace struct {
IsTiling bool
activeLayoutNum uint
layouts []Layout
}
func CreateWorkspaces() map[uint]*Workspace {
workspaces := make(map[uint]*Workspace)
for i := uint(0); i < state.DeskCount; i++ {
ws := Workspace{
IsTiling: false,
layouts: createLayouts(i),
}
workspaces[i] = &ws
}
return workspaces
}
func createLayouts(workspaceNum uint) []Layout {
return []Layout{
&VerticalLayout{&VertHorz{
Store: buildStore(),
Proportion: 0.5,
WorkspaceNum: workspaceNum,
}},
&HorizontalLayout{&VertHorz{
Store: buildStore(),
Proportion: 0.5,
WorkspaceNum: workspaceNum,
}},
&FullScreen{
Store: buildStore(),
WorkspaceNum: workspaceNum,
},
}
}
func (ws *Workspace) ActiveLayout() Layout {
return ws.layouts[ws.activeLayoutNum]
}
// Cycle through the available layouts
func (ws *Workspace) SwitchLayout() {
ws.activeLayoutNum = (ws.activeLayoutNum + 1) % uint(len(ws.layouts))
ws.ActiveLayout().Do()
}
// Adds client to all the layouts in a workspace
func (ws *Workspace) AddClient(c Client) {
for _, l := range ws.layouts {
l.Add(c)
}
}
// Removes client from all the layouts in a workspace
func (ws *Workspace) RemoveClient(c Client) {
for _, l := range ws.layouts {
l.Remove(c)
}
}
// Tiles the active layout in a workspace
func (ws *Workspace) Tile() {
if ws.IsTiling {
ws.ActiveLayout().Do()
}
}
// Untiles the active layout in a workspace.
func (ws *Workspace) Untile() {
ws.IsTiling = false
ws.ActiveLayout().Undo()
}
func (ws *Workspace) printStore() {
l := ws.ActiveLayout()
st := l.sto()
fmt.Println("Number of masters is ", len(st.masters))
fmt.Println("Number of slaves is", len(st.slaves))
for i, c := range st.masters {
fmt.Println("master ", " ", i, " - ", c.name())
}
for i, c := range st.slaves {
fmt.Println("slave ", " ", i, " - ", c.name())
}
}