diff options
author | Bruce Evans <bde@FreeBSD.org> | 2017-04-03 09:21:00 +0000 |
---|---|---|
committer | Bruce Evans <bde@FreeBSD.org> | 2017-04-03 09:21:00 +0000 |
commit | 2b881cf4c6e57f5ad821d9a4824cf294f273d0fc (patch) | |
tree | 1381c3bc3ccc0557928729615ad4154ae467049c /usr.sbin/vidcontrol | |
parent | 1b8c842e06c1e7851299a7a5c6e53e085a9c15f2 (diff) | |
download | src-2b881cf4c6e57f5ad821d9a4824cf294f273d0fc.tar.gz src-2b881cf4c6e57f5ad821d9a4824cf294f273d0fc.zip |
Notes
Diffstat (limited to 'usr.sbin/vidcontrol')
-rw-r--r-- | usr.sbin/vidcontrol/vidcontrol.c | 95 |
1 files changed, 50 insertions, 45 deletions
diff --git a/usr.sbin/vidcontrol/vidcontrol.c b/usr.sbin/vidcontrol/vidcontrol.c index 5fc74b08dd4b..2cd9bfe53a1a 100644 --- a/usr.sbin/vidcontrol/vidcontrol.c +++ b/usr.sbin/vidcontrol/vidcontrol.c @@ -95,6 +95,7 @@ static int vesa_cols; static int vesa_rows; static int font_height; static int vt4_mode = 0; +static int video_mode_changed; static struct vid_info info; static struct video_info new_mode_info; @@ -117,25 +118,25 @@ static void init(void) { if (ioctl(0, VT_GETACTIVE, &cur_info.active_vty) == -1) - errc(1, errno, "getting active vty"); + err(1, "getting active vty"); cur_info.console_info.size = sizeof(cur_info.console_info); if (ioctl(0, CONS_GETINFO, &cur_info.console_info) == -1) - errc(1, errno, "getting console information"); + err(1, "getting console information"); /* vt(4) use unicode, so no screen mapping required. */ if (vt4_mode == 0 && ioctl(0, GIO_SCRNMAP, &cur_info.screen_map) == -1) - errc(1, errno, "getting screen map"); + err(1, "getting screen map"); if (ioctl(0, CONS_GET, &cur_info.video_mode_number) == -1) - errc(1, errno, "getting video mode number"); + err(1, "getting video mode number"); cur_info.video_mode_info.vi_mode = cur_info.video_mode_number; if (ioctl(0, CONS_MODEINFO, &cur_info.video_mode_info) == -1) - errc(1, errno, "getting video mode parameters"); + err(1, "getting video mode parameters"); } @@ -149,7 +150,9 @@ init(void) static void revert(void) { - int size[3]; + int save_errno, size[3]; + + save_errno = errno; ioctl(0, VT_ACTIVATE, cur_info.active_vty); @@ -160,24 +163,27 @@ revert(void) if (vt4_mode == 0) ioctl(0, PIO_SCRNMAP, &cur_info.screen_map); - if (cur_info.video_mode_number >= M_VESA_BASE) - ioctl(0, _IO('V', cur_info.video_mode_number - M_VESA_BASE), - NULL); - else - ioctl(0, _IO('S', cur_info.video_mode_number), NULL); - - if (cur_info.video_mode_info.vi_flags & V_INFO_GRAPHICS) { - size[0] = cur_info.video_mode_info.vi_width / 8; - size[1] = cur_info.video_mode_info.vi_height / - cur_info.console_info.font_size; - size[2] = cur_info.console_info.font_size; - - ioctl(0, KDRASTER, size); + if (video_mode_changed) { + if (cur_info.video_mode_number >= M_VESA_BASE) + ioctl(0, + _IO('V', cur_info.video_mode_number - M_VESA_BASE), + NULL); + else + ioctl(0, _IO('S', cur_info.video_mode_number), NULL); + if (cur_info.video_mode_info.vi_flags & V_INFO_GRAPHICS) { + size[0] = cur_info.video_mode_info.vi_width / 8; + size[1] = cur_info.video_mode_info.vi_height / + cur_info.console_info.font_size; + size[2] = cur_info.console_info.font_size; + ioctl(0, KDRASTER, size); + } } /* Restore some colors last since mode setting forgets some. */ fprintf(stderr, "\033[=%dF", cur_info.console_info.mv_norm.fore); fprintf(stderr, "\033[=%dG", cur_info.console_info.mv_norm.back); + + errno = save_errno; } @@ -298,7 +304,6 @@ load_scrnmap(const char *filename) rewind(fd); if (fread(&scrnmap, 1, size, fd) != (size_t)size) { - warnx("bad screenmap file"); fclose(fd); revert(); errx(1, "bad screenmap file"); @@ -307,7 +312,7 @@ load_scrnmap(const char *filename) if (ioctl(0, PIO_SCRNMAP, &scrnmap) == -1) { revert(); - errc(1, errno, "loading screenmap"); + err(1, "loading screenmap"); } fclose(fd); @@ -329,7 +334,7 @@ load_default_scrnmap(void) if (ioctl(0, PIO_SCRNMAP, &scrnmap) == -1) { revert(); - errc(1, errno, "loading default screenmap"); + err(1, "loading default screenmap"); } } @@ -346,7 +351,7 @@ print_scrnmap(void) if (ioctl(0, GIO_SCRNMAP, &map) == -1) { revert(); - errc(1, errno, "getting screenmap"); + err(1, "getting screenmap"); } for (i=0; i<sizeof(map); i++) { if (i != 0 && i % 16 == 0) @@ -415,7 +420,7 @@ load_default_vt4font(void) { if (ioctl(0, PIO_VFONT_DEFAULT) == -1) { revert(); - errc(1, errno, "loading default vt font"); + err(1, "loading default vt font"); } } @@ -574,7 +579,6 @@ load_font(const char *type, const char *filename) rewind(fd); if (fsize(fd) != size || fread(fontmap, 1, size, fd) != (size_t)size) { - warnx("%s: bad font file", filename); fclose(fd); free(fontmap); revert(); @@ -584,7 +588,7 @@ load_font(const char *type, const char *filename) if (ioctl(0, io, fontmap) == -1) { revert(); - errc(1, errno, "loading font"); + err(1, "loading font"); } fclose(fd); @@ -614,7 +618,7 @@ set_screensaver_timeout(char *arg) if (ioctl(0, CONS_BLANKTIME, &nsec) == -1) { revert(); - errc(1, errno, "setting screensaver period"); + err(1, "setting screensaver period"); } } @@ -641,7 +645,7 @@ set_cursor_type(char *appearance) if (ioctl(0, CONS_CURSORTYPE, &type) == -1) { revert(); - errc(1, errno, "setting cursor type"); + err(1, "setting cursor type"); } } @@ -694,7 +698,7 @@ video_mode(int argc, char **argv, int *mode_index) int new_mode_num = 0; unsigned long mode = 0; int cur_mode; - int ioerr; + int save_errno; int size[3]; int i; @@ -723,10 +727,10 @@ video_mode(int argc, char **argv, int *mode_index) if (modes[i].name == NULL) return; if (ioctl(0, mode, NULL) < 0) { - ioerr = errno; revert(); - errc(1, ioerr, "cannot set videomode"); + err(1, "cannot set videomode"); } + video_mode_changed = 1; } /* @@ -737,7 +741,7 @@ video_mode(int argc, char **argv, int *mode_index) if (ioctl(0, CONS_MODEINFO, &new_mode_info) == -1) { revert(); - errc(1, errno, "obtaining new video mode parameters"); + err(1, "obtaining new video mode parameters"); } if (mode == 0) { @@ -753,8 +757,9 @@ video_mode(int argc, char **argv, int *mode_index) if (ioctl(0, mode, NULL) == -1) { revert(); - errc(1, errno, "setting video mode"); + err(1, "setting video mode"); } + video_mode_changed = 1; /* * For raster modes it's not enough to just set the mode. @@ -791,7 +796,7 @@ video_mode(int argc, char **argv, int *mode_index) /* set raster mode */ if (ioctl(0, KDRASTER, size)) { - ioerr = errno; + save_errno = errno; if (cur_mode >= M_VESA_BASE) ioctl(0, _IO('V', cur_mode - M_VESA_BASE), @@ -799,8 +804,8 @@ video_mode(int argc, char **argv, int *mode_index) else ioctl(0, _IO('S', cur_mode), NULL); revert(); - errc(1, ioerr, - "cannot activate raster display"); + errno = save_errno; + err(1, "cannot activate raster display"); } } @@ -894,7 +899,7 @@ set_console(char *arg) errx(1, "console number out of range"); } else if (ioctl(0, VT_ACTIVATE, n) == -1) { revert(); - errc(1, errno, "switching vty"); + err(1, "switching vty"); } } @@ -934,7 +939,7 @@ set_mouse_char(char *arg) if (ioctl(0, CONS_MOUSECTL, &mouse) == -1) { revert(); - errc(1, errno, "setting mouse character"); + err(1, "setting mouse character"); } } @@ -959,7 +964,7 @@ set_mouse(char *arg) if (ioctl(0, CONS_MOUSECTL, &mouse) == -1) { revert(); - errc(1, errno, "%sing the mouse", + err(1, "%sing the mouse", mouse.operation == MOUSE_SHOW ? "show" : "hid"); } } @@ -981,7 +986,7 @@ set_lockswitch(char *arg) if (ioctl(0, VT_LOCKSWITCH, &data) == -1) { revert(); - errc(1, errno, "turning %s vty switching", + err(1, "turning %s vty switching", data == 0x01 ? "off" : "on"); } } @@ -1041,7 +1046,7 @@ show_adapter_info(void) if (ioctl(0, CONS_ADPINFO, &ad) == -1) { revert(); - errc(1, errno, "obtaining adapter information"); + err(1, "obtaining adapter information"); } printf("fb%d:\n", ad.va_index); @@ -1200,7 +1205,7 @@ dump_screen(int mode, int opt) if (ioctl(0, CONS_GETINFO, &_info) == -1) { revert(); - errc(1, errno, "obtaining current video mode parameters"); + err(1, "obtaining current video mode parameters"); return; } @@ -1218,7 +1223,7 @@ dump_screen(int mode, int opt) if (ioctl(0, CONS_SCRSHOT, &shot) == -1) { revert(); - errc(1, errno, "dumping screen"); + err(1, "dumping screen"); } if (mode == DUMP_FMT_RAW) { @@ -1284,7 +1289,7 @@ set_history(char *opt) if (ioctl(0, CONS_HISTORY, &size) == -1) { revert(); - errc(1, errno, "setting history buffer size"); + err(1, "setting history buffer size"); } } @@ -1298,7 +1303,7 @@ clear_history(void) { if (ioctl(0, CONS_CLRHIST) == -1) { revert(); - errc(1, errno, "clearing history buffer"); + err(1, "clearing history buffer"); } } |