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
|
#include "wm.h"
typedef struct {
uint32 singular_anchor;
uint32 anchor_triplet;
int *positive_axis;
int *negative_axis;
int margin;
} Edge;
// -----------------------------------------------------------------------
// general purpose function on rectangles
void
scale_box(struct wlr_box *box, float scale)
{
box->width = ROUND((box->x + box->width) * scale) - ROUND(box->x * scale);
box->height = ROUND((box->y + box->height) * scale) - ROUND(box->y * scale);
box->x = ROUND(box->x * scale);
box->y = ROUND(box->y * scale);
}
void
exclude(struct wlr_box *usable_area, uint32 anchor, int32 exclusive,
int32 margin_top, int32 margin_right, int32 margin_bottom, int32 margin_left)
{
Edge edges[] = {
{ // Top
.singular_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP,
.anchor_triplet = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT |
ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP,
.positive_axis = &usable_area->y,
.negative_axis = &usable_area->height,
.margin = margin_top,
},
{ // Bottom
.singular_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM,
.anchor_triplet = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT |
ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM,
.positive_axis = NULL,
.negative_axis = &usable_area->height,
.margin = margin_bottom,
},
{ // Left
.singular_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT,
.anchor_triplet = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM,
.positive_axis = &usable_area->x,
.negative_axis = &usable_area->width,
.margin = margin_left,
},
{ // Right
.singular_anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT,
.anchor_triplet = ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT |
ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM,
.positive_axis = NULL,
.negative_axis = &usable_area->width,
.margin = margin_right,
}
};
for(size_t i = 0; i < arrlen(edges); i++) {
if((anchor == edges[i].singular_anchor || anchor == edges[i].anchor_triplet)
&& exclusive + edges[i].margin > 0) {
if(edges[i].positive_axis)
*edges[i].positive_axis += exclusive + edges[i].margin;
if(edges[i].negative_axis)
*edges[i].negative_axis -= exclusive + edges[i].margin;
break;
}
}
}
// -----------------------------------------------------------------------
// user facing functions
void
spawn(Arg *arg)
{
wlr_log(WLR_DEBUG, "spawning %s", ((char **)arg->v)[0]);
if(!fork()) {
dup2(2, 1);
setsid();
execvp(((char **)arg->v)[0], (char **)arg->v);
}
}
void
quit(Arg *arg)
{
wl_display_terminate(server.display);
}
#define CONFIG(a,b,...) a cfg·##b = __VA_ARGS__
#include "config.h"
#undef CONFIG
|