spkp

Stacking wayland compositor
git clone git://git.z3bra.org/sp:kp.git
Log | Files | Refs

commit b441298945c16788b62304a66c43a3ceb3204eb0
parent 7cd85fd0d45f27540871c22f58c080c8b17b57dc
Author: Willy Goiffon <dev@z3bra.org>
Date:   Fri, 13 Nov 2020 10:13:23 +0100

Move border rendering to its own function

Diffstat:
Mcompositor.c | 52++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 42 insertions(+), 10 deletions(-)

diff --git a/compositor.c b/compositor.c @@ -183,6 +183,7 @@ static void cb_paint_cursor(struct wl_listener *, void *); static void add_keyboard(struct state *, struct wlr_input_device *); static void add_pointer(struct state *, struct wlr_input_device *); static void render(struct wlr_surface *, int, int, void *); +static void render_border(struct wlr_box *, struct rdata *, int); static void focus(struct window *); static int keybinding(struct state *, uint32_t, uint32_t, enum wlr_key_state); static struct window *underneath(struct state *, double, double); @@ -801,13 +802,13 @@ add_pointer(struct state *server, struct wlr_input_device *device) void render(struct wlr_surface *surface, int x, int y, void *data) { - float *color, matrix[9]; + float matrix[9]; struct rdata *rdata; struct window *window; struct wlr_output *output; struct wlr_surface *focus; struct wlr_texture *texture; - struct wlr_box box, border; + struct wlr_box box; enum wl_output_transform transform; rdata = data; @@ -826,20 +827,51 @@ render(struct wlr_surface *surface, int x, int y, void *data) box.height = surface->current.height; focus = window->server->seat->keyboard_state.focused_surface; - if (surface == window->toplevel->surface) { - border.x = box.x - bordersize; - border.y = box.y - bordersize; - border.width = box.width + bordersize * 2; - border.height = box.height + bordersize * 2; - color = surface == focus ? activecolor : bordercolor; - wlr_render_rect(rdata->renderer, &border, color, output->transform_matrix); - } + if (surface == window->toplevel->surface) + render_border(&box, rdata, (surface == focus)); 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); } +void +render_border(struct wlr_box *content, struct rdata *rdata, int active) +{ + float *color; + struct wlr_box box; + + color = active ? activecolor : bordercolor; + + /* top */ + box.x = content->x - bordersize; + box.y = content->y - bordersize; + box.width = bordersize * 2 + content->width; + box.height = bordersize; + wlr_render_rect(rdata->renderer, &box, color, rdata->output->transform_matrix); + + /* bottom */ + box.x = content->x - bordersize; + box.y = content->y + content->height; + box.width = bordersize * 2 + content->width; + box.height = bordersize; + wlr_render_rect(rdata->renderer, &box, color, rdata->output->transform_matrix); + + /* left */ + box.x = content->x - bordersize; + box.y = content->y; + box.width = bordersize; + box.height = content->height; + wlr_render_rect(rdata->renderer, &box, color, rdata->output->transform_matrix); + + /* right */ + box.x = content->x + content->width; + box.y = content->y; + box.width = bordersize; + box.height = content->height; + wlr_render_rect(rdata->renderer, &box, color, rdata->output->transform_matrix); +} + /* * Set keyboard focus on the given top-level window. */