feat: render tiling move indicator with round corners
This commit is contained in:
parent
1881b01d3f
commit
6ca742d4f2
|
@ -4,7 +4,7 @@
|
||||||
#include <GLES2/gl2.h>
|
#include <GLES2/gl2.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
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 {
|
struct gles2_tex_shader {
|
||||||
GLuint program;
|
GLuint program;
|
||||||
|
@ -44,6 +44,7 @@ struct fx_renderer {
|
||||||
GLint pos_attrib;
|
GLint pos_attrib;
|
||||||
} quad;
|
} quad;
|
||||||
|
|
||||||
|
struct rounded_quad_shader rounded_quad;
|
||||||
struct rounded_quad_shader rounded_tl_quad;
|
struct rounded_quad_shader rounded_tl_quad;
|
||||||
struct rounded_quad_shader rounded_tr_quad;
|
struct rounded_quad_shader rounded_tr_quad;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <wayland-server-core.h>
|
#include <wayland-server-core.h>
|
||||||
#include <wlr/types/wlr_output.h>
|
#include <wlr/types/wlr_output.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "sway/desktop/fx_renderer.h"
|
||||||
#include "sway/tree/node.h"
|
#include "sway/tree/node.h"
|
||||||
#include "sway/tree/view.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,
|
pixman_region32_t *output_damage, const struct wlr_box *_box,
|
||||||
float color[static 4]);
|
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 premultiply_alpha(float color[4], float opacity);
|
||||||
|
|
||||||
void scale_box(struct wlr_box *box, float scale);
|
void scale_box(struct wlr_box *box, float scale);
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
// shaders
|
// shaders
|
||||||
#include "quad_vert_src.h"
|
#include "quad_vert_src.h"
|
||||||
#include "quad_frag_src.h"
|
#include "quad_frag_src.h"
|
||||||
|
#include "quad_round_frag_src.h"
|
||||||
#include "quad_round_tl_frag_src.h"
|
#include "quad_round_tl_frag_src.h"
|
||||||
#include "quad_round_tr_frag_src.h"
|
#include "quad_round_tr_frag_src.h"
|
||||||
#include "corner_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");
|
renderer->shaders.quad.pos_attrib = glGetAttribLocation(prog, "pos");
|
||||||
|
|
||||||
// rounded quad fragment shaders
|
// 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);
|
prog = link_program(quad_vert_src, quad_round_tl_frag_src);
|
||||||
if (!init_rounded_quad_shader(&renderer->shaders.rounded_tl_quad, prog)) {
|
if (!init_rounded_quad_shader(&renderer->shaders.rounded_tl_quad, prog)) {
|
||||||
goto error;
|
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;
|
struct rounded_quad_shader *shader = NULL;
|
||||||
|
|
||||||
switch (corner_location) {
|
switch (corner_location) {
|
||||||
|
case ALL:
|
||||||
|
shader = &renderer->shaders.rounded_quad;
|
||||||
|
break;
|
||||||
case TOP_LEFT:
|
case TOP_LEFT:
|
||||||
shader = &renderer->shaders.rounded_tl_quad;
|
shader = &renderer->shaders.rounded_tl_quad;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -3,6 +3,7 @@ embed = find_program('./embed.sh', native: true)
|
||||||
shaders = [
|
shaders = [
|
||||||
'quad.vert',
|
'quad.vert',
|
||||||
'quad.frag',
|
'quad.frag',
|
||||||
|
'quad_round.frag',
|
||||||
'quad_round_tl.frag',
|
'quad_round_tl.frag',
|
||||||
'quad_round_tr.frag',
|
'quad_round_tr.frag',
|
||||||
'corner.frag',
|
'corner.frag',
|
||||||
|
|
15
sway/desktop/shaders/quad_round.frag
Normal file
15
sway/desktop/shaders/quad_round.frag
Normal file
|
@ -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);
|
||||||
|
}
|
|
@ -45,7 +45,8 @@ static void handle_render(struct sway_seat *seat,
|
||||||
struct wlr_box box;
|
struct wlr_box box;
|
||||||
memcpy(&box, &e->drop_box, sizeof(struct wlr_box));
|
memcpy(&box, &e->drop_box, sizeof(struct wlr_box));
|
||||||
scale_box(&box, output->wlr_output->scale);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue