/
floating.go
123 lines (104 loc) · 2.55 KB
/
floating.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
// 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 layout
import (
"math/rand"
"time"
"github.com/BurntSushi/xgbutil/xrect"
)
type Floating struct {
clients []Client
geom xrect.Rect
}
func NewFloating() *Floating {
return &Floating{
clients: make([]Client, 0),
}
}
func (f *Floating) InitialPlacement(c Client) {
rand.Seed(time.Now().UnixNano())
cgeom := c.Geom()
x, y := f.geom.X(), f.geom.Y()
xlimit := f.geom.Width() - cgeom.Width()
ylimit := f.geom.Height() - cgeom.Height()
if xlimit > 0 {
x += rand.Intn(xlimit)
}
if ylimit > 0 {
y += rand.Intn(ylimit)
}
f.Move(c, x, y)
}
func (f *Floating) Place() {}
func (f *Floating) Unplace() {}
func (f *Floating) Destroy() {}
func (f *Floating) Name() string {
return "Floating"
}
func (f *Floating) SetGeom(geom xrect.Rect) {
f.geom = geom
}
// Save is called when a workspace switches from a floating layout to a
// tiling layout. It should save the "last-floating" state for all floating
// clients.
func (f *Floating) Save() {
for _, c := range f.clients {
if _, ok := c.Layout().(*Floating); ok {
c.SaveState("last-floating")
}
}
}
// Reposition is called when a workspace switches from a tiling layout to a
// floating layout. It should reload the "last-floating" client state.
func (f *Floating) Reposition() {
if f.geom == nil {
return
}
for _, c := range f.clients {
// Don't reposition windows that are already in the floating layout.
if c.ShouldForceFloating() {
continue
}
if _, ok := c.Layout().(*Floating); ok {
c.LoadState("last-floating")
}
}
}
func (f *Floating) Exists(c Client) bool {
for _, client := range f.clients {
if client == c {
return true
}
}
return false
}
func (f *Floating) Add(c Client) {
if !f.Exists(c) {
f.clients = append(f.clients, c)
}
}
func (f *Floating) Remove(c Client) {
for i, client := range f.clients {
if client == c {
f.clients = append(f.clients[:i], f.clients[i+1:]...)
}
}
}
func (f *Floating) MROpt(c Client, flags, x, y, width, height int) {
c.MROpt(true, flags, x, y, width, height)
c.SaveState("last-floating")
}
func (f *Floating) MoveResize(c Client, x, y, width, height int) {
c.MoveResizeValid(x, y, width, height)
c.SaveState("last-floating")
}
func (f *Floating) Move(c Client, x, y int) {
c.Move(x, y)
c.SaveState("last-floating")
}
func (f *Floating) Resize(c Client, width, height int) {
c.Resize(true, width, height)
c.SaveState("last-floating")
}