Path: utzoo!utgpu!watmath!clyde!att!rutgers!uwvax!dave@cs.wisc.edu
From: dave@cs.wisc.edu (Dave Cohrs)
Newsgroups: comp.unix.wizards
Subject: Re: how do I tell the size of a pseudoterm window?
Keywords: xterm resize
Message-ID: <6766@spool.cs.wisc.edu>
Date: 1 Dec 88 23:29:42 GMT
References: <2081@vedge.UUCP>
Sender: news@spool.cs.wisc.edu
Reply-To: dave@cs.wisc.edu (Dave Cohrs)
Organization: U of Wisconsin CS Dept
Lines: 45

In article <2081@vedge.UUCP> lai@vedge.UUCP (David Lai) asks about
window sizes.

In 4.3BSD and related systems (SunOS 4.0 and Ultrix too), the current
size of a window is kept as part of the per-tty information, and you
can get/set it via a couple ioctls:

#include 

int
getwinsz()
{
	struct winsize ws;

	ioctl(f, TIOCGWINSZ, &ws);
	printf("current window size: %d x %d chars, %d x %d pixels\n",
		ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel);

	return 0;
}

The ioctl to set the window size is TIOCSWINSZ (f would be the fd of
your tty).  If you want to be signal()ed when some process changes
your window size, you use the SIGWINCH signal.

	signal(SIGWINCH, getwinsz);	/* your types may vary */

In this case, getwinsz() will be called whenever someone, like xterm
changes your window size.

There is an equivalent but different pair of ioctls on older SunOS's.
There doesn't appear to be such functionality in SystemV (they have
a different philosophy about what a window is, I think).

The TERMCAP variable won't automatically change.  If you have X, then
you have a "resize" program, and you can use it to change your TERMCAP
variable.  Of course, if you have an "ls" that look as your window
size, it should use the ioctl() as well, not just TERMCAP.  I suppose
you could hack your shell to change the TERMCAP variable for you.

dave cohrs
--
Dave Cohrs
+1 608 262-6617                        UW-Madison Computer Sciences Department
dave@cs.wisc.edu                       ...!{harvard,rutgers,ucbvax}!uwvax!dave