-
Notifications
You must be signed in to change notification settings - Fork 0
/
layouts.c
158 lines (138 loc) · 4.33 KB
/
layouts.c
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
#include "atlas.h"
#include "config.h"
#include "util.h"
#include <X11/Xlib.h>
#include <stdio.h>
void arrange(Monitor *m) {
if (m)
toggleWindowVisibility(m->stack);
else
for (m = monitors; m; m = m->next)
toggleWindowVisibility(m->stack);
if (m) {
arrangeMonitor(m);
restack(m);
} else
for (m = monitors; m; m = m->next)
arrangeMonitor(m);
}
void arrangeMonitor(Monitor *m) {
safe_strcpy(m->layoutSymbol, m->layouts[m->selectedLayout]->symbol,
sizeof m->layoutSymbol);
if (m->layouts[m->selectedLayout]->arrange)
m->layouts[m->selectedLayout]->arrange(m);
}
void setlayout(const Arg *arg) {
if (!arg || !arg->v ||
arg->v != selectedMonitor->layouts[selectedMonitor->selectedLayout])
selectedMonitor->selectedLayout ^= 1;
if (arg && arg->v)
selectedMonitor->layouts[selectedMonitor->selectedLayout] =
(Layout *)arg->v;
safe_strcpy(selectedMonitor->layoutSymbol,
selectedMonitor->layouts[selectedMonitor->selectedLayout]->symbol,
sizeof selectedMonitor->layoutSymbol);
if (selectedMonitor->active)
arrange(selectedMonitor);
}
/* arg > 1.0 will set mfact absolutely */
void setMasterRatio(const Arg *arg) {
float f;
if (!arg ||
!selectedMonitor->layouts[selectedMonitor->selectedLayout]->arrange)
return;
f = arg->f < 1.0 ? arg->f + selectedMonitor->masterFactor : arg->f - 1.0;
if (f < 0.05 || f > 0.95)
return;
selectedMonitor->masterFactor = f;
arrange(selectedMonitor);
}
void monocle(Monitor *m) {
unsigned int n = 0;
Client *c;
for (c = m->clients; c; c = c->next)
if (ISVISIBLE(c))
n++;
if (n > 0) /* override layout symbol */
snprintf(m->layoutSymbol, sizeof m->layoutSymbol, "[%d]", n);
for (c = getNextTiledWindow(m->clients); c; c = getNextTiledWindow(c->next))
resize(c, m->wx, m->wy, m->ww - 2 * c->borderWidth,
m->wh - 2 * c->borderWidth, 0);
}
void dwindlegaps(Monitor *m) {
Client *c;
unsigned int n = 0;
// Count visible clients
for (c = getNextTiledWindow(m->clients); c; c = getNextTiledWindow(c->next))
n++;
if (n == 0)
return;
// Calculate available space considering outer gaps
int x = m->wx + cfg.outerGaps;
int y = m->wy + cfg.outerGaps;
int w = m->ww - (2 * cfg.outerGaps);
int h = m->wh - (2 * cfg.outerGaps);
// Single window case
if (n == 1) {
c = getNextTiledWindow(m->clients);
resize(c, x, y, w - (2 * c->borderWidth), h - (2 * c->borderWidth), 0);
return;
}
c = getNextTiledWindow(m->clients);
int i = 0;
int remaining_w = w;
int remaining_h = h;
int current_x = x;
int current_y = y;
while (c) {
Client *next = getNextTiledWindow(c->next);
// Initialize ratios if not set
if (c->horizontalRatio <= 0)
c->horizontalRatio = 0.5;
if (c->verticalRatio <= 0)
c->verticalRatio = 0.5;
if (!next) {
// Last window uses remaining space
resize(c, current_x, current_y, remaining_w - (2 * c->borderWidth),
remaining_h - (2 * c->borderWidth), 0);
break;
}
if (i % 2 == 0) {
// Vertical split using horizontalRatio
int new_w = (remaining_w - cfg.innerGaps) * c->horizontalRatio;
resize(c, current_x, current_y, new_w - (2 * c->borderWidth),
remaining_h - (2 * c->borderWidth), 0);
current_x += new_w + cfg.innerGaps;
remaining_w = remaining_w - new_w - cfg.innerGaps;
} else {
// Horizontal split using verticalRatio
int new_h = (remaining_h - cfg.innerGaps) * c->verticalRatio;
resize(c, current_x, current_y, remaining_w - (2 * c->borderWidth),
new_h - (2 * c->borderWidth), 0);
current_y += new_h + cfg.innerGaps;
remaining_h = remaining_h - new_h - cfg.innerGaps;
}
c = next;
i++;
}
}
void restack(Monitor *m) {
Client *c;
XEvent ev;
XWindowChanges wc;
if (!m->active)
return;
if (m->active->isFloating || !m->layouts[m->selectedLayout]->arrange)
XRaiseWindow(display, m->active->win);
if (m->layouts[m->selectedLayout]->arrange) {
wc.stack_mode = Below;
for (c = m->stack; c; c = c->nextInStack)
if (!c->isFloating && ISVISIBLE(c)) {
XConfigureWindow(display, c->win, CWSibling | CWStackMode, &wc);
wc.sibling = c->win;
}
}
XSync(display, False);
while (XCheckMaskEvent(display, EnterWindowMask, &ev))
;
}