From: Thomas Zimmermann <tzimmermann@suse.de>
To: Jani Nikula <jani.nikula@linux.intel.com>,
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
Subject: Re: [PATCH v3 1/5] vt: Add cursor-size helpers
Date: Mon, 28 Sep 2026 13:45:14 +0200 [thread overview]
Message-ID: <2c5caf22-1fa4-43d7-95c0-782c111ab3f7@suse.de> (raw)
In-Reply-To: <7e3cccd612e87e6e85271a026d9fc737a56eaa6c@intel.com>
Hi
Am 28.09.26 um 11:07 schrieb Jani Nikula:
> On Mon, 28 Sep 2026, Thomas Zimmermann <tzimmermann@suse.de> 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.
>>
>> Users control the cursor size with the vt module's parameter cur_default
>> or with the ESC sequence \e[?Nc, where N is the cursor-size constant. In
>> case of an invalid setting, the new helpers fall back to cur_default and
>> then underline cursors; in this order.
>>
>> 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. VGA BIOSes also tend to use underline by.
>> default. Upon initialization vt applies its default to the console, but
>> each console might fall back to it own default. For example, running the
>> ESC code from above with the invalid constant of 8 magically flips the
>> cursor from underline to block size on vgacon. Another call with N set
>> to 0 (i.e., default) magically flips it back to underlyine. Making
>> underline the new default everywhere harmonizes vt, fbcon and most VGA
>> BIOSes.
>>
>> v3:
>> - mention user interfaces to control cursor size in commit message (GregKH)
>> - elaborate defaults (GregKH)
>> - move retry logic into helper
>> - handle CUR_DEF
>> v2:
>> - export non-font interface for vgacon
>> - avoid interference from concurrent user space (Sashiko)
>> - fix function docs (Sashiko)
>>
>> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
>> Reviewed-by: Helge Deller <deller@gmx.de>
>> ---
>> drivers/tty/vt/vt.c | 104 +++++++++++++++++++++++++++++++++
>> include/linux/console_struct.h | 7 +++
>> 2 files changed, 111 insertions(+)
>>
>> diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
>> index 57edf37495a8..8141296ccad0 100644
>> --- a/drivers/tty/vt/vt.c
>> +++ b/drivers/tty/vt/vt.c
>> @@ -71,6 +71,7 @@
>> * by Adam Tla/lka <atlka@pg.gda.pl>, Aug 2006
>> */
>>
>> +#include <linux/compiler.h>
>> #include <linux/module.h>
>> #include <linux/types.h>
>> #include <linux/sched/signal.h>
>> @@ -264,6 +265,109 @@ unsigned int vc_font_size(const struct vc_font *font)
>> }
>> EXPORT_SYMBOL_GPL(vc_font_size);
>>
>> +/*
>> + * Cursors
>> + */
>> +
>> +static unsigned int vc_cursor_size(unsigned int cursor_size)
>> +{
>> + const unsigned int cursor_default_size = CUR_SIZE(READ_ONCE(cur_default));
>> +
>> +retry:
>> + switch (cursor_size) {
>> + case CUR_NONE:
>> + case CUR_UNDERLINE:
>> + case CUR_LOWER_THIRD:
>> + case CUR_LOWER_HALF:
>> + case CUR_TWO_THIRDS:
>> + case CUR_BLOCK:
>> + return cursor_size;
>> + default:
>> + pr_warn_once("Unknown cursor %u\n", cursor_size);
>> + fallthrough;
>> + case CUR_DEF:
>> + /*
>> + * Use user-given default size, or underline if
>> + * the given default is invalid.
>> + */
>> + if (cursor_size != cursor_default_size)
>> + cursor_size = cursor_default_size;
>> + else
>> + cursor_size = CUR_UNDERLINE;
>> + goto retry;
> Complete bikeshed, but IMO goto for retries is ugly. It's fine for error
> handling, but this could trivially be a loop.
Ok. I have no strong opinion about it.
Best regards
Thomas
>
> BR,
> Jani.
>
>> + }
>> +}
>> +
>> +/**
>> + * 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)
>> +{
>> + switch (vc_cursor_size(cursor_size)) {
>> + case CUR_NONE:
>> + return cell_height;
>> + case CUR_UNDERLINE:
>> + default:
>> + 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;
>> + }
>> +}
>> +EXPORT_SYMBOL_GPL(vc_cursor_start);
>> +
>> +/**
>> + * vc_cursor_end - Calculates the first scanline after the cursor 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 first scanline after the cursor within the character cell
>> + */
>> +unsigned int vc_cursor_end(unsigned int cell_height, unsigned int cursor_size)
>> +{
>> + switch (vc_cursor_size(cursor_size)) {
>> + case CUR_UNDERLINE:
>> + default:
>> + if (cell_height < 10)
>> + return cell_height;
>> + else
>> + return cell_height - 1;
>> + case CUR_NONE:
>> + case CUR_LOWER_THIRD:
>> + case CUR_LOWER_HALF:
>> + case CUR_TWO_THIRDS:
>> + case CUR_BLOCK:
>> + return cell_height;
>> + }
>> +}
>> +EXPORT_SYMBOL_GPL(vc_cursor_end);
>> +
>> /*
>> * /sys/class/tty/tty0/
>> *
>> diff --git a/include/linux/console_struct.h b/include/linux/console_struct.h
>> index fe915afdece5..1d37c7898ea0 100644
>> --- a/include/linux/console_struct.h
>> +++ b/include/linux/console_struct.h
>> @@ -204,6 +204,10 @@ struct vc {
>> extern struct vc vc_cons [MAX_NR_CONSOLES];
>> extern void vc_SAK(struct work_struct *work);
>>
>> +/*
>> + * Cursors
>> + */
>> +
>> #define CUR_MAKE(size, change, set) ((size) | ((change) << 8) | \
>> ((set) << 16))
>> #define CUR_SIZE(c) ((c) & 0x00000f)
>> @@ -222,6 +226,9 @@ extern void vc_SAK(struct work_struct *work);
>> #define CUR_CHANGE(c) ((c) & 0x00ff00)
>> #define CUR_SET(c) (((c) & 0xff0000) >> 8)
>>
>> +unsigned int vc_cursor_start(unsigned int cell_height, unsigned int cursor_size);
>> +unsigned int vc_cursor_end(unsigned int cell_height, unsigned int cursor_size);
>> +
>> bool con_is_visible(const struct vc_data *vc);
>>
>> #endif /* _LINUX_CONSOLE_STRUCT_H */
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)
next prev parent reply other threads:[~2026-09-28 11:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 8:55 [PATCH v3 0/5] fbcon,vgacon,vt: Share helpers for text cursors Thomas Zimmermann
2026-09-28 8:55 ` [PATCH v3 1/5] vt: Add cursor-size helpers Thomas Zimmermann
2026-09-28 9:07 ` Jani Nikula
2026-09-28 11:45 ` Thomas Zimmermann [this message]
2026-10-01 8:59 ` Greg KH
2026-09-28 8:55 ` [PATCH v3 2/5] vgacon: Remove trailing whitespaces Thomas Zimmermann
2026-09-28 8:55 ` [PATCH v3 3/5] vgacon: Use vt_cursor_{start,end}() Thomas Zimmermann
2026-09-28 8:55 ` [PATCH v3 4/5] lib/fonts: Add font_glyph_cursor() helper Thomas Zimmermann
2026-09-28 8:55 ` [PATCH v3 5/5] fbcon: Replace fbcon_fill_cursor_mask() with fbcon_cursor_glyph() Thomas Zimmermann
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=2c5caf22-1fa4-43d7-95c0-782c111ab3f7@suse.de \
--to=tzimmermann@suse.de \
--cc=deller@gmx.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=gregkh@linuxfoundation.org \
--cc=jani.nikula@linux.intel.com \
--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