src/video/x11/SDL_x11modes.c
changeset 1336 3692456e7b0f
parent 1318 f95502c6fc72
child 1338 604d73db6802
equal deleted inserted replaced
1335:c39265384763 1336:3692456e7b0f
    49 #endif /* XFREE86_VM */
    49 #endif /* XFREE86_VM */
    50 
    50 
    51 #ifdef XFREE86_VM
    51 #ifdef XFREE86_VM
    52 static void save_mode(_THIS)
    52 static void save_mode(_THIS)
    53 {
    53 {
    54     memset(&saved_mode, 0, sizeof(saved_mode));
    54     SDL_memset(&saved_mode, 0, sizeof(saved_mode));
    55     SDL_NAME(XF86VidModeGetModeInfo)(SDL_Display,SDL_Screen,&saved_mode);
    55     SDL_NAME(XF86VidModeGetModeInfo)(SDL_Display,SDL_Screen,&saved_mode);
    56     SDL_NAME(XF86VidModeGetViewPort)(SDL_Display,SDL_Screen,&saved_view.x,&saved_view.y);
    56     SDL_NAME(XF86VidModeGetViewPort)(SDL_Display,SDL_Screen,&saved_view.x,&saved_view.y);
    57 }
    57 }
    58 #endif
    58 #endif
    59 
    59 
   258 {
   258 {
   259     XVisualInfo *vi, template;
   259     XVisualInfo *vi, template;
   260     int nvis;
   260     int nvis;
   261 
   261 
   262     if ( visual_id ) {
   262     if ( visual_id ) {
   263         memset(&template, 0, (sizeof template));
   263         SDL_memset(&template, 0, (sizeof template));
   264         template.visualid = strtol(visual_id, NULL, 0);
   264         template.visualid = SDL_strtol(visual_id, NULL, 0);
   265         vi = pXGetVisualInfo(SDL_Display, VisualIDMask, &template, &nvis);
   265         vi = pXGetVisualInfo(SDL_Display, VisualIDMask, &template, &nvis);
   266         if ( vi ) {
   266         if ( vi ) {
   267             int n = this->hidden->nvisuals;
   267             int n = this->hidden->nvisuals;
   268             this->hidden->visuals[n].depth = vi->depth;
   268             this->hidden->visuals[n].depth = vi->depth;
   269             this->hidden->visuals[n].visual = vi->visual;
   269             this->hidden->visuals[n].visual = vi->visual;
   302 #ifdef XFREE86_VM
   302 #ifdef XFREE86_VM
   303     /* Metro-X 4.3.0 and earlier has a broken implementation of
   303     /* Metro-X 4.3.0 and earlier has a broken implementation of
   304        XF86VidModeGetAllModeLines() - it hangs the client.
   304        XF86VidModeGetAllModeLines() - it hangs the client.
   305      */
   305      */
   306     buggy_X11 = 0;
   306     buggy_X11 = 0;
   307     if ( strcmp(ServerVendor(SDL_Display), "Metro Link Incorporated") == 0 ) {
   307     if ( SDL_strcmp(ServerVendor(SDL_Display), "Metro Link Incorporated") == 0 ) {
   308         FILE *metro_fp;
   308         FILE *metro_fp;
   309 
   309 
   310         metro_fp = fopen("/usr/X11R6/lib/X11/Metro/.version", "r");
   310         metro_fp = fopen("/usr/X11R6/lib/X11/Metro/.version", "r");
   311         if ( metro_fp != NULL ) {
   311         if ( metro_fp != NULL ) {
   312             int major, minor, patch, version;
   312             int major, minor, patch, version;
   358                     modes[i]->vtotal) );
   358                     modes[i]->vtotal) );
   359         }
   359         }
   360 #endif
   360 #endif
   361 
   361 
   362         qsort(modes, nmodes, sizeof *modes, cmpmodes);
   362         qsort(modes, nmodes, sizeof *modes, cmpmodes);
   363         SDL_modelist = (SDL_Rect **)malloc((nmodes+2)*sizeof(SDL_Rect *));
   363         SDL_modelist = (SDL_Rect **)SDL_malloc((nmodes+2)*sizeof(SDL_Rect *));
   364         if ( SDL_modelist ) {
   364         if ( SDL_modelist ) {
   365             n = 0;
   365             n = 0;
   366             for ( i=0; i<nmodes; ++i ) {
   366             for ( i=0; i<nmodes; ++i ) {
   367                 int w, h;
   367                 int w, h;
   368 
   368 
   376                 /* Check to see if we should add the screen size (Xinerama) */
   376                 /* Check to see if we should add the screen size (Xinerama) */
   377                 w = modes[i]->hdisplay;
   377                 w = modes[i]->hdisplay;
   378                 h = modes[i]->vdisplay;
   378                 h = modes[i]->vdisplay;
   379                 if ( (screen_w * screen_h) >= (w * h) ) {
   379                 if ( (screen_w * screen_h) >= (w * h) ) {
   380                     if ( (screen_w != w) || (screen_h != h) ) {
   380                     if ( (screen_w != w) || (screen_h != h) ) {
   381                         SDL_modelist[n] = (SDL_Rect *)malloc(sizeof(SDL_Rect));
   381                         SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
   382                         if ( SDL_modelist[n] ) {
   382                         if ( SDL_modelist[n] ) {
   383                             SDL_modelist[n]->x = 0;
   383                             SDL_modelist[n]->x = 0;
   384                             SDL_modelist[n]->y = 0;
   384                             SDL_modelist[n]->y = 0;
   385                             SDL_modelist[n]->w = screen_w;
   385                             SDL_modelist[n]->w = screen_w;
   386                             SDL_modelist[n]->h = screen_h;
   386                             SDL_modelist[n]->h = screen_h;
   390                     screen_w = 0;
   390                     screen_w = 0;
   391                     screen_h = 0;
   391                     screen_h = 0;
   392                 }
   392                 }
   393 
   393 
   394                 /* Add the size from the video mode list */
   394                 /* Add the size from the video mode list */
   395                 SDL_modelist[n] = (SDL_Rect *)malloc(sizeof(SDL_Rect));
   395                 SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
   396                 if ( SDL_modelist[n] == NULL ) {
   396                 if ( SDL_modelist[n] == NULL ) {
   397                     break;
   397                     break;
   398                 }
   398                 }
   399                 SDL_modelist[n]->x = 0;
   399                 SDL_modelist[n]->x = 0;
   400                 SDL_modelist[n]->y = 0;
   400                 SDL_modelist[n]->y = 0;
   447 #ifdef XIG_DEBUG
   447 #ifdef XIG_DEBUG
   448         fprintf(stderr, "XME: nummodes = %d, active mode = %d\n",
   448         fprintf(stderr, "XME: nummodes = %d, active mode = %d\n",
   449                 nummodes, ractive);
   449                 nummodes, ractive);
   450 #endif
   450 #endif
   451 
   451 
   452         SDL_modelist = (SDL_Rect **)malloc((nummodes+1)*sizeof(SDL_Rect *));
   452         SDL_modelist = (SDL_Rect **)SDL_malloc((nummodes+1)*sizeof(SDL_Rect *));
   453 
   453 
   454                                 /* we get the list already sorted in */
   454                                 /* we get the list already sorted in */
   455                                 /* descending order.  We'll copy it in */
   455                                 /* descending order.  We'll copy it in */
   456                                 /* reverse order so SDL is happy */
   456                                 /* reverse order so SDL is happy */
   457         if (SDL_modelist) {
   457         if (SDL_modelist) {
   458             for ( i=0, j=nummodes-1; j>=0; i++, j-- ) {
   458             for ( i=0, j=nummodes-1; j>=0; i++, j-- ) {
   459                 if ((SDL_modelist[i] = 
   459                 if ((SDL_modelist[i] = 
   460                      (SDL_Rect *)malloc(sizeof(SDL_Rect))) == NULL)
   460                      (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect))) == NULL)
   461                   break;
   461                   break;
   462 #ifdef XIG_DEBUG
   462 #ifdef XIG_DEBUG
   463                 fprintf(stderr, "XME: mode = %4d, w = %4d, h = %4d\n",
   463                 fprintf(stderr, "XME: mode = %4d, w = %4d, h = %4d\n",
   464                        i, modelist[i].width, modelist[i].height);
   464                        i, modelist[i].width, modelist[i].height);
   465 #endif
   465 #endif
   488         int use_directcolor = 1;
   488         int use_directcolor = 1;
   489         XPixmapFormatValues *pf;
   489         XPixmapFormatValues *pf;
   490 
   490 
   491         /* Search for the visuals in deepest-first order, so that the first
   491         /* Search for the visuals in deepest-first order, so that the first
   492            will be the richest one */
   492            will be the richest one */
   493         if ( getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) {
   493         if ( SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) {
   494                 use_directcolor = 0;
   494                 use_directcolor = 0;
   495         }
   495         }
   496         this->hidden->nvisuals = 0;
   496         this->hidden->nvisuals = 0;
   497         if ( ! add_visual_byid(this, getenv("SDL_VIDEO_X11_VISUALID")) ) {
   497         if ( ! add_visual_byid(this, SDL_getenv("SDL_VIDEO_X11_VISUALID")) ) {
   498                 for ( i=0; i<SDL_TABLESIZE(depth_list); ++i ) {
   498                 for ( i=0; i<SDL_TABLESIZE(depth_list); ++i ) {
   499                         if ( depth_list[i] > 8 ) {
   499                         if ( depth_list[i] > 8 ) {
   500                                 if ( use_directcolor ) {
   500                                 if ( use_directcolor ) {
   501                                         add_visual(this, depth_list[i], DirectColor);
   501                                         add_visual(this, depth_list[i], DirectColor);
   502                                 }
   502                                 }
   524 
   524 
   525         pXFree(pf);
   525         pXFree(pf);
   526     }
   526     }
   527 
   527 
   528     if ( SDL_modelist == NULL ) {
   528     if ( SDL_modelist == NULL ) {
   529         SDL_modelist = (SDL_Rect **)malloc((1+1)*sizeof(SDL_Rect *));
   529         SDL_modelist = (SDL_Rect **)SDL_malloc((1+1)*sizeof(SDL_Rect *));
   530         if ( SDL_modelist ) {
   530         if ( SDL_modelist ) {
   531             n = 0;
   531             n = 0;
   532             SDL_modelist[n] = (SDL_Rect *)malloc(sizeof(SDL_Rect));
   532             SDL_modelist[n] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
   533             if ( SDL_modelist[n] ) {
   533             if ( SDL_modelist[n] ) {
   534                 SDL_modelist[n]->x = 0;
   534                 SDL_modelist[n]->x = 0;
   535                 SDL_modelist[n]->y = 0;
   535                 SDL_modelist[n]->y = 0;
   536                 SDL_modelist[n]->w = screen_w;
   536                 SDL_modelist[n]->w = screen_w;
   537                 SDL_modelist[n]->h = screen_h;
   537                 SDL_modelist[n]->h = screen_h;
   576 
   576 
   577 #ifdef XINERAMA_DEBUG
   577 #ifdef XINERAMA_DEBUG
   578         printf("X11 detected Xinerama:\n");
   578         printf("X11 detected Xinerama:\n");
   579 #endif
   579 #endif
   580 #if 0 /* Apparently the vidmode extension doesn't work with Xinerama */
   580 #if 0 /* Apparently the vidmode extension doesn't work with Xinerama */
   581         const char *variable = getenv("SDL_VIDEO_X11_XINERAMA_SCREEN");
   581         const char *variable = SDL_getenv("SDL_VIDEO_X11_XINERAMA_SCREEN");
   582         if ( variable ) {
   582         if ( variable ) {
   583                 desired = atoi(variable);
   583                 desired = atoi(variable);
   584         }
   584         }
   585 #endif
   585 #endif
   586         xinerama = SDL_NAME(XineramaQueryScreens)(SDL_Display, &screens);
   586         xinerama = SDL_NAME(XineramaQueryScreens)(SDL_Display, &screens);
   629 {
   629 {
   630     int i;
   630     int i;
   631 
   631 
   632     if ( SDL_modelist ) {
   632     if ( SDL_modelist ) {
   633         for ( i=0; SDL_modelist[i]; ++i ) {
   633         for ( i=0; SDL_modelist[i]; ++i ) {
   634             free(SDL_modelist[i]);
   634             SDL_free(SDL_modelist[i]);
   635         }
   635         }
   636         free(SDL_modelist);
   636         SDL_free(SDL_modelist);
   637         SDL_modelist = NULL;
   637         SDL_modelist = NULL;
   638     }
   638     }
   639 }
   639 }
   640 
   640 
   641 int X11_ResizeFullScreen(_THIS)
   641 int X11_ResizeFullScreen(_THIS)
   725         /* If not, try to put us there - if fail... oh well */
   725         /* If not, try to put us there - if fail... oh well */
   726         if ( windows[nwindows-1] != FSwindow ) {
   726         if ( windows[nwindows-1] != FSwindow ) {
   727             tmpwin = windows[nwindows-1];
   727             tmpwin = windows[nwindows-1];
   728             for ( i=0; i<nwindows; ++i ) {
   728             for ( i=0; i<nwindows; ++i ) {
   729                 if ( windows[i] == FSwindow ) {
   729                 if ( windows[i] == FSwindow ) {
   730                     memcpy(&windows[i], &windows[i+1],
   730                     SDL_memcpy(&windows[i], &windows[i+1],
   731                            (nwindows-i-1)*sizeof(windows[i]));
   731                            (nwindows-i-1)*sizeof(windows[i]));
   732                     break;
   732                     break;
   733                 }
   733                 }
   734             }
   734             }
   735             windows[nwindows-1] = FSwindow;
   735             windows[nwindows-1] = FSwindow;