X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2FCommon%2Ffreeglut_window.c;h=1468627ac9f42ed237af566375bb63f95873c8be;hb=9486b7d6a3bf0d00cc00ab98380e99810250aa84;hp=802cf07f3319c072da695f32a00be0775891c62b;hpb=cf06fb91082cdf943efeef507086ba1d8cee6eb7;p=freeglut diff --git a/src/Common/freeglut_window.c b/src/Common/freeglut_window.c index 802cf07..1468627 100644 --- a/src/Common/freeglut_window.c +++ b/src/Common/freeglut_window.c @@ -89,11 +89,6 @@ #endif /* TARGET_HOST_POSIX_X11 */ -#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) #define ATTRIB_VAL(a,v) {ATTRIB(a); ATTRIB(v);} @@ -128,6 +123,18 @@ extern void fgPlatformOpenWindow( SFG_Window* window, const char* title, GLboolean sizeUse, int w, int h, GLboolean gameMode, GLboolean isSubWindow ); extern void fgPlatformCloseWindow( SFG_Window* window ); +extern void fgPlatformGlutShowWindow( void ); +extern void fgPlatformGlutHideWindow( void ); +extern void fgPlatformGlutIconifyWindow( void ); +extern void fgPlatformGlutSetWindowTitle( const char* title ); +extern void fgPlatformGlutSetIconTitle( const char* title ); +extern void fgPlatformGlutPositionWindow( int x, int y ); +extern void fgPlatformGlutPushWindow( void ); +extern void fgPlatformGlutPopWindow( void ); +extern void fgPlatformGlutFullScreen( SFG_Window *win ); +extern void fgPlatformGlutLeaveFullScreen( SFG_Window *win ); +extern void fgPlatformGlutFullScreenToggle( SFG_Window *win ); + /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */ @@ -391,7 +398,7 @@ static GLXContext fghCreateNewContext( SFG_Window* window ) /* "classic" context creation */ Display *dpy = fgDisplay.Display; - GLXFBConfig config = *(window->Window.FBConfig); + GLXFBConfig config = *(window->Window.pContext.FBConfig); int render_type = ( !menu && index_mode ) ? GLX_COLOR_INDEX_TYPE : GLX_RGBA_TYPE; GLXContext share_list = NULL; Bool direct = ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT ); @@ -541,12 +548,12 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, if( window->IsMenu && ( ! fgStructure.MenuContext ) ) fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ; - window->Window.FBConfig = fgChooseFBConfig( &num_FBConfigs ); + window->Window.pContext.FBConfig = fgChooseFBConfig( &num_FBConfigs ); if( window->IsMenu && ( ! fgStructure.MenuContext ) ) fgState.DisplayMode = current_DisplayMode ; - if( ! window->Window.FBConfig ) + if( ! window->Window.pContext.FBConfig ) { /* * The "fgChooseFBConfig" returned a null meaning that the visual @@ -556,25 +563,25 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, if( !( fgState.DisplayMode & GLUT_DOUBLE ) ) { fgState.DisplayMode |= GLUT_DOUBLE ; - window->Window.FBConfig = fgChooseFBConfig( &num_FBConfigs ); + window->Window.pContext.FBConfig = fgChooseFBConfig( &num_FBConfigs ); fgState.DisplayMode &= ~GLUT_DOUBLE; } if( fgState.DisplayMode & GLUT_MULTISAMPLE ) { fgState.DisplayMode &= ~GLUT_MULTISAMPLE ; - window->Window.FBConfig = fgChooseFBConfig( &num_FBConfigs ); + window->Window.pContext.FBConfig = fgChooseFBConfig( &num_FBConfigs ); fgState.DisplayMode |= GLUT_MULTISAMPLE; } } - FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.FBConfig != NULL, + FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.pContext.FBConfig != NULL, "FBConfig with necessary capabilities not found", "fgOpenWindow" ); /* Get the X visual. */ for (i = 0; i < num_FBConfigs; i++) { visualInfo = glXGetVisualFromFBConfig( fgDisplay.Display, - window->Window.FBConfig[i] ); + window->Window.pContext.FBConfig[i] ); if (visualInfo) break; } @@ -743,7 +750,7 @@ void fgPlatformCloseWindow( SFG_Window* window ) { if( window->Window.Context ) glXDestroyContext( fgDisplay.Display, window->Window.Context ); - XFree( window->Window.FBConfig ); + XFree( window->Window.pContext.FBConfig ); if( window->Window.Handle ) { XDestroyWindow( fgDisplay.Display, window->Window.Handle ); @@ -751,6 +758,154 @@ void fgPlatformCloseWindow( SFG_Window* window ) /* XFlush( fgDisplay.Display ); */ /* XXX Shouldn't need this */ } + +static Bool fghWindowIsVisible( Display *display, XEvent *event, XPointer arg) +{ + Window window = (Window)arg; + return (event->type == MapNotify) && (event->xmap.window == window); +} + + + + +/* + * This function makes the current window visible + */ +void fgPlatformGlutShowWindow( void ) +{ + XMapWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle ); + XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ +} + +/* + * This function hides the current window + */ +void fgPlatformGlutHideWindow( void ) +{ + if( fgStructure.CurrentWindow->Parent == NULL ) + XWithdrawWindow( fgDisplay.Display, + fgStructure.CurrentWindow->Window.Handle, + fgDisplay.Screen ); + else + XUnmapWindow( fgDisplay.Display, + fgStructure.CurrentWindow->Window.Handle ); + XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ +} + +/* + * Iconify the current window (top-level windows only) + */ +void fgPlatformGlutIconifyWindow( void ) +{ + XIconifyWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle, + fgDisplay.Screen ); + XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ +} + +/* + * Set the current window's title + */ +void fgPlatformGlutSetWindowTitle( const char* title ) +{ + XTextProperty text; + + text.value = (unsigned char *) title; + text.encoding = XA_STRING; + text.format = 8; + text.nitems = strlen( title ); + + XSetWMName( + fgDisplay.Display, + fgStructure.CurrentWindow->Window.Handle, + &text + ); + + XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ +} + +/* + * Set the current window's iconified title + */ +void fgPlatformGlutSetIconTitle( const char* title ) +{ + XTextProperty text; + + text.value = (unsigned char *) title; + text.encoding = XA_STRING; + text.format = 8; + text.nitems = strlen( title ); + + XSetWMIconName( + fgDisplay.Display, + fgStructure.CurrentWindow->Window.Handle, + &text + ); + + XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ +} + +/* + * Change the current window's position + */ +void fgPlatformGlutPositionWindow( int x, int y ) +{ + XMoveWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle, + x, y ); + XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ +} + +/* + * Lowers the current window (by Z order change) + */ +void fgPlatformGlutPushWindow( void ) +{ + XLowerWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle ); +} + +/* + * Raises the current window (by Z order change) + */ +void fgPlatformGlutPopWindow( void ) +{ + XRaiseWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle ); +} + +/* + * Resize the current window so that it fits the whole screen + */ +void fgPlatformGlutFullScreen( SFG_Window *win ) +{ + if(!glutGet(GLUT_FULL_SCREEN)) { + if(fghToggleFullscreen() != -1) { + win->State.IsFullscreen = GL_TRUE; + } + } +} + +/* + * If we are fullscreen, resize the current window back to its original size + */ +void fgPlatformGlutLeaveFullScreen( SFG_Window *win ) +{ + if(glutGet(GLUT_FULL_SCREEN)) { + if(fghToggleFullscreen() != -1) { + win->State.IsFullscreen = GL_FALSE; + } + } +} + +/* + * Toggle the window's full screen state. + */ +void fgPlatformGlutFullScreenToggle( SFG_Window *win ) +{ + if(fghToggleFullscreen() != -1) { + win->State.IsFullscreen = !win->State.IsFullscreen; + } +} + + + #endif /* TARGET_HOST_POSIX_X11 */ @@ -766,13 +921,6 @@ void fgSetWindow ( SFG_Window *window ) } -#if TARGET_HOST_POSIX_X11 -static Bool fghWindowIsVisible( Display *display, XEvent *event, XPointer arg) -{ - Window window = (Window)arg; - return (event->type == MapNotify) && (event->xmap.window == window); -} -#endif /* @@ -955,16 +1103,7 @@ void FGAPIENTRY glutShowWindow( void ) FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutShowWindow" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutShowWindow" ); -#if TARGET_HOST_POSIX_X11 - - XMapWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle ); - XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ - -#elif TARGET_HOST_MS_WINDOWS - - ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_SHOW ); - -#endif + fgPlatformGlutShowWindow (); fgStructure.CurrentWindow->State.Redisplay = GL_TRUE; } @@ -977,22 +1116,7 @@ void FGAPIENTRY glutHideWindow( void ) FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutHideWindow" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutHideWindow" ); -#if TARGET_HOST_POSIX_X11 - - if( fgStructure.CurrentWindow->Parent == NULL ) - XWithdrawWindow( fgDisplay.Display, - fgStructure.CurrentWindow->Window.Handle, - fgDisplay.Screen ); - else - XUnmapWindow( fgDisplay.Display, - fgStructure.CurrentWindow->Window.Handle ); - XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ - -#elif TARGET_HOST_MS_WINDOWS - - ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_HIDE ); - -#endif + fgPlatformGlutHideWindow (); fgStructure.CurrentWindow->State.Redisplay = GL_FALSE; } @@ -1006,17 +1130,8 @@ void FGAPIENTRY glutIconifyWindow( void ) FREEGLUT_EXIT_IF_NO_WINDOW ( "glutIconifyWindow" ); fgStructure.CurrentWindow->State.Visible = GL_FALSE; -#if TARGET_HOST_POSIX_X11 - XIconifyWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle, - fgDisplay.Screen ); - XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ - -#elif TARGET_HOST_MS_WINDOWS - - ShowWindow( fgStructure.CurrentWindow->Window.Handle, SW_MINIMIZE ); - -#endif + fgPlatformGlutIconifyWindow (); fgStructure.CurrentWindow->State.Redisplay = GL_FALSE; } @@ -1030,35 +1145,7 @@ void FGAPIENTRY glutSetWindowTitle( const char* title ) FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" ); if( ! fgStructure.CurrentWindow->Parent ) { -#if TARGET_HOST_POSIX_X11 - - XTextProperty text; - - text.value = (unsigned char *) title; - text.encoding = XA_STRING; - text.format = 8; - text.nitems = strlen( title ); - - XSetWMName( - fgDisplay.Display, - fgStructure.CurrentWindow->Window.Handle, - &text - ); - - XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ - -#elif TARGET_HOST_MS_WINDOWS -# ifdef _WIN32_WCE - { - wchar_t* wstr = fghWstrFromStr(title); - SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr ); - free(wstr); - } -# else - SetWindowText( fgStructure.CurrentWindow->Window.Handle, title ); -# endif - -#endif + fgPlatformGlutSetWindowTitle ( title ); } } @@ -1072,35 +1159,7 @@ void FGAPIENTRY glutSetIconTitle( const char* title ) if( ! fgStructure.CurrentWindow->Parent ) { -#if TARGET_HOST_POSIX_X11 - - XTextProperty text; - - text.value = (unsigned char *) title; - text.encoding = XA_STRING; - text.format = 8; - text.nitems = strlen( title ); - - XSetWMIconName( - fgDisplay.Display, - fgStructure.CurrentWindow->Window.Handle, - &text - ); - - XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ - -#elif TARGET_HOST_MS_WINDOWS -# ifdef _WIN32_WCE - { - wchar_t* wstr = fghWstrFromStr(title); - SetWindowText( fgStructure.CurrentWindow->Window.Handle, wstr ); - free(wstr); - } -# else - SetWindowText( fgStructure.CurrentWindow->Window.Handle, title ); -# endif - -#endif + fgPlatformGlutSetIconTitle ( title ); } } @@ -1137,30 +1196,7 @@ void FGAPIENTRY glutPositionWindow( int x, int y ) glutLeaveFullScreen(); } -#if TARGET_HOST_POSIX_X11 - - XMoveWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle, - x, y ); - XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ - -#elif TARGET_HOST_MS_WINDOWS - - { - RECT winRect; - - /* "GetWindowRect" returns the pixel coordinates of the outside of the window */ - GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect ); - MoveWindow( - fgStructure.CurrentWindow->Window.Handle, - x, - y, - winRect.right - winRect.left, - winRect.bottom - winRect.top, - TRUE - ); - } - -#endif + fgPlatformGlutPositionWindow ( x, y ); } /* @@ -1171,20 +1207,7 @@ void FGAPIENTRY glutPushWindow( void ) FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPushWindow" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPushWindow" ); -#if TARGET_HOST_POSIX_X11 - - XLowerWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle ); - -#elif TARGET_HOST_MS_WINDOWS - - SetWindowPos( - fgStructure.CurrentWindow->Window.Handle, - HWND_BOTTOM, - 0, 0, 0, 0, - SWP_NOSIZE | SWP_NOMOVE - ); - -#endif + fgPlatformGlutPushWindow (); } /* @@ -1195,20 +1218,7 @@ void FGAPIENTRY glutPopWindow( void ) FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPopWindow" ); FREEGLUT_EXIT_IF_NO_WINDOW ( "glutPopWindow" ); -#if TARGET_HOST_POSIX_X11 - - XRaiseWindow( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle ); - -#elif TARGET_HOST_MS_WINDOWS - - SetWindowPos( - fgStructure.CurrentWindow->Window.Handle, - HWND_TOP, - 0, 0, 0, 0, - SWP_NOSIZE | SWP_NOMOVE - ); - -#endif + fgPlatformGlutPopWindow (); } /* @@ -1238,91 +1248,7 @@ void FGAPIENTRY glutFullScreen( void ) return; } -#if TARGET_HOST_POSIX_X11 - if(!glutGet(GLUT_FULL_SCREEN)) { - if(fghToggleFullscreen() != -1) { - win->State.IsFullscreen = GL_TRUE; - } - } - -#elif TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) /* FIXME: what about WinCE */ - - if (glutGet(GLUT_FULL_SCREEN)) - { - /* Leave full screen state before entering fullscreen again (resizing?) */ - glutLeaveFullScreen(); - } - - { -#if(WINVER >= 0x0500) /* Windows 2000 or later */ - DWORD s; - RECT rect; - HMONITOR hMonitor; - MONITORINFO mi; - - /* For fullscreen mode, first remove all window decoration - * and set style to popup so it will overlap the taskbar - * then force to maximize on the screen on which it has the most - * overlap. - */ - - - /* store current window rect */ - GetWindowRect( win->Window.Handle, &win->State.OldRect ); - - /* store current window style */ - win->State.OldStyle = s = GetWindowLong(win->Window.Handle, GWL_STYLE); - - /* remove decorations from style and add popup style*/ - s &= ~WS_OVERLAPPEDWINDOW; - s |= WS_POPUP; - SetWindowLong(win->Window.Handle, GWL_STYLE, s); - SetWindowPos(win->Window.Handle, HWND_TOP, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); - - /* For fullscreen mode, find the monitor that is covered the most - * by the window and get its rect as the resize target. - */ - hMonitor= MonitorFromRect(&win->State.OldRect, MONITOR_DEFAULTTONEAREST); - mi.cbSize = sizeof(mi); - GetMonitorInfo(hMonitor, &mi); - rect = mi.rcMonitor; -#else /* if (WINVER >= 0x0500) */ - RECT rect; - - /* For fullscreen mode, force the top-left corner to 0,0 - * and adjust the window rectangle so that the client area - * covers the whole screen. - */ - - rect.left = 0; - rect.top = 0; - rect.right = fgDisplay.ScreenWidth; - rect.bottom = fgDisplay.ScreenHeight; - - AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | - WS_CLIPCHILDREN, FALSE ); -#endif /* (WINVER >= 0x0500) */ - - /* - * then resize window - * SWP_NOACTIVATE Do not activate the window - * SWP_NOOWNERZORDER Do not change position in z-order - * SWP_NOSENDCHANGING Suppress WM_WINDOWPOSCHANGING message - * SWP_NOZORDER Retains the current Z order (ignore 2nd param) - */ - SetWindowPos( fgStructure.CurrentWindow->Window.Handle, - HWND_TOP, - rect.left, - rect.top, - rect.right - rect.left, - rect.bottom - rect.top, - SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | - SWP_NOZORDER - ); - - win->State.IsFullscreen = GL_TRUE; - } -#endif + fgPlatformGlutFullScreen ( win ); } /* @@ -1337,37 +1263,7 @@ void FGAPIENTRY glutLeaveFullScreen( void ) win = fgStructure.CurrentWindow; -#if TARGET_HOST_POSIX_X11 - if(glutGet(GLUT_FULL_SCREEN)) { - if(fghToggleFullscreen() != -1) { - win->State.IsFullscreen = GL_FALSE; - } - } - -#elif TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE) /* FIXME: what about WinCE */ - if (!glutGet(GLUT_FULL_SCREEN)) - { - /* nothing to do */ - return; - } - - /* restore style of window before making it fullscreen */ - SetWindowLong(win->Window.Handle, GWL_STYLE, win->State.OldStyle); - SetWindowPos(win->Window.Handle, HWND_TOP, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); - - /* Then resize */ - SetWindowPos(win->Window.Handle, - HWND_TOP, - win->State.OldRect.left, - win->State.OldRect.top, - win->State.OldRect.right - win->State.OldRect.left, - win->State.OldRect.bottom - win->State.OldRect.top, - SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | - SWP_NOZORDER - ); - - win->State.IsFullscreen = GL_FALSE; -#endif + fgPlatformGlutLeaveFullScreen ( win ); } /* @@ -1382,16 +1278,7 @@ void FGAPIENTRY glutFullScreenToggle( void ) win = fgStructure.CurrentWindow; -#if TARGET_HOST_POSIX_X11 - if(fghToggleFullscreen() != -1) { - win->State.IsFullscreen = !win->State.IsFullscreen; - } -#elif TARGET_HOST_MS_WINDOWS - if (!win->State.IsFullscreen) - glutFullScreen(); - else - glutLeaveFullScreen(); -#endif + fgPlatformGlutFullScreenToggle ( win ); } /*