From 299884750e87e05c9d804e7f0fbcb08e02b37a8d Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sat, 16 Sep 2006 14:35:58 -0700 Subject: [PATCH] Proper handling of different screen sizes (we're 78x29 in graphics mode...) --- com32/include/unistd.h | 1 + com32/lib/Makefile | 2 +- com32/lib/sys/ansicon_write.c | 7 ++++--- com32/lib/sys/file.h | 5 +++++ com32/lib/sys/isatty.c | 1 + com32/lib/sys/opendev.c | 3 +-- com32/lib/sys/vesacon_write.c | 9 ++++++++- com32/modules/menumain.c | 15 +++++++++++++++ 8 files changed, 36 insertions(+), 7 deletions(-) diff --git a/com32/include/unistd.h b/com32/include/unistd.h index 84120d3..d0b8309 100644 --- a/com32/include/unistd.h +++ b/com32/include/unistd.h @@ -20,6 +20,7 @@ __extern ssize_t write(int, const void *, size_t); __extern int isatty(int); +__extern int getscreensize(int, int *, int *); /* Standard file descriptor numbers. */ #define STDIN_FILENO 0 diff --git a/com32/lib/Makefile b/com32/lib/Makefile index e3cef23..a6355c9 100644 --- a/com32/lib/Makefile +++ b/com32/lib/Makefile @@ -28,7 +28,7 @@ LIBOBJS = \ sys/fileinfo.o sys/opendev.o sys/read.o sys/write.o sys/ftell.o \ sys/close.o sys/open.o sys/fileread.o sys/fileclose.o \ sys/isatty.o sys/fstat.o sys/openconsole.o sys/line_input.o \ - sys/colortable.o \ + sys/colortable.o sys/screensize.o \ \ sys/stdcon_read.o sys/stdcon_write.o sys/rawcon_read.o \ sys/rawcon_write.o sys/err_read.o sys/err_write.o \ diff --git a/com32/lib/sys/ansicon_write.c b/com32/lib/sys/ansicon_write.c index 1fab2ac..c500adb 100644 --- a/com32/lib/sys/ansicon_write.c +++ b/com32/lib/sys/ansicon_write.c @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 2004 H. Peter Anvin - All Rights Reserved + * Copyright 2004-2006 H. Peter Anvin - All Rights Reserved * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -80,8 +80,6 @@ int __ansicon_open(struct file_info *fp) static com32sys_t ireg; /* Auto-initalized to all zero */ com32sys_t oreg; - (void)fp; - if (!ansicon_counter) { /* Are we disabled? */ ireg.eax.w[0] = 0x000b; @@ -109,6 +107,9 @@ int __ansicon_open(struct file_info *fp) } } + fp->o.rows = ti.rows; + fp->o.cols = ti.cols; + ansicon_counter++; return 0; } diff --git a/com32/lib/sys/file.h b/com32/lib/sys/file.h index 3b73848..6138608 100644 --- a/com32/lib/sys/file.h +++ b/com32/lib/sys/file.h @@ -91,6 +91,11 @@ struct file_info { char *datap; /* Current data pointer */ char buf[MAXBLOCK]; } i; + + /* Output file data */ + struct { + int rows, cols; /* Rows and columns */ + } o; }; extern struct file_info __file_info[NFILES]; diff --git a/com32/lib/sys/isatty.c b/com32/lib/sys/isatty.c index c0a14db..837a90a 100644 --- a/com32/lib/sys/isatty.c +++ b/com32/lib/sys/isatty.c @@ -48,5 +48,6 @@ int isatty(int fd) return -1; } + /* __DEV_TTY == 1 */ return (fp->iop->flags & __DEV_TTY); } diff --git a/com32/lib/sys/opendev.c b/com32/lib/sys/opendev.c index 1bcc101..a61da0c 100644 --- a/com32/lib/sys/opendev.c +++ b/com32/lib/sys/opendev.c @@ -61,10 +61,9 @@ int opendev(const struct input_dev *idev, return -1; } + /* The file structure is already zeroed */ fp->iop = &dev_error_r; fp->oop = &dev_error_w; - fp->i.offset = 0; - fp->i.nbytes = 0; fp->i.datap = fp->i.buf; if (idev) { diff --git a/com32/lib/sys/vesacon_write.c b/com32/lib/sys/vesacon_write.c index da94006..7f1570b 100644 --- a/com32/lib/sys/vesacon_write.c +++ b/com32/lib/sys/vesacon_write.c @@ -85,15 +85,22 @@ int __vesacon_open(struct file_info *fp) ti.disabled = 1; } else { /* Switch mode */ - if (__vesacon_init()) + if (__vesacon_init()) { + vesacon_counter = -1; return EAGAIN; + } /* Initial state */ __ansi_init(&ti); ti.rows = __vesacon_text_rows; } + } else if (vesacon_counter == -1) { + return EAGAIN; } + fp->o.rows = ti.rows; + fp->o.cols = ti.cols; + vesacon_counter++; return 0; } diff --git a/com32/modules/menumain.c b/com32/modules/menumain.c index 282618c..433f169 100644 --- a/com32/modules/menumain.c +++ b/com32/modules/menumain.c @@ -845,12 +845,27 @@ execute(const char *cmdline) int menu_main(int argc, char *argv[]) { const char *cmdline; + int rows, cols; + int i; (void)argc; install_default_color_table(); + if (getscreensize(1, &rows, &cols)) { + /* Unknown screen size? */ + rows = 24; + cols = 80; + } + + WIDTH = cols; parse_config(argv[1]); + /* If anyone has specified negative parameters, consider them + relative to the bottom row of the screen. */ + for (i = 0; mparm[i].name; i++) + if (mparm[i].value < 0) + mparm[i].value = max(mparm[i].value+rows, 0); + if (draw_background) draw_background(menu_background); -- 2.7.4