Advertisement
vanRijn

Lubos Lunak's fakeXinerama.c

Aug 26th, 2011
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.30 KB | None | 0 0
  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.
  9.  
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12.  
  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.
  20.  
  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 $ */
  27.  
  28. #include <X11/Xlibint.h>
  29. #include <X11/extensions/Xinerama.h>
  30. #include <stdio.h>
  31.  
  32. static int num_screens = -1;
  33. static struct
  34.     {
  35.     int x_org, y_org;
  36.     int width, height;
  37.     } screen_info[ 10 ];
  38.  
  39. static void skipComments( FILE* f )
  40.     {
  41.     char tmp[ 4096 ];
  42.     for(;;)
  43.         {
  44.         int c;
  45.         for(;;)
  46.             {
  47.             c = fgetc( f );
  48.             if( c == EOF )
  49.                 return;
  50.             if( c != ' ' && c != '\t' && c != '\n' )
  51.                 break;
  52.             }
  53.         if( c != '#' )
  54.             {
  55.             ungetc( c, f );
  56.             return;
  57.             }
  58.         fgets( tmp, 4096, f );
  59.         }
  60.     }
  61.  
  62. static void initFakeXinerama()
  63.     {
  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 )
  80.         {
  81.         num_screens = 0;
  82.         fclose( f );
  83.         return;
  84.         }
  85.     if( num_screens >= 10 )
  86.         num_screens = 10;
  87.     for( i = 0;
  88.          i < num_screens;
  89.          ++i )
  90.         {
  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 )
  94.             {
  95.             num_screens = 0;
  96.             fclose( f );
  97.             return;
  98.             }
  99.         }
  100.     fclose( f );
  101.     }
  102.  
  103. Bool XineramaQueryExtension (
  104.    Display *dpy,
  105.    int     *event_base,
  106.    int     *error_base
  107. )
  108. {
  109.     (void) dpy;
  110.     *event_base = 0;
  111.     *error_base = 0;
  112.     return True;
  113. }
  114.  
  115. Status XineramaQueryVersion(
  116.    Display *dpy,
  117.    int     *major,
  118.    int     *minor
  119. )
  120. {
  121.     (void) dpy;
  122.     *major = 1;
  123.     *minor = 1;
  124.     return 1;
  125. }
  126.  
  127. Bool XineramaIsActive(Display *dpy)
  128. {
  129.     (void) dpy;
  130.     initFakeXinerama();
  131.     return num_screens != 0;
  132. }
  133.  
  134. XineramaScreenInfo *
  135. XineramaQueryScreens(
  136.    Display *dpy,
  137.    int     *number
  138. )
  139. {
  140.     XineramaScreenInfo      *scrnInfo = NULL;
  141.     initFakeXinerama();
  142.     if(num_screens) {
  143.     if((scrnInfo = Xmalloc(sizeof(XineramaScreenInfo) * num_screens))) {
  144.         int i;
  145.  
  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;
  152.         }
  153.  
  154.         *number = num_screens;
  155.     } else
  156.             ;
  157.     }
  158.     return scrnInfo;
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement