From dca519a601d876c02fb4e49ffda63a35a225a47b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Strohh=C3=A4cker?= Date: Mon, 10 Jul 2006 19:32:15 +0000 Subject: [PATCH] fix keyboard handling for sdl windib driver as far as possible Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2670 --- include/video.h | 4 ++++ src/gui/sdl_mapper.cpp | 21 ++++++++++++++++++++- src/gui/sdlmain.cpp | 39 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/include/video.h b/include/video.h index e439369e..3f192e81 100644 --- a/include/video.h +++ b/include/video.h @@ -64,6 +64,10 @@ void GFX_SwitchFullScreen(void); bool GFX_StartUpdate(Bit8u * & pixels,Bitu & pitch); void GFX_EndUpdate( const Bit16u *changedLines ); +#if defined (WIN32) +bool GFX_SDLUsingWinDIB(void); +#endif + /* Mouse related */ void GFX_CaptureMouse(void); extern bool mouselocked; //true if mouse is confined to window diff --git a/src/gui/sdl_mapper.cpp b/src/gui/sdl_mapper.cpp index 822d43dc..dfe4918b 100644 --- a/src/gui/sdl_mapper.cpp +++ b/src/gui/sdl_mapper.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: sdl_mapper.cpp,v 1.25 2006-06-24 17:29:39 c2woody Exp $ */ +/* $Id: sdl_mapper.cpp,v 1.26 2006-07-10 19:32:15 c2woody Exp $ */ #define OLD_JOYSTICK 1 @@ -333,6 +333,25 @@ Bitu GetKeyCode(SDL_keysym keysym) { #if !defined (WIN32) && !defined (MACOSX) /* Linux adds 8 to all scancodes */ else key-=8; +#endif +#if defined (WIN32) + switch (key) { + case 0x1c: // ENTER + case 0x35: // SLASH + case 0x45: // PAUSE + case 0x47: // HOME + case 0x48: // cursor UP + case 0x49: // PAGE UP + case 0x4b: // cursor LEFT + case 0x4d: // cursor RIGHT + case 0x4f: // END + case 0x50: // cursor DOWN + case 0x51: // PAGE DOWN + case 0x52: // INSERT + case 0x53: // DELETE + if (GFX_SDLUsingWinDIB()) key=scancode_map[(Bitu)keysym.sym]; + break; + } #endif return key; } else { diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index a470d9c4..5e3488d6 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: sdlmain.cpp,v 1.119 2006-06-29 19:05:54 qbix79 Exp $ */ +/* $Id: sdlmain.cpp,v 1.120 2006-07-10 19:32:15 c2woody Exp $ */ #ifndef _GNU_SOURCE #define _GNU_SOURCE @@ -203,6 +203,9 @@ struct SDL_Block { Bitu sensitivity; } mouse; SDL_Rect updateRects[1024]; +#if defined (WIN32) + bool using_windib; +#endif }; static SDL_Block sdl; @@ -253,6 +256,11 @@ static void PauseDOSBox(bool pressed) { } } +#if defined (WIN32) +bool GFX_SDLUsingWinDIB(void) { + return sdl.using_windib; +} +#endif /* Reset the screen with current values in the sdl structure */ Bitu GFX_GetBestMode(Bitu flags) { @@ -423,6 +431,7 @@ dosurface: SDL_QuitSubSystem(SDL_INIT_VIDEO); putenv("SDL_VIDEODRIVER=windib"); SDL_InitSubSystem(SDL_INIT_VIDEO); + sdl.using_windib=true; sdl.surface = SDL_SetVideoMode(width,height,bpp,SDL_HWSURFACE); } #endif @@ -525,6 +534,9 @@ dosurface: goto dosurface; } SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); +#if defined (WIN32) && SDL_VERSION_ATLEAST(1, 2, 11) + SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 0 ); +#endif GFX_SetupSurfaceScaled(SDL_OPENGL,0); if (!sdl.surface || sdl.surface->format->BitsPerPixel<15) { LOG_MSG("SDL:OPENGL:Can't open drawing surface, are you running in 16bpp(or higher) mode?"); @@ -1335,6 +1347,31 @@ int main(int argc, char* argv[]) { |SDL_INIT_JOYSTICK #endif ) < 0 ) E_Exit("Can't init SDL %s",SDL_GetError()); +#if defined (WIN32) +#if SDL_VERSION_ATLEAST(1, 2, 10) + sdl.using_windib=true; +#else + sdl.using_windib=false; +#endif + char sdl_drv_name[128]; + if (getenv("SDL_VIDEODRIVER")==NULL) { + if (SDL_VideoDriverName(sdl_drv_name,128)!=NULL) { + if (strcmp(sdl_drv_name,"directx")!=0) { + SDL_QuitSubSystem(SDL_INIT_VIDEO); + putenv("SDL_VIDEODRIVER=directx"); + SDL_InitSubSystem(SDL_INIT_VIDEO); + } + sdl.using_windib=false; + } + } else { + char* sdl_videodrv = getenv("SDL_VIDEODRIVER"); + if (strcmp(sdl_videodrv,"directx")==0) sdl.using_windib = false; + else if (strcmp(sdl_videodrv,"windib")==0) sdl.using_windib = true; + } + if (SDL_VideoDriverName(sdl_drv_name,128)!=NULL) { + if (strcmp(sdl_drv_name,"windib")==0) LOG_MSG("SDL_Init: Starting up with SDL windib video driver.\n Try to update your video card and directx drivers!"); + } +#endif Section_prop * sdl_sec=control->AddSection_prop("sdl",&GUI_StartUp); sdl_sec->AddInitFunction(&MAPPER_StartUp); sdl_sec->Add_bool("fullscreen",false);