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

Commit 4c89dc433162250ebe67a6ae5eeaa7d0cfd8f2e2
Parent: d184232071f0b0a77988fd5e996e33b1774a0464
Author: mcol <mcol@posteo.net>
Date: 2021-01-24 14:04:20 +0000
Committer: mcol <mcol@posteo.net>
Committed: 2021-01-24 14:04:20 +0000

Draw borders around windows and allow configuration per desk

src/types.h Modified

@@ -115,6 +115,9 @@
     struct server *server;
     struct wl_list views;
     float background[4];
+    float border_normal[4];
+    float border_focus[4];
+    int border_width;
     struct wallpaper *wallpaper;
     double panned_x, panned_y;
     int index;

src/output.c Modified

@@ -20,6 +20,7 @@
     struct view *view;
     struct timespec *when;
     double zoom;
+    bool is_focussed;
 };
 
 
@@ -45,25 +46,40 @@
 	    break;
 	}
     }
-    x += view->x + sx;
-    y += view->y + sy;
+    x = (x + view->x + sx) * output->scale * rdata->zoom;
+    y = (y + view->y + sy) * output->scale * rdata->zoom;
+    int width = surface->current.width * output->scale * rdata->zoom;
+    int height = surface->current.height * output->scale * rdata->zoom;
+    int border_width = server->current_desk->border_width;
+
+    if (view->surface->surface == surface) {
+	struct wlr_box borders = {
+	    .x = x - border_width,
+	    .y = y - border_width,
+	    .width = width + border_width * 2,
+	    .height = height + border_width * 2,
+	};
+	wlr_render_rect(
+	    rdata->renderer,
+	    &borders,
+	    rdata->is_focussed ? server->current_desk->border_focus : server->current_desk->border_normal,
+	    output->transform_matrix
+	);
+    }
 
-    // scale for HiDPI
     struct wlr_box box = {
-	.x = x * output->scale * rdata->zoom,
-	.y = y * output->scale * rdata->zoom,
-	.width = surface->current.width * output->scale * rdata->zoom,
-	.height = surface->current.height * output->scale * rdata->zoom,
+	.x = x,
+	.y = y,
+	.width = width,
+	.height = height,
     };
-
-    // this is where any rendering magic might happen
     float matrix[9];
     enum wl_output_transform transform =
 	wlr_output_transform_invert(surface->current.transform);
     wlr_matrix_project_box(matrix, &box, transform, 0,
 	output->transform_matrix);
-
     wlr_render_texture_with_matrix(rdata->renderer, texture, matrix, 1);
+
     wlr_surface_send_frame_done(surface, rdata->when);
 }
 
@@ -104,6 +120,7 @@
 
     // paint clients
     struct view *view;
+    struct view *focussed = wl_container_of(server->current_desk->views.next, focussed, link);
     wl_list_for_each_reverse(view, &desk->views, link) {
 	struct render_data rdata = {
 	    .output = output->wlr_output,
@@ -111,6 +128,7 @@
 	    .renderer = renderer,
 	    .when = &now,
 	    .zoom = zoom,
+	    .is_focussed = (view == focussed),
 	};
 	wlr_xdg_surface_for_each_surface(
 	    view->surface, render_surface, &rdata

src/desk.c Modified

@@ -10,6 +10,9 @@
     desk->server = server;
     wl_list_init(&desk->views);
     assign_colour("#5D479D", desk->background);
+    assign_colour("#3e3e73", desk->border_normal);
+    assign_colour("#998dd1", desk->border_focus);
+    desk->border_width = 4;
     desk->wallpaper = NULL;
     desk->index = server->desk_count;
     desk->zoom = 1;

src/config.c Modified

@@ -345,6 +345,16 @@
 		server->vt_switching = false;
 	    else if (!strcasecmp(s, "on"))
 		server->vt_switching = true;
+	} else if (!strcasecmp(s, "borders")) {
+	    s = strtok(NULL, " \t\n\r");
+	    struct desk *desk = wl_container_of(server->desks.prev, desk, link);
+	    if (!strcasecmp(s, "normal"))
+		assign_colour(strtok(NULL, " \t\n\r"), desk->border_normal);
+	    else if (!strcasecmp(s, "focus"))
+		assign_colour(strtok(NULL, " \t\n\r"), desk->border_focus);
+	    else if (!strcasecmp(s, "width"))
+		if ((s = strtok(NULL, " \t\n\r")) && is_number(s))
+		    desk->border_width = strtod(s, NULL);
 	} else if (!strcasecmp(s, "scroll_direction")) {
 	    s = strtok(NULL, " \t\n\r");
 	    if (!strcasecmp(s, "natural"))

readme.rst Modified

@@ -14,7 +14,6 @@
 This project is still new, and will not be useful.
 
 To do list:
- - border decorations
  - make configuration much nicer and remove all the strcmps
  - fix issue where Shift-using key bindings require pre-shifted key in config
  - pan desk when focussing window in direction that isn't in view
@@ -22,4 +21,3 @@
  - functions to shift desk view
  - pinch gestures for desk zooming
  - draw rect with mouse when zoomed out to set new view
- - xdg-decoration protocol?

deskwm.conf Modified

@@ -84,6 +84,14 @@
 # This can be a path to a png image, or a colour in the form #rrggbb.
 background ~/pattern.png
 
+# window border colors
+borders normal #998dd1
+borders focus #3e3e73
+borders width 4
+
 # This adds another desk. Following commands will apply to this desk.
 add_desk
 background #f9f9fb
+borders normal #1f1c32
+borders focus #406794
+borders width 5