gimp but for windows: a wayland compositor
git clone https://github.com/m-col/wimp
Files | Refs | Readme

Commit a342482973b79b927b11731bef82c3bebc624d6b
Parent: a9235752ae540d0f96073c83b8a690f5c9e58f34
Author: mcol <mcol@posteo.net>
Date: 2021-02-21 22:15:11 +0000
Committer: mcol <mcol@posteo.net>
Committed: 2021-02-21 22:15:11 +0000

move border-drawing to dedicated function + don't crash when view is small

src/shell.c Modified

@@ -10,6 +10,10 @@
 
 
 void view_apply_geometry(struct view *view, struct wlr_box *new) {
+    if (new->width <= 0 || new->height <= 0) {
+	return;
+    }
+
     struct wlr_box old = {
 	.x = view->x,
 	.y = view->y,

src/output.c Modified

@@ -26,6 +26,56 @@
 };
 
 
+static void render_borders(
+    struct render_data *rdata, int x, int y, int width, int height
+) {
+    double border_width = ceil(wimp.current_desk->border_width * rdata->zoom);
+    int corner = CORNER * rdata->zoom;
+
+    struct wlr_output *output = rdata->output;
+    float *colour = rdata->is_focussed ?
+	wimp.current_desk->corner_focus : wimp.current_desk->corner_normal;
+
+    // edges including corners
+    struct wlr_box border = {
+	.x = x - border_width,
+	.y = y - border_width,
+	.width = width + border_width * 2,
+	.height = border_width,
+    };
+    wlr_render_rect(rdata->renderer, &border, colour, output->transform_matrix); // N
+    border.y = y + height;
+    wlr_render_rect(rdata->renderer, &border, colour, output->transform_matrix); // S
+    border.y = y - border_width;
+    border.width = border_width;
+    border.height = height + border_width * 2;
+    wlr_render_rect(rdata->renderer, &border, colour, output->transform_matrix); // W
+    border.x = x + width;
+    wlr_render_rect(rdata->renderer, &border, colour, output->transform_matrix); // E
+
+    // edges excluding corners
+    colour = rdata->is_focussed ?  wimp.current_desk->border_focus : wimp.current_desk->border_normal;
+    border.y += corner;
+    border.height -= corner * 2;
+    if (border.height > 0) {
+	wlr_render_rect(rdata->renderer, &border, colour, output->transform_matrix); // E
+	border.x = x - border_width;
+	wlr_render_rect(rdata->renderer, &border, colour, output->transform_matrix); // W
+    } else {
+	border.x = x - border_width;
+    }
+    border.y = y - border_width;
+    border.x += corner;
+    border.height = border_width;
+    border.width = width + border_width * 2 - corner * 2;
+    if (border.width > 0) {
+	wlr_render_rect(rdata->renderer, &border, colour, output->transform_matrix); // S
+	border.y = y + height;
+	wlr_render_rect(rdata->renderer, &border, colour, output->transform_matrix); // N
+    }
+}
+
+
 static void render_surface(
     struct wlr_surface *surface, int sx, int sy, void *data
 ) {
@@ -42,40 +92,8 @@
     int width = surface->current.width * output->scale * rdata->zoom;
     int height = surface->current.height * output->scale * rdata->zoom;
 
-    if (rdata->bordered == surface) {
-	if (wimp.current_desk->border_width > 0) {
-	    double border_width = ceil(wimp.current_desk->border_width * rdata->zoom);
-	    float *colour = rdata->is_focussed ?
-		wimp.current_desk->corner_focus : wimp.current_desk->corner_normal;
-	    struct wlr_box border = {
-		.x = x - border_width,
-		.y = y - border_width,
-		.width = width + border_width * 2,
-		.height = border_width,
-	    };
-	    wlr_render_rect(rdata->renderer, &border, colour, output->transform_matrix);
-	    border.y = y + height;
-	    wlr_render_rect(rdata->renderer, &border, colour, output->transform_matrix);
-	    border.y = y - border_width;
-	    border.width = border_width;
-	    border.height = height + border_width * 2;
-	    wlr_render_rect(rdata->renderer, &border, colour, output->transform_matrix);
-	    border.x = x + width;
-	    wlr_render_rect(rdata->renderer, &border, colour, output->transform_matrix);
-	    colour = rdata->is_focussed ? wimp.current_desk->border_focus : wimp.current_desk->border_normal;
-	    border.y += CORNER;
-	    border.height -= CORNER * 2;
-	    wlr_render_rect(rdata->renderer, &border, colour, output->transform_matrix);
-	    border.x = x - border_width;
-	    wlr_render_rect(rdata->renderer, &border, colour, output->transform_matrix);
-	    border.y = y - border_width;
-	    border.x += CORNER;
-	    border.height = border_width;
-	    border.width = width + border_width * 2 - CORNER * 2;
-	    wlr_render_rect(rdata->renderer, &border, colour, output->transform_matrix);
-	    border.y = y + height;
-	    wlr_render_rect(rdata->renderer, &border, colour, output->transform_matrix);
-	}
+    if (rdata->bordered == surface && wimp.current_desk->border_width > 0) {
+	render_borders(rdata, x, y, width, height);
     }
 
     struct wlr_box box = {