Hello,

I'm currently on my own window manager/system... just to see if I could do it, really.
Most of the mechanics of moving the windows, resizing them, etc. has been laid down, I'm currently working on repainting the windows as necessary. However, I seem to be encountering some trouble. Debugging seems to indicate that there may be an issue with the following function:-
Code:
t_region *difference(short sX, short sY, short sWidth, short sHeight, short sX1, short sY1, short sWidth1, short sHeight1)
{
	t_region *regions = NULL, *current;

	if (sX < sX1)
	{
		current = create_region(sX, sY, (sX + sWidth < sX1) ? sWidth : sX1, sHeight);
		regions = append_regions(regions, current);
	}

	if (sX + sWidth > sX1 + sWidth1)
	{
		current = create_region((sX > sX1 + sWidth1) ? sX : sX1 + sWidth1, sY, sWidth - sWidth1, sHeight);
		regions = append_regions(regions, current);
	}

	if (sY < sY1)
	{
		current = create_region(sX, sY, sWidth, (sY + sHeight < sY1) ? sHeight : sY1);
		regions = append_regions(regions, current);
	}

	if (sY + sHeight > sY1 + sHeight1)
	{
		current = create_region(sX, (sY > sY1 + sHeight1) ? sY : sY1 + sHeight1, sWidth, sHeight - sHeight1);
		regions = append_regions(regions, current);
	}

	return regions;
}
The function is supposed to find the difference of two overlapping rectangles (the area left when one is "subtracted" from the other). As I don't fancy messing about with complex polygons it simply returns up to 4 rectangles describing the area left.

I've googled for a couple of days looking for a clear reference to match this against, but came up with literally hundreds of API pages(!).

So, could anyone just tell me whether the checks being performed are correct? Do I need to modify the source rectangle(s) after creating one of the differences? Does this work for all overlapping rectangles, or would I need to determine which is inside which, or clip them so one is completely inside the other?