From 0b834c2efaf2c93256a67ed71ec41de0787b0ed6 Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Thu, 10 Sep 2020 22:25:26 +0100 Subject: [PATCH] output: draw openbox style view-cycle border --- src/output.c | 75 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 18 deletions(-) diff --git a/src/output.c b/src/output.c index dff14038..d588a508 100644 --- a/src/output.c +++ b/src/output.c @@ -12,29 +12,69 @@ static void draw_rect(struct draw_data *d, struct wlr_box box) wlr_render_rect(d->renderer, &box, d->rgba, d->transform_matrix); } +static void draw_line(struct draw_data *d, int x1, int y1, int x2, int y2) +{ + struct wlr_box box = { + .x = x1, + .y = y1, + .width = abs(x2 - x1) + 1, + .height = abs(y2 - y1) + 1, + }; + wlr_render_rect(d->renderer, &box, d->rgba, d->transform_matrix); +} + +/* clang-format off */ +static void draw_rect_unfilled(struct draw_data *d, struct wlr_box box) +{ + draw_line(d, box.x, box.y, box.x + box.width - 1, box.y); + draw_line(d, box.x + box.width - 1, box.y, box.x + box.width - 1, box.y + box.height - 1); + draw_line(d, box.x, box.y + box.height - 1, box.x + box.width - 1, box.y + box.height - 1); + draw_line(d, box.x, box.y, box.x, box.y + box.height - 1); +} +/* clang-format on */ + +static void shrink(struct wlr_box *box, int size) +{ + box->x += size; + box->y += size; + box->width -= 2 * size; + box->height -= 2 * size; +} + static void render_cycle_box(struct output *output) { + struct wlr_box box; if (!output->server->cycle_view) return; struct view *view; wl_list_for_each_reverse (view, &output->server->views, link) { - if (view != output->server->cycle_view) - continue; - struct wlr_box box; - if ((view->type == LAB_XWAYLAND_VIEW) || - !rc.client_side_decorations) { - box = deco_max_extents(view); - } else { - box.x = view->x; - box.y = view->y; - box.width = view->w; - box.height = view->h; - } - float cycle_color[] = { 0.0, 0.0, 0.0, 0.2 }; - wlr_render_rect(output->server->renderer, &box, cycle_color, - output->wlr_output->transform_matrix); - return; + if (view == output->server->cycle_view) + goto render_it; } + return; +render_it: + if ((view->type == LAB_XWAYLAND_VIEW) || !rc.client_side_decorations) { + box = deco_max_extents(view); + } else { + box.x = view->x; + box.y = view->y; + box.width = view->w; + box.height = view->h; + } + struct draw_data dd = { + .renderer = view->server->renderer, + .transform_matrix = output->wlr_output->transform_matrix, + }; + dd.rgba = (float[4]){ 1.0, 1.0, 1.0, 1.0 }; + draw_rect_unfilled(&dd, box); + dd.rgba = (float[4]){ 0.0, 0.0, 0.0, 1.0 }; + for (int i = 0; i < 4; i++) { + shrink(&box, 1); + draw_rect_unfilled(&dd, box); + } + dd.rgba = (float[4]){ 1.0, 1.0, 1.0, 1.0 }; + shrink(&box, 1); + draw_rect_unfilled(&dd, box); } static void render_icon(struct draw_data *d, struct wlr_box box, @@ -209,8 +249,7 @@ void output_frame(struct wl_listener *listener, void *data) /* Render xwayland override_redirect surfaces */ struct xwayland_unmanaged *unmanaged; wl_list_for_each_reverse (unmanaged, - &output->server->unmanaged_surfaces, - link) { + &output->server->unmanaged_surfaces, link) { struct render_data rdata = { .output = output->wlr_output, .output_layout = output->server->output_layout,