IRIS Keyboard & etc.
Rob Warnock
rpw3 at rigden.wpd.sgi.com
Tue Mar 6 16:06:46 AEST 1990
In article <2715 at fs1.cam.nist.gov> blue at cam.nist.gov (Jim Blue) writes:
+---------------
| I have been active at RTFM, all 31 volumes (though most of them don't apply)
| but haven't found how to get the number of lines and columns inside a wsh.
| (getsize() gives the size in pixels, but not in lines and columns.) Since vi,
| among other programs knows how to do this, it must be possible.
+---------------
Well, I don't know about "vi", but when porting a "lines&columns" app
to an Iris recently, I found the more-or-less-standard Berkeley kernel
screen size stuff [fragments attached below] to work just fine. That
is, TIOCGWINSZ to get the size, and SIGWINCH to know when it changes.
Resizing by dragging on a corner "does the right thing". So "wsh" must
be telling the kernel.
-Rob
-----
Rob Warnock, MS-9U/510 rpw3 at sgi.com rpw3 at pei.com
Silicon Graphics, Inc. (415)335-1673 Protocol Engines, Inc.
2011 N. Shoreline Blvd.
Mountain View, CA 94039-7311
============== attachment: code fragments ==================================
#ifdef TIOCGWINSZ /* try to get window size from kernel */
struct winsize winsize;
#ifdef SIGWINCH /* and if changing dynamically, track it
int onwinch();
#endif
#endif
==============
...somewhere in main()...
#ifdef SIGWINCH
signal(SIGWINCH, onwinch());
#endif
==============
...wherever it is (in main()?) you try to find out screen size...
#ifdef TIOCGWINSZ
if (ioctl(0, TIOCGWINSZ, &winsize) >= 0
&& winsize.ws_row > 0 /* avoid common stty screwup */
&& winsize.ws_col > 0 ) {
MaxRow = winsize.ws_row - 1; /* make 0-based */
MaxCol = winsize.ws_col - 1;
} else
#endif
{ /* just use termcap size */
MaxRow = tgetnum ("li") - 1;
MaxCol = tgetnum ("co") - 1;
}
...do whatever calculations are needed based on the screen size...
==============
#ifdef SIGWINCH
onwinch()
{
/*
* screen size changed -- do the right things
*/
if (ioctl(0, TIOCGWINSZ, &winsize) >= 0
&& winsize.ws_row > 0 /* avoid common stty screwup */
&& winsize.ws_col > 0 ) {
MaxRow = winsize.ws_row - 1;
MaxCol = winsize.ws_col - 1;
} else {
MaxRow = tgetnum ("li") - 1;
MaxCol = tgetnum ("co") - 1;
}
...do whatever calculations for values that have to change because
the screen size changed, then...
redraw(); /* clear and draw from scratch */
signal(SIGWINCH, onwinch); /* re-enable signal */
}
#endif
More information about the Comp.sys.sgi
mailing list