diff --git a/include/sway/desktop/fx_renderer.h b/include/sway/desktop/fx_renderer.h index 0bbfcec3..b461ba02 100644 --- a/include/sway/desktop/fx_renderer.h +++ b/include/sway/desktop/fx_renderer.h @@ -4,7 +4,7 @@ #include #include -enum corner_location { NONE, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT }; +enum corner_location { ALL, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT }; struct gles2_tex_shader { GLuint program; @@ -44,6 +44,7 @@ struct fx_renderer { GLint pos_attrib; } quad; + struct rounded_quad_shader rounded_quad; struct rounded_quad_shader rounded_tl_quad; struct rounded_quad_shader rounded_tr_quad; diff --git a/include/sway/output.h b/include/sway/output.h index 26b9709f..dc34686a 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -5,6 +5,7 @@ #include #include #include "config.h" +#include "sway/desktop/fx_renderer.h" #include "sway/tree/node.h" #include "sway/tree/view.h" @@ -162,6 +163,12 @@ void render_rect(struct sway_output *output, pixman_region32_t *output_damage, const struct wlr_box *_box, float color[static 4]); +void render_rounded_rect(struct sway_output *output, + pixman_region32_t *output_damage, const struct wlr_box *_box, + float color[static 4], int corner_radius, + enum corner_location corner_location); + + void premultiply_alpha(float color[4], float opacity); void scale_box(struct wlr_box *box, float scale); diff --git a/sway/desktop/fx_renderer.c b/sway/desktop/fx_renderer.c index 8963f06e..970da9b3 100644 --- a/sway/desktop/fx_renderer.c +++ b/sway/desktop/fx_renderer.c @@ -20,6 +20,7 @@ // shaders #include "quad_vert_src.h" #include "quad_frag_src.h" +#include "quad_round_frag_src.h" #include "quad_round_tl_frag_src.h" #include "quad_round_tr_frag_src.h" #include "corner_frag_src.h" @@ -163,6 +164,10 @@ struct fx_renderer *fx_renderer_create(struct wlr_egl *egl) { renderer->shaders.quad.pos_attrib = glGetAttribLocation(prog, "pos"); // rounded quad fragment shaders + prog = link_program(quad_vert_src, quad_round_frag_src); + if (!init_rounded_quad_shader(&renderer->shaders.rounded_quad, prog)) { + goto error; + } prog = link_program(quad_vert_src, quad_round_tl_frag_src); if (!init_rounded_quad_shader(&renderer->shaders.rounded_tl_quad, prog)) { goto error; @@ -407,6 +412,9 @@ void fx_render_rounded_rect(struct fx_renderer *renderer, const struct wlr_box * struct rounded_quad_shader *shader = NULL; switch (corner_location) { + case ALL: + shader = &renderer->shaders.rounded_quad; + break; case TOP_LEFT: shader = &renderer->shaders.rounded_tl_quad; break; diff --git a/sway/desktop/shaders/meson.build b/sway/desktop/shaders/meson.build index 661ccc35..069bb73f 100644 --- a/sway/desktop/shaders/meson.build +++ b/sway/desktop/shaders/meson.build @@ -3,6 +3,7 @@ embed = find_program('./embed.sh', native: true) shaders = [ 'quad.vert', 'quad.frag', + 'quad_round.frag', 'quad_round_tl.frag', 'quad_round_tr.frag', 'corner.frag', diff --git a/sway/desktop/shaders/quad_round.frag b/sway/desktop/shaders/quad_round.frag new file mode 100644 index 00000000..e347284b --- /dev/null +++ b/sway/desktop/shaders/quad_round.frag @@ -0,0 +1,15 @@ +precision mediump float; +varying vec4 v_color; +varying vec2 v_texcoord; + +uniform vec2 size; +uniform vec2 position; +uniform float radius; + +void main() { + vec2 half_size = size / 2.0; + vec2 q = abs(gl_FragCoord.xy - position - half_size) - half_size + radius; + float distance = min(max(q.x,q.y),0.0) + length(max(q,0.0)) - radius; + float smoothedAlpha = 1.0 - smoothstep(-1.0, 1.0, distance); + gl_FragColor = mix(vec4(0), v_color, smoothedAlpha); +} diff --git a/sway/input/seatop_move_tiling.c b/sway/input/seatop_move_tiling.c index 223c6c08..87e887ca 100644 --- a/sway/input/seatop_move_tiling.c +++ b/sway/input/seatop_move_tiling.c @@ -45,7 +45,8 @@ static void handle_render(struct sway_seat *seat, struct wlr_box box; memcpy(&box, &e->drop_box, sizeof(struct wlr_box)); scale_box(&box, output->wlr_output->scale); - render_rect(output, damage, &box, color); + render_rounded_rect(output, damage, &box, color, + e->con->corner_radius * output->wlr_output->scale, ALL); } }