From 08a6da05412961ddf629415a92749b02d875fa62 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Mon, 4 Oct 2021 17:25:48 -0700 Subject: feat(wm): layer shell --- sys/cmd/wm/util.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) (limited to 'sys/cmd/wm/util.c') diff --git a/sys/cmd/wm/util.c b/sys/cmd/wm/util.c index 28b0e54..cf4f68a 100644 --- a/sys/cmd/wm/util.c +++ b/sys/cmd/wm/util.c @@ -1,5 +1,16 @@ #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) { @@ -8,3 +19,80 @@ scale_box(struct wlr_box *box, float 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) +{ + 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 -- cgit v1.2.1