From: Simon Glass <simon.glass@canonical.com>
The left margin should be per-context so that different clients can
maintain their own margin settings. Move the xstart_frac field from
vidconsole_priv into vidconsole_ctx.
Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---
drivers/video/console_truetype.c | 2 +-
drivers/video/vidconsole-uclass.c | 14 +++++++-------
include/video_console.h | 6 +++---
3 files changed, 11 insertions(+), 11 deletions(-)
@@ -944,7 +944,7 @@ static void select_metrics(struct udevice *dev, struct console_tt_metrics *met)
priv->cur_met = met;
com->x_charsize = met->font_size;
com->y_charsize = met->font_size;
- vc_priv->xstart_frac = VID_TO_POS(2);
+ com->xstart_frac = VID_TO_POS(2);
com->cols = vid_priv->xsize / met->font_size;
com->rows = vid_priv->ysize / met->font_size;
vc_priv->tab_width_frac = VID_TO_POS(met->font_size) * 8 / 2;
@@ -77,7 +77,7 @@ static int vidconsole_back(struct udevice *dev)
vidconsole_hide_cursor(dev);
ctx->xcur_frac -= VID_TO_POS(ctx->x_charsize);
- if (ctx->xcur_frac < priv->xstart_frac) {
+ if (ctx->xcur_frac < ctx->xstart_frac) {
ctx->xcur_frac = (ctx->cols - 1) *
VID_TO_POS(ctx->x_charsize);
ctx->ycur -= ctx->y_charsize;
@@ -100,7 +100,7 @@ static void vidconsole_newline(struct udevice *dev)
const int rows = CONFIG_VAL(CONSOLE_SCROLL_LINES);
int i, ret;
- ctx->xcur_frac = priv->xstart_frac;
+ ctx->xcur_frac = ctx->xstart_frac;
ctx->ycur += ctx->y_charsize;
/* Check if we need to scroll the terminal */
@@ -139,7 +139,7 @@ void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y)
vidconsole_hide_cursor(dev);
ctx->xcur_frac = VID_TO_POS(x);
- priv->xstart_frac = ctx->xcur_frac;
+ ctx->xstart_frac = ctx->xcur_frac;
ctx->ycur = y;
/* make sure not to kern against the previous character */
@@ -182,7 +182,7 @@ static void get_cursor_position(struct vidconsole_priv *priv,
struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv);
*row = ctx->ycur / ctx->y_charsize;
- *col = VID_TO_PIXEL(ctx->xcur_frac - priv->xstart_frac) /
+ *col = VID_TO_PIXEL(ctx->xcur_frac - ctx->xstart_frac) /
ctx->x_charsize;
}
@@ -333,7 +333,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch)
#endif
}
ctx->ycur = 0;
- ctx->xcur_frac = priv->xstart_frac;
+ ctx->xcur_frac = ctx->xstart_frac;
} else {
debug("unsupported clear mode: %d\n", mode);
}
@@ -507,7 +507,7 @@ int vidconsole_put_char(struct udevice *dev, char ch)
/* beep */
break;
case '\r':
- ctx->xcur_frac = priv->xstart_frac;
+ ctx->xcur_frac = ctx->xstart_frac;
break;
case '\n':
vidconsole_newline(dev);
@@ -984,7 +984,7 @@ void vidconsole_set_bitmap_font(struct udevice *dev,
ctx->rows = vid_priv->ysize / fontdata->height;
/* xsize_frac is set in vidconsole_pre_probe() */
}
- vc_priv->xstart_frac = 0;
+ ctx->xstart_frac = 0;
}
void vidconsole_idle(struct udevice *dev)
@@ -113,6 +113,7 @@ struct vidconsole_ansi {
* @ansi: ANSI escape-sequence state
* @utf8_buf: Buffer to accumulate UTF-8 byte sequence
* @curs: Cursor state and management
+ * @xstart_frac: Left margin for the text console in fractional units
*/
struct vidconsole_ctx {
int rows;
@@ -128,13 +129,14 @@ struct vidconsole_ctx {
struct vidconsole_ansi ansi;
char utf8_buf[5];
struct vidconsole_cursor curs;
+ int xstart_frac;
};
/**
* struct vidconsole_priv - uclass-private data about a console device
*
* Drivers must set up @ctx.rows, @ctx.cols, @ctx.x_charsize, @ctx.y_charsize
- * in their probe() method. Drivers may set up @xstart_frac if desired.
+ * in their probe() method. Drivers may set up @ctx.xstart_frac if desired.
*
* Note that these values relate to the rotated console, so that an 80x25
* console which is rotated 90 degrees will have rows=80 and cols=25
@@ -148,7 +150,6 @@ struct vidconsole_ctx {
* @ctx: Per-client context
* @tab_width_frac: Tab width in fractional units
* @xsize_frac: Width of the display in fractional units
- * @xstart_frac: Left margin for the text console in fractional units
* @quiet: Suppress all output from stdio
*/
struct vidconsole_priv {
@@ -156,7 +157,6 @@ struct vidconsole_priv {
struct vidconsole_ctx ctx;
int tab_width_frac;
int xsize_frac;
- int xstart_frac;
bool quiet;
};