X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_window.c;h=f3c509a5023d29d5d6572682b2bef6e1372b7c1d;hb=123cc1d42bff9bdda4cc5a1b621d51b019814257;hp=00bdfdd75094bd6205463a22becd309dd9e63f3d;hpb=026710ef54197b252aec1082765bdc61fe2bb731;p=freeglut diff --git a/src/freeglut_window.c b/src/freeglut_window.c index 00bdfdd..f3c509a 100644 --- a/src/freeglut_window.c +++ b/src/freeglut_window.c @@ -31,6 +31,7 @@ #if TARGET_HOST_POSIX_X11 #include /* LONG_MAX */ +#include /* usleep */ #endif #if defined(_WIN32_WCE) @@ -140,6 +141,10 @@ typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShar #endif /* TARGET_HOST_MS_WINDOWS */ +#ifdef WM_TOUCH + typedef BOOL (WINAPI *pRegisterTouchWindow)(HWND,ULONG); + static pRegisterTouchWindow fghRegisterTouchWindow = (pRegisterTouchWindow)0xDEADBEEF; +#endif /* pushing attribute/value pairs into an array */ #define ATTRIB(a) attributes[where++]=(a) @@ -220,7 +225,7 @@ static void fghContextCreationError( void ) * Chooses a visual basing on the current display mode settings */ -GLXFBConfig* fgChooseFBConfig( void ) +GLXFBConfig* fgChooseFBConfig( int *numcfgs ) { GLboolean wantIndexedMode = GL_FALSE; int attributes[ 100 ]; @@ -385,6 +390,9 @@ GLXFBConfig* fgChooseFBConfig( void ) fbconfig = NULL; } + if (numcfgs) + *numcfgs = fbconfigArraySize; + return fbconfig; } } @@ -676,7 +684,7 @@ static void fghFillPFD( PIXELFORMATDESCRIPTOR *ppfd, HDC hdc, unsigned char laye ppfd->cGreenShift = 0; ppfd->cBlueShift = 0; ppfd->cAlphaShift = 0; - ppfd->cAccumBits = 0; + ppfd->cAccumBits = ( fgState.DisplayMode & GLUT_ACCUM ) ? 1 : 0; ppfd->cAccumRedBits = 0; ppfd->cAccumGreenBits = 0; ppfd->cAccumBlueBits = 0; @@ -730,9 +738,16 @@ GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly, PIXELFORMATDESCRIPTOR pfd; PIXELFORMATDESCRIPTOR* ppfd = &pfd; int pixelformat; + HDC current_hDC; + GLboolean success; + + if (checkOnly) + current_hDC = CreateDC(TEXT("DISPLAY"), NULL ,NULL ,NULL); + else + current_hDC = window->Window.Device; - fghFillPFD( ppfd, window->Window.Device, layer_type ); - pixelformat = ChoosePixelFormat( window->Window.Device, ppfd ); + fghFillPFD( ppfd, current_hDC, layer_type ); + pixelformat = ChoosePixelFormat( current_hDC, ppfd ); /* windows hack for multismapling/sRGB */ if ( ( fgState.DisplayMode & GLUT_MULTISAMPLE ) || @@ -754,10 +769,10 @@ GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly, hWnd=CreateWindow(_T("FREEGLUT_dummy"), _T(""), WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW , 0,0,0,0, 0, 0, fgDisplay.Instance, 0 ); hDC=GetDC(hWnd); SetPixelFormat( hDC, pixelformat, ppfd ); - + rc = wglCreateContext( hDC ); wglMakeCurrent(hDC, rc); - + if ( fghIsExtensionSupported( hDC, "WGL_ARB_multisample" ) ) { PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARBProc = @@ -770,7 +785,7 @@ GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly, float fAttributes[] = { 0, 0 }; UINT numFormats; fghFillPixelFormatAttributes( attributes, ppfd ); - bValid = wglChoosePixelFormatARBProc(window->Window.Device, attributes, fAttributes, 1, &iPixelFormat, &numFormats); + bValid = wglChoosePixelFormatARBProc(hDC, attributes, fAttributes, 1, &iPixelFormat, &numFormats); if ( bValid && numFormats > 0 ) { @@ -786,7 +801,12 @@ GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly, UnregisterClass(_T("FREEGLUT_dummy"), fgDisplay.Instance); } - return ( pixelformat != 0 ) && ( checkOnly || SetPixelFormat( window->Window.Device, pixelformat, ppfd ) ); + success = ( pixelformat != 0 ) && ( checkOnly || SetPixelFormat( current_hDC, pixelformat, ppfd ) ); + + if (checkOnly) + DeleteDC(current_hDC); + + return success; #endif /* defined(_WIN32_WCE) */ } @@ -809,17 +829,20 @@ void fgSetWindow ( SFG_Window *window ) ); } #elif TARGET_HOST_MS_WINDOWS - if( fgStructure.CurrentWindow ) - ReleaseDC( fgStructure.CurrentWindow->Window.Handle, - fgStructure.CurrentWindow->Window.Device ); - - if ( window ) + if ( window != fgStructure.CurrentWindow ) { - window->Window.Device = GetDC( window->Window.Handle ); - wglMakeCurrent( - window->Window.Device, - window->Window.Context - ); + if( fgStructure.CurrentWindow ) + ReleaseDC( fgStructure.CurrentWindow->Window.Handle, + fgStructure.CurrentWindow->Window.Device ); + + if ( window ) + { + window->Window.Device = GetDC( window->Window.Handle ); + wglMakeCurrent( + window->Window.Device, + window->Window.Context + ); + } } #endif fgStructure.CurrentWindow = window; @@ -887,6 +910,14 @@ static void get_display_origin(int *xp,int *yp) #endif +#if TARGET_HOST_POSIX_X11 +static Bool fghWindowIsVisible( Display *display, XEvent *event, XPointer arg) +{ + Window window = arg; + return (event->type == MapNotify) && (event->xmap.window == window); +} +#endif + /* * Opens a window. Requires a SFG_Window object created and attached @@ -903,14 +934,16 @@ void fgOpenWindow( SFG_Window* window, const char* title, XTextProperty textProperty; XSizeHints sizeHints; XWMHints wmHints; + XEvent eventReturnBuffer; /* return buffer required for a call */ unsigned long mask; + int num_FBConfigs, i; unsigned int current_DisplayMode = fgState.DisplayMode ; /* Save the display mode if we are creating a menu window */ if( window->IsMenu && ( ! fgStructure.MenuContext ) ) fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ; - window->Window.FBConfig = fgChooseFBConfig( ); + window->Window.FBConfig = fgChooseFBConfig( &num_FBConfigs ); if( window->IsMenu && ( ! fgStructure.MenuContext ) ) fgState.DisplayMode = current_DisplayMode ; @@ -925,14 +958,14 @@ void fgOpenWindow( SFG_Window* window, const char* title, if( !( fgState.DisplayMode & GLUT_DOUBLE ) ) { fgState.DisplayMode |= GLUT_DOUBLE ; - window->Window.FBConfig = fgChooseFBConfig( ); + window->Window.FBConfig = fgChooseFBConfig( &num_FBConfigs ); fgState.DisplayMode &= ~GLUT_DOUBLE; } if( fgState.DisplayMode & GLUT_MULTISAMPLE ) { fgState.DisplayMode &= ~GLUT_MULTISAMPLE ; - window->Window.FBConfig = fgChooseFBConfig( ); + window->Window.FBConfig = fgChooseFBConfig( &num_FBConfigs ); fgState.DisplayMode |= GLUT_MULTISAMPLE; } } @@ -941,8 +974,15 @@ void fgOpenWindow( SFG_Window* window, const char* title, "FBConfig with necessary capabilities not found", "fgOpenWindow" ); /* Get the X visual. */ - visualInfo = glXGetVisualFromFBConfig( fgDisplay.Display, - *(window->Window.FBConfig) ); + for (i = 0; i < num_FBConfigs; i++) { + visualInfo = glXGetVisualFromFBConfig( fgDisplay.Display, + window->Window.FBConfig[i] ); + if (visualInfo) + break; + } + + FREEGLUT_INTERNAL_ERROR_EXIT( visualInfo != NULL, + "visualInfo could not be retrieved from FBConfig", "fgOpenWindow" ); /* * XXX HINT: the masks should be updated when adding/removing callbacks. @@ -1084,10 +1124,18 @@ void fgOpenWindow( SFG_Window* window, const char* title, window->Window.Context ); + /* register extension events _before_ window is mapped */ + #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H + fgRegisterDevices( fgDisplay.Display, &(window->Window.Handle) ); + #endif + XMapWindow( fgDisplay.Display, window->Window.Handle ); XFree(visualInfo); + if( !isSubWindow) + XPeekIfEvent( fgDisplay.Display, &eventReturnBuffer, &fghWindowIsVisible, window->Window.Handle ); + #elif TARGET_HOST_MS_WINDOWS WNDCLASS wc; @@ -1242,11 +1290,18 @@ void fgOpenWindow( SFG_Window* window, const char* title, else if ( fgState.DisplayMode & GLUT_BORDERLESS ) { SetWindowLong ( window->Window.Handle, GWL_STYLE, - WindowStyle & ~(WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX)); + WindowStyle & ~(WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_DLGFRAME | WS_SIZEBOX)); } /* SetWindowPos(window->Window.Handle, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); */ + /* Enable multitouch: additional flag TWF_FINETOUCH, TWF_WANTPALM */ + #ifdef WM_TOUCH + if (fghRegisterTouchWindow == (pRegisterTouchWindow)0xDEADBEEF) + fghRegisterTouchWindow = (pRegisterTouchWindow)GetProcAddress(GetModuleHandle("user32"),"RegisterTouchWindow"); + if (fghRegisterTouchWindow) + fghRegisterTouchWindow( window->Window.Handle, TWF_FINETOUCH | TWF_WANTPALM ); + #endif #if defined(_WIN32_WCE) ShowWindow( window->Window.Handle, SW_SHOW ); @@ -1277,6 +1332,13 @@ void fgOpenWindow( SFG_Window* window, const char* title, */ void fgCloseWindow( SFG_Window* window ) { + /* if we're in gamemode and we're closing the gamemode window, + * call glutLeaveGameMode first to make sure the gamemode is + * properly closed before closing the window + */ + if (fgStructure.GameModeWindow != NULL && fgStructure.GameModeWindow->ID==window->ID) + glutLeaveGameMode(); + #if TARGET_HOST_POSIX_X11 if( window->Window.Context )