-
Notifications
You must be signed in to change notification settings - Fork 0
/
desktop.go
394 lines (340 loc) · 6.8 KB
/
desktop.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
package desktops
import (
"fmt"
"github.com/thrisp/scpwm/euclid/branch"
"github.com/thrisp/scpwm/euclid/settings"
)
type Desktop interface {
settings.Settings
Set(string, interface{})
Index() int
Monitor() uint32
Id() string
Name() string
Focus()
Focused() bool
Floating() bool
Layout() string
Clients() *branch.Branch
}
func NewDesktop(monitor uint32, name string, s settings.Settings) Desktop {
d := &desktop{
Settings: s,
}
d.Set("name", name)
d.Set("monitor", monitor)
return d
}
type desktop struct {
settings.Settings
idx int
monitor uint32
name string
focused bool
floating bool
layout string
clients *branch.Branch
}
func (d *desktop) Set(k string, v interface{}) {
switch k {
case "index":
if value, ok := v.(int); ok {
d.idx = value
}
case "monitor":
if value, ok := v.(uint32); ok {
d.monitor = value
}
case "name":
if value, ok := v.(string); ok {
d.name = value
}
case "focus":
if value, ok := v.(bool); ok {
d.focused = value
}
case "floating":
if value, ok := v.(bool); ok {
d.floating = value
}
case "layout":
if value, ok := v.(string); ok {
d.layout = value
}
}
}
func (d *desktop) Index() int {
return d.idx
}
func (d *desktop) Monitor() uint32 {
return d.monitor
}
func (d *desktop) Id() string {
return fmt.Sprintf("%s-%d-%d", d.name, d.idx, d.monitor)
}
func (d *desktop) Name() string {
if d.name == "" {
return d.defaultName()
}
return d.name
}
func (d *desktop) defaultName() string {
return fmt.Sprintf("%s%d", d.String("DefaultDesktopName"), d.idx)
}
func (d *desktop) Focus() {
d.focused = true
}
func (d *desktop) Focused() bool {
return d.focused
}
func (d *desktop) Floating() bool {
return d.floating
}
func (d *desktop) Layout() string {
return d.layout
}
func (d *desktop) Clients() *branch.Branch {
return d.clients
}
/*
import (
"github.com/thrisp/scpwm/euclid/settings"
"github.com/thrisp/scpwm/euclid/monitor"
)
type Desktop interface {
Monitor() monitor.Monitor
Focused() bool
Last() bool
Merge(Desktop)
Arrange()
Focus()
Unfocus()
Show()
Hide()
Urgent() bool
//Clients() Clients
}
type desktop struct {
///loc coordinate
m monitor.Monitor
id string
name string
layout Layout
pad Pad
windowGap int
borderWidth uint
floating bool
focused bool
last bool
clients Clients
}
func New(m monitor.Monitor, n string) Desktop {
//d := e.desktopDefault()
//d.layout = tiled
//d.pad = DefaultPad()
//if n == "" {
// d.name = d.id
//} else {
// d.name = n
//}
//d.loc.m = m
//d.loc.d = d
//d.clients = NewClients()
//return d
return nil
}
func (d *desktop) Focused() bool {
return d.focused
}
func (d *desktop) Last() bool {
return d.last
}
func (d *desktop) Merge(dst Desktop) {
//for _, c := range dst.Clients() {
//c.loc.m = d.loc.m
//c.loc.d = d
//}
//d.clients = append(d.clients, dst.clients...)
// reconfigure clients to this desktop
}
//func (d *desktop) TiledCount() int {
//var cnt int
//for _, c := range d.clients {
// if c.Tiled() {
// cnt++
// }
//}
//return cnt
//}
func (d *desktop) Focus() {
//d.loc.m.Focus()
//if !d.focused {
// d.focused = true
// d.Show()
// //ewmh_update_current_Desktop();
//}
}
func (d *desktop) Show() {
//if d.e.Bool("visible") {
// n := d.root.rightExtrema()
// for n != nil {
// //window_show(n->client->window);
// n = nextLeaf(n, d.root)
// }
//}
}
func (d *desktop) Unfocus() {
if d.focused {
d.focused = false
d.last = true
d.Hide()
}
}
func (d *desktop) Hide() {
//if d.e.Bool("visible") {
// n := d.root.rightExtrema()
// for n != nil {
// //window_hide(n->client->window);
// n = nextLeaf(n, d.root)
// }
//}
}
func (d *desktop) Urgent() bool {
//for _, c := range d.clients {
// if c.urgent {
// return true
// }
//}
return false
}
func (d *desktop) Remove() {
//if d.clients.Number() <= 0 {
// d.loc = NoCoordinate
// d.pad = nil
// d.clients = nil
// d = nil
//}
// raise a notice of some sort
}
type Layout int
const (
tiled Layout = iota
monocle
)
func (d *Desktop) Change(l Layout) {
d.layout = l
d.Arrange()
}
//func (d *Desktop) Transfer(to *Monitor) {
//cds := d.loc.m.desktops
//cds.Pop(d)
//adjust cds focus etc
//nds := to.desktops
//nds.d = append(nds.d, d)
//d.loc.m = to
//adjust everything to new monitor
//ewmh_update_wm_Desktops();
//ewmh_update_Desktop_names();
//ewmh_update_current_Desktop();
//}
//func (d *Desktop) Neighbor(sel Selector) *Desktop {
// return nil
//}
type desktopStatus int
const (
dsAll desktopStatus = iota
dsFree
dsOccupied
)
var stringDesktopStatus map[string]desktopStatus = map[string]desktopStatus{
"all": dsAll,
"free": dsFree,
"occupied": dsOccupied,
}
type desktopUrgency int
const (
duAll desktopUrgency = iota
duOn
duOff
)
var stringDesktopUrgency map[string]desktopUrgency = map[string]desktopUrgency{
"all": duAll,
"on": duOn,
"off": duOff,
}
//func selectDesktop(e *Euclid, sel ...Selector) bool {
// return false
//}
func DesktopFromDescription(desc []string, ref, dst *coordinate) bool {
//sel := DesktopSelectFromString(desc)
//dst.d = nil
cycle_dir_t cyc;
history_dir_t hdi;
char *colon;
int idx;
if (parse_cycle_direction(desc, &cyc)) {
dst->monitor = ref->monitor;
dst->Desktop = closest_Desktop(ref->monitor, ref->Desktop, cyc, sel);
} else if (parse_history_direction(desc, &hdi)) {
history_find_Desktop(hdi, ref, dst, sel);
} else if (streq("last", desc)) {
history_find_Desktop(HISTORY_OLDER, ref, dst, sel);
} else if (streq("focused", desc)) {
coordinates_t loc = {mon, mon->desk, NULL};
if (Desktop_matches(&loc, ref, sel)) {
dst->monitor = mon;
dst->Desktop = mon->desk;
}
} else if ((colon = strchr(desc, ':')) != NULL) {
*colon = '\0';
if (monitor_from_desc(desc, ref, dst)) {
if (streq("focused", colon + 1)) {
dst->Desktop = dst->monitor->desk;
} else if (parse_index(colon + 1, &idx)) {
Desktop_from_index(idx, dst, dst->monitor);
}
}
} else if (parse_index(desc, &idx)) {
Desktop_from_index(idx, dst, NULL);
} else {
locate_Desktop(desc, dst);
}
return (dst->Desktop != NULL);
}
return false
}
func DesktopFromIndex(idx int, loc *coordinate) bool {
mon := m.Pop(Head)
for mon != nil {
if m != nil && m != mon {
d := mon.Desktop.Pop(Head)
for d != nil {
if idx == 1 {
loc.m = mon
loc.d = d
loc.n = nil
return true
}
d = d.Pop(Next)
idx--
}
}
mon = mon.Pop(Next)
}
return false
}
func MatchDesktop(loc, ref *coordinate, sel DesktopSelect) bool {
if sel.status != dsAll && loc.d.root == nil {
if sel.status == dsOccupied || sel.status == dsFree {
return false
}
}
if sel.urgent && !loc.d.Urgent() {
return false
}
if sel.local && ref.m != loc.m {
return false
}
return true
}
*/