aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/wm/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/cmd/wm/util.c')
-rw-r--r--sys/cmd/wm/util.c88
1 files changed, 88 insertions, 0 deletions
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