Re: [PATCH 2/2] vt: add TIOCL_GETCURSORPOS to retrieve the screen cursor position

Jiri Slaby
2025-05-14T05:57:57Z

On 14. 05. 25, 3:52, Nicolas Pitre wrote:
...
> So let's work around this limitation by adding TIOCL_GETCURSORPOS as a
> fallback method to get the cursor position when /dev/vcsa reports 255.
...
> --- a/drivers/tty/vt/vt.c
> +++ b/drivers/tty/vt/vt.c
...
> +/* invoked via ioctl(TIOCLINUX) */
> +static int get_cursor_pos(struct tty_struct *tty)
> +{
> + struct vc_data *vc = tty->driver_data;
> + unsigned int x, y;
> +
> + console_lock();
> + x = vc->state.x;
> + y = vc->state.y;
> + console_unlock();
> +
> + /*
> + * Clamp x to 16 bits, y to 15 bits. A display larger than 65535x32767
> + * characters won't be a concern for the foreseeable future.
> + * Bit 31 is reserved to represent negative error codes elsewhere.
> + */
> + return min(x, 0xFFFFu) | (min(y, 0x7FFFu) << 16);

Hmm, I would do a proper struct instead. Like winsize.

> --- a/include/uapi/linux/tiocl.h
> +++ b/include/uapi/linux/tiocl.h
> @@ -38,4 +38,8 @@ struct tiocl_selection {
> #define TIOCL_GETKMSGREDIRECT 17 /* get the vt the kernel messages are restricted to */
> #define TIOCL_GETBRACKETEDPASTE 18 /* get whether paste may be bracketed */
>
> +#define TIOCL_GETCURSORPOS 20 /* Get screen cursor position */

The same question about man-pages :).

thanks,
--
js
suse labs