svn commit: r322708 - in head/sys: dev/syscons sys
Bruce Evans
bde at FreeBSD.org
Sat Aug 19 21:40:43 UTC 2017
Author: bde
Date: Sat Aug 19 21:40:42 2017
New Revision: 322708
URL: https://svnweb.freebsd.org/changeset/base/322708
Log:
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.
Modified:
head/sys/dev/syscons/scterm-teken.c
head/sys/dev/syscons/syscons.c
head/sys/dev/syscons/syscons.h
head/sys/sys/consio.h
Modified: head/sys/dev/syscons/scterm-teken.c
==============================================================================
--- head/sys/dev/syscons/scterm-teken.c Sat Aug 19 21:17:53 2017 (r322707)
+++ head/sys/dev/syscons/scterm-teken.c Sat Aug 19 21:40:42 2017 (r322708)
@@ -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:
Modified: head/sys/dev/syscons/syscons.c
==============================================================================
--- head/sys/dev/syscons/syscons.c Sat Aug 19 21:17:53 2017 (r322707)
+++ head/sys/dev/syscons/syscons.c Sat Aug 19 21:40:42 2017 (r322708)
@@ -873,6 +873,7 @@ sctty_ioctl(struct tty *tp, u_long cmd, caddr_t data,
{
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,
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 b
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 b
/* 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;
Modified: head/sys/dev/syscons/syscons.h
==============================================================================
--- head/sys/dev/syscons/syscons.h Sat Aug 19 21:17:53 2017 (r322707)
+++ head/sys/dev/syscons/syscons.h Sat Aug 19 21:40:42 2017 (r322708)
@@ -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 */
Modified: head/sys/sys/consio.h
==============================================================================
--- head/sys/sys/consio.h Sat Aug 19 21:17:53 2017 (r322707)
+++ head/sys/sys/consio.h Sat Aug 19 21:40:42 2017 (r322708)
@@ -187,9 +187,9 @@ typedef struct mouse_info mouse_info_t;
#define CONS_HIDDEN_CURSOR (1 << 2)
#define CONS_CURSOR_ATTRS (CONS_BLINK_CURSOR | CONS_CHAR_CURSOR | \
CONS_HIDDEN_CURSOR)
+#define CONS_SHAPEONLY_CURSOR (1 << 29)
#define CONS_RESET_CURSOR (1 << 30)
#define CONS_LOCAL_CURSOR (1U << 31)
-#define CONS_CURSOR_FLAGS (CONS_RESET_CURSOR | CONS_LOCAL_CURSOR)
struct cshape {
/* shape[0]: flags, shape[1]: base, shape[2]: height */
int shape[3];
More information about the svn-src-all
mailing list