]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_glx.c
modified gamma handling, now VID_UpdateGamma is only called from VID_Finish, and...
[xonotic/darkplaces.git] / vid_glx.c
index 80fa95abbf7d3cf69df929a394ae6a04b5a1d447..eab081aad9cc7f655986244d7e6b12ce2fe4fb79 100644 (file)
--- a/vid_glx.c
+++ b/vid_glx.c
@@ -45,6 +45,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 // Tell startup code that we have a client
 int cl_available = true;
 
+// note: if we used the XRandR extension we could support refresh rates
+qboolean vid_supportrefreshrate = false;
+
 //GLX prototypes
 XVisualInfo *(GLAPIENTRY *qglXChooseVisual)(Display *dpy, int screen, int *attribList);
 GLXContext (GLAPIENTRY *qglXCreateContext)(Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct);
@@ -94,16 +97,16 @@ static float        mouse_x, mouse_y;
 static int p_mouse_x, p_mouse_y;
 
 #if !defined(__APPLE__) && !defined(SUNOS)
-cvar_t vid_dga = {CVAR_SAVE, "vid_dga", "1"};
-cvar_t vid_dga_mouseaccel = {0, "vid_dga_mouseaccel", "1"};
+// FIXME: vid_dga_mouseaccel is poorly named, it is actually the multiplier for mouse movement, not an acceleration (which would be a power function or something)
+cvar_t vid_dga = {CVAR_SAVE, "vid_dga", "1", "make use of DGA mouse input"};
+cvar_t vid_dga_mouseaccel = {0, "vid_dga_mouseaccel", "1", "speed of mouse when using DGA mouse input"};
 #endif
 
 qboolean vidmode_ext = false;
 
 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;
@@ -316,6 +319,28 @@ static void IN_Activate (qboolean grab)
        }
 }
 
+static keynum_t buttonremap[18] =
+{
+       K_MOUSE1,
+       K_MOUSE3,
+       K_MOUSE2,
+       K_MWHEELUP,
+       K_MWHEELDOWN,
+       K_MOUSE4,
+       K_MOUSE5,
+       K_MOUSE6,
+       K_MOUSE7,
+       K_MOUSE8,
+       K_MOUSE9,
+       K_MOUSE10,
+       K_MOUSE11,
+       K_MOUSE12,
+       K_MOUSE13,
+       K_MOUSE14,
+       K_MOUSE15,
+       K_MOUSE16,
+};
+
 static void HandleEvents(void)
 {
        XEvent event;
@@ -375,94 +400,18 @@ static void HandleEvents(void)
 
                case ButtonPress:
                        // mouse button pressed
-                       switch(event.xbutton.button)
-                       {
-                       case 1:
-                               Key_Event(K_MOUSE1, 0, true);
-                               break;
-                       case 2:
-                               Key_Event(K_MOUSE3, 0, true);
-                               break;
-                       case 3:
-                               Key_Event(K_MOUSE2, 0, true);
-                               break;
-                       case 4:
-                               Key_Event(K_MWHEELUP, 0, true);
-                               break;
-                       case 5:
-                               Key_Event(K_MWHEELDOWN, 0, true);
-                               break;
-                       case 6:
-                               Key_Event(K_MOUSE4, 0, true);
-                               break;
-                       case 7:
-                               Key_Event(K_MOUSE5, 0, true);
-                               break;
-                       case 8:
-                               Key_Event(K_MOUSE6, 0, true);
-                               break;
-                       case 9:
-                               Key_Event(K_MOUSE7, 0, true);
-                               break;
-                       case 10:
-                               Key_Event(K_MOUSE8, 0, true);
-                               break;
-                       case 11:
-                               Key_Event(K_MOUSE9, 0, true);
-                               break;
-                       case 12:
-                               Key_Event(K_MOUSE10, 0, true);
-                               break;
-                       default:
-                               Con_Printf("HandleEvents: ButtonPress gave value %d, 1-12 expected\n", event.xbutton.button);
-                               break;
-                       }
+                       if (event.xbutton.button <= 18)
+                               Key_Event(buttonremap[event.xbutton.button - 1], 0, true);
+                       else
+                               Con_Printf("HandleEvents: ButtonPress gave value %d, 1-18 expected\n", event.xbutton.button);
                        break;
 
                case ButtonRelease:
                        // mouse button released
-                       switch(event.xbutton.button)
-                       {
-                       case 1:
-                               Key_Event(K_MOUSE1, 0, false);
-                               break;
-                       case 2:
-                               Key_Event(K_MOUSE3, 0, false);
-                               break;
-                       case 3:
-                               Key_Event(K_MOUSE2, 0, false);
-                               break;
-                       case 4:
-                               Key_Event(K_MWHEELUP, 0, false);
-                               break;
-                       case 5:
-                               Key_Event(K_MWHEELDOWN, 0, false);
-                               break;
-                       case 6:
-                               Key_Event(K_MOUSE4, 0, false);
-                               break;
-                       case 7:
-                               Key_Event(K_MOUSE5, 0, false);
-                               break;
-                       case 8:
-                               Key_Event(K_MOUSE6, 0, false);
-                               break;
-                       case 9:
-                               Key_Event(K_MOUSE7, 0, false);
-                               break;
-                       case 10:
-                               Key_Event(K_MOUSE8, 0, false);
-                               break;
-                       case 11:
-                               Key_Event(K_MOUSE9, 0, false);
-                               break;
-                       case 12:
-                               Key_Event(K_MOUSE10, 0, false);
-                               break;
-                       default:
-                               Con_Printf("HandleEvents: ButtonRelease gave value %d, 1-12 expected\n", event.xbutton.button);
-                               break;
-                       }
+                       if (event.xbutton.button <= 18)
+                               Key_Event(buttonremap[event.xbutton.button - 1], 0, false);
+                       else
+                               Con_Printf("HandleEvents: ButtonRelease gave value %d, 1-18 expected\n", event.xbutton.button);
                        break;
 
                case CreateNotify:
@@ -573,7 +522,7 @@ void VID_Shutdown(void)
 
                // 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);
@@ -610,8 +559,9 @@ void InitSig(void)
        signal(SIGTERM, signal_handler);
 }
 
-void VID_Finish (void)
+void VID_Finish (qboolean allowmousegrab)
 {
+       int rampsize;
        qboolean vid_usemouse;
 
        vid_usevsync = vid_vsync.integer && !cls.timedemo && gl_videosyncavailable;
@@ -624,7 +574,7 @@ void VID_Finish (void)
 
 // 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 && !cls.demoplayback)
                vid_usemouse = true;
        if (!vid_activewindow)
                vid_usemouse = false;
@@ -638,16 +588,19 @@ void VID_Finish (void)
                        qglFinish();
                qglXSwapBuffers(vidx11_display, win);
        }
+
+       if(XF86VidModeGetGammaRampSize(vidx11_display, vidx11_screen, &rampsize))
+               VID_UpdateGamma(false, rampsize);
 }
 
-int VID_SetGamma(unsigned short *ramps)
+int VID_SetGamma(unsigned short *ramps, int rampsize)
 {
-       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)
 {
-       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)
@@ -679,7 +632,7 @@ void VID_BuildGLXAttrib(int *attrib, int stencil)
        *attrib++ = None;
 }
 
-int VID_InitMode(int fullscreen, int width, int height, int bpp)
+int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate)
 {
        int i;
        int attrib[32];
@@ -752,6 +705,14 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp)
                // 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;
@@ -788,6 +749,8 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp)
                        }
                        else
                                fullscreen = 0;
+
+                       free(vidmodes);
                }
        }