Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!ucla-cs!elroy.jpl.nasa.gov!decwrl!sgi!rpw3@rigden.wpd.sgi.com From: rpw3@rigden.wpd.sgi.com (Rob Warnock) Newsgroups: comp.sys.sgi Subject: Re: IRIS Keyboard & etc. Message-ID: <52816@sgi.sgi.com> Date: 6 Mar 90 06:06:46 GMT References: <2715@fs1.cam.nist.gov> Sender: rpw3@rigden.wpd.sgi.com Reply-To: rpw3@rigden.UUCP (Robert P. Warnock) Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 79 In article <2715@fs1.cam.nist.gov> blue@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@sgi.com rpw3@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