From 69502d33621e8850057db1b8ca9f9a6334a88316 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Sat, 22 May 2010 12:18:02 +0200 Subject: [PATCH 1/6] Implement CDriverGL::setMode for X --- .../src/3d/driver/opengl/driver_opengl.cpp | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.cpp b/code/nel/src/3d/driver/opengl/driver_opengl.cpp index 3d9c40b31..057d7e276 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl.cpp @@ -1612,9 +1612,46 @@ bool CDriverGL::setMode(const GfxMode& mode) _WindowX = clientRect.left; _WindowY = clientRect.top; _FullScreen = !mode.Windowed; -#else - // TODO linux version !!! -#endif + +#elif defined(NL_OS_UNIX) // NL_OS_WINDOWS + + // Update WM hints (update size and disallow resizing) + XSizeHints size_hints; + size_hints.x = 0; + size_hints.y = 0; + size_hints.width = mode.Width; + size_hints.height = mode.Height; + size_hints.flags = PSize | PMinSize | PMaxSize; + size_hints.min_width = mode.Width; + size_hints.min_height = mode.Height; + size_hints.max_width = mode.Width; + size_hints.max_height = mode.Height; + + XSetWMNormalHints(dpy, win, &size_hints); + + // Toggle fullscreen + if (mode.Windowed == _FullScreen) + { + XEvent xev; + memset(&xev, 0, sizeof(xev)); + xev.type = ClientMessage; + xev.xclient.window = win; + xev.xclient.message_type = XInternAtom(dpy, "_NET_WM_STATE", false); + xev.xclient.format = 32; + xev.xclient.data.l[0] = !mode.Windowed; + xev.xclient.data.l[1] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", false); + xev.xclient.data.l[2] = 0; + XSendEvent(dpy, DefaultRootWindow(dpy), false, SubstructureNotifyMask, &xev); + + //TODO: Change X display mode + } + _FullScreen = !mode.Windowed; + + // Resize and update the window + XResizeWindow(dpy, win, mode.Width, mode.Height); + XMapWindow(dpy, win); + +#endif // NL_OS_UNIX return true; } From 9cb84682aef261bb067d9e5b4cf8a80d41dc392e Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Sat, 22 May 2010 12:54:26 +0200 Subject: [PATCH 2/6] Add X mode setting when fullscreen --- .../src/3d/driver/opengl/driver_opengl.cpp | 63 ++++++++++++++----- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.cpp b/code/nel/src/3d/driver/opengl/driver_opengl.cpp index 057d7e276..066392c20 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl.cpp @@ -1096,22 +1096,7 @@ bool CDriverGL::setDisplay(void *wnd, const GfxMode &mode, bool show, bool resiz XSetWindowAttributes attr; attr.colormap = cmap; attr.background_pixel = BlackPixel(dpy, DefaultScreen(dpy)); - -#ifdef XF86VIDMODE - // If we're going to attempt fullscreen, we need to set redirect to True, - // This basically places the window with no borders in the top left - // corner of the screen. - if (mode.Windowed) - { - attr.override_redirect = False; - } - else - { - attr.override_redirect = True; - } -#else attr.override_redirect = False; -#endif int attr_flags = CWOverrideRedirect | CWColormap | CWBackPixel; @@ -1615,6 +1600,52 @@ bool CDriverGL::setMode(const GfxMode& mode) #elif defined(NL_OS_UNIX) // NL_OS_WINDOWS +#ifdef XF86VIDMODE + if (!mode.Windowed) + { + if (mode.Windowed == _FullScreen) + { + memset(&_OldScreenMode, 0, sizeof(_OldScreenMode)); + XF86VidModeGetModeLine(dpy, DefaultScreen(dpy), &_OldDotClock, &_OldScreenMode); + XF86VidModeGetViewPort(dpy, DefaultScreen(dpy), &_OldX, &_OldY); + } + + XF86VidModeModeInfo **modes; + int nmodes; + if (XF86VidModeGetAllModeLines(dpy, DefaultScreen(dpy), &nmodes, &modes)) + { + for (int i = 0; i < nmodes; i++) + { + nldebug("3D: Available mode - %dx%d", modes[i]->hdisplay, modes[i]->vdisplay); + if(modes[i]->hdisplay == mode.Width && modes[i]->vdisplay == mode.Height) + { + if(XF86VidModeSwitchToMode(dpy, DefaultScreen(dpy), modes[i])) + { + nlinfo("3D: Switching to mode %dx%d", modes[i]->hdisplay, modes[i]->vdisplay); + XF86VidModeSetViewPort(dpy, DefaultScreen(dpy), 0, 0); + } + break; + } + } + } + } + else if (mode.Windowed == _FullScreen) + { + XF86VidModeModeInfo info; + nlinfo("3D: Switching back to original mode"); + + // This is a bit ugly - a quick hack to copy the ModeLine structure + // into the modeInfo structure. + memcpy((XF86VidModeModeLine *)((char *)&info + sizeof(info.dotclock)),&_OldScreenMode, sizeof(XF86VidModeModeLine)); + info.dotclock = _OldDotClock; + + nlinfo("3D: Switching back mode to %dx%d", info.hdisplay, info.vdisplay); + XF86VidModeSwitchToMode(dpy, DefaultScreen(dpy), &info); + nlinfo("3D: Switching back viewport to %d,%d",_OldX, _OldY); + XF86VidModeSetViewPort(dpy, DefaultScreen(dpy), _OldX, _OldY); + } +#endif // XF86VIDMODE + // Update WM hints (update size and disallow resizing) XSizeHints size_hints; size_hints.x = 0; @@ -1642,8 +1673,6 @@ bool CDriverGL::setMode(const GfxMode& mode) xev.xclient.data.l[1] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", false); xev.xclient.data.l[2] = 0; XSendEvent(dpy, DefaultRootWindow(dpy), false, SubstructureNotifyMask, &xev); - - //TODO: Change X display mode } _FullScreen = !mode.Windowed; From 9b5e5c99727e70cd678dcfdf8a5b0dfaba58cb5a Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Sat, 22 May 2010 13:06:56 +0200 Subject: [PATCH 3/6] Refactor a bit --- .../src/3d/driver/opengl/driver_opengl.cpp | 63 +------------------ 1 file changed, 3 insertions(+), 60 deletions(-) diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.cpp b/code/nel/src/3d/driver/opengl/driver_opengl.cpp index 066392c20..e20679c21 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl.cpp @@ -1141,66 +1141,7 @@ bool CDriverGL::setDisplay(void *wnd, const GfxMode &mode, bool show, bool resiz // XEvent event; // XIfEvent(dpy, &event, WaitForNotify, (char *)this); -#ifdef XF86VIDMODE - if (!mode.Windowed) - { - // Set window to the right size, map it to the display, and raise it to the front - XResizeWindow(dpy, win, width, height); - XMapRaised(dpy, win); - XRaiseWindow(dpy, win); - - // grab the mouse and keyboard on the fullscreen window - if ((XGrabPointer(dpy, win, True, 0, GrabModeAsync, GrabModeAsync, win, None, CurrentTime) != GrabSuccess) || - (XGrabKeyboard(dpy, win, True, GrabModeAsync, GrabModeAsync, CurrentTime) != 0) ) - { - // Until I work out how to deal with this nicely, it just gives - // an error and exits the prorgam. - nlerror("Unable to grab keyboard and mouse"); - } - else - { - // Save the old screen mode and dotclock and viewport - memset(&_OldScreenMode, 0, sizeof(_OldScreenMode)); - XF86VidModeGetModeLine(dpy, DefaultScreen(dpy), &_OldDotClock, &_OldScreenMode); - XF86VidModeGetViewPort(dpy, DefaultScreen(dpy), &_OldX, &_OldY); - - // Get a list of modes, search for an appropriate one. - XF86VidModeModeInfo **modes; - int nmodes; - if (XF86VidModeGetAllModeLines(dpy, DefaultScreen(dpy), &nmodes, &modes)) - { - int mode_index = -1; // Gah, magic numbers all bad. - for (int i = 0; i < nmodes; i++) - { - nldebug("3D: Available mode - %dx%d", modes[i]->hdisplay, modes[i]->vdisplay); - if(modes[i]->hdisplay == width && modes[i]->vdisplay == height) - { - mode_index = i; - break; - } - } - // Switch to the mode - if (mode_index != -1) - { - if(XF86VidModeSwitchToMode(dpy, DefaultScreen(dpy), modes[mode_index])) - { - nlinfo("3D: Switching to mode %dx%d", modes[mode_index]->hdisplay, modes[mode_index]->vdisplay); - XF86VidModeSetViewPort(dpy, DefaultScreen(dpy), 0, 0); - _FullScreen = true; - } - } - else - { - // This is a problem, since we've nuked the border from - // window in the setup stage, until I work out how - // to get it back (recreate window? seems excessive) - nlerror("Couldn't find an appropriate mode %dx%d", width, height); - } - } - } - } - -#endif // XF86VIDMODE + setMode(mode); #endif // NL_OS_UNIX @@ -1603,6 +1544,7 @@ bool CDriverGL::setMode(const GfxMode& mode) #ifdef XF86VIDMODE if (!mode.Windowed) { + // Store old mdoe in order to restore it when leaving fullscreen if (mode.Windowed == _FullScreen) { memset(&_OldScreenMode, 0, sizeof(_OldScreenMode)); @@ -1610,6 +1552,7 @@ bool CDriverGL::setMode(const GfxMode& mode) XF86VidModeGetViewPort(dpy, DefaultScreen(dpy), &_OldX, &_OldY); } + // Find the requested mode and use it XF86VidModeModeInfo **modes; int nmodes; if (XF86VidModeGetAllModeLines(dpy, DefaultScreen(dpy), &nmodes, &modes)) From 102822ff009370e51c41c7e949a3c957eeabbd7b Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Tue, 1 Jun 2010 11:37:11 +0200 Subject: [PATCH 4/6] Fixed: #926 fixed XF86VidModeModeInfo creation, should work on 64b --- .../src/3d/driver/opengl/driver_opengl.cpp | 65 ++++++++++--------- code/nel/src/3d/driver/opengl/driver_opengl.h | 2 + 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.cpp b/code/nel/src/3d/driver/opengl/driver_opengl.cpp index 618db783c..e5d54e894 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl.cpp @@ -1466,6 +1466,37 @@ static void modifyStyle (HWND hWnd, int nStyleOffset, LONG_PTR dwRemove, LONG_PT } #endif +// -------------------------------------------------- +void CDriverGL::switchBackToOldMode() +{ +#ifdef NL_OS_WINDOWS + ChangeDisplaySettings(&_OldScreenMode, 0); +#elif defined(XF86VIDMODE) + XF86VidModeModeInfo info; + nlinfo("3D: Switching back to original mode"); + + // This is UGLY + info.dotclock = _OldDotClock; + info.hdisplay = _OldScreenMode.hdisplay; + info.hsyncstart = _OldScreenMode.hsyncstart; + info.hsyncend = _OldScreenMode.hsyncend; + info.htotal = _OldScreenMode.htotal; + info.vdisplay = _OldScreenMode.vdisplay; + info.vsyncstart = _OldScreenMode.vsyncstart; + info.vsyncend = _OldScreenMode.vsyncend; + info.vtotal = _OldScreenMode.vtotal; + info.flags = _OldScreenMode.flags; + info.privsize = _OldScreenMode.privsize; + info.c_private = _OldScreenMode.c_private; + + nlinfo("3D: Switching back mode to %dx%d", info.hdisplay, info.vdisplay); + XF86VidModeSwitchToMode(dpy, DefaultScreen(dpy), &info); + nlinfo("3D: Switching back viewport to %d,%d",_OldX, _OldY); + XF86VidModeSetViewPort(dpy, DefaultScreen(dpy), _OldX, _OldY); +#endif // XF86VIDMODE +} + + // -------------------------------------------------- bool CDriverGL::setMode(const GfxMode& mode) { @@ -1475,7 +1506,7 @@ bool CDriverGL::setMode(const GfxMode& mode) { if (_FullScreen) { - ChangeDisplaySettings (NULL,0); + switchBackToOldMode(); modifyStyle(_hWnd, GWL_STYLE, WS_POPUP, WS_OVERLAPPEDWINDOW+WS_CLIPCHILDREN+WS_CLIPSIBLINGS); } _WindowWidth = mode.Width; @@ -1596,20 +1627,7 @@ bool CDriverGL::setMode(const GfxMode& mode) } } else if (mode.Windowed == _FullScreen) - { - XF86VidModeModeInfo info; - nlinfo("3D: Switching back to original mode"); - - // This is a bit ugly - a quick hack to copy the ModeLine structure - // into the modeInfo structure. - memcpy((XF86VidModeModeLine *)((char *)&info + sizeof(info.dotclock)),&_OldScreenMode, sizeof(XF86VidModeModeLine)); - info.dotclock = _OldDotClock; - - nlinfo("3D: Switching back mode to %dx%d", info.hdisplay, info.vdisplay); - XF86VidModeSwitchToMode(dpy, DefaultScreen(dpy), &info); - nlinfo("3D: Switching back viewport to %d,%d",_OldX, _OldY); - XF86VidModeSetViewPort(dpy, DefaultScreen(dpy), _OldX, _OldY); - } + switchBackToOldMode(); #endif // XF86VIDMODE // Update WM hints (update size and disallow resizing) @@ -2166,7 +2184,7 @@ bool CDriverGL::release() if(_FullScreen) { - ChangeDisplaySettings(&_OldScreenMode, 0); + switchBackToOldMode(); _FullScreen= false; } } @@ -2199,28 +2217,15 @@ bool CDriverGL::release() nlwarning("OpenGL Driver: Missing Mac Implementation"); #elif defined (NL_OS_UNIX) - -#ifdef XF86VIDMODE if(_FullScreen) { - XF86VidModeModeInfo info; - nlinfo("3D: Switching back to original mode"); + switchBackToOldMode(); - // This is a bit ugly - a quick hack to copy the ModeLine structure - // into the modeInfo structure. - memcpy((XF86VidModeModeLine *)((char *)&info + sizeof(info.dotclock)),&_OldScreenMode, sizeof(XF86VidModeModeLine)); - info.dotclock = _OldDotClock; - - nlinfo("3D: Switching back mode to %dx%d", info.hdisplay, info.vdisplay); - XF86VidModeSwitchToMode(dpy, DefaultScreen(dpy), &info); - nlinfo("3D: Switching back viewport to %d,%d",_OldX, _OldY); - XF86VidModeSetViewPort(dpy, DefaultScreen(dpy), _OldX, _OldY); // Ungrab the keyboard (probably not necessary); XUnmapWindow(dpy, win); XSync(dpy, True); XUngrabKeyboard(dpy, CurrentTime); } -#endif // XF86VIDMODE if (ctx) { diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.h b/code/nel/src/3d/driver/opengl/driver_opengl.h index 1d981d170..aad98fc5d 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.h +++ b/code/nel/src/3d/driver/opengl/driver_opengl.h @@ -841,6 +841,8 @@ private: bool _CurrentGlNormalize; private: + void switchBackToOldMode(); + // Get the proj matrix setupped in GL void refreshProjMatrixFromGL(); From 70d25e6056b67978482abffd685b1f6ef42c4fc1 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Tue, 1 Jun 2010 11:45:04 +0200 Subject: [PATCH 5/6] Changed: #926 enable window resizing --- code/nel/src/3d/driver/opengl/driver_opengl.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.cpp b/code/nel/src/3d/driver/opengl/driver_opengl.cpp index e5d54e894..9f7725b12 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl.cpp @@ -1636,11 +1636,15 @@ bool CDriverGL::setMode(const GfxMode& mode) size_hints.y = 0; size_hints.width = mode.Width; size_hints.height = mode.Height; - size_hints.flags = PSize | PMinSize | PMaxSize; - size_hints.min_width = mode.Width; - size_hints.min_height = mode.Height; - size_hints.max_width = mode.Width; - size_hints.max_height = mode.Height; + size_hints.flags = PSize; + if (!mode.Windowed) + { + size_hints.flags = PSize | PMinSize | PMaxSize; + size_hints.min_width = mode.Width; + size_hints.min_height = mode.Height; + size_hints.max_width = mode.Width; + size_hints.max_height = mode.Height; + } XSetWMNormalHints(dpy, win, &size_hints); From acc2f84ef9608f10cbdf812f9e2b72f2944edc8c Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 2 Jun 2010 12:19:56 +0200 Subject: [PATCH 6/6] Changed: #927 Move OS specific code from client or server to NeL when it's possible --- code/ryzom/client/src/main_loop.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/code/ryzom/client/src/main_loop.cpp b/code/ryzom/client/src/main_loop.cpp index 3c624b16e..4ebb7ad9b 100644 --- a/code/ryzom/client/src/main_loop.cpp +++ b/code/ryzom/client/src/main_loop.cpp @@ -1498,14 +1498,7 @@ bool mainLoop() { beep( 680, 400 ); beep( 440, 400 ); - #ifdef NL_OS_WINDOWS - // Get the window - HWND hWnd = (HWND)Driver->getDisplay (); - nlassert (hWnd); - // Show the window - ShowWindow (hWnd, SW_SHOW); - SetForegroundWindow(hWnd); - #endif // NL_OS_WINDOW + Driver->showWindow(); } FPU_CHECKER_ONCE