Path: utzoo!utgpu!watmath!clyde!att!rutgers!ucsd!sdcsvax!ucsdhub!esosun!seismo!uunet!auspex!guy From: guy@auspex.UUCP (Guy Harris) Newsgroups: comp.unix.wizards Subject: Re: how do I tell the size of a pseudoterm window? Keywords: xterm resize Message-ID: <561@auspex.UUCP> Date: 2 Dec 88 10:16:22 GMT References: <2081@vedge.UUCP> Reply-To: guy@auspex.UUCP (Guy Harris) Organization: Auspex Systems, Santa Clara Lines: 66 >1) How is a program able to tell the size of a pseudoterm's window. Many systems have adopted the 4.3BSD TIOCGWINSZ "ioctl"; the kernel stores the screen size along with the tty modes. SunOS 3.2 and later has it, and I'd suspect many of the other "started with BSD" UNIX systems do as well. (Some may have stuck at 4.2BSD level, though, and haven't picked it up.) SunOS releases prior to 3.2 had TIOCGSIZE, which was a Sun invention which antedated 4.3BSD (for better or worse, Berkeley didn't pick Sun's version up). (Yes, I know it's not in the 3.x documentation, but it is there, along with "stty size", "stty rows", and "stty cols".) > Is there a termcap entry which specifies that the screen can be > resized? (The termcap man pages dont mention it). No, and that's why the "termcap" man pages don't mention it. Instead, you have: 1) the Sun mechanism, wherein the "termcap" library code does a TIOCGSIZE or TIOCGWINSZ, and if the sizes it gets back are non-zero, it ignores the ones in the "termcap" entry and uses the ones from the "ioctl"; 2) the 4.3BSD mechanism, where this is left up to the code that uses the "termcap" library routines; "curses" does it for you, but programs that don't use "curses", such as "vi", have to be modified to do the "ioctl" and override the values in the "termcap" entry. (In SunOS the S5 "curses"/"terminfo" library takes approach 1), so applications don't have to know about it.) > How does a program get 'signalled' when a resize occurs (ie. like vi > doing a redraw after a resize) ? If the window size for a pseudo-tty is changed, a SIGWINCH signal is delivered to the process group for that pseudo-tty. >2) How can the termcap be modified automatically when a 'resize' occurs, when > not in a program (ie at the shell prompt)? This would be useful so that > the next 'ls' or other such commands would output an appropriate number > of columns. With difficulty, at best. The 4.3BSD scheme, and the SunOS scheme which preceded it, render this unnecessary, since software that cares how big the screen is tries the "ioctl" first and, only if it returns zero for the sizes, uses the value from the "termcap" entry. >I am looking for a general case solution which should be able to be >applied to various windowing systems. Does this involve a special >tty/pty driver? The technique described above requires: 1) a tty/pty driver which supports TIOCGWINSZ/TIOCSWINSZ or equivalents (such as the older SunOS TIOCGSIZE/TIOCSSIZE); 2) a SIGWINCH signal, and some way for it to be delivered when the window size is changed (if you do the 4.3BSD TIOCSWINSZ "ioctl", which sets the sizes, on either the master or slave side, the tty driver delivers a SIGWINCH if the sizes are actually being changed). 4.3BSD has all this, as does SunOS and, as indicated above, many other "started with BSD" systems. Various System V releases, and other UNIX variants, may have picked it up as well.