-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathLayouts.tq
158 lines (138 loc) · 4.88 KB
/
Layouts.tq
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
min = `a,b| (a > b) ? b ! a`
@Layout
{
- prepare: wm
{
idx = wm activeWindows indexOf: (AccessibilityWindow frontMostWindow)
if idx ~= -1 then
wm activeWindows swap: 0 with: idx
}
- windowBefore: window inWm: wm
{
windows = wm managedWindowsForScreen: window screen
space: wm currentSpaceId
^(windows itemBefore: window) || windows last
}
- windowAfter: window inWm: wm
{
windows = wm managedWindowsForScreen: window screen
space: wm currentSpaceId
^(windows itemAfter: window) || windows first
}
- focusOnWindow: window inWm: wm `window raise`
}
@TallLayout < Layout
{
- reflow: wm screen: screen space: spaceId
{
windows = wm managedWindowsForScreen: screen space: spaceId
screenFrame = screen flippedFrame
masterCount = wm maxMastersOnScreen: screen space: spaceId
left = screenFrame[0][0]
top = screenFrame[0][1]
masterCount = min(windows count, masterCount)
subCount = (windows count) - masterCount
split = screenFrame[1][0]
if windows count > masterCount {
split *= wm ratioForScreen: screen space: spaceId
subWidth = (screenFrame[1][0] - split) / subCount
}
i = 0
windows each: { win |
if i < masterCount {
h = screenFrame[1][1] / masterCount
y = top + h*i
masterCount = wm maxMastersOnScreen: screen space: spaceId
frame = [[left, y], [split, h]]
win setFrame: frame
} else {
h = screenFrame[1][1] / subCount
y = top + h*(i - masterCount)
frame = [[left + split, y], [screenFrame[1][0] - split, h]]
win setFrame: frame
}
++i
}
}
}
@MultiColLayout < Layout
{
accessor: #horizontallyFlipped
- reflow: wm screen: screen space: spaceId
{
windows = wm managedWindowsForScreen: screen space: spaceId
screenFrame = screen flippedFrame
masterCount = wm maxMastersOnScreen: screen space: spaceId
left = screenFrame[0][0]
top = screenFrame[0][1]
masterCount = min(windows count, masterCount)
subCount = windows count - masterCount
^nil if masterCount == 0
if subCount > 0 {
subX = screenFrame[1][0] * (wm ratioForScreen: screen space: spaceId)
subWidth = (screenFrame[1][0] - subX)
subX += left
} else
subWidth = 0
masterWidth = (screenFrame[1][0] - subWidth) / masterCount
subX = left if @horizontallyFlipped
i = 0
windows each: { win |
if i < masterCount {
x = i * masterWidth
x = screenFrame[1][0] - x - masterWidth if @horizontallyFlipped
x += left
masterCount = wm maxMastersOnScreen: screen space: spaceId
frame = [[x, top], [masterWidth, screenFrame[1][1]]]
win setFrame: frame
} else {
h = screenFrame[1][1] / subCount
y = top + h*(i - masterCount)
frame = [[subX, y], [subWidth, h]]
win setFrame: frame
}
++i
}
}
}
@WideLayout < Layout
{
- reflow: wm screen: screen space: spaceId
{
windows = wm managedWindowsForScreen: screen space: spaceId
screenFrame = screen flippedFrame
masterCount = wm maxMastersOnScreen: screen space: spaceId
left = screenFrame[0][0]
top = screenFrame[0][1]
masterCount = min(windows count, masterCount)
subCount = (windows count) - masterCount
split = screenFrame[1][1]
`split *= wm ratioForScreen: screen space: spaceId` unless: (windows count) <= masterCount
i = 0
windows each: { win |
if i < masterCount {
w = screenFrame[1][0] / masterCount
x = left + w*i
masterCount = wm maxMastersOnScreen: screen space: spaceId \ why is this here? TODO verify it is ok to delete
frame = [[x, top], [w, split]]
win setFrame: frame
} else {
w = screenFrame[1][0] / subCount
x = left + w*(i - masterCount)
frame = [[x, top + split], [w, screenFrame[1][1] - split]]
win setFrame: frame
}
++i
}
}
}
@FullscreenLayout < Layout
{
- reflow: wm screen: screen space: spaceId
{
windows = wm managedWindowsForScreen: screen space: spaceId
screenFrame = screen flippedFrame
masterCount = wm maxMastersOnScreen: screen space: spaceId
windows each: `window| window setFrame: screenFrame`
}
}