1 diff -urN SDL-1.2.5.old/src/video/x11/SDL_x11modes.c SDL-1.2.5/src/video/x11/SDL_x11modes.c
2 --- SDL-1.2.5.old/src/video/x11/SDL_x11modes.c 2002-09-29 17:35:25.000000000 -0700
3 +++ SDL-1.2.5/src/video/x11/SDL_x11modes.c 2003-04-13 22:03:43.000000000 -0700
7 #define MAX(a, b) (a > b ? a : b)
8 +#define V_INTERLACE 0x010
9 +#define V_DBLSCAN 0x020
12 Bool SDL_NAME(XF86VidModeGetModeInfo)(Display *dpy, int scr, SDL_NAME(XF86VidModeModeInfo) *info)
18 +static int get_vidmode_filter(SDL_NAME(XF86VidModeModeInfo) **modes, int nmodes, char **bitmap)
21 + int use_all_modes, use_specific_mode;
22 + const char *variable;
28 + temp = (char *)malloc((nmodes)*sizeof(char));
32 + for ( i = 0; i < nmodes; ++i )
35 + variable = getenv("SDL_VIDEO_X11_USE_ALL_MODES");
36 + use_all_modes = variable ? atoi(variable) : 0;
37 + variable = getenv("SDL_VIDEO_X11_USE_SPECIFIC_MODE");
38 + use_specific_mode = variable ? atoi(variable) : 0;
40 + qsort(modes, nmodes, sizeof *modes, cmpmodes);
42 + if ( use_all_modes ) {
43 + for ( i = 0; i < nmodes; ++i )
46 +/* } else if ( use_specific_mode ) { ... */
48 + int previous_refresh, current_refresh;
49 + SDL_NAME(XF86VidModeModeInfo) *previous, *current;
51 + previous = modes[0];
52 + previous_refresh = (int)(previous->dotclock * 1000.0 /
53 + (previous->htotal * previous->vtotal));
54 + if ( previous->flags & V_INTERLACE ) previous_refresh *= 2;
55 + else if ( previous->flags & V_DBLSCAN ) previous_refresh /= 2;
58 + for ( i = 1; i < nmodes; ++i ) {
60 + current_refresh = (int)(current->dotclock * 1000.0 /
61 + (current->htotal * current->vtotal));
62 + if ( current->flags & V_INTERLACE ) current_refresh *= 2;
63 + else if ( current->flags & V_DBLSCAN ) current_refresh /= 2;
65 + /* Compare this mode to the previous one */
66 + if ( current->hdisplay == previous->hdisplay &&
67 + current->vdisplay == previous->vdisplay ) {
68 + if ( current_refresh > previous_refresh ) {
79 + previous_refresh = current_refresh;
88 static void get_real_resolution(_THIS, int* w, int* h);
90 static void set_best_resolution(_THIS, int width, int height)
92 SDL_NAME(XF86VidModeModeInfo) **modes;
97 if ( SDL_NAME(XF86VidModeGetModeLine)(SDL_Display, SDL_Screen, &i, &mode) &&
98 - SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display,SDL_Screen,&nmodes,&modes)){
99 - qsort(modes, nmodes, sizeof *modes, cmpmodes);
100 + SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display,SDL_Screen,&nmodes,&modes) &&
101 + get_vidmode_filter(modes, nmodes, &bitmap) ) {
103 printf("Available modes:\n");
104 for ( i = 0; i < nmodes; ++i ) {
107 for ( i = nmodes-1; i > 0 ; --i ) {
108 if ( (modes[i]->hdisplay >= width) &&
109 - (modes[i]->vdisplay >= height) )
110 + (modes[i]->vdisplay >= height) &&
114 if ( (modes[i]->hdisplay != mode.hdisplay) ||
116 SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, modes[i]);
119 + if (bitmap) free(bitmap);
122 #endif /* XFREE86_VM */
124 int vm_major, vm_minor;
126 SDL_NAME(XF86VidModeModeInfo) **modes;
127 + char *bitmap = (char*)0;
130 int xme_major, xme_minor;
131 @@ -330,15 +407,18 @@
135 - SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) ) {
136 + SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) &&
137 + get_vidmode_filter(modes, nmodes, &bitmap) ) {
139 - qsort(modes, nmodes, sizeof *modes, cmpmodes);
140 SDL_modelist = (SDL_Rect **)malloc((nmodes+2)*sizeof(SDL_Rect *));
141 if ( SDL_modelist ) {
143 for ( i=0; i<nmodes; ++i ) {
146 + /* Exclude those vidmodes that have been filtered out */
147 + if (!bitmap[i]) continue;
149 /* Check to see if we should add the screen size (Xinerama) */
150 w = modes[i]->hdisplay;
151 h = modes[i]->vdisplay;
153 SDL_modelist[n] = NULL;
156 + if (bitmap) free(bitmap);
158 use_vidmode = vm_major * 100 + vm_minor;