/******************************************************************************

  open_window.c

  This file contains two procecedures to do with opening windows.  The first,
  open_window creates a window with particular attributes and then maps
  it to the screen.

  SOURCE REFERENCES:
	Nye, A (1990)  The definitive guides to the X window system
		(Vol 2): Xlib Programming Manual for Version 11.  O'Reilly
		and Associates, Inc.: Sebastopol.

******************************************************************************/

#include "mainheader.h"			/* header file */

/******************************************************************************
		OPEN_WINDOW
******************************************************************************/

Window 
open_window(myDisplay,myScreen,myDepth,x, y, width, height)

/* This procedure creates a window with particular attributes and then maps
   it to the screen. */
Display         *myDisplay;             /* pointer to the display */
int             myScreen;               /* screen we are using */
int             myDepth;                /* colour plane depth */

int		x, y;			/* coords of top left corner of window */
int		width, height;		/* dimensions of the window */

{

/*--------- DECLARATIONS ---------*/
int 			border_width = 20;	/* border width of the window */

XSetWindowAttributes	myWindowAttributes;	/* structure of window attibutes */
unsigned long		myWindowMask;		/* mask for window attributes */
XSizeHints		theSizeHints;		/* window hints for window manger */
static Window		myWindow;		/* window structure */

/*----------------------------------------------------------------------------
	SET WINDOW ATTRIBUTES
----------------------------------------------------------------------------*/

/* border colour */
	myWindowAttributes.border_pixel = BlackPixel (myDisplay, myScreen);

/* background colour */
	myWindowAttributes.background_pixel = WhitePixel (myDisplay, myScreen);

/* if window manager intervenes or not */
	myWindowAttributes.override_redirect = True;

/* create mask for attributes */
	myWindowMask = CWBackPixel | CWBorderPixel | CWOverrideRedirect;

/*---------------------------------------------------------------------------- 
	CREATE THE WINDOW

  FOR MORE INFORMATION SEE:
	XCreateWindow		p. 124 and man XCreateWindow (3X11)
-----------------------------------------------------------------------------*/

	myWindow = XCreateWindow (myDisplay, 
				RootWindow (myDisplay, myScreen),
				x, y, width, height, border_width,
				myDepth, InputOutput, CopyFromParent,
				myWindowMask, &myWindowAttributes);

/*---------------------------------------------------------------------------- 
	SETUP HINTS FOR WINDOW MANAGER
----------------------------------------------------------------------------*/

	theSizeHints.flags 	= PPosition | PSize;	/* set mask for the hints */
	theSizeHints.x 		= x;			/* x position */
	theSizeHints.y 		= y;			/* y position */
	theSizeHints.width 	= width;		/* width of the window */
	theSizeHints.height 	= height;		/* height of the window */

/*---------------------------------------------------------------------------- 
	PASS HINTS TO WINDOW MANAGER

  FOR MORE INFORMATION SEE:
	XSetNormalHints		p. 456
-----------------------------------------------------------------------------*/

	XSetNormalHints (myDisplay, myWindow, &theSizeHints);

/*---------------------------------------------------------------------------- 
	MAP WINDOW ONTO THE SCREEN

  FOR MORE INFORMATION SEE:
	XMapWindow		p. 318 and man XMapWindow(3X11)
	XFlush			p. 192 and man XFlush(3X11)
-----------------------------------------------------------------------------*/

	XMapWindow (myDisplay, myWindow);

	XFlush (myDisplay);

	return(myWindow);

}
/****************************************************************************
		END OF FILE OPEN_WINDOW.C
****************************************************************************/

