mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-11 02:59:40 +02:00
cursor trail support cursor shape beam and underline
This commit is contained in:
@@ -5,17 +5,40 @@ norm(float x, float y) {
|
||||
return sqrtf(x * x + y * y);
|
||||
}
|
||||
|
||||
inline static bool
|
||||
get_cursor_edge(float *left, float *right, float *top, float *bottom, Window *w) {
|
||||
#define WD w->render_data
|
||||
*left = WD.xstart + WD.screen->cursor_render_info.x * WD.dx;
|
||||
*bottom = WD.ystart - (WD.screen->cursor_render_info.y + 1) * WD.dy;
|
||||
switch (WD.screen->cursor->shape) {
|
||||
case CURSOR_BLOCK:
|
||||
*right = *left + WD.dx;
|
||||
*top = *bottom + WD.dy;
|
||||
return true;
|
||||
case CURSOR_BEAM:
|
||||
*right = *left + WD.dx / WD.screen->cell_size.width * OPT(cursor_beam_thickness);
|
||||
*top = *bottom + WD.dy;
|
||||
return true;
|
||||
case CURSOR_UNDERLINE:
|
||||
*right = *left + WD.dx;
|
||||
*top = *bottom + WD.dy / WD.screen->cell_size.height * OPT(cursor_underline_thickness);
|
||||
return true;
|
||||
case CURSOR_HOLLOW:
|
||||
// TODO - implement
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
update_cursor_trail(CursorTrail *ct, Window *w, monotonic_t now) {
|
||||
#define WD w->render_data
|
||||
// the trail corners move towards the cursor corner at a speed proportional to their distance from the cursor corner.
|
||||
// equivalent to exponential ease out animation.
|
||||
static const int ci[4][2] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
|
||||
float cursor_edge_x[2], cursor_edge_y[2];
|
||||
cursor_edge_x[0] = WD.xstart + WD.screen->cursor_render_info.x * WD.dx;
|
||||
cursor_edge_x[1] = cursor_edge_x[0] + WD.dx;
|
||||
cursor_edge_y[0] = WD.ystart - WD.screen->cursor_render_info.y * WD.dy;
|
||||
cursor_edge_y[1] = cursor_edge_y[0] - WD.dy;
|
||||
if (!get_cursor_edge(cursor_edge_x, cursor_edge_x + 1, cursor_edge_y, cursor_edge_y + 1, w)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// todo - make these configurable
|
||||
// the decay time for the trail to reach 1/1024 of its distance from the cursor corner
|
||||
@@ -54,5 +77,6 @@ update_cursor_trail(CursorTrail *ct, Window *w, monotonic_t now) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#undef WD
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user