/* $Xorg: XPanoramiX.c,v 1.4 2000/08/17 19:45:51 cpqbld Exp $ */
/*****************************************************************
Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of Digital Equipment Corporation
shall not be used in advertising or otherwise to promote the sale, use or other
dealings in this Software without prior written authorization from Digital
Equipment Corporation.
******************************************************************/
/* $XFree86: xc/lib/Xinerama/Xinerama.c,v 1.2 2001/07/23 17:20:28 dawes Exp $ */

#include <X11/Xlibint.h>
#include <X11/extensions/Xinerama.h>

/* 
 * This library provides a fake Xinerama if you ever need to lie to your
 * xorg-server. The initial code is from the awesome Lubos Lunak (see
 * http://ktown.kde.org/~seli/fakexinerama/).
 * To compile, use: 
 *     gcc -O2 -Wall Xinerama.c -fPIC -o libXinerama.so.1.0.0 -shared
 * The actual resolutions are hard-coded to increase performance. See the
 * comments for how to configure it properly.
 * Also, we will lie only to one Display (the first). All other display will see
 * no Xinerama.
 * Patch in support for more if you need it. :)
 * - muflax <mail@muflax.com>
 */

struct _screen_info {
    int x_org, y_org;
    int width, height;
};

/* 
 * The fake (virtual) Xinerama screens:
 * Provide one struct for each screen, starting with their coordinates,
 * followed by their size.
 * Also, adjust num_screens accordingly. :)
 */
#define NUM_SCREENS 2
static struct _screen_info screen_info[NUM_SCREENS] = {
    {0, 0, 1680, 1050},
    {1680, 0, 1280, 1024}
};

Bool XineramaQueryExtension(
        Display * dpy,
		int *event_base, 
        int *error_base)
{
    (void) dpy;
    *event_base = 0;
    *error_base = 0;
    return True;
}

Status XineramaQueryVersion(Display * dpy, int *major, int *minor)
{
    (void) dpy;
    *major = 1;
    *minor = 1;
    return 1;
}

/* 
 * Which Display should we lie to? Currently, we lie to :x.0 and tell all others
 * not to use Xinerama. If you want support for more Xinerama monitors, add some
 * _screen_info structs for each and modify the functions accordingly.
 */
Bool XineramaIsActive(Display * dpy)
{
    if ((DefaultScreen(dpy)) > 0)
        return 0;
    else
        return NUM_SCREENS > 0;
}

XineramaScreenInfo *XineramaQueryScreens(Display * dpy, int *number)
{
    XineramaScreenInfo *scrnInfo = NULL;
	if ((scrnInfo = Xmalloc(sizeof(XineramaScreenInfo) * NUM_SCREENS))) {
	    int i;

	    for (i = 0; i < NUM_SCREENS; i++) {
            scrnInfo[i].screen_number = i;
            scrnInfo[i].x_org = screen_info[i].x_org;
            scrnInfo[i].y_org = screen_info[i].y_org;
            scrnInfo[i].width = screen_info[i].width;
            scrnInfo[i].height = screen_info[i].height;
	    }

	    *number = NUM_SCREENS;
	};
    return scrnInfo;
}
