aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/wm/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/wm/util.c')
-rw-r--r--src/cmd/wm/util.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/cmd/wm/util.c b/src/cmd/wm/util.c
new file mode 100644
index 0000000..7871d15
--- /dev/null
+++ b/src/cmd/wm/util.c
@@ -0,0 +1,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