#include "wm.h"

int screencount;
wmScreen *screens;

void initscreen(int s)
{
	XGCValues gv;
	XSetWindowAttributes attr;

	screens[s].rootwindow = RootWindow(display, s);
	screens[s].width = DisplayWidth(display, s);
	screens[s].height = DisplayHeight(display, s);
	screens[s].black = BlackPixel(display, s);
	screens[s].white = WhitePixel(display, s);

	gv.foreground = screens[s].black ^ screens[s].white;
	gv.background = screens[s].white;

	screens[s].gc = XCreateGC( display, screens[s].rootwindow,
		GCForeground | GCBackground, &gv);

	attr.event_mask = ExposureMask |
		SubstructureRedirectMask | SubstructureNotifyMask |
		ButtonPressMask | ButtonReleaseMask |
		PropertyChangeMask | EnterWindowMask;

	attr.background_pixel = screens[s].black;

	XChangeWindowAttributes( display, screens[s].rootwindow,
		CWEventMask | CWBackPixel, &attr);

	XClearWindow(display, screens[s].rootwindow);	

	XSync(display, 0);
}

void initscreens()
{
	int s;
	screencount = ScreenCount(display);
	screens = (wmScreen *) malloc(screencount * sizeof(wmScreen));

	for (s = 0; s < screencount; s++) {
		/* order */
		initscreen(s);
		initcursor(s);
	}
}

