fade out cursor trail where cursor is hidden

This commit is contained in:
Rick Choi 2024-10-27 13:55:53 +09:00
parent 12c37c9df3
commit 8f19a9ce97
4 changed files with 22 additions and 2 deletions

View file

@ -123,6 +123,21 @@ update_cursor_trail_state(CursorTrail *ct, Window *w, monotonic_t now, OSWindow
}
}
const bool cursor_trail_always_visible = false;
if (cursor_trail_always_visible) {
log_error("A: cursor trail always visible");
ct->opacity = 1.0f;
} else if (WD.screen->modes.mDECTCEM) {
log_error("B: cursor is visible");
ct->opacity += monotonic_t_to_s_double(now - ct->updated_at) / OPT(cursor_trail_decay_slow);
ct->opacity = fminf(ct->opacity, 1.0f);
} else {
log_error("C: cursor is invisible");
ct->opacity -= monotonic_t_to_s_double(now - ct->updated_at) / OPT(cursor_trail_decay_slow);
ct->opacity = fmaxf(ct->opacity, 0.0f);
}
ct->updated_at = now;
ct->needs_render = false;

View file

@ -1149,6 +1149,8 @@ init_trail_program(void) {
void
draw_cursor_trail(CursorTrail *trail, Window *active_window) {
bind_program(TRAIL_PROGRAM);
glEnable(GL_BLEND);
BLEND_ONTO_OPAQUE;
glUniform4fv(trail_program_layout.uniforms.x_coords, 1, trail->corner_x);
glUniform4fv(trail_program_layout.uniforms.y_coords, 1, trail->corner_y);
@ -1157,9 +1159,10 @@ draw_cursor_trail(CursorTrail *trail, Window *active_window) {
glUniform2fv(trail_program_layout.uniforms.cursor_edge_y, 1, trail->cursor_edge_y);
color_vec3(trail_program_layout.uniforms.trail_color, active_window ? active_window->render_data.screen->last_rendered.cursor_bg : OPT(foreground));
glUniform1fv(trail_program_layout.uniforms.trail_opacity, 1, &trail->opacity);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisable(GL_BLEND);
unbind_program();
}

View file

@ -219,6 +219,7 @@ typedef struct {
typedef struct {
bool needs_render;
monotonic_t updated_at;
float opacity;
float corner_x[4];
float corner_y[4];
float cursor_edge_x[2];

View file

@ -1,6 +1,7 @@
uniform vec2 cursor_edge_x;
uniform vec2 cursor_edge_y;
uniform vec3 trail_color;
uniform float trail_opacity;
in vec2 frag_pos;
out vec4 final_color;
@ -10,6 +11,6 @@ void main() {
cursor_edge_y[1] <= frag_pos.y && frag_pos.y <= cursor_edge_y[0]) {
discard;
} else {
final_color = vec4(trail_color, 1.0);
final_color = vec4(trail_color, trail_opacity);
}
}