On Tue, Sep 15, 2026 at 02:29:12PM +0200, Thomas Zimmermann wrote: > Cursors in the VT subsystem are blocks within a character cell that are > filled with the foreground color. The new helpers vc_cursor_start() and > vc_cursor_end() return the scanlines in which the cursor block starts rsp. > ends. This is compatible with VGA hardware > > In terms of cursor design, the new cursor-size helpers follow established > styles in fbcon. The only exception is in underline cursors for fonts with > a size larger than 10. The underlining dash is now one pixel closer to > the font-glyph data, so that the cursor looks less detached. This follows > the style used by vgacon. > > Similar code in vgacon and fbcon ignores the cursor's default size stored > in vt.cur_default. The consoles default to full-block cursors, while vt > defaults to underline cursors. The new helper fall back to cur_default and > then underline cursors; in this order. > > v2: > - export non-font interface for vgacon > - avoid interference from concurrent user space (Sashiko) > - fix function docs (Sashiko) > > Signed-off-by: Thomas Zimmermann <[email protected]> > Reviewed-by: Helge Deller <[email protected]> > --- > drivers/tty/vt/vt.c | 93 ++++++++++++++++++++++++++++++++++ > include/linux/console_struct.h | 7 +++ > 2 files changed, 100 insertions(+) > > diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c > index 57edf37495a8..5d2583cd6e79 100644 > --- a/drivers/tty/vt/vt.c > +++ b/drivers/tty/vt/vt.c > @@ -71,6 +71,7 @@ > * by Adam Tla/lka <[email protected]>, Aug 2006 > */ > > +#include <linux/compiler.h> > #include <linux/module.h> > #include <linux/types.h> > #include <linux/sched/signal.h> > @@ -264,6 +265,98 @@ unsigned int vc_font_size(const struct vc_font *font) > } > EXPORT_SYMBOL_GPL(vc_font_size); > > +/* > + * Cursors > + */ > + > +/** > + * vc_cursor_start - Calculates the cursor's first scanline within a > character cell > + * @cell_height: The overall height of the character cell > + * @cursor_size: The size constant of cursor pattern > + * > + * The parameter @cell_height is the height of the character cell as > + * displayed by the console. The argument given in @cursor_size is one > + * of the CUR_ constants, as stored in struct @vc_data.vc_cursor_type. > + * For unknown values, the helper draws the default cursor or an underline > + * dash. > + * > + * Returns: > + * The index of the cursor's first scanline within the character cell > + */ > +unsigned int vc_cursor_start(unsigned int cell_height, unsigned int > cursor_size) > +{ > + const unsigned int cursor_default_size = > CUR_SIZE(READ_ONCE(cur_default)); > + > +retry: > + switch (cursor_size) { > + case CUR_NONE: > + return cell_height; > + case CUR_UNDERLINE: > + if (cell_height < 10) > + return cell_height - 1; > + else > + return cell_height - 3; > + case CUR_LOWER_THIRD: > + return cell_height - cell_height / 3; > + case CUR_LOWER_HALF: > + return cell_height - cell_height / 2; > + case CUR_TWO_THIRDS: > + return cell_height - (cell_height * 2) / 3; > + case CUR_BLOCK: > + return 0; > + default: > + pr_warn_once("Unknown cursor %u\n", cursor_size);
Can userspace trigger this? If not, who can? > + if (cursor_size != cursor_default_size) > + cursor_size = cursor_default_size; > + else > + cursor_size = CUR_UNDERLINE; Why underline as a default? thanks, greg k-h
