annotate src/video/x11/SDL_x11modes.c @ 227:24878c14b391

Added X11 Xinerama support - fullscreen starts on screen 0
author Sam Lantinga <slouken@libsdl.org>
date Sat, 03 Nov 2001 17:03:16 +0000
parents a1c973c35fef
children 275a934573a7
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
13 Library General Public License for more details.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
16 License along with this library; if not, write to the Free
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
20 slouken@devolution.com
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23 #ifdef SAVE_RCSID
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 static char rcsid =
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25 "@(#) $Id$";
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 /* Utilities for getting and setting the X display mode */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30 #include <stdlib.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 #include <string.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 #include "SDL_timer.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34 #include "SDL_error.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35 #include "SDL_events.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 #include "SDL_events_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37 #include "SDL_x11video.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38 #include "SDL_x11wm_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 #include "SDL_x11modes_c.h"
88
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
40 #include "SDL_x11image_c.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41
227
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
42 #ifdef HAVE_XINERAMA
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
43 #include <X11/extensions/Xinerama.h>
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
44 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46 #ifdef XFREE86_VM
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47 Bool XVidMode(GetModeInfo, (Display *dpy, int scr, XF86VidModeModeInfo *info))
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49 XF86VidModeModeLine *l = (XF86VidModeModeLine*)((char*)info + sizeof info->dotclock);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
50 return XVidMode(GetModeLine, (dpy, scr, &info->dotclock, l));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
51 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52 #endif /* XFREE86_VM */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
53
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
54 #ifdef XFREE86_VM
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
55 static void save_mode(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57 memset(&saved_mode, 0, sizeof(saved_mode));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
58 XVidMode(GetModeInfo, (SDL_Display,SDL_Screen,&saved_mode));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
59 XVidMode(GetViewPort, (SDL_Display,SDL_Screen,&saved_view.x,&saved_view.y));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
60 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
61 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
62
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
63 #ifdef XFREE86_VM
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
64 static void restore_mode(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
65 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
66 XF86VidModeModeLine mode;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
67 int unused;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
68
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
69 if ( XVidMode(GetModeLine, (SDL_Display, SDL_Screen, &unused, &mode)) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
70 if ( (saved_mode.hdisplay != mode.hdisplay) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
71 (saved_mode.vdisplay != mode.vdisplay) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
72 XVidMode(SwitchToMode, (SDL_Display, SDL_Screen, &saved_mode));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
73 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
74 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
75 if ( (saved_view.x != 0) || (saved_view.y != 0) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
76 XVidMode(SetViewPort, (SDL_Display, SDL_Screen, saved_view.x, saved_view.y));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
77 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
78 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
79 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
80
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
81 #ifdef XFREE86_VM
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
82 static int cmpmodes(const void *va, const void *vb)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
83 {
91
e85e03f195b4 From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents: 90
diff changeset
84 const XF86VidModeModeInfo *a = *(const XF86VidModeModeInfo**)va;
e85e03f195b4 From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents: 90
diff changeset
85 const XF86VidModeModeInfo *b = *(const XF86VidModeModeInfo**)vb;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
86 if(a->hdisplay > b->hdisplay)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
87 return -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
88 return b->vdisplay - a->vdisplay;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
89 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
90 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
91
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
92 static void set_best_resolution(_THIS, int width, int height)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
93 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
94 #ifdef XFREE86_VM
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
95 if ( use_vidmode ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
96 XF86VidModeModeLine mode;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
97 XF86VidModeModeInfo **modes;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
98 int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
99 int nmodes;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
100
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
101 if ( XVidMode(GetModeLine, (SDL_Display, SDL_Screen, &i, &mode)) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
102 XVidMode(GetAllModeLines, (SDL_Display,SDL_Screen,&nmodes,&modes))){
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
103 qsort(modes, nmodes, sizeof *modes, cmpmodes);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
104 #ifdef XFREE86_DEBUG
227
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
105 printf("Available modes:\n");
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
106 for ( i = 0; i < nmodes; ++i ) {
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
107 printf("Mode %d: %dx%d\n", i,
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
108 modes[i]->hdisplay, modes[i]->vdisplay);
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
109 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
110 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
111 for ( i = nmodes-1; i > 0 ; --i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
112 if ( (modes[i]->hdisplay >= width) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
113 (modes[i]->vdisplay >= height) )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
114 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
115 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
116 if ( (modes[i]->hdisplay != mode.hdisplay) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
117 (modes[i]->vdisplay != mode.vdisplay) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
118 XVidMode(SwitchToMode, (SDL_Display, SDL_Screen, modes[i]));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
119 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
120 XFree(modes);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
121 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
122 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
123 #endif /* XFREE86_VM */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
124 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
125
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
126 static void get_real_resolution(_THIS, int* w, int* h)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
127 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
128 #ifdef XFREE86_VM
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
129 if ( use_vidmode ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
130 XF86VidModeModeLine mode;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
131 int unused;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
132
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
133 if ( XVidMode(GetModeLine, (SDL_Display, SDL_Screen, &unused, &mode)) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
134 *w = mode.hdisplay;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
135 *h = mode.vdisplay;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
136 return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
137 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
138 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
139 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
140 *w = DisplayWidth(SDL_Display, SDL_Screen);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
141 *h = DisplayHeight(SDL_Display, SDL_Screen);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
142 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
143
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
144 /* Called after mapping a window - waits until the window is mapped */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
145 void X11_WaitMapped(_THIS, Window win)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
146 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
147 XEvent event;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
148 do {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
149 XMaskEvent(SDL_Display, StructureNotifyMask, &event);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
150 } while ( (event.type != MapNotify) || (event.xmap.event != win) );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
151 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
152
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
153 /* Called after unmapping a window - waits until the window is unmapped */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
154 void X11_WaitUnmapped(_THIS, Window win)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
155 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
156 XEvent event;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
157 do {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
158 XMaskEvent(SDL_Display, StructureNotifyMask, &event);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
159 } while ( (event.type != UnmapNotify) || (event.xunmap.event != win) );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
160 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
161
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
162 static void move_cursor_to(_THIS, int x, int y)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
163 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
164 XWarpPointer(SDL_Display, None, SDL_Root, 0, 0, 0, 0, x, y);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
165 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
166
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
167 static int add_visual(_THIS, int depth, int class)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
168 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
169 XVisualInfo vi;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
170 if(XMatchVisualInfo(SDL_Display, SDL_Screen, depth, class, &vi)) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
171 int n = this->hidden->nvisuals;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
172 this->hidden->visuals[n].depth = vi.depth;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
173 this->hidden->visuals[n].visual = vi.visual;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
174 this->hidden->nvisuals++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
175 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
176 return(this->hidden->nvisuals);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
177 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
178 static int add_visual_byid(_THIS, const char *visual_id)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
179 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
180 XVisualInfo *vi, template;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
181 int nvis;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
182
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
183 if ( visual_id ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
184 memset(&template, 0, (sizeof template));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
185 template.visualid = strtol(visual_id, NULL, 0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
186 vi = XGetVisualInfo(SDL_Display, VisualIDMask, &template, &nvis);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
187 if ( vi ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
188 int n = this->hidden->nvisuals;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
189 this->hidden->visuals[n].depth = vi->depth;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
190 this->hidden->visuals[n].visual = vi->visual;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
191 this->hidden->nvisuals++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
192 XFree(vi);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
193 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
194 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
195 return(this->hidden->nvisuals);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
196 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
197
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
198 /* Global for the error handler */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
199 int vm_event, vm_error = -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
200
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
201 int X11_GetVideoModes(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
202 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
203 #ifdef XFREE86_VM
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
204 int buggy_X11;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
205 int vm_major, vm_minor;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
206 int nmodes;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
207 XF86VidModeModeInfo **modes;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
208 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
209 int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
210
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
211 vm_error = -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
212 use_vidmode = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
213 #ifdef XFREE86_VM
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
214 /* Metro-X 4.3.0 and earlier has a broken implementation of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
215 XF86VidModeGetAllModeLines() - it hangs the client.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
216 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
217 buggy_X11 = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
218 if ( strcmp(ServerVendor(SDL_Display), "Metro Link Incorporated") == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
219 FILE *metro_fp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
220
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
221 metro_fp = fopen("/usr/X11R6/lib/X11/Metro/.version", "r");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
222 if ( metro_fp != NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
223 int major, minor, patch, version;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
224 major = 0; minor = 0; patch = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
225 fscanf(metro_fp, "%d.%d.%d", &major, &minor, &patch);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
226 version = major*100+minor*10+patch;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
227 if ( version < 431 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
228 buggy_X11 = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
229 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
230 fclose(metro_fp);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
231 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
232 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
233 #if defined(__alpha__) || defined(__powerpc__)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
234 /* The alpha and PPC XFree86 servers are also buggy */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
235 buggy_X11 = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
236 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
237 /* Enumerate the available fullscreen modes */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
238 if ( ! buggy_X11 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
239 if ( XVidMode(QueryExtension, (SDL_Display, &vm_event, &vm_error)) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
240 XVidMode(QueryVersion, (SDL_Display, &vm_major, &vm_minor)) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
241 #ifdef BROKEN_XFREE86_4001
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
242 #ifdef X_XF86VidModeGetDotClocks /* Compiled under XFree86 4.0 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
243 /* Earlier X servers hang when doing vidmode */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
244 if ( vm_major < 2 ) {
227
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
245 #ifdef XFREE86_DEBUG
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
246 printf("Compiled under XFree86 4.0, server is XFree86 3.X\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
247 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
248 buggy_X11 = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
249 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
250 #else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
251 /* XFree86 3.X code works with XFree86 4.0 servers */;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
252 #endif /* XFree86 4.0 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
253 #endif /* XFree86 4.02 and newer are fixed wrt backwards compatibility */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
254 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
255 buggy_X11 = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
256 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
257 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
258 if ( ! buggy_X11 &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
259 XVidMode(GetAllModeLines, (SDL_Display, SDL_Screen,&nmodes,&modes)) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
260
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
261 qsort(modes, nmodes, sizeof *modes, cmpmodes);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
262 SDL_modelist = (SDL_Rect **)malloc((nmodes+1)*sizeof(SDL_Rect *));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
263 if ( SDL_modelist ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
264 for ( i=0; i<nmodes; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
265 SDL_modelist[i] = (SDL_Rect *)malloc(sizeof(SDL_Rect));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
266 if ( SDL_modelist[i] == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
267 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
268 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
269 SDL_modelist[i]->x = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
270 SDL_modelist[i]->y = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
271 SDL_modelist[i]->w = modes[i]->hdisplay;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
272 SDL_modelist[i]->h = modes[i]->vdisplay;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
273 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
274 SDL_modelist[i] = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
275 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
276 XFree(modes);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
277
100
a1c973c35fef Fixed using the video mode extension on older servers
Sam Lantinga <slouken@lokigames.com>
parents: 98
diff changeset
278 use_vidmode = vm_major * 100 + vm_minor;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
279 save_mode(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
280 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
281 #endif /* XFREE86_VM */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
282
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
283 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
284 static int depth_list[] = { 32, 24, 16, 15, 8 };
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
285 int j, np;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
286 int use_directcolor = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
287 XPixmapFormatValues *pf;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
288
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
289 /* Search for the visuals in deepest-first order, so that the first
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
290 will be the richest one */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
291 if ( getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
292 use_directcolor = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
293 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
294 this->hidden->nvisuals = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
295 if ( ! add_visual_byid(this, getenv("SDL_VIDEO_X11_VISUALID")) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
296 for ( i=0; i<SDL_TABLESIZE(depth_list); ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
297 if ( depth_list[i] > 8 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
298 if ( use_directcolor ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
299 add_visual(this, depth_list[i], DirectColor);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
300 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
301 add_visual(this, depth_list[i], TrueColor);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
302 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
303 add_visual(this, depth_list[i], PseudoColor);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
304 add_visual(this, depth_list[i], StaticColor);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
305 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
306 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
307 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
308 if ( this->hidden->nvisuals == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
309 SDL_SetError("Found no sufficiently capable X11 visuals");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
310 return -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
311 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
312
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
313 /* look up the pixel quantum for each depth */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
314 pf = XListPixmapFormats(SDL_Display, &np);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
315 for(i = 0; i < this->hidden->nvisuals; i++) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
316 int d = this->hidden->visuals[i].depth;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
317 for(j = 0; j < np; j++)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
318 if(pf[j].depth == d)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
319 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
320 this->hidden->visuals[i].bpp = j < np ? pf[j].bits_per_pixel : d;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
321 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
322
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
323 XFree(pf);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
324 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
325
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
326 if ( SDL_modelist == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
327 SDL_modelist = (SDL_Rect **)malloc((1+1)*sizeof(SDL_Rect *));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
328 i = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
329 if ( SDL_modelist ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
330 SDL_modelist[i] = (SDL_Rect *)malloc(sizeof(SDL_Rect));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
331 if ( SDL_modelist[i] ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
332 SDL_modelist[i]->x = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
333 SDL_modelist[i]->y = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
334 SDL_modelist[i]->w = DisplayWidth(SDL_Display, SDL_Screen);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
335 SDL_modelist[i]->h = DisplayHeight(SDL_Display, SDL_Screen);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
336 ++i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
337 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
338 SDL_modelist[i] = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
339 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
340 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
341
227
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
342 #ifdef XFREE86_DEBUG
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
343 if ( use_vidmode ) {
227
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
344 printf("XFree86 VidMode is enabled\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
345 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
346 if ( SDL_modelist ) {
227
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
347 printf("X11 video mode list:\n");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
348 for ( i=0; SDL_modelist[i]; ++i ) {
227
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
349 printf("\t%dx%d\n", SDL_modelist[i]->w, SDL_modelist[i]->h);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
350 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
351 }
227
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
352 #endif /* XFREE86_DEBUG */
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
353
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
354 /* The default X/Y fullscreen offset is 0/0 */
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
355 xinerama_x = 0;
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
356 xinerama_y = 0;
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
357
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
358 #ifdef HAVE_XINERAMA
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
359 /* Query Xinerama extention */
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
360 if ( XineramaQueryExtension(SDL_Display, &i, &i) &&
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
361 XineramaIsActive(SDL_Display) ) {
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
362 /* Find out which screen is the zero'th one */
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
363 int screens;
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
364 XineramaScreenInfo *xinerama;
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
365
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
366 #ifdef XINERAMA_DEBUG
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
367 printf("X11 detected Xinerama:\n");
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
368 #endif
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
369 xinerama = XineramaQueryScreens(SDL_Display, &screens);
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
370 for ( i = 0; i < screens; i++ ) {
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
371 #ifdef XINERAMA_DEBUG
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
372 printf("xinerama %d: %dx%d+%d+%d\n",
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
373 xinerama[i].screen_number,
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
374 xinerama[i].width, xinerama[i].height,
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
375 xinerama[i].x_org, xinerama[i].y_org);
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
376 #endif
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
377 if ( xinerama[i].screen_number == 0 ) {
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
378 xinerama_x = xinerama[i].x_org;
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
379 xinerama_y = xinerama[i].y_org;
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
380 }
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
381 }
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
382 XFree(xinerama);
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
383 }
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
384 #endif /* HAVE_XINERAMA */
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
385
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
386 return 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
387 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
388
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
389 int X11_SupportedVisual(_THIS, SDL_PixelFormat *format)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
390 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
391 int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
392 for(i = 0; i < this->hidden->nvisuals; i++)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
393 if(this->hidden->visuals[i].bpp == format->BitsPerPixel)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
394 return 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
395 return 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
396 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
397
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
398 SDL_Rect **X11_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
399 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
400 if ( X11_SupportedVisual(this, format) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
401 if ( flags & SDL_FULLSCREEN ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
402 return(SDL_modelist);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
403 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
404 return((SDL_Rect **)-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
405 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
406 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
407 return((SDL_Rect **)0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
408 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
409 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
410
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
411 void X11_FreeVideoModes(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
412 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
413 int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
414
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
415 if ( SDL_modelist ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
416 for ( i=0; SDL_modelist[i]; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
417 free(SDL_modelist[i]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
418 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
419 free(SDL_modelist);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
420 SDL_modelist = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
421 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
422 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
423
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
424 int X11_ResizeFullScreen(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
425 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
426 int x, y;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
427 int real_w, real_h;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
428
227
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
429 x = xinerama_x;
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
430 y = xinerama_y;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
431 if ( currently_fullscreen ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
432 /* Switch resolution and cover it with the FSwindow */
227
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
433 move_cursor_to(this, x, y);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
434 set_best_resolution(this, current_w, current_h);
227
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
435 move_cursor_to(this, x, y);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
436 get_real_resolution(this, &real_w, &real_h);
227
24878c14b391 Added X11 Xinerama support - fullscreen starts on screen 0
Sam Lantinga <slouken@libsdl.org>
parents: 100
diff changeset
437 XMoveResizeWindow(SDL_Display, FSwindow, x, y, real_w, real_h);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
438 move_cursor_to(this, real_w/2, real_h/2);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
439
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
440 /* Center and reparent the drawing window */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
441 x = (real_w - current_w)/2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
442 y = (real_h - current_h)/2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
443 XReparentWindow(SDL_Display, SDL_Window, FSwindow, x, y);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
444 /* FIXME: move the mouse to the old relative location */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
445 XSync(SDL_Display, True); /* Flush spurious mode change events */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
446 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
447 return(1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
448 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
449
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
450 void X11_QueueEnterFullScreen(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
451 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
452 switch_waiting = 0x01 | SDL_FULLSCREEN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
453 switch_time = SDL_GetTicks() + 1500;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
454 #if 0 /* This causes a BadMatch error if the window is iconified (not needed) */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
455 XSetInputFocus(SDL_Display, WMwindow, RevertToNone, CurrentTime);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
456 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
457 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
458
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
459 int X11_EnterFullScreen(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
460 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
461 int okay;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
462 #if 0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
463 Window tmpwin, *windows;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
464 int i, nwindows;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
465 #endif
98
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
466 int real_w, real_h;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
467
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
468 okay = 1;
98
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
469 if ( currently_fullscreen ) {
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
470 return(okay);
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
471 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
472
98
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
473 /* Ungrab the input so that we can move the mouse around */
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
474 X11_GrabInputNoLock(this, SDL_GRAB_OFF);
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
475
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
476 /* Map the fullscreen window to blank the screen */
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
477 get_real_resolution(this, &real_w, &real_h);
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
478 XMoveResizeWindow(SDL_Display, FSwindow, 0, 0, real_w, real_h);
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
479 XMapRaised(SDL_Display, FSwindow);
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
480 X11_WaitMapped(this, FSwindow);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
481
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
482 #if 0 /* This seems to break WindowMaker in focus-follows-mouse mode */
98
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
483 /* Make sure we got to the top of the window stack */
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
484 if ( XQueryTree(SDL_Display, SDL_Root, &tmpwin, &tmpwin,
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
485 &windows, &nwindows) && windows ) {
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
486 /* If not, try to put us there - if fail... oh well */
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
487 if ( windows[nwindows-1] != FSwindow ) {
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
488 tmpwin = windows[nwindows-1];
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
489 for ( i=0; i<nwindows; ++i ) {
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
490 if ( windows[i] == FSwindow ) {
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
491 memcpy(&windows[i], &windows[i+1],
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
492 (nwindows-i-1)*sizeof(windows[i]));
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
493 break;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
494 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
495 }
98
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
496 windows[nwindows-1] = FSwindow;
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
497 XRestackWindows(SDL_Display, windows, nwindows);
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
498 XSync(SDL_Display, False);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
499 }
98
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
500 XFree(windows);
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
501 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
502 #else
98
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
503 XRaiseWindow(SDL_Display, FSwindow);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
504 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
505
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
506 #ifdef XFREE86_VM
98
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
507 /* Save the current video mode */
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
508 if ( use_vidmode ) {
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
509 XVidMode(LockModeSwitch, (SDL_Display, SDL_Screen, True));
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
510 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
511 #endif
98
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
512 currently_fullscreen = 1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
513
98
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
514 /* Set the new resolution */
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
515 okay = X11_ResizeFullScreen(this);
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
516 if ( ! okay ) {
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
517 X11_LeaveFullScreen(this);
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
518 }
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
519 /* Set the colormap */
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
520 if ( SDL_XColorMap ) {
8a5aff5c1294 Fixed some problems with the fullscreen code. Wooo. :)
Sam Lantinga <slouken@lokigames.com>
parents: 91
diff changeset
521 XInstallColormap(SDL_Display, SDL_XColorMap);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
522 }
88
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
523 if ( okay )
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
524 X11_GrabInputNoLock(this, this->input_grab | SDL_GRAB_FULLSCREEN);
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
525
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
526 /* We may need to refresh the screen at this point (no backing store)
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
527 We also don't get an event, which is why we explicitly refresh. */
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
528 if ( this->screen ) {
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
529 if ( this->screen->flags & SDL_OPENGL ) {
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
530 SDL_PrivateExpose();
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
531 } else {
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
532 X11_RefreshDisplay(this);
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
533 }
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
534 }
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
535
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
536 return(okay);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
537 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
538
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
539 int X11_LeaveFullScreen(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
540 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
541 if ( currently_fullscreen ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
542 XReparentWindow(SDL_Display, SDL_Window, WMwindow, 0, 0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
543 #ifdef XFREE86_VM
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
544 if ( use_vidmode ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
545 restore_mode(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
546 XVidMode(LockModeSwitch, (SDL_Display, SDL_Screen, False));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
547 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
548 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
549 XUnmapWindow(SDL_Display, FSwindow);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
550 X11_WaitUnmapped(this, FSwindow);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
551 XSync(SDL_Display, True); /* Flush spurious mode change events */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
552 currently_fullscreen = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
553 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
554 /* If we get popped out of fullscreen mode for some reason, input_grab
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
555 will still have the SDL_GRAB_FULLSCREEN flag set, since this is only
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
556 temporary. In this case, release the grab unless the input has been
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
557 explicitly grabbed.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
558 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
559 X11_GrabInputNoLock(this, this->input_grab & ~SDL_GRAB_FULLSCREEN);
88
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
560
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
561 /* We may need to refresh the screen at this point (no backing store)
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
562 We also don't get an event, which is why we explicitly refresh. */
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
563 if ( this->screen ) {
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
564 if ( this->screen->flags & SDL_OPENGL ) {
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
565 SDL_PrivateExpose();
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
566 } else {
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
567 X11_RefreshDisplay(this);
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
568 }
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
569 }
71774090f286 Hopefully fixed the fullscreen mode code for KDE
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
570
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
571 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
572 }