Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-//#include <termios.h>
-//#include <sys/ioctl.h>
-//#include <sys/stat.h>
-//#include <sys/vt.h>
-//#include <stdarg.h>
-//#include <stdio.h>
#include <signal.h>
#include <dlfcn.h>
static qboolean vid_usingmouse = false;
static qboolean vid_usingvsync = false;
static qboolean vid_usevsync = false;
+static qboolean vid_x11_hardwaregammasupported = false;
+static int vid_x11_gammarampsize = 0;
static float mouse_x, mouse_y;
static int p_mouse_x, p_mouse_y;
static int win_x, win_y;
-static XF86VidModeModeInfo **vidmodes;
-static int num_vidmodes;
+static XF86VidModeModeInfo init_vidmode;
static qboolean vid_isfullscreen = false;
static Visual *vidx11_visual;
case XK_Alt_L:
case XK_Meta_L:
+ case XK_ISO_Level3_Shift:
case XK_Alt_R:
case XK_Meta_R: key = K_ALT; break;
#endif
XWarpPointer(vidx11_display, None, win, 0, 0, 0, 0, vid.width / 2, vid.height / 2);
- XGrabKeyboard(vidx11_display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
+ if (vid_grabkeyboard.integer || vid_isfullscreen)
+ XGrabKeyboard(vidx11_display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
mouse_x = mouse_y = 0;
cl_ignoremousemove = true;
case MapNotify:
// window restored
vid_hidden = false;
- vid_activewindow = false;
VID_RestoreSystemGamma();
break;
case UnmapNotify:
// window iconified/rolledup/whatever
vid_hidden = true;
- vid_activewindow = false;
VID_RestoreSystemGamma();
break;
case FocusIn:
Con_Printf("Unable to open symbol list for %s\n", name);
return false;
}
- strcpy(gl_driver, name);
+ strlcpy(gl_driver, name, sizeof(gl_driver));
return true;
}
// FIXME: glXDestroyContext here?
if (vid_isfullscreen)
- XF86VidModeSwitchToMode(vidx11_display, vidx11_screen, vidmodes[0]);
+ XF86VidModeSwitchToMode(vidx11_display, vidx11_screen, &init_vidmode);
if (win)
XDestroyWindow(vidx11_display, win);
XCloseDisplay(vidx11_display);
signal(SIGTERM, signal_handler);
}
-void VID_Finish (void)
+void VID_Finish (qboolean allowmousegrab)
{
qboolean vid_usemouse;
Con_Print("glXSwapIntervalSGI didn't accept the vid_vsync change, it will take effect on next vid_restart (GLX_SGI_swap_control does not allow turning off vsync)\n");
}
-// handle the mouse state when windowed if that's changed
+ // handle the mouse state when windowed if that's changed
vid_usemouse = false;
- if (vid_mouse.integer && !key_consoleactive && !cls.demoplayback)
+ if (allowmousegrab && vid_mouse.integer && !key_consoleactive && (key_dest != key_game || !cls.demoplayback))
vid_usemouse = true;
if (!vid_activewindow)
vid_usemouse = false;
if (r_render.integer)
{
+ CHECKGLERROR
if (r_speeds.integer || gl_finish.integer)
- qglFinish();
- qglXSwapBuffers(vidx11_display, win);
+ {
+ qglFinish();CHECKGLERROR
+ }
+ qglXSwapBuffers(vidx11_display, win);CHECKGLERROR
}
+
+ if (vid_x11_hardwaregammasupported)
+ VID_UpdateGamma(false, vid_x11_gammarampsize);
}
-int VID_SetGamma(unsigned short *ramps)
+int VID_SetGamma(unsigned short *ramps, int rampsize)
{
- int rampsize;
- // FIXME: it would be good to generate ramps of the size reported by X,
- // for instance Quadro cards seem to use 1024 color ramps not 256
- if(!XF86VidModeGetGammaRampSize(vidx11_display, vidx11_screen, &rampsize))
- return 0;
- if(rampsize != 256)
- return 0;
- return XF86VidModeSetGammaRamp(vidx11_display, vidx11_screen, 256, ramps, ramps + 256, ramps + 512);
+ return XF86VidModeSetGammaRamp(vidx11_display, vidx11_screen, rampsize, ramps, ramps + rampsize, ramps + rampsize*2);
}
-int VID_GetGamma(unsigned short *ramps)
+int VID_GetGamma(unsigned short *ramps, int rampsize)
{
- int rampsize;
- if(!XF86VidModeGetGammaRampSize(vidx11_display, vidx11_screen, &rampsize))
- return 0;
- if(rampsize != 256)
- return 0;
- return XF86VidModeGetGammaRamp(vidx11_display, vidx11_screen, 256, ramps, ramps + 256, ramps + 512);
+ return XF86VidModeGetGammaRamp(vidx11_display, vidx11_screen, rampsize, ramps, ramps + rampsize, ramps + rampsize*2);
}
void VID_Init(void)
mouse_avail = false;
}
-void VID_BuildGLXAttrib(int *attrib, int stencil)
+void VID_BuildGLXAttrib(int *attrib, qboolean stencil, qboolean stereobuffer)
{
*attrib++ = GLX_RGBA;
*attrib++ = GLX_RED_SIZE;*attrib++ = 1;
*attrib++ = GLX_STENCIL_SIZE;*attrib++ = 8;
*attrib++ = GLX_ALPHA_SIZE;*attrib++ = 1;
}
+ if (stereobuffer)
+ *attrib++ = GLX_STEREO;
*attrib++ = None;
}
-int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate)
+int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate, int stereobuffer)
{
int i;
int attrib[32];
return false;
}
- VID_BuildGLXAttrib(attrib, bpp == 32);
+ VID_BuildGLXAttrib(attrib, bpp == 32, stereobuffer);
visinfo = qglXChooseVisual(vidx11_display, vidx11_screen, attrib);
if (!visinfo)
{
// Are we going fullscreen? If so, let's change video mode
if (fullscreen)
{
+ XF86VidModeModeLine *current_vidmode;
+ XF86VidModeModeInfo **vidmodes;
+ int num_vidmodes;
+
+ // This nice hack comes from the SDL source code
+ current_vidmode = (XF86VidModeModeLine*)((char*)&init_vidmode + sizeof(init_vidmode.dotclock));
+ XF86VidModeGetModeLine(vidx11_display, vidx11_screen, (int*)&init_vidmode.dotclock, current_vidmode);
+
XF86VidModeGetAllModeLines(vidx11_display, vidx11_screen, &num_vidmodes, &vidmodes);
best_dist = 9999999;
best_fit = -1;
}
else
fullscreen = 0;
+
+ free(vidmodes);
}
}
vid_usingvsync = false;
vid_hidden = false;
vid_activewindow = true;
+ vid_x11_hardwaregammasupported = XF86VidModeGetGammaRampSize(vidx11_display, vidx11_screen, &vid_x11_gammarampsize) != 0;
GL_Init();
return true;
}
void Sys_SendKeyEvents(void)
{
+ static qboolean sound_active = true;
+
+ // enable/disable sound on focus gain/loss
+ if (!vid_activewindow && sound_active)
+ {
+ S_BlockSound ();
+ sound_active = false;
+ }
+ else if (vid_activewindow && !sound_active)
+ {
+ S_UnblockSound ();
+ sound_active = true;
+ }
+
HandleEvents();
}