-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathworkspace.go
126 lines (115 loc) · 3.02 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
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
package main
// THIS IS AN AUTOGENERATED FILE; DO NOT EDIT
import (
"fmt"
"github.com/BurntSushi/xgb/xproto"
)
func (wp *Workspace) Up(w ManagedWindow) error {
wp.mu.Lock()
defer wp.mu.Unlock()
for colnum, column := range wp.columns {
idx := -1
for i, candwin := range column.Windows {
if w.Window == candwin.Window {
idx = i
break
}
}
if idx != -1 {
if idx == 0 {
return fmt.Errorf("Window already at top of column")
}
wp.columns[colnum].Windows[idx], wp.columns[colnum].Windows[idx-1] = wp.columns[colnum].Windows[idx-1], wp.columns[colnum].Windows[idx]
return nil
}
}
return fmt.Errorf("Window not managed by workspace")
}
func (wp *Workspace) Down(w ManagedWindow) error {
wp.mu.Lock()
defer wp.mu.Unlock()
for colnum, column := range wp.columns {
idx := -1
for i, candwin := range column.Windows {
if w.Window == candwin.Window {
idx = i
break
}
}
if idx != -1 {
if idx >= len(wp.columns[colnum].Windows)-1 {
return fmt.Errorf("Window already at bottom of column")
}
wp.columns[colnum].Windows[idx], wp.columns[colnum].Windows[idx+1] = wp.columns[colnum].Windows[idx+1], wp.columns[colnum].Windows[idx]
return nil
}
}
return fmt.Errorf("Window not managed by workspace")
}
func (wp *Workspace) Left(w ManagedWindow) error {
wp.mu.Lock()
defer wp.mu.Unlock()
for colnum, column := range wp.columns {
idx := -1
for i, candwin := range column.Windows {
if w.Window == candwin.Window {
idx = i
break
}
}
if idx != -1 {
if colnum <= 0 {
return fmt.Errorf("Already in first column of workspace.")
}
// Found the window at at idx, so delete it and return.
// (I wish Go made it easier to delete from a slice.)
wp.columns[colnum].Windows = append(column.Windows[0:idx], column.Windows[idx+1:]...)
wp.columns[colnum-1].Windows = append(wp.columns[colnum-1].Windows, w)
return nil
}
}
return fmt.Errorf("Window not managed by workspace")
}
func (wp *Workspace) Right(w ManagedWindow) error {
wp.mu.Lock()
defer wp.mu.Unlock()
for colnum, column := range wp.columns {
idx := -1
for i, candwin := range column.Windows {
if w.Window == candwin.Window {
idx = i
break
}
}
if idx != -1 {
if colnum >= len(wp.columns)-1 {
return fmt.Errorf("Already at end of workspace.")
}
// Found the window at at idx, so delete it and return.
// (I wish Go made it easier to delete from a slice.)
wp.columns[colnum].Windows = append(column.Windows[0:idx], column.Windows[idx+1:]...)
wp.columns[colnum+1].Windows = append(wp.columns[colnum+1].Windows, w)
return nil
}
}
return fmt.Errorf("Window not managed by workspace")
}
func (c *Column) Resize(delta int) {
c.SizeDelta += delta
}
func (w *Workspace) ContainsWindow(win xproto.Window) bool {
for _, c := range w.columns {
for _, w := range c.Windows {
if w.Window == win {
return true
}
}
}
return false
}
func (w *Workspace) IsActive() bool {
if activeWindow == nil {
return false
}
return w.ContainsWindow(*activeWindow)
}