]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_sdl.c
Fixed the SDL video driver on Mac OS X (crash when restarting). Thanks to BigMac...
[xonotic/darkplaces.git] / vid_sdl.c
index 196fe4f497b39b7bc0fd511b268946e291078a22..295d8bca9174781c5b6f611c03af3a58f2bb2bc0 100644 (file)
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -28,9 +28,6 @@ static qboolean vid_isfullscreen;
 
 static SDL_Surface *screen;
 
-static void IN_Init( void );
-static void IN_Shutdown( void );
-
 /////////////////////////
 // Input handling
 ////
@@ -202,53 +199,39 @@ static int MapKey( unsigned int sdlkey )
     return tbl_sdltoquake[ sdlkey ];
 }
 
-static void IN_Activate( void )
-{
-       SDL_WM_GrabInput( SDL_GRAB_ON );
-       SDL_ShowCursor( SDL_DISABLE );
-}
-
-static void IN_Deactivate( void )
-{
-       SDL_WM_GrabInput( SDL_GRAB_OFF );
-       SDL_ShowCursor( SDL_ENABLE );
-}
-
-void IN_Commands (void)
-{
-}
-
-static void IN_MouseMove (void)
+static void IN_Activate( qboolean grab )
 {
-       int x, y;
-
-       if( !vid_usingmouse ) {
-               IN_Mouse( 0, 0 );
-               return;
+       if (grab)
+       {
+               if (!vid_usingmouse)
+               {
+                       vid_usingmouse = true;
+                       cl_ignoremousemove = true;
+                       SDL_WM_GrabInput( SDL_GRAB_ON );
+                       SDL_ShowCursor( SDL_DISABLE );
+               }
+       }
+       else
+       {
+               if (vid_usingmouse)
+               {
+                       vid_usingmouse = false;
+                       cl_ignoremousemove = true;
+                       SDL_WM_GrabInput( SDL_GRAB_OFF );
+                       SDL_ShowCursor( SDL_ENABLE );
+               }
        }
-
-       SDL_GetRelativeMouseState( &x, &y );
-       IN_Mouse( x, y );
 }
 
 void IN_Move( void )
 {
-       IN_MouseMove();
-}
-
-static void IN_Init( void )
-{
-       // init keyboard
-       SDL_EnableUNICODE( SDL_ENABLE );
-       // enable key repeat since everyone expects it
-       SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
-
-       // init mouse
-       vid_usingmouse = false;
-}
-
-static void IN_Shutdown( void )
-{
+       if( vid_usingmouse )
+       {
+               int x, y;
+               SDL_GetRelativeMouseState( &x, &y );
+               in_mouse_x = x;
+               in_mouse_y = y;
+       }
 }
 
 /////////////////////
@@ -324,9 +307,6 @@ void VID_Init (void)
        if (SDL_Init(SDL_INIT_VIDEO) < 0)
                Sys_Error ("Failed to init video: %s\n", SDL_GetError());
        vid_isfullscreen = false;
-
-       SDL_SetEventFilter( (SDL_EventFilter) Sys_EventFilter );
-       IN_Init();
 }
 
 // set the icon (we dont use SDL here since it would be too much a PITA)
@@ -379,9 +359,7 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp)
                We cant switch from one OpenGL video mode to another.
                Thus we first switch to some stupid 2D mode and then back to OpenGL.
        */
-#ifndef MACOSX
        SDL_SetVideoMode( 0, 0, 0, 0 );
-#endif
 
        // SDL usually knows best
        drivername = NULL;
@@ -438,7 +416,15 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp)
                VID_Shutdown();
                return false;
        }
+
+       // set window title
        VID_SetCaption();
+       // set up an event filter to ask confirmation on close button in WIN32
+       SDL_SetEventFilter( (SDL_EventFilter) Sys_EventFilter );
+       // init keyboard
+       SDL_EnableUNICODE( SDL_ENABLE );
+       // enable key repeat since everyone expects it
+       SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
 
        gl_renderer = qglGetString(GL_RENDERER);
        gl_vendor = qglGetString(GL_VENDOR);
@@ -455,13 +441,12 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp)
        vid_hidden = false;
        vid_activewindow = false;
        vid_usingmouse = false;
-       IN_Init();
        return true;
 }
 
 void VID_Shutdown (void)
 {
-       IN_Shutdown();
+       IN_Activate(false);
        SDL_QuitSubSystem(SDL_INIT_VIDEO);
 }
 
@@ -475,13 +460,6 @@ int VID_GetGamma (unsigned short *ramps)
        return !SDL_GetGammaRamp( ramps, ramps + 256, ramps + 512);
 }
 
-void VID_GetWindowSize (int *x, int *y, int *width, int *height)
-{
-       *x = *y = 0;
-       *width = screen->w;
-       *height = screen->h;
-}
-
 void VID_Finish (void)
 {
        Uint8 appstate;
@@ -507,11 +485,5 @@ void VID_Finish (void)
        if( !vid_activewindow )
                vid_usemouse = false;
 
-       if( vid_usemouse && !vid_usingmouse ) {
-               vid_usingmouse = true;
-               IN_Activate();
-       } else if( !vid_usemouse && vid_usingmouse ) {
-               vid_usingmouse = false;
-               IN_Deactivate();
-       }
+       IN_Activate(vid_usemouse);
 }