aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/syscons
diff options
context:
space:
mode:
authorBruce Evans <bde@FreeBSD.org>2017-08-19 21:40:42 +0000
committerBruce Evans <bde@FreeBSD.org>2017-08-19 21:40:42 +0000
commit4ea1f4f5eaa9722ffe01aa493e0b60b818e4f14e (patch)
tree5cc49889ef63ee9e4fdd96db6b6b12749256d2be /sys/dev/syscons
parentcef5e2bd91b4fe56b6704846da5502be31945a15 (diff)
downloadsrc-4ea1f4f5eaa9722ffe01aa493e0b60b818e4f14e.tar.gz
src-4ea1f4f5eaa9722ffe01aa493e0b60b818e4f14e.zip
Rename curr_curs_attr to base_curr_attr. The actual current cursor
attribute field is curs_attr. The base field holds user data translated in a reversible way and is needed because current field holds this in an irreversible way for efficiency. Factor out some common code for the reversible translation. This is slightly simpler now, and much easier to expand. Translate the magic flags value -1 to a single control flag internally up front so other flags can be trusted later. This can be used for the relevant ioctl() too. Remove CONS_CURSOR_FLAGS which contained all the control flags. It was unused and not useful. After adding more flags, there will be tests on a couple at a time but never on them all. This API should have used this to disallow unknown flags.
Notes
Notes: svn path=/head/; revision=322708
Diffstat (limited to 'sys/dev/syscons')
-rw-r--r--sys/dev/syscons/scterm-teken.c4
-rw-r--r--sys/dev/syscons/syscons.c71
-rw-r--r--sys/dev/syscons/syscons.h2
3 files changed, 44 insertions, 33 deletions
diff --git a/sys/dev/syscons/scterm-teken.c b/sys/dev/syscons/scterm-teken.c
index 8aebac8e1cb3..617a72b633a4 100644
--- a/sys/dev/syscons/scterm-teken.c
+++ b/sys/dev/syscons/scterm-teken.c
@@ -730,9 +730,9 @@ scteken_param(void *arg, int cmd, unsigned int value)
break;
case TP_SHOWCURSOR:
if (value != 0)
- flags = scp->curr_curs_attr.flags & ~CONS_HIDDEN_CURSOR;
+ flags = scp->base_curs_attr.flags & ~CONS_HIDDEN_CURSOR;
else
- flags = scp->curr_curs_attr.flags | CONS_HIDDEN_CURSOR;
+ flags = scp->base_curs_attr.flags | CONS_HIDDEN_CURSOR;
sc_change_cursor_shape(scp, flags | CONS_LOCAL_CURSOR, -1, -1);
break;
case TP_SWITCHVT:
diff --git a/sys/dev/syscons/syscons.c b/sys/dev/syscons/syscons.c
index 4141dea4b05f..bf610c993027 100644
--- a/sys/dev/syscons/syscons.c
+++ b/sys/dev/syscons/syscons.c
@@ -873,6 +873,7 @@ sctty_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
{
int error;
int i;
+ struct cursor_attr *cap;
sc_softc_t *sc;
scr_stat *scp;
int s;
@@ -942,15 +943,17 @@ sctty_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
return 0;
case CONS_GETCURSORSHAPE: /* get cursor shape (new interface) */
- if (((int *)data)[0] & CONS_LOCAL_CURSOR) {
- ((int *)data)[0] = scp->curr_curs_attr.flags;
- ((int *)data)[1] = scp->curr_curs_attr.base;
- ((int *)data)[2] = scp->curr_curs_attr.height;
- } else {
- ((int *)data)[0] = sc->curs_attr.flags;
- ((int *)data)[1] = sc->curs_attr.base;
- ((int *)data)[2] = sc->curs_attr.height;
+ switch (((int *)data)[0] & CONS_LOCAL_CURSOR) {
+ case 0:
+ cap = &sc->curs_attr;
+ break;
+ case CONS_LOCAL_CURSOR:
+ cap = &scp->base_curs_attr;
+ break;
}
+ ((int *)data)[1] = cap->base;
+ ((int *)data)[2] = cap->height;
+ ((int *)data)[0] = cap->flags;
return 0;
case CONS_SETCURSORSHAPE: /* set cursor shape (new interface) */
@@ -2982,15 +2985,15 @@ update_cursor_image(scr_stat *scp)
void
sc_set_cursor_image(scr_stat *scp)
{
- scp->curs_attr.flags = scp->curr_curs_attr.flags;
+ scp->curs_attr = scp->base_curs_attr;
if (scp->curs_attr.flags & CONS_HIDDEN_CURSOR) {
/* hidden cursor is internally represented as zero-height underline */
scp->curs_attr.flags = CONS_CHAR_CURSOR;
scp->curs_attr.base = scp->curs_attr.height = 0;
} else if (scp->curs_attr.flags & CONS_CHAR_CURSOR) {
- scp->curs_attr.base = imin(scp->curr_curs_attr.base,
+ scp->curs_attr.base = imin(scp->base_curs_attr.base,
scp->font_size - 1);
- scp->curs_attr.height = imin(scp->curr_curs_attr.height,
+ scp->curs_attr.height = imin(scp->base_curs_attr.height,
scp->font_size - scp->curs_attr.base);
} else { /* block cursor */
scp->curs_attr.base = 0;
@@ -3005,19 +3008,30 @@ sc_set_cursor_image(scr_stat *scp)
}
static void
+sc_adjust_ca(struct cursor_attr *cap, int flags, int base, int height)
+{
+ if (0) {
+ /* Dummy clause to avoid changing indentation later. */
+ } else {
+ if (base >= 0)
+ cap->base = base;
+ if (height >= 0)
+ cap->height = height;
+ if (!(flags & CONS_SHAPEONLY_CURSOR))
+ cap->flags = flags & CONS_CURSOR_ATTRS;
+ }
+}
+
+static void
change_cursor_shape(scr_stat *scp, int flags, int base, int height)
{
if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp))
sc_remove_cursor_image(scp);
- if (base >= 0)
- scp->curr_curs_attr.base = base;
- if (height >= 0)
- scp->curr_curs_attr.height = height;
if (flags & CONS_RESET_CURSOR)
- scp->curr_curs_attr = scp->dflt_curs_attr;
+ scp->base_curs_attr = scp->dflt_curs_attr;
else
- scp->curr_curs_attr.flags = flags & CONS_CURSOR_ATTRS;
+ sc_adjust_ca(&scp->base_curs_attr, flags, base, height);
if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp)) {
sc_set_cursor_image(scp);
@@ -3033,8 +3047,11 @@ sc_change_cursor_shape(scr_stat *scp, int flags, int base, int height)
int s;
int i;
+ if (flags == -1)
+ flags = CONS_SHAPEONLY_CURSOR;
+
s = spltty();
- if ((flags != -1) && (flags & CONS_LOCAL_CURSOR)) {
+ if (flags & CONS_LOCAL_CURSOR) {
/* local (per vty) change */
change_cursor_shape(scp, flags, base, height);
splx(s);
@@ -3043,16 +3060,10 @@ sc_change_cursor_shape(scr_stat *scp, int flags, int base, int height)
/* global change */
sc = scp->sc;
- if (base >= 0)
- sc->curs_attr.base = base;
- if (height >= 0)
- sc->curs_attr.height = height;
- if (flags != -1) {
- if (flags & CONS_RESET_CURSOR)
- sc->curs_attr = sc->dflt_curs_attr;
- else
- sc->curs_attr.flags = flags & CONS_CURSOR_ATTRS;
- }
+ if (flags & CONS_RESET_CURSOR)
+ sc->curs_attr = sc->dflt_curs_attr;
+ else
+ sc_adjust_ca(&sc->curs_attr, flags, base, height);
for (i = sc->first_vty; i < sc->first_vty + sc->vtys; ++i) {
if ((tp = SC_DEV(sc, i)) == NULL)
@@ -3212,7 +3223,7 @@ scinit(int unit, int flags)
sc->dflt_curs_attr.height = howmany(scp->font_size, 8);
sc->dflt_curs_attr.flags = 0;
sc->curs_attr = sc->dflt_curs_attr;
- scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
+ scp->base_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
#ifndef SC_NO_SYSMOUSE
sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
@@ -3525,7 +3536,7 @@ init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
scp->ts = NULL;
scp->rndr = NULL;
scp->border = (SC_NORM_ATTR >> 4) & 0x0f;
- scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
+ scp->base_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
scp->mouse_cut_start = scp->xsize*scp->ysize;
scp->mouse_cut_end = -1;
scp->mouse_signal = 0;
diff --git a/sys/dev/syscons/syscons.h b/sys/dev/syscons/syscons.h
index 491404c51862..fc9c8f50b07d 100644
--- a/sys/dev/syscons/syscons.h
+++ b/sys/dev/syscons/syscons.h
@@ -313,7 +313,7 @@ typedef struct scr_stat {
int cursor_pos; /* cursor buffer position */
int cursor_oldpos; /* cursor old buffer position */
struct cursor_attr dflt_curs_attr;
- struct cursor_attr curr_curs_attr;
+ struct cursor_attr base_curs_attr;
struct cursor_attr curs_attr;
int mouse_pos; /* mouse buffer position */