From 559d18ca74e251f36be16546d69ce81e4aae0be8 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 29 Jan 2006 06:11:38 +0000 Subject: [PATCH] Re-query the SDL_WINDOWID each time we initialize the video --- src/video/wincommon/SDL_lowvideo.h | 2 +- src/video/wincommon/SDL_sysevents.c | 5 +---- src/video/wincommon/SDL_wingl.c | 8 ++------ src/video/windib/SDL_dibevents.c | 19 +++++++++---------- src/video/windib/SDL_dibvideo.c | 4 ++-- src/video/windx5/SDL_dx5events.c | 5 ++++- src/video/windx5/SDL_dx5video.c | 6 +++--- 7 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/video/wincommon/SDL_lowvideo.h b/src/video/wincommon/SDL_lowvideo.h index 8e5acee49..b877946ee 100644 --- a/src/video/wincommon/SDL_lowvideo.h +++ b/src/video/wincommon/SDL_lowvideo.h @@ -61,7 +61,7 @@ extern LPSTR SDL_Appname; #endif extern HINSTANCE SDL_Instance; extern HWND SDL_Window; -extern const char *SDL_windowid; +extern BOOL SDL_windowid; /* Variables and functions exported to other parts of the native video subsystem (SDL_sysevents.c) diff --git a/src/video/wincommon/SDL_sysevents.c b/src/video/wincommon/SDL_sysevents.c index 62ddfeff3..a4a3f8cd0 100644 --- a/src/video/wincommon/SDL_sysevents.c +++ b/src/video/wincommon/SDL_sysevents.c @@ -672,7 +672,7 @@ void *SDL_GetModuleHandle(void) } /* This allows the SDL_WINDOWID hack */ -const char *SDL_windowid = NULL; +BOOL SDL_windowid = FALSE; static int app_registered = 0; @@ -743,9 +743,6 @@ int SDL_RegisterApp(char *name, Uint32 style, void *hInst) } #endif /* WM_MOUSELEAVE */ - /* Check for SDL_WINDOWID hack */ - SDL_windowid = getenv("SDL_WINDOWID"); - #ifndef NO_GETKEYBOARDSTATE /* Initialise variables for SDL_ToUnicode() */ codepage = GetCodePage(); diff --git a/src/video/wincommon/SDL_wingl.c b/src/video/wincommon/SDL_wingl.c index 186cba4dc..ac14c0433 100644 --- a/src/video/wincommon/SDL_wingl.c +++ b/src/video/wincommon/SDL_wingl.c @@ -44,15 +44,11 @@ static char rcsid = static int WIN_GL_ResetWindow(_THIS) { int status = 0; - int can_reset = 1; - /* If we were passed a window, then we can't create a new one */ - if ( SDL_windowid ) { - can_reset = 0; - } #if 0 /* This doesn't work with DirectX code (see CVS comments) */ #ifndef _WIN32_WCE /* FIXME WinCE needs the UNICODE version of CreateWindow() */ - if ( can_reset ) { + /* If we were passed a window, then we can't create a new one */ + if ( !SDL_windowid ) { /* Save the existing window attributes */ LONG style; RECT rect = { 0, 0, 0, 0 }; diff --git a/src/video/windib/SDL_dibevents.c b/src/video/windib/SDL_dibevents.c index 29fe2df3f..0db2564ae 100644 --- a/src/video/windib/SDL_dibevents.c +++ b/src/video/windib/SDL_dibevents.c @@ -404,24 +404,23 @@ static SDL_keysym *TranslateKey(UINT vkey, UINT scancode, SDL_keysym *keysym, in int DIB_CreateWindow(_THIS) { -#if defined(_WIN32_WCE) && (_WIN32_WCE < 300) - wchar_t *SDL_windowid_t; -#endif + char *windowid = getenv("SDL_WINDOWID"); #ifndef CS_BYTEALIGNCLIENT #define CS_BYTEALIGNCLIENT 0 #endif SDL_RegisterApp("SDL_app", CS_BYTEALIGNCLIENT, 0); - if ( SDL_windowid ) { -// wince 2.1 does not have strtol + SDL_windowid = (windowid != NULL); + if ( SDL_windowid ) { #if defined(_WIN32_WCE) && (_WIN32_WCE < 300) - SDL_windowid_t = malloc((strlen(SDL_windowid) + 1) * sizeof(wchar_t)); - MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, SDL_windowid, -1, SDL_windowid_t, strlen(SDL_windowid) + 1); - SDL_Window = (HWND)wcstol(SDL_windowid_t, NULL, 0); - free(SDL_windowid_t); + /* wince 2.1 does not have strtol */ + wchar_t *windowid_t = malloc((strlen(windowid) + 1) * sizeof(wchar_t)); + MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, windowid, -1, windowid_t, strlen(windowid) + 1); + SDL_Window = (HWND)wcstol(windowid_t, NULL, 0); + free(windowid_t); #else - SDL_Window = (HWND)strtol(SDL_windowid, NULL, 0); + SDL_Window = (HWND)strtol(windowid, NULL, 0); #endif if ( SDL_Window == NULL ) { SDL_SetError("Couldn't get user specified window"); diff --git a/src/video/windib/SDL_dibvideo.c b/src/video/windib/SDL_dibvideo.c index 8322f93e2..96bda2aeb 100644 --- a/src/video/windib/SDL_dibvideo.c +++ b/src/video/windib/SDL_dibvideo.c @@ -589,7 +589,7 @@ SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, } /* DJM: Don't piss of anyone who has setup his own window */ - if ( SDL_windowid == NULL ) + if ( !SDL_windowid ) SetWindowLong(SDL_Window, GWL_STYLE, style); /* Delete the old bitmap if necessary */ @@ -665,7 +665,7 @@ SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, } /* Resize the window */ - if ( SDL_windowid == NULL ) { + if ( !SDL_windowid ) { HWND top; UINT swp_flags; const char *window = getenv("SDL_VIDEO_WINDOW_POS"); diff --git a/src/video/windx5/SDL_dx5events.c b/src/video/windx5/SDL_dx5events.c index b46678805..ff4177279 100644 --- a/src/video/windx5/SDL_dx5events.c +++ b/src/video/windx5/SDL_dx5events.c @@ -848,6 +848,7 @@ static SDL_keysym *TranslateKey(UINT scancode, SDL_keysym *keysym, int pressed) int DX5_CreateWindow(_THIS) { + char *windowid = getenv("SDL_WINDOWID"); int i; /* Clear out DirectInput variables in case we fail */ @@ -861,8 +862,10 @@ int DX5_CreateWindow(_THIS) #define CS_BYTEALIGNCLIENT 0 #endif SDL_RegisterApp("SDL_app", CS_BYTEALIGNCLIENT, 0); + + SDL_windowid = (windowid != NULL); if ( SDL_windowid ) { - SDL_Window = (HWND)strtol(SDL_windowid, NULL, 0); + SDL_Window = (HWND)strtol(windowid, NULL, 0); if ( SDL_Window == NULL ) { SDL_SetError("Couldn't get user specified window"); return(-1); diff --git a/src/video/windx5/SDL_dx5video.c b/src/video/windx5/SDL_dx5video.c index 8abc6f1db..41b01ec52 100644 --- a/src/video/windx5/SDL_dx5video.c +++ b/src/video/windx5/SDL_dx5video.c @@ -1133,11 +1133,11 @@ SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current, } /* DJM: Don't piss of anyone who has setup his own window */ - if ( SDL_windowid == NULL ) + if ( !SDL_windowid ) SetWindowLong(SDL_Window, GWL_STYLE, style); /* Resize the window (copied from SDL WinDIB driver) */ - if ( SDL_windowid == NULL ) { + if ( !SDL_windowid ) { HWND top; UINT swp_flags; const char *window = getenv("SDL_VIDEO_WINDOW_POS"); @@ -1223,7 +1223,7 @@ SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current, #endif } /* DJM: Don't piss of anyone who has setup his own window */ - if ( SDL_windowid == NULL ) + if ( !SDL_windowid ) SetWindowLong(SDL_Window, GWL_STYLE, style); /* Set DirectDraw sharing mode.. exclusive when fullscreen */