Exemplo n.º 1
0
static size_t _gfx_x11_init_modes(

		Screen*              scr,
		XRRScreenResources*  res)
{
	/* Split depth */
	GFXColorDepth depth;
	_gfx_split_depth(
		XDefaultDepthOfScreen(scr),
		&depth.redBits,
		&depth.greenBits,
		&depth.blueBits
	);

	/* Reserve space for all modes */
	size_t first = gfx_vector_get_size(&_gfx_x11.modes);
	gfx_vector_reserve(&_gfx_x11.modes, first + res->nmode);

	unsigned int i;
	for(i = 0; i < res->nmode; ++i)
	{
		/* Skip refresh rate of zero */
		unsigned int refresh = 0;
		if(res->modes[i].hTotal && res->modes[i].vTotal)
		{
			refresh =
				(unsigned int)lround((double)res->modes[i].dotClock /
				((double)res->modes[i].hTotal * (double)res->modes[i].vTotal));
		}

		if(refresh)
		{
			/* Create new mode */
			GFX_X11_Mode mode;
			mode.id           = res->modes[i].id;
			mode.mode.width   = res->modes[i].width;
			mode.mode.height  = res->modes[i].height;
			mode.mode.depth   = depth;
			mode.mode.refresh = refresh;

			gfx_vector_insert(&_gfx_x11.modes, &mode, _gfx_x11.modes.end);
		}
	}

	return first;
}
Exemplo n.º 2
0
void main(int argc, char **argv)
{
  int   i,j,k,
        x_return, y_return;
  float D;
  unsigned int width_return, height_return,
               border_width_return, depth_return;
  Window root_return;  
  char *display_name;
  int screen;
  XSetWindowAttributes winAttributes;
  char *window_name = "sbXcityfly";
  char *icon_name = "sbXcityfly";

  static ButtonRec buttonDefs[]={
    {&buttonDefs[1],  "1",     "Translation ON ",         0, 
     SPW_BwFlagRoundButton},
    {&buttonDefs[2],  "2",     "Rotation ON ",            0, 
     SPW_BwFlagRoundButton},
    {&buttonDefs[3],  "3",     "Single Axis Filter OFF",  0, 
     SPW_BwFlagRoundButton},
    {&buttonDefs[4],  "4",     "Roll ON ",                0, 
     SPW_BwFlagRoundButton},
    {&buttonDefs[5],  "5",     "Decrease sensitivity",    0, 
     SPW_BwFlagRoundButton},
    {&buttonDefs[6], "Sensi",  "Sensitivity:    1 ",      0, 
     SPW_BwFlagNoButton},
    {&buttonDefs[7],  "6",     "Increase sensitivity",    0, 
     SPW_BwFlagRoundButton},
    {&buttonDefs[8],  "7",     " ",                       0, 
     SPW_BwFlagRoundButton},
    {&buttonDefs[9],  "8",     "Rezero",                  0, 
     SPW_BwFlagRoundButton},
    {&buttonDefs[10],  "P",    "Reset View",              0, 
     SPW_BwFlagRoundButton},
    {&buttonDefs[11], NULL,    NULL,                      0, 
     SPW_BwFlagSeparator},
    {&buttonDefs[12], "ESC",   "Quit",            XK_Escape, 
     SPW_BwFlagKey},
    {NULL,                NULL,    NULL,                      0, 
             SPW_BwFlagSeparator},
  };


  /*
   *  Connect to the X Server
   */

  if ((display_name=getenv("DISPLAY")) == NULL)
    display_name=":0";
  
  if ((Spw_Dpy=XOpenDisplay(display_name)) == NULL)
    {
      fprintf(stderr,"%s: Could not open X Display\n",argv[0]);
      exit(1);
    }
  
  screen=DefaultScreen(Spw_Dpy);
  Spw_Gc=DefaultGC(Spw_Dpy,screen);
  XSetBackground(Spw_Dpy,Spw_Gc,BlackPixel(Spw_Dpy,screen));
  XSetForeground(Spw_Dpy,Spw_Gc,WhitePixel(Spw_Dpy,screen));
  winAttributes.background_pixel=BlackPixel(Spw_Dpy,screen);

  /*
   *  Create the main window proportional to the root window
   */
  XGetGeometry(Spw_Dpy, DefaultRootWindow(Spw_Dpy), &root_return,
               &x_return,&y_return,
               &width_return, &height_return,& border_width_return,
               &depth_return);

  Spw_WindowSize = .8 * MIN(height_return,width_return);
  Spw_WindowWidth = Spw_WindowSize;
  Spw_WindowHeight = Spw_WindowSize;

  Spw_mainWindow = XCreateWindow(Spw_Dpy,DefaultRootWindow(Spw_Dpy),
                                 250, 0, Spw_WindowWidth, Spw_WindowHeight,1,
                                 CopyFromParent,CopyFromParent,CopyFromParent,
                                 CWBackPixel,&winAttributes);
  Spw_mainBuffer= XCreatePixmap(Spw_Dpy, Spw_mainWindow, 
                                Spw_WindowWidth, Spw_WindowHeight,
                                XDefaultDepthOfScreen(XDefaultScreenOfDisplay(Spw_Dpy)));

  /*
   *  Select the colors to draw in
   */
  Spw_white   = AllocPublicColor(0xffff,0xffff,0xffff);
  Spw_black   = AllocPublicColor(0x0000,0x0000,0x0000);
  Spw_grey    = AllocPublicColor(0xffff,0xffff,0xffff);
  Spw_green   = AllocPublicColor(0x0000,0xffff,0x0000);
  
  /*
   * Set up and map the window
   */
  XStoreName(Spw_Dpy, Spw_mainWindow, argv[0]);
  setWindowHints(Spw_mainWindow, argv, argc, window_name, icon_name,
                 "sbXcityfly", "SBxcityfly");
  XMapWindow(Spw_Dpy, Spw_mainWindow);

  /*
   *  Initialize the Spaceball and Button Window
   */

  if (!(SPW_InputCheckForSpaceball(Spw_Dpy, Spw_mainWindow, "sbXcityfly")) )
    {
      fprintf (stderr, "Sorry, no Spaceball found!\n");
      exit(0);
    }
  
  Spw_ButtonWindow=SPW_BwInit(Spw_Dpy, DefaultScreenOfDisplay(Spw_Dpy), 
                   "sbXcityfly", buttonDefs);
  
  if(!Spw_ButtonWindow)
    {
      fprintf(stderr, "Error: BwInit returned NULL\n");
      exit(-1);
    }
  
   SpwUpdateButtons();

  /*
   *  Set up the geometry to be displayed
   */

   D = 1.0/tan( (double) ((M_PI/180.0)*(FOV/2.0)) );
   SPW_InitializeMatrix(Spw_Persp, 1.0, 0.0,  0.0,  0.0,
                               0.0, 1.0,  0.0,  0.0,
                                      0.0, 0.0, -1.0, -1.0/D,
                               0.0, 0.0,  0.0,  0.0);

   GetUniqPoints(bldg, buniq, Spw_SizeBldg );
   GetUniqPoints(land, luniq, Spw_SizeLand );

  /*
   *  Go into main loop, clean up if we ever exit cleanly
   */

   DispatchLoop();
   XDestroyWindow(Spw_Dpy, Spw_mainWindow);
   XCloseDisplay(Spw_Dpy);

} /* end of main */
Exemplo n.º 3
0
int initsystem(void)  /* retourne 1 si initialisation reussie */
{
    int i;
    int windowW;
    int windowH;
    XSetWindowAttributes xswa;
    XGCValues xgcv;
    XSizeHints xsh;

    windowW=WIDTH*RATIO;
    windowH=HEIGHT*RATIO;
    display=XOpenDisplay(0);

    if (!display) return(0);
    else
    {
        mousek=0;
        XAutoRepeatOff(display);
        timestart=last=systime();
        screen=XDefaultScreenOfDisplay(display);
        rdepth=sdepth=XDefaultDepthOfScreen(screen);
        if (emulmono) sdepth=1;
        XSynchronize(display,0);

        black=XBlackPixelOfScreen(screen);
        white=XWhitePixelOfScreen(screen);
        colormap=XDefaultColormapOfScreen(screen);
        visual=XDefaultVisualOfScreen(screen);

        xswa.event_mask=VisibilityChangeMask;
        xswa.background_pixel=black;
        xswa.border_pixel=white;
        xswa.override_redirect=0;
        xswa.backing_store=Always;
        xswa.bit_gravity=StaticGravity;
        xswa.win_gravity=CenterGravity;
        window=XCreateWindow(display,XRootWindowOfScreen(screen),
                             randval(50),randval(100),windowW,windowH,0,
                             XDefaultDepthOfScreen(screen),InputOutput,
                             XDefaultVisualOfScreen(screen),
                             CWWinGravity|CWBitGravity|CWBackingStore|CWEventMask|
                             CWBackPixel|CWOverrideRedirect|CWBorderPixel,&xswa);

        if (sdepth!=1)
            xcolormap=XCreateColormap(display,window,
                                      visual,AllocAll);

        xgcv.foreground = white;
        xgcv.background = black;
        gc=XCreateGC(display,window,GCForeground | GCBackground,&xgcv);

        XSetGraphicsExposures(display,gc,False);
        /* CAPITAL!!! : evite d'accumuler sans cesse des expose events */

        xsh.x=0;
        xsh.y=0;
        xsh.width=windowW;
        xsh.height=windowH;
        xsh.min_width=windowW;
        xsh.max_width=windowW;
        xsh.min_height=windowH;
        xsh.max_height=windowH;
        xsh.flags=PPosition|PSize|PMinSize|PMaxSize;

        XSetNormalHints(display, window, &xsh);
        XStoreName(display,window,"");
        XMapWindow(display, window);
        XSelectInput(display,window,PointerMotionMask|ButtonPressMask|
                     ButtonReleaseMask|KeyPressMask|KeyReleaseMask);
        XFlush(display);
        XSync(display,0);

        for (i=0; i<(NBCOLORS+2); i++)
        {
            if (i&1) pixels[i]=white;
            else pixels[i]=black;
            if (i==NBCOLORS) pixels[i]=0;
            if (i==(NBCOLORS+1)) pixels[i]=(1<<rdepth)-1;
            xgcv.foreground=pixels[i];
            xgcv.background=black;
            gctab[i]=XCreateGC(display,window,
                               GCForeground|GCBackground,&xgcv);
            XSetFunction(display,gctab[i],GXcopy);
            XSetFillStyle(display,gctab[i],FillSolid);
        }

        ecran[0]=XCreatePixmap(display,window,windowW,windowH,rdepth);
        ecran[1]=XCreatePixmap(display,window,windowW,windowH,rdepth);

        for(i=0; i<9; i++)
            graypixmap[i]=XCreatePixmapFromBitmapData(display,window,
                          &graypat[i][0],8,8,white,black,rdepth);

        setpalette(egapal);

        cls();
        swap();
        cls();

        empty();
        waitdelay(500);

        return(1);
    }
}
Exemplo n.º 4
0
/*--------------------------------------------------------*/
void open_gwindow_( )
{
/*
 * create new graphics window on first entry....
 */
  int                          font,black,white;
  int                          scr_width,scr_height;
  int                          j;
  unsigned long                valuemask;
  static int                   depth;    /* number of planes  */
  static Visual               *visual;   /*VISUAL TYPE       */
  static XSizeHints            win_position;   /*position and size for
                                            window manager.*/

/*
 * initialize display id and screen id....
 */
      disp_id = XOpenDisplay(0);
      if (!disp_id) {
         printf("Display not opened!\n");
         exit(-1);
      }
/*
 * next instruction for debugging only....
 */
/*      XSynchronize(disp_id, 1); */
  
  screen_id  =  XDefaultScreenOfDisplay(disp_id);
  root_win_id = XRootWindowOfScreen(screen_id);
  black =       XBlackPixelOfScreen(screen_id);
  white =       XWhitePixelOfScreen(screen_id);
  scr_width =   XWidthOfScreen(screen_id);
  scr_height =  XHeightOfScreen(screen_id);
  depth  =      XDefaultDepthOfScreen(screen_id);
  visual =      XDefaultVisualOfScreen(screen_id);


/*
 * set up backing store....
 */
      valuemask = CWBitGravity | CWBackingStore | CWBackPixel;
      setwinattr.bit_gravity = SouthWestGravity;
      setwinattr.backing_store = Always;
      setwinattr.background_pixel = white;
/*
 * create the window....
 */
      win_id  = XCreateWindow(disp_id,
			      root_win_id,
			      scr_width - win_width - 15,
			      scr_height - win_height - 35,
			      win_width, 
			      win_height, 
			      10,
			      depth,
			      InputOutput,
			      visual,
			      valuemask,
			      &setwinattr);
/* WMHints structure */
  win_position.x = scr_width - win_width - 15;
  win_position.y = scr_height - win_height - 35;
  win_position.width = win_width;
  win_position.height = win_height;
  win_position.flags=USPosition|USSize;
  
  XSetWMNormalHints(disp_id, win_id, &win_position); 

      XStoreName(disp_id, win_id, WINDNAME);
/*
 * get named color values....
 */

      color[1]   = define_color_("BLUE");
      color[2]   = define_color_("DEEP SKY BLUE");
      color[3]   = define_color_("LIGHT SKY BLUE");

      color[4]   = define_color_("SEA GREEN");
      color[5]  = define_color_("MEDIUM SEA GREEN");
      color[6]  = define_color_("GREEN");

      color[7]  = define_color_("BROWN");
      color[8]  = define_color_("CHOCOLATE");
      color[9]  = define_color_("SANDY BROWN");

      color[10]   = define_color_("RED");
      color[11]   = define_color_("CORAL");
      color[12]   = define_color_("ORANGE");

      color[13]  = define_color_("YELLOW3");
      color[14]  = define_color_("YELLOW2");
      color[15]  = define_color_("YELLOW");

      color[16]  = define_color_("PEACH PUFF");
      color[17]  = define_color_("PAPAYA WHIP");
      color[18]  = define_color_("OLD LACE");

      color[19]   = white;
      color[20]   = black;
      color[21]   = black;


/*
 * create graphics context....
 */
      xgcvl.background = color[19];
      xgcvl.foreground = color[20];
      gc_id = XCreateGC(disp_id, win_id, GCForeground | GCBackground, &xgcvl);
      xgcvl.function = GXinvert;
      gc_comp_id = XCreateGC(disp_id, win_id, GCFunction, &xgcvl);
/*
 * load the font for text writing....
 */
      font = XLoadFont(disp_id, FONTNAME);
      XSetFont(disp_id, gc_id, font);

  /* Map the window.... */
  XSelectInput(disp_id,win_id,ExposureMask|VisibilityChangeMask);
  XMapRaised(disp_id,win_id);

  /*
   * Wait for the window to be raised. Some X servers do not 
   * generate an initial expose event, so also check the visibility
   * event.
   */
  XMaskEvent(disp_id,ExposureMask|VisibilityChangeMask,&event);
  XSelectInput(disp_id,win_id,0);
  XSync(disp_id,1);
}
Exemplo n.º 5
0
void
SplashInitPlatform(Splash * splash) {
    int shapeVersionMajor, shapeVersionMinor;

    // This setting enables the synchronous Xlib mode!
    // Don't use it == 1 in production builds!
#if (defined DEBUG)
    _Xdebug = 1;
#endif

    pthread_mutex_init(&splash->lock, NULL);

    // We should not ignore any errors.
    //XSetErrorHandler(HandleError);
//    XSetIOErrorHandler(HandleIOError);
    XSetIOErrorHandler(NULL);
    splash->display = XOpenDisplay(NULL);
    if (!splash->display) {
        splash->isVisible = -1;
        return;
    }

    shapeSupported = XShapeQueryExtension(splash->display, &shapeEventBase,
            &shapeErrorBase);
    if (shapeSupported) {
        XShapeQueryVersion(splash->display, &shapeVersionMajor,
                &shapeVersionMinor);
    }

    splash->screen = XDefaultScreenOfDisplay(splash->display);
    splash->visual = XDefaultVisualOfScreen(splash->screen);
    switch (splash->visual->class) {
    case TrueColor: {
            int depth = XDefaultDepthOfScreen(splash->screen);

            splash->byteAlignment = 1;
            splash->maskRequired = shapeSupported;
            initFormat(&splash->screenFormat, splash->visual->red_mask,
                    splash->visual->green_mask, splash->visual->blue_mask, 0);
            splash->screenFormat.byteOrder =
                (XImageByteOrder(splash->display) == LSBFirst ?
                 BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST);
            splash->screenFormat.depthBytes = (depth + 7) / 8;
            // TrueColor depth probably can't be less
            // than 8 bits, and it's always byte padded
            break;
        }
    case PseudoColor: {
            int availableColors;
            int numColors;
            int numComponents[3];
            unsigned long colorIndex[SPLASH_COLOR_MAP_SIZE];
            XColor xColors[SPLASH_COLOR_MAP_SIZE];
            int i;
            int depth = XDefaultDepthOfScreen(splash->screen);
            int scale = 65535 / MAX_COLOR_VALUE;

            availableColors = GetNumAvailableColors(splash->display, splash->screen,
                    splash->visual->map_entries);
            numColors = quantizeColors(availableColors, numComponents);
            if (numColors > availableColors) {
                // Could not allocate the color cells. Most probably
                // the pool got exhausted. Disable the splash screen.
                XCloseDisplay(splash->display);
                splash->isVisible = -1;
                splash->display = NULL;
                splash->screen = NULL;
                splash->visual = NULL;
                fprintf(stderr, "Warning: unable to initialize the splashscreen. Not enough available color cells.\n");
                return;
            }
            splash->cmap = AllocColors(splash->display, splash->screen,
                    numColors, colorIndex);
            for (i = 0; i < numColors; i++) {
                splash->colorIndex[i] = colorIndex[i];
            }
            initColorCube(numComponents, splash->colorMap, splash->dithers,
                    splash->colorIndex);
            for (i = 0; i < numColors; i++) {
                xColors[i].pixel = colorIndex[i];
                xColors[i].red = (unsigned short)
                    QUAD_RED(splash->colorMap[colorIndex[i]]) * scale;
                xColors[i].green = (unsigned short)
                    QUAD_GREEN(splash->colorMap[colorIndex[i]]) * scale;
                xColors[i].blue = (unsigned short)
                    QUAD_BLUE(splash->colorMap[colorIndex[i]]) * scale;
                xColors[i].flags = DoRed | DoGreen | DoBlue;
            }
            XStoreColors(splash->display, splash->cmap, xColors, numColors);
            initFormat(&splash->screenFormat, 0, 0, 0, 0);
            splash->screenFormat.colorIndex = splash->colorIndex;
            splash->screenFormat.depthBytes = (depth + 7) / 8;  // or always 8?
            splash->screenFormat.colorMap = splash->colorMap;
            splash->screenFormat.dithers = splash->dithers;
            splash->screenFormat.numColors = numColors;
            splash->screenFormat.byteOrder = BYTE_ORDER_NATIVE;
            break;
        }
    default:
        ; /* FIXME: should probably be fixed, but javaws splash screen doesn't support other visuals either */
    }
}
Exemplo n.º 6
0
 int screen::IMPL::depth() const
 {
   return XDefaultDepthOfScreen( _xscrn );
 }