dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: deller@gmx.de, gregkh@linuxfoundation.org, jirislaby@kernel.org,
	simona@ffwll.ch
Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-serial@vger.kernel.org, sashiko-reviews@lists.linux.dev,
	Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH 1/5] vt: Add cursor-size helpers
Date: Fri, 11 Sep 2026 11:25:19 +0200	[thread overview]
Message-ID: <20260911094518.78093-2-tzimmermann@suse.de> (raw)
In-Reply-To: <20260911094518.78093-1-tzimmermann@suse.de>

Cursors in the VT subsystem are blocks within a character cell that are
filled with the foreground color. The new helpers vc_font_cursor_start()
and vc_font_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.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/tty/vt/vt.c            | 90 ++++++++++++++++++++++++++++++++++
 include/linux/console_struct.h |  2 +
 2 files changed, 92 insertions(+)

diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 8f467b22b799..87c4bc2ef495 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -264,6 +264,96 @@ unsigned int vc_font_size(const struct vc_font *font)
 }
 EXPORT_SYMBOL_GPL(vc_font_size);
 
+static unsigned int vc_cursor_start(unsigned int height, unsigned int cursor_size)
+{
+retry:
+	switch (cursor_size) {
+	case CUR_NONE:
+		return height;
+	case CUR_UNDERLINE:
+		if (height < 10)
+			return height - 1;
+		else
+			return height - 3;
+	case CUR_LOWER_THIRD:
+		return height - height / 3;
+	case CUR_LOWER_HALF:
+		return height - height / 2;
+	case CUR_TWO_THIRDS:
+		return height - (height * 2) / 3;
+	case CUR_BLOCK:
+		return 0;
+	default:
+		pr_warn_once("Unknown cursor %u\n", cursor_size);
+		if (cursor_size != CUR_SIZE(cur_default))
+			cursor_size = CUR_SIZE(cur_default);
+		else
+			cursor_size = CUR_UNDERLINE;
+		goto retry;
+	}
+}
+
+/**
+ * vc_font_cursor_start - Calculates the cursor's first scanline within a glyph
+ * @font: The VC font
+ * @cursor_type: The type of cursor pattern
+ *
+ * The parameter @font is an initialized font. The argument in @cursor_type
+ * is one of the CUR_ constants, as stored in struct @vc_data.vc_cursor_type. For
+ * unknown values, the helper draws an underline dash.
+ *
+ * Returns:
+ * The index of the cursor's first scanline within the glyph
+ */
+unsigned int vc_font_cursor_start(const struct vc_font *font, unsigned int cursor_type)
+{
+	return vc_cursor_start(font->height, CUR_SIZE(cursor_type));
+}
+EXPORT_SYMBOL_GPL(vc_font_cursor_start);
+
+static unsigned int vc_cursor_end(unsigned int height, unsigned int cursor_size)
+{
+retry:
+	switch (cursor_size) {
+	case CUR_UNDERLINE:
+		if (height < 10)
+			return height;
+		else
+			return height - 1;
+	case CUR_NONE:
+	case CUR_LOWER_THIRD:
+	case CUR_LOWER_HALF:
+	case CUR_TWO_THIRDS:
+	case CUR_BLOCK:
+		return height;
+	default:
+		pr_warn_once("Unknown cursor %u\n", cursor_size);
+		if (cursor_size != CUR_SIZE(cur_default))
+			cursor_size = CUR_SIZE(cur_default);
+		else
+			cursor_size = CUR_UNDERLINE;
+		goto retry;
+	}
+}
+
+/**
+ * vc_font_cursor_end - Calculates the first scanline after the cursor within a glyph
+ * @font: The VC font
+ * @cursor_type: The type of cursor pattern
+ *
+ * The parameter @font is an initialized font. The argument in @cursor_type
+ * is one of the CUR_ constants, as stored in struct @vc_data.vc_cursor_type. For
+ * unknown values, the helper draws an underline dash.
+ *
+ * Returns:
+ * The index of the first scanline after the cursor within the glyph
+ */
+unsigned int vc_font_cursor_end(const struct vc_font *font, unsigned int cursor_type)
+{
+	return vc_cursor_end(font->height, CUR_SIZE(cursor_type));
+}
+EXPORT_SYMBOL_GPL(vc_font_cursor_end);
+
 /*
  * /sys/class/tty/tty0/
  *
diff --git a/include/linux/console_struct.h b/include/linux/console_struct.h
index fe915afdece5..6f30f209e1b0 100644
--- a/include/linux/console_struct.h
+++ b/include/linux/console_struct.h
@@ -84,6 +84,8 @@ struct vc_font {
 
 unsigned int vc_font_pitch(const struct vc_font *font);
 unsigned int vc_font_size(const struct vc_font *font);
+unsigned int vc_font_cursor_start(const struct vc_font *font, unsigned int cursor_type);
+unsigned int vc_font_cursor_end(const struct vc_font *font, unsigned int cursor_type);
 
 /*
  * Example: vc_data of a console that was scrolled 3 lines down.
-- 
2.55.0


  reply	other threads:[~2026-09-11  9:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11  9:25 [PATCH 0/5] fbcon,vgacon,vt: Share helpers for text cursors Thomas Zimmermann
2026-09-11  9:25 ` Thomas Zimmermann [this message]
2026-09-11  9:55   ` [PATCH 1/5] vt: Add cursor-size helpers sashiko-bot
2026-09-12 19:01   ` Helge Deller
2026-09-11  9:25 ` [PATCH 2/5] vgacon: Remove trailing whitespaces Thomas Zimmermann
2026-09-11  9:46   ` sashiko-bot
2026-09-11  9:25 ` [PATCH 3/5] vgacon: Use vt_font_cursor_{start,end}() Thomas Zimmermann
2026-09-11  9:58   ` sashiko-bot
2026-09-11  9:25 ` [PATCH 4/5] lib/fonts: Add font_glyph_cursor() helper Thomas Zimmermann
2026-09-11  9:52   ` sashiko-bot
2026-09-11  9:25 ` [PATCH 5/5] fbcon: Replace fbcon_fill_cursor_mask() with fbcon_cursor_glyph() Thomas Zimmermann
2026-09-11  9:50   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260911094518.78093-2-tzimmermann@suse.de \
    --to=tzimmermann@suse.de \
    --cc=deller@gmx.de \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=simona@ffwll.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox