[comp.sys.att] a program to fix your windows after the ua exits

geoff@burl.ATT.COM (geoff) (07/02/87)

I had the same problem as others on the net about the ua and word processor
leaving the screen funky after exiting.  I wrote the following (trivial)
program to restore your screen to a normal size.  It defaults to a standard
screen, but you can change this by changing ROWS, COLS, TOP, and LEFT.
It expects these parameters in characters and changes them to pixels before
making the call (changes to this are pretty obvious).
	cheers.

		geoff sherwood
		...![ ihnp4 ulysses cbosgd mgnetp ]!burl!geoff
		...![ ihnp4 cbosgd akgua masscomp ]!clyde!geoff
		
------------------------------- cut ---------------------------------

/* FIXWIND -- a program to restore (or change) window sizes
/* Copyright 1987 by Geoffrey C. Sherwood
/* This software may be freely distributed, but the author makes
/* no claims except that it seems to work.  Your mileage may vary.
/*
/* It looks for shell variables called COLS, ROWS, TOP, and LEFT
/* to determine desired window size and position.  It also looks
/* for WINDOWNAME to set the user line (what you see with the window
/* manager).  These values default to 80, 24, 0, 0, and "UNIX window"
/* if they are not set, giving you a standard borderless screen.
/* 
/* It was written to handle the annoying way that the ua and wp (the
/* word processor) leave your screen after you exit them.
/* */

#include <stdio.h>
#include <fcntl.h>
#include <sys/window.h>
main()
{
	struct utdata utd;
	struct uwdata uwd;
	int cols, rows, top, left;
	char *cp;
	char *getenv();

	/* find the windowname */
	utd.ut_num = WTXTUSER;
	if ((cp = getenv("WINDOWNAME")) == NULL) {
		cp = "UNIX window";
	}
	strncpy( utd.ut_text, cp, WTXTLEN );

	/* call ioctl to set window name */
	if (ioctl(0, WIOCSETTEXT, &utd) == -1) {
		perror("ioctl setting text");
	}


	/* find the number of rows the window needs */
	if ((cp = getenv("ROWS")) == NULL) {
		rows = 24;
	} else {
		rows = atoi( cp );
	}

	/* find the number of columns the window needs */
	if ((cp = getenv("COLS")) == NULL) {
		cols = 80;
	} else {
		cols = atoi( cp );
	}

	/* find the position of the top of the window */
	if ((cp = getenv("TOP")) == NULL) {
		top = 0;
	} else {
		top = atoi( cp );
	}

	/* find the position of the left edge of the window */
	if ((cp = getenv("LEFT")) == NULL) {
		left = 0;
	} else {
		left = atoi( cp );
	}

	/* copy the paramters into the structure and call ioctl
	 * to set them.
	 */
	uwd.uw_x = left*9;
	uwd.uw_y = top*12+12;
	uwd.uw_height = rows*12;
	uwd.uw_width = cols*9;
	uwd.uw_uflags = NBORDER;

	if (ioctl(0, WIOCSETD, &uwd) == -1) {
		perror("ioctl setting params");
	}
}