Released version 3-2015061300
[notion.git] / test / integration / Xinerama.c
blob9913745b4b005427dd818928b65d84ec1be40bdc
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 // re-init every time we're invoked, because we want to be able to test
69 // adding/removing screens
70 //if( num_screens != -1 )
71 // return;
72 num_screens = 0;
73 home = getenv( "HOME" );
74 if( home == NULL )
75 return;
76 sprintf( buf, "%s/.fakexinerama", home );
77 f = fopen( buf, "r" );
78 if( f == NULL )
79 return;
80 skipComments( f );
81 if( fscanf( f, "%d\n", &num_screens ) != 1 )
83 num_screens = 0;
84 fclose( f );
85 return;
87 if( num_screens >= 10 )
88 num_screens = 10;
89 for( i = 0;
90 i < num_screens;
91 ++i )
93 skipComments( f );
94 if( fscanf( f, "%d %d %d %d\n", &screen_info[ i ].x_org, &screen_info[ i ].y_org,
95 &screen_info[ i ].width, &screen_info[ i ].height ) != 4 )
97 num_screens = 0;
98 fclose( f );
99 return;
102 fclose( f );
105 Bool XineramaQueryExtension (
106 Display *dpy,
107 int *event_base,
108 int *error_base
111 (void) dpy;
112 *event_base = 0;
113 *error_base = 0;
114 return True;
117 Status XineramaQueryVersion(
118 Display *dpy,
119 int *major,
120 int *minor
123 (void) dpy;
124 *major = 1;
125 *minor = 1;
126 return 1;
129 Bool XineramaIsActive(Display *dpy)
131 (void) dpy;
132 initFakeXinerama();
133 return num_screens != 0;
136 XineramaScreenInfo *
137 XineramaQueryScreens(
138 Display *dpy,
139 int *number
142 XineramaScreenInfo *scrnInfo = NULL;
143 initFakeXinerama();
144 if(num_screens) {
145 if((scrnInfo = Xmalloc(sizeof(XineramaScreenInfo) * num_screens))) {
146 int i;
148 for(i = 0; i < num_screens; i++) {
149 scrnInfo[i].screen_number = i;
150 scrnInfo[i].x_org = screen_info[ i ].x_org;
151 scrnInfo[i].y_org = screen_info[ i ].y_org;
152 scrnInfo[i].width = screen_info[ i ].width;
153 scrnInfo[i].height = screen_info[ i ].height;
156 *number = num_screens;
157 } else
160 return scrnInfo;