output: draw openbox style view-cycle border

This commit is contained in:
Johan Malm 2020-09-10 22:25:26 +01:00
parent c0a807765e
commit 0b834c2efa

View file

@ -12,17 +12,48 @@ static void draw_rect(struct draw_data *d, struct wlr_box box)
wlr_render_rect(d->renderer, &box, d->rgba, d->transform_matrix); 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) static void render_cycle_box(struct output *output)
{ {
struct wlr_box box;
if (!output->server->cycle_view) if (!output->server->cycle_view)
return; return;
struct view *view; struct view *view;
wl_list_for_each_reverse (view, &output->server->views, link) { wl_list_for_each_reverse (view, &output->server->views, link) {
if (view != output->server->cycle_view) if (view == output->server->cycle_view)
continue; goto render_it;
struct wlr_box box; }
if ((view->type == LAB_XWAYLAND_VIEW) || return;
!rc.client_side_decorations) { render_it:
if ((view->type == LAB_XWAYLAND_VIEW) || !rc.client_side_decorations) {
box = deco_max_extents(view); box = deco_max_extents(view);
} else { } else {
box.x = view->x; box.x = view->x;
@ -30,11 +61,20 @@ static void render_cycle_box(struct output *output)
box.width = view->w; box.width = view->w;
box.height = view->h; box.height = view->h;
} }
float cycle_color[] = { 0.0, 0.0, 0.0, 0.2 }; struct draw_data dd = {
wlr_render_rect(output->server->renderer, &box, cycle_color, .renderer = view->server->renderer,
output->wlr_output->transform_matrix); .transform_matrix = output->wlr_output->transform_matrix,
return; };
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, 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 */ /* Render xwayland override_redirect surfaces */
struct xwayland_unmanaged *unmanaged; struct xwayland_unmanaged *unmanaged;
wl_list_for_each_reverse (unmanaged, wl_list_for_each_reverse (unmanaged,
&output->server->unmanaged_surfaces, &output->server->unmanaged_surfaces, link) {
link) {
struct render_data rdata = { struct render_data rdata = {
.output = output->wlr_output, .output = output->wlr_output,
.output_layout = output->server->output_layout, .output_layout = output->server->output_layout,