Add fake-xinerama, create test that tests spurious screens are removed
[notion/jeffpc.git] / test / integration / Xinerama.c
blob1ed9b32ccec8a5120c73249c21b542d06092b7ba
1 /* $Xorg: XPanoramiX.c,v 1.4 2000/08/17 19:45:51 cpqbld Exp $ */
2 /*****************************************************************
3 Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software.
10 The above copyright notice and this permission notice shall be included in
11 all copies or substantial portions of the Software.
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16 DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
17 BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
18 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
19 IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of Digital Equipment Corporation
22 shall not be used in advertising or otherwise to promote the sale, use or other
23 dealings in this Software without prior written authorization from Digital
24 Equipment Corporation.
25 ******************************************************************/
26 /* $XFree86: xc/lib/Xinerama/Xinerama.c,v 1.2 2001/07/23 17:20:28 dawes Exp $ */
28 #include <X11/Xlibint.h>
29 #include <X11/extensions/Xinerama.h>
30 #include <stdio.h>
32 static int num_screens = -1;
33 static struct
35 int x_org, y_org;
36 int width, height;
37 } screen_info[ 10 ];
39 static void skipComments( FILE* f )
41 char tmp[ 4096 ];
42 for(;;)
44 int c;
45 for(;;)
47 c = fgetc( f );
48 if( c == EOF )
49 return;
50 if( c != ' ' && c != '\t' && c != '\n' )
51 break;
53 if( c != '#' )
55 ungetc( c, f );
56 return;
58 fgets( tmp, 4096, f );
62 static void initFakeXinerama()
64 const char* home;
65 char buf[ 4096 ];
66 FILE* f;
67 int i;
68 if( num_screens != -1 )
69 return;
70 num_screens = 0;
71 home = getenv( "HOME" );
72 if( home == NULL )
73 return;
74 sprintf( buf, "%s/.fakexinerama", home );
75 f = fopen( buf, "r" );
76 if( f == NULL )
77 return;
78 skipComments( f );
79 if( fscanf( f, "%d\n", &num_screens ) != 1 )
81 num_screens = 0;
82 fclose( f );
83 return;
85 if( num_screens >= 10 )
86 num_screens = 10;
87 for( i = 0;
88 i < num_screens;
89 ++i )
91 skipComments( f );
92 if( fscanf( f, "%d %d %d %d\n", &screen_info[ i ].x_org, &screen_info[ i ].y_org,
93 &screen_info[ i ].width, &screen_info[ i ].height ) != 4 )
95 num_screens = 0;
96 fclose( f );
97 return;
100 fclose( f );
103 Bool XineramaQueryExtension (
104 Display *dpy,
105 int *event_base,
106 int *error_base
109 (void) dpy;
110 *event_base = 0;
111 *error_base = 0;
112 return True;
115 Status XineramaQueryVersion(
116 Display *dpy,
117 int *major,
118 int *minor
121 (void) dpy;
122 *major = 1;
123 *minor = 1;
124 return 1;
127 Bool XineramaIsActive(Display *dpy)
129 (void) dpy;
130 initFakeXinerama();
131 return num_screens != 0;
134 XineramaScreenInfo *
135 XineramaQueryScreens(
136 Display *dpy,
137 int *number
140 XineramaScreenInfo *scrnInfo = NULL;
141 initFakeXinerama();
142 if(num_screens) {
143 if((scrnInfo = Xmalloc(sizeof(XineramaScreenInfo) * num_screens))) {
144 int i;
146 for(i = 0; i < num_screens; i++) {
147 scrnInfo[i].screen_number = i;
148 scrnInfo[i].x_org = screen_info[ i ].x_org;
149 scrnInfo[i].y_org = screen_info[ i ].y_org;
150 scrnInfo[i].width = screen_info[ i ].width;
151 scrnInfo[i].height = screen_info[ i ].height;
154 *number = num_screens;
155 } else
158 return scrnInfo;