diff options
author | emaste <emaste@FreeBSD.org> | 2014-05-29 21:52:42 +0000 |
---|---|---|
committer | emaste <emaste@FreeBSD.org> | 2014-05-29 21:52:42 +0000 |
commit | ad73b7a65dced17d0fd343cb331d2197ee671d8c (patch) | |
tree | f678fc0b15802b66b711d1823eb865394ec3c642 | |
parent | 8ef756fbbea701a6ffa6199b91419c97ef168d28 (diff) | |
download | FreeBSD-src-ad73b7a65dced17d0fd343cb331d2197ee671d8c.zip FreeBSD-src-ad73b7a65dced17d0fd343cb331d2197ee671d8c.tar.gz |
Correct vt(4) border calculations on font switch
If a vt(4) font does not exactly fit the screen dimensions, the console
window is offset so that it is centered. A rectangle is drawn at the
top, left, right, and bottom of the screen, to erase any leftovers that
are outside of the new usable console area.
If the x offset or y offset is 0 then the left border or top border
respectively is not drawn. The right and bottom borders may be one
pixel larger than necessary due to rounding, and are always drawn.
Prior to this change a 0 offset would result in a panic when calling
vt_drawrect with an x or y coordinate of -1.
Sponsored by: The FreeBSD Foundation
-rw-r--r-- | sys/dev/vt/vt_core.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/sys/dev/vt/vt_core.c b/sys/dev/vt/vt_core.c index 39b9265..900dafd 100644 --- a/sys/dev/vt/vt_core.c +++ b/sys/dev/vt/vt_core.c @@ -1171,22 +1171,27 @@ static int vt_set_border(struct vt_window *vw, struct vt_font *vf, term_color_t c) { struct vt_device *vd = vw->vw_device; - int l, r, t, b, w, h; + int x, y, off_x, off_y; if (vd->vd_driver->vd_drawrect == NULL) return (ENOTSUP); - w = vd->vd_width - 1; - h = vd->vd_height - 1; - l = vd->vd_offset.tp_col - 1; - r = w - l; - t = vd->vd_offset.tp_row - 1; - b = h - t; - - vd->vd_driver->vd_drawrect(vd, 0, 0, w, t, 1, c); /* Top bar. */ - vd->vd_driver->vd_drawrect(vd, 0, t, l, b, 1, c); /* Left bar. */ - vd->vd_driver->vd_drawrect(vd, r, t, w, b, 1, c); /* Right bar. */ - vd->vd_driver->vd_drawrect(vd, 0, b, w, h, 1, c); /* Bottom bar. */ + x = vd->vd_width - 1; + y = vd->vd_height - 1; + off_x = vd->vd_offset.tp_col; + off_y = vd->vd_offset.tp_row; + + /* Top bar. */ + if (off_y > 0) + vd->vd_driver->vd_drawrect(vd, 0, 0, x, off_y - 1, 1, c); + /* Left bar. */ + if (off_x > 0) + vd->vd_driver->vd_drawrect(vd, 0, off_y, off_x - 1, y - off_y, + 1, c); + /* Right bar. May be 1 pixel wider than necessary due to rounding. */ + vd->vd_driver->vd_drawrect(vd, x - off_x, off_y, x, y - off_y, 1, c); + /* Bottom bar. May be 1 mixel taller than necessary due to rounding. */ + vd->vd_driver->vd_drawrect(vd, 0, y - off_y, x, y, 1, c); return (0); } |