Fixed: #928 XRandR modesetting
This commit is contained in:
parent
9d2232c3d8
commit
3c40ce800a
5 changed files with 426 additions and 126 deletions
|
@ -101,6 +101,7 @@ IF(WITH_3D)
|
||||||
IF(NOT WITH_COCOA)
|
IF(NOT WITH_COCOA)
|
||||||
FIND_PACKAGE(X11)
|
FIND_PACKAGE(X11)
|
||||||
FIND_PACKAGE(XF86VidMode)
|
FIND_PACKAGE(XF86VidMode)
|
||||||
|
FIND_PACKAGE(XRandR)
|
||||||
ENDIF(NOT WITH_COCOA)
|
ENDIF(NOT WITH_COCOA)
|
||||||
ENDIF(NOT WIN32)
|
ENDIF(NOT WIN32)
|
||||||
ENDIF(WITH_DRIVER_OPENGL)
|
ENDIF(WITH_DRIVER_OPENGL)
|
||||||
|
|
46
code/nel/CMakeModules/FindXRandR.cmake
Normal file
46
code/nel/CMakeModules/FindXRandR.cmake
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
# - Locate XRandR library
|
||||||
|
# This module defines
|
||||||
|
# XRandR_LIBRARY, the library to link against
|
||||||
|
# XRandR_FOUND, if false, do not try to link to XRandR
|
||||||
|
# XRandR_INCLUDE_DIR, where to find headers.
|
||||||
|
|
||||||
|
IF(XRandR_LIBRARY AND XRandR_INCLUDE_DIR)
|
||||||
|
# in cache already
|
||||||
|
SET(XRandR_FIND_QUIETLY TRUE)
|
||||||
|
ENDIF(XRandR_LIBRARY AND XRandR_INCLUDE_DIR)
|
||||||
|
|
||||||
|
|
||||||
|
FIND_PATH(XRandR_INCLUDE_DIR
|
||||||
|
Xrandr.h
|
||||||
|
PATHS
|
||||||
|
$ENV{XRandR_DIR}/include
|
||||||
|
/usr/include/X11/
|
||||||
|
/usr/X11R6/include/
|
||||||
|
PATH_SUFFIXES extensions
|
||||||
|
)
|
||||||
|
|
||||||
|
FIND_LIBRARY(XRandR_LIBRARY
|
||||||
|
Xrandr
|
||||||
|
PATHS
|
||||||
|
$ENV{XRandR_DIR}/lib
|
||||||
|
/usr/X11R6/lib
|
||||||
|
/usr/lib
|
||||||
|
/sw/lib
|
||||||
|
/opt/local/lib
|
||||||
|
/opt/csw/lib
|
||||||
|
/opt/lib
|
||||||
|
/usr/freeware/lib64
|
||||||
|
)
|
||||||
|
|
||||||
|
IF(XRandR_LIBRARY AND XRandR_INCLUDE_DIR)
|
||||||
|
SET(XRandR_FOUND "YES")
|
||||||
|
SET(XRandR_DEFINITIONS -DXRANDR)
|
||||||
|
IF(NOT XRandR_FIND_QUIETLY)
|
||||||
|
MESSAGE(STATUS "Found XRandR: ${XRandR_LIBRARY}")
|
||||||
|
ENDIF(NOT XRandR_FIND_QUIETLY)
|
||||||
|
ELSE(XRandR_LIBRARY AND XRandR_INCLUDE_DIR)
|
||||||
|
IF(NOT XRandR_FIND_QUIETLY)
|
||||||
|
MESSAGE(STATUS "Warning: Unable to find XRandR!")
|
||||||
|
ENDIF(NOT XRandR_FIND_QUIETLY)
|
||||||
|
ENDIF(XRandR_LIBRARY AND XRandR_INCLUDE_DIR)
|
||||||
|
|
|
@ -47,6 +47,11 @@ ELSE(WIN32)
|
||||||
ADD_DEFINITIONS(${XF86VidMode_DEFINITIONS})
|
ADD_DEFINITIONS(${XF86VidMode_DEFINITIONS})
|
||||||
TARGET_LINK_LIBRARIES(${NLDRV_OGL_LIB} ${XF86VidMode_LIBRARY})
|
TARGET_LINK_LIBRARIES(${NLDRV_OGL_LIB} ${XF86VidMode_LIBRARY})
|
||||||
ENDIF(XF86VidMode_FOUND)
|
ENDIF(XF86VidMode_FOUND)
|
||||||
|
IF(XRandR_FOUND)
|
||||||
|
INCLUDE_DIRECTORIES(${XRandR_INCLUDE_DIR})
|
||||||
|
ADD_DEFINITIONS(${XRandR_DEFINITIONS})
|
||||||
|
TARGET_LINK_LIBRARIES(${NLDRV_OGL_LIB} ${XRandR_LIBRARY})
|
||||||
|
ENDIF(XRandR_FOUND)
|
||||||
ENDIF(APPLE)
|
ENDIF(APPLE)
|
||||||
ENDIF(WIN32)
|
ENDIF(WIN32)
|
||||||
|
|
||||||
|
|
|
@ -686,11 +686,17 @@ private:
|
||||||
Cursor _cursor;
|
Cursor _cursor;
|
||||||
NLMISC::CUnixEventEmitter _EventEmitter;
|
NLMISC::CUnixEventEmitter _EventEmitter;
|
||||||
XVisualInfo* _visual_info;
|
XVisualInfo* _visual_info;
|
||||||
|
uint32 _xrandr_version;
|
||||||
|
uint32 _xvidmode_version;
|
||||||
|
|
||||||
|
#ifdef XRANDR
|
||||||
|
sint _OldSizeID;
|
||||||
|
#endif // XRANDR
|
||||||
|
|
||||||
#ifdef XF86VIDMODE
|
#ifdef XF86VIDMODE
|
||||||
int _OldDotClock; // old dotclock
|
sint _OldDotClock; // old dotclock
|
||||||
XF86VidModeModeLine _OldScreenMode; // old modeline
|
XF86VidModeModeLine _OldScreenMode; // old modeline
|
||||||
int _OldX, _OldY; //Viewport settings
|
sint _OldX, _OldY; //Viewport settings
|
||||||
#endif //XF86VIDMODE
|
#endif //XF86VIDMODE
|
||||||
|
|
||||||
#endif // NL_OS_UNIX
|
#endif // NL_OS_UNIX
|
||||||
|
@ -1252,10 +1258,8 @@ private:
|
||||||
|
|
||||||
|
|
||||||
// Monitor color parameters backup
|
// Monitor color parameters backup
|
||||||
#ifdef WIN32
|
|
||||||
bool _NeedToRestaureGammaRamp;
|
bool _NeedToRestaureGammaRamp;
|
||||||
uint16 _GammaRampBackuped[3*256];
|
uint16 _GammaRampBackuped[3*256];
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/// \fragment shaders
|
/// \fragment shaders
|
||||||
|
|
|
@ -32,6 +32,9 @@
|
||||||
#elif defined (NL_OS_UNIX)
|
#elif defined (NL_OS_UNIX)
|
||||||
# include <GL/gl.h>
|
# include <GL/gl.h>
|
||||||
# include <GL/glx.h>
|
# include <GL/glx.h>
|
||||||
|
# ifdef XRANDR
|
||||||
|
# include <X11/extensions/Xrandr.h>
|
||||||
|
# endif
|
||||||
#endif // NL_OS_UNIX
|
#endif // NL_OS_UNIX
|
||||||
|
|
||||||
#include "nel/misc/mouse_device.h"
|
#include "nel/misc/mouse_device.h"
|
||||||
|
@ -201,6 +204,30 @@ bool CDriverGL::init (uint windowIcon, emptyProc exitFunc)
|
||||||
nldebug("3D: XOpenDisplay on '%s' OK", getenv("DISPLAY"));
|
nldebug("3D: XOpenDisplay on '%s' OK", getenv("DISPLAY"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_xrandr_version = 0;
|
||||||
|
|
||||||
|
#ifdef XRANDR
|
||||||
|
_OldSizeID = 0;
|
||||||
|
sint xrandr_major, xrandr_minor;
|
||||||
|
if (XRRQueryVersion(_dpy, &xrandr_major, &xrandr_minor))
|
||||||
|
{
|
||||||
|
_xrandr_version = xrandr_major * 100 + xrandr_minor;
|
||||||
|
nlinfo("3D: XRandR %d.%d found", xrandr_major, xrandr_minor);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
_xvidmode_version = 0;
|
||||||
|
|
||||||
|
#ifdef XF86VIDMODE
|
||||||
|
sint event = 0, error = -1, vm_major = 0, vm_minor = 0;
|
||||||
|
if (XF86VidModeQueryExtension(_dpy, &event, &error) && XF86VidModeQueryVersion(_dpy, &vm_major, &vm_minor))
|
||||||
|
{
|
||||||
|
_xvidmode_version = vm_major * 100 + vm_minor;
|
||||||
|
nlinfo("3D: XF86VidMode %d.%d found", major, minor);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -756,12 +783,41 @@ bool CDriverGL::saveScreenMode()
|
||||||
|
|
||||||
#elif defined(NL_OS_UNIX)
|
#elif defined(NL_OS_UNIX)
|
||||||
|
|
||||||
|
int screen = DefaultScreen(_dpy);
|
||||||
|
res = false;
|
||||||
|
|
||||||
|
#ifdef XRANDR
|
||||||
|
|
||||||
|
if (!res && _xrandr_version > 0)
|
||||||
|
{
|
||||||
|
XRRScreenConfiguration *screen_config = XRRGetScreenInfo(_dpy, RootWindow(_dpy, screen));
|
||||||
|
|
||||||
|
if (screen_config)
|
||||||
|
{
|
||||||
|
Rotation saved_rotation;
|
||||||
|
_OldSizeID = XRRConfigCurrentConfiguration(screen_config, &saved_rotation);
|
||||||
|
nlinfo("3D: current XRandR mode %d", _OldSizeID);
|
||||||
|
XRRFreeScreenConfigInfo(screen_config);
|
||||||
|
|
||||||
|
res = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nlwarning("3D: XRRGetScreenInfo failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // XRANDR
|
||||||
|
|
||||||
#if defined(XF86VIDMODE)
|
#if defined(XF86VIDMODE)
|
||||||
|
|
||||||
// Store old mode in order to restore it when leaving fullscreen
|
if (!res && _xvidmode_version > 0)
|
||||||
memset(&_OldScreenMode, 0, sizeof(XF86VidModeModeLine));
|
{
|
||||||
XF86VidModeGetModeLine(_dpy, DefaultScreen(_dpy), &_OldDotClock, &_OldScreenMode);
|
// Store old mode in order to restore it when leaving fullscreen
|
||||||
res = XF86VidModeGetViewPort(_dpy, DefaultScreen(_dpy), &_OldX, &_OldY);
|
memset(&_OldScreenMode, 0, sizeof(XF86VidModeModeLine));
|
||||||
|
XF86VidModeGetModeLine(_dpy, screen, &_OldDotClock, &_OldScreenMode);
|
||||||
|
res = XF86VidModeGetViewPort(_dpy, screen, &_OldX, &_OldY);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // XF86VIDMODE
|
#endif // XF86VIDMODE
|
||||||
|
|
||||||
|
@ -788,29 +844,62 @@ bool CDriverGL::restoreScreenMode()
|
||||||
|
|
||||||
#elif defined(NL_OS_UNIX)
|
#elif defined(NL_OS_UNIX)
|
||||||
|
|
||||||
|
int screen = DefaultScreen(_dpy);
|
||||||
|
|
||||||
|
#ifdef XRANDR
|
||||||
|
|
||||||
|
if (!res && _xrandr_version > 0)
|
||||||
|
{
|
||||||
|
Window root = RootWindow(_dpy, screen);
|
||||||
|
|
||||||
|
XRRScreenConfiguration *screen_config = XRRGetScreenInfo(_dpy, root);
|
||||||
|
|
||||||
|
if (screen_config)
|
||||||
|
{
|
||||||
|
Rotation saved_rotation;
|
||||||
|
SizeID size = XRRConfigCurrentConfiguration(screen_config, &saved_rotation);
|
||||||
|
if (XRRSetScreenConfig(_dpy, screen_config, root, _OldSizeID, saved_rotation, CurrentTime) == RRSetConfigSuccess)
|
||||||
|
{
|
||||||
|
nlinfo("3D: Switching back to XRandR mode %d", _OldSizeID);
|
||||||
|
res = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
XRRFreeScreenConfigInfo(screen_config);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nlwarning("3D: XRRGetScreenInfo failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // XRANDR
|
||||||
|
|
||||||
#if defined(XF86VIDMODE)
|
#if defined(XF86VIDMODE)
|
||||||
|
|
||||||
XF86VidModeModeInfo info;
|
if (!res && _xvidmode_version > 0)
|
||||||
nlinfo("3D: Switching back to original mode");
|
{
|
||||||
|
XF86VidModeModeInfo info;
|
||||||
|
nlinfo("3D: Switching back to original mode");
|
||||||
|
|
||||||
// This is UGLY
|
// This is UGLY
|
||||||
info.dotclock = _OldDotClock;
|
info.dotclock = _OldDotClock;
|
||||||
info.hdisplay = _OldScreenMode.hdisplay;
|
info.hdisplay = _OldScreenMode.hdisplay;
|
||||||
info.hsyncstart = _OldScreenMode.hsyncstart;
|
info.hsyncstart = _OldScreenMode.hsyncstart;
|
||||||
info.hsyncend = _OldScreenMode.hsyncend;
|
info.hsyncend = _OldScreenMode.hsyncend;
|
||||||
info.htotal = _OldScreenMode.htotal;
|
info.htotal = _OldScreenMode.htotal;
|
||||||
info.vdisplay = _OldScreenMode.vdisplay;
|
info.vdisplay = _OldScreenMode.vdisplay;
|
||||||
info.vsyncstart = _OldScreenMode.vsyncstart;
|
info.vsyncstart = _OldScreenMode.vsyncstart;
|
||||||
info.vsyncend = _OldScreenMode.vsyncend;
|
info.vsyncend = _OldScreenMode.vsyncend;
|
||||||
info.vtotal = _OldScreenMode.vtotal;
|
info.vtotal = _OldScreenMode.vtotal;
|
||||||
info.flags = _OldScreenMode.flags;
|
info.flags = _OldScreenMode.flags;
|
||||||
info.privsize = _OldScreenMode.privsize;
|
info.privsize = _OldScreenMode.privsize;
|
||||||
info.c_private = _OldScreenMode.c_private;
|
info.c_private = _OldScreenMode.c_private;
|
||||||
|
|
||||||
nlinfo("3D: Switching back mode to %dx%d", info.hdisplay, info.vdisplay);
|
nlinfo("3D: Switching back mode to %dx%d", info.hdisplay, info.vdisplay);
|
||||||
XF86VidModeSwitchToMode(_dpy, DefaultScreen(_dpy), &info);
|
XF86VidModeSwitchToMode(_dpy, screen, &info);
|
||||||
nlinfo("3D: Switching back viewport to %d,%d",_OldX, _OldY);
|
nlinfo("3D: Switching back viewport to %d,%d",_OldX, _OldY);
|
||||||
res = XF86VidModeSetViewPort(_dpy, DefaultScreen(_dpy), _OldX, _OldY);
|
res = XF86VidModeSetViewPort(_dpy, screen, _OldX, _OldY);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // XF86VIDMODE
|
#endif // XF86VIDMODE
|
||||||
|
|
||||||
|
@ -819,6 +908,14 @@ bool CDriverGL::restoreScreenMode()
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------
|
||||||
|
#ifdef XF86VIDMODE
|
||||||
|
static sint modeInfoToFrequency(XF86VidModeModeInfo *info)
|
||||||
|
{
|
||||||
|
return (info->htotal && info->vtotal) ? (1000 * info->dotclock / (info->htotal * info->vtotal)) : 0;
|
||||||
|
}
|
||||||
|
#endif // XF86VIDMODE
|
||||||
|
|
||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
bool CDriverGL::setScreenMode(const GfxMode &mode)
|
bool CDriverGL::setScreenMode(const GfxMode &mode)
|
||||||
{
|
{
|
||||||
|
@ -880,37 +977,89 @@ bool CDriverGL::setScreenMode(const GfxMode &mode)
|
||||||
|
|
||||||
#elif defined(NL_OS_UNIX)
|
#elif defined(NL_OS_UNIX)
|
||||||
|
|
||||||
#if defined(XF86VIDMODE)
|
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
// Find the requested mode and use it
|
#ifdef XRANDR
|
||||||
XF86VidModeModeInfo **modes;
|
|
||||||
int nmodes;
|
if (!found && _xrandr_version > 0)
|
||||||
if (XF86VidModeGetAllModeLines(_dpy, DefaultScreen(_dpy), &nmodes, &modes))
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < nmodes; i++)
|
int screen = DefaultScreen(_dpy);
|
||||||
|
Window root = RootWindow(_dpy, screen);
|
||||||
|
|
||||||
|
XRRScreenConfiguration *screen_config = XRRGetScreenInfo(_dpy, root);
|
||||||
|
|
||||||
|
if (screen_config)
|
||||||
{
|
{
|
||||||
nldebug("3D: Available mode - %dx%d", modes[i]->hdisplay, modes[i]->vdisplay);
|
Rotation saved_rotation;
|
||||||
if (modes[i]->hdisplay == mode.Width && modes[i]->vdisplay == mode.Height)
|
SizeID size = XRRConfigCurrentConfiguration(screen_config, &saved_rotation);
|
||||||
|
|
||||||
|
sint nsizes;
|
||||||
|
XRRScreenSize *sizes = XRRConfigSizes(screen_config, &nsizes);
|
||||||
|
sint size = -1;
|
||||||
|
|
||||||
|
for (sint i = 0; i < nsizes; ++i)
|
||||||
{
|
{
|
||||||
if (XF86VidModeSwitchToMode(_dpy, DefaultScreen(_dpy), modes[i]))
|
if (sizes[i].width == mode.Width && sizes[i].height == mode.Height)
|
||||||
{
|
{
|
||||||
nlinfo("3D: Switching to mode %dx%d", modes[i]->hdisplay, modes[i]->vdisplay);
|
size = i;
|
||||||
XF86VidModeSetViewPort(_dpy, DefaultScreen(_dpy), 0, 0);
|
break;
|
||||||
found = true;
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (size > -1 && XRRSetScreenConfig(_dpy, screen_config, root, size, saved_rotation, CurrentTime) == RRSetConfigSuccess)
|
||||||
|
{
|
||||||
|
nlinfo("3D: Switching to XRandR mode %d: %dx%d", size, sizes[size].width, sizes[size].height);
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nlwarning("3D: No corresponding screen mode or XRRSetScreenConfig failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
XRRFreeScreenConfigInfo(screen_config);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nlwarning("3D: XRRGetScreenInfo failed");
|
||||||
}
|
}
|
||||||
XFree(modes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(XF86VIDMODE)
|
||||||
|
|
||||||
|
if (!found && _xvidmode_version > 0)
|
||||||
|
{
|
||||||
|
// Find the requested mode and use it
|
||||||
|
XF86VidModeModeInfo **modes;
|
||||||
|
int nmodes;
|
||||||
|
if (XF86VidModeGetAllModeLines(_dpy, DefaultScreen(_dpy), &nmodes, &modes))
|
||||||
|
{
|
||||||
|
for (int i = 0; i < nmodes; i++)
|
||||||
|
{
|
||||||
|
const uint16 freq = modeInfoToFrequency(modes[i]);
|
||||||
|
|
||||||
|
nldebug("3D: Available mode - %dx%d %d Hz", modes[i]->hdisplay, modes[i]->vdisplay, (int)freq);
|
||||||
|
if (modes[i]->hdisplay == mode.Width && modes[i]->vdisplay == mode.Height /* && freq == mode.Frequency */)
|
||||||
|
{
|
||||||
|
if (XF86VidModeSwitchToMode(_dpy, DefaultScreen(_dpy), modes[i]))
|
||||||
|
{
|
||||||
|
nlinfo("3D: XF86VidMode Switching to mode %dx%d", modes[i]->hdisplay, modes[i]->vdisplay);
|
||||||
|
XF86VidModeSetViewPort(_dpy, DefaultScreen(_dpy), 0, 0);
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
XFree(modes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // XF86VIDMODE
|
||||||
|
|
||||||
if (!found)
|
if (!found)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
#endif // XF86VIDMODE
|
|
||||||
|
|
||||||
#endif // NL_OS_WINDOWS
|
#endif // NL_OS_WINDOWS
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -1115,43 +1264,32 @@ bool CDriverGL::setWindowStyle(EWindowStyle windowStyle)
|
||||||
|
|
||||||
#elif defined(NL_OS_UNIX)
|
#elif defined(NL_OS_UNIX)
|
||||||
|
|
||||||
XSetWindowAttributes attr;
|
|
||||||
|
|
||||||
#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 (windowStyle == EWSWindowed)
|
|
||||||
{
|
|
||||||
attr.override_redirect = False;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
attr.override_redirect = True;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
attr.override_redirect = False;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int attr_flags = CWOverrideRedirect;
|
|
||||||
|
|
||||||
XChangeWindowAttributes(_dpy, _win, attr_flags, &attr);
|
|
||||||
|
|
||||||
// x11 fullscreen is not working on mac os x
|
// x11 fullscreen is not working on mac os x
|
||||||
|
|
||||||
#if !defined(NL_OS_MAC)
|
#if !defined(NL_OS_MAC)
|
||||||
|
|
||||||
// Toggle fullscreen
|
// Toggle fullscreen
|
||||||
if (windowStyle != getWindowStyle())
|
if (windowStyle != getWindowStyle())
|
||||||
{
|
{
|
||||||
XEvent xev;
|
XEvent xev;
|
||||||
memset(&xev, 0, sizeof(xev));
|
memset(&xev, 0, sizeof(xev));
|
||||||
xev.type = ClientMessage;
|
xev.type = ClientMessage;
|
||||||
|
// xev.xclient.serial = 0;
|
||||||
|
// xev.xclient.send_event = True;
|
||||||
|
// xev.xclient.display = _dpy;
|
||||||
xev.xclient.window = _win;
|
xev.xclient.window = _win;
|
||||||
xev.xclient.message_type = XInternAtom(_dpy, "_NET_WM_STATE", False);
|
xev.xclient.message_type = XInternAtom(_dpy, "_NET_WM_STATE", False);
|
||||||
xev.xclient.format = 32;
|
xev.xclient.format = 32;
|
||||||
xev.xclient.data.l[0] = windowStyle == EWSFullscreen ? 1:0;
|
xev.xclient.data.l[0] = windowStyle == EWSFullscreen ? 1:0;
|
||||||
xev.xclient.data.l[1] = XInternAtom(_dpy, "_NET_WM_STATE_FULLSCREEN", False);
|
xev.xclient.data.l[1] = XInternAtom(_dpy, "_NET_WM_STATE_FULLSCREEN", False);
|
||||||
xev.xclient.data.l[2] = 0;
|
xev.xclient.data.l[2] = 0;
|
||||||
XSendEvent(_dpy, DefaultRootWindow(_dpy), False, SubstructureNotifyMask, &xev);
|
xev.xclient.data.l[3] = 0;
|
||||||
|
xev.xclient.data.l[4] = 0;
|
||||||
|
if (XSendEvent(_dpy, DefaultRootWindow(_dpy), False, SubstructureNotifyMask, &xev) != Success)
|
||||||
|
{
|
||||||
|
nlwarning("3D: Failed to toggle to fullscreen");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1222,32 +1360,84 @@ bool CDriverGL::getModes(std::vector<GfxMode> &modes)
|
||||||
|
|
||||||
#elif defined (NL_OS_UNIX)
|
#elif defined (NL_OS_UNIX)
|
||||||
|
|
||||||
# ifdef XF86VIDMODE
|
bool found = false;
|
||||||
|
int screen = DefaultScreen(_dpy);
|
||||||
|
|
||||||
|
#if defined(XRANDR)
|
||||||
|
if (!found && _xrandr_version >= 100)
|
||||||
|
{
|
||||||
|
XRRScreenConfiguration *screen_config = XRRGetScreenInfo(_dpy, RootWindow(_dpy, screen));
|
||||||
|
|
||||||
|
if (screen_config)
|
||||||
|
{
|
||||||
|
// retrieve the list of resolutions
|
||||||
|
int nsizes = 0;
|
||||||
|
XRRScreenSize *sizes = XRRConfigSizes(screen_config, &nsizes);
|
||||||
|
|
||||||
|
if (nsizes > 0)
|
||||||
|
{
|
||||||
|
nldebug("3D: %d available XRandR modes:", nsizes);
|
||||||
|
|
||||||
|
for (sint i = 0; i < nsizes; ++i)
|
||||||
|
{
|
||||||
|
// Add this mode
|
||||||
|
GfxMode mode;
|
||||||
|
mode.Width = sizes[i].width;
|
||||||
|
mode.Height = sizes[i].height;
|
||||||
|
mode.Frequency = 0;
|
||||||
|
modes.push_back(mode);
|
||||||
|
|
||||||
|
nldebug("3D: Mode %d: %dx%d", i, mode.Width, mode.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nlwarning("3D: No XRandR modes available");
|
||||||
|
}
|
||||||
|
|
||||||
|
XRRFreeScreenConfigInfo(screen_config);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nlwarning("3D: XRRGetScreenInfo failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef XF86VIDMODE
|
||||||
int nmodes;
|
int nmodes;
|
||||||
XF86VidModeModeInfo **ms;
|
XF86VidModeModeInfo **ms;
|
||||||
Bool ok = XF86VidModeGetAllModeLines(_dpy, DefaultScreen(_dpy), &nmodes, &ms);
|
if (!found && XF86VidModeGetAllModeLines(_dpy, screen, &nmodes, &ms))
|
||||||
if(ok)
|
|
||||||
{
|
{
|
||||||
nldebug("3D: %d available modes:", nmodes);
|
nlinfo("3D: %d available XF86VidMode modes:", nmodes);
|
||||||
for (int j = 0; j < nmodes; j++)
|
for (int j = 0; j < nmodes; j++)
|
||||||
{
|
{
|
||||||
// Add this mode
|
// Add this mode
|
||||||
GfxMode mode;
|
GfxMode mode;
|
||||||
mode.Width = (uint16)ms[j]->hdisplay;
|
mode.Width = (uint16)ms[j]->hdisplay;
|
||||||
mode.Height = (uint16)ms[j]->vdisplay;
|
mode.Height = (uint16)ms[j]->vdisplay;
|
||||||
const uint16 pixelsCount = ms[j]->htotal * ms[j]->vtotal;
|
mode.Frequency = modeInfoToFrequency(ms[j]);
|
||||||
mode.Frequency = pixelsCount ? 1000 * ms[j]->dotclock / pixelsCount:0;
|
nlinfo("3D: Mode %d: %dx%d, %d Hz", j, mode.Width, mode.Height, mode.Frequency);
|
||||||
nldebug("3D: Mode %d: %dx%d, %d Hz", j, mode.Width, mode.Height, mode.Frequency);
|
|
||||||
modes.push_back (mode);
|
modes.push_back (mode);
|
||||||
}
|
}
|
||||||
XFree(ms);
|
XFree(ms);
|
||||||
}
|
}
|
||||||
else
|
#endif // XF86VIDMODE
|
||||||
|
|
||||||
|
if (!found)
|
||||||
{
|
{
|
||||||
nlwarning("XF86VidModeGetAllModeLines returns 0, cannot get available video mode");
|
// Add current screen mode
|
||||||
return false;
|
GfxMode mode;
|
||||||
|
mode.Width = DisplayWidth(_dpy, screen);
|
||||||
|
mode.Height = DisplayHeight(_dpy, screen);
|
||||||
|
mode.Frequency = 0;
|
||||||
|
modes.push_back(mode);
|
||||||
|
|
||||||
|
nldebug("3D: X11 available mode:");
|
||||||
|
nldebug("3D: %dx%d", mode.Width, mode.Height);
|
||||||
}
|
}
|
||||||
# endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
|
@ -1290,31 +1480,96 @@ bool CDriverGL::getCurrentScreenMode(GfxMode &mode)
|
||||||
|
|
||||||
#elif defined(NL_OS_UNIX)
|
#elif defined(NL_OS_UNIX)
|
||||||
|
|
||||||
# ifdef XF86VIDMODE
|
bool found = false;
|
||||||
sint pixelClock;
|
int screen = DefaultScreen(_dpy);
|
||||||
XF86VidModeModeLine xmode;
|
|
||||||
|
|
||||||
if (!XF86VidModeGetModeLine(_dpy, DefaultScreen(_dpy), &pixelClock, &xmode))
|
|
||||||
{
|
|
||||||
nlwarning("XF86VidModeGetModeLine returns 0, cannot get current video mode");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// x11 fullscreen is not working on mac os x
|
// x11 fullscreen is not working on mac os x
|
||||||
#if !defined(NL_OS_MAC)
|
#if defined(NL_OS_MAC)
|
||||||
mode.Windowed = !_FullScreen;
|
|
||||||
#else
|
|
||||||
mode.Windowed = true;
|
mode.Windowed = true;
|
||||||
|
found = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mode.OffScreen = false;
|
#ifdef XRANDR
|
||||||
mode.Depth = (uint) DefaultDepth(_dpy, DefaultScreen(_dpy));
|
|
||||||
mode.Frequency = 1000 * pixelClock / (xmode.htotal * xmode.vtotal) ;
|
|
||||||
mode.Width = xmode.hdisplay;
|
|
||||||
mode.Height = xmode.vdisplay;
|
|
||||||
|
|
||||||
nldebug("Current mode : %dx%d, %d Hz, %dbit", mode.Width, mode.Height, mode.Frequency, mode.Depth);
|
if (!found && _xrandr_version > 0)
|
||||||
# endif
|
{
|
||||||
|
XRRScreenConfiguration *screen_config = XRRGetScreenInfo(_dpy, RootWindow(_dpy, screen));
|
||||||
|
|
||||||
|
if (screen_config)
|
||||||
|
{
|
||||||
|
int nsizes;
|
||||||
|
XRRScreenSize *sizes = XRRConfigSizes(screen_config, &nsizes);
|
||||||
|
if (nsizes > 0)
|
||||||
|
{
|
||||||
|
Rotation cur_rotation;
|
||||||
|
SizeID size = XRRConfigCurrentConfiguration(screen_config, &cur_rotation);
|
||||||
|
|
||||||
|
mode.Windowed = !_FullScreen;
|
||||||
|
mode.OffScreen = false;
|
||||||
|
mode.Depth = (uint) DefaultDepth(_dpy, screen);
|
||||||
|
mode.Frequency = 0;
|
||||||
|
mode.Width = sizes[size].width;
|
||||||
|
mode.Height = sizes[size].height;
|
||||||
|
|
||||||
|
found = true;
|
||||||
|
|
||||||
|
nlinfo("3D: Current XRandR mode %d: %dx%d, %dbit", size, mode.Width, mode.Height, mode.Depth);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nlwarning("3D: No XRandR modes available");
|
||||||
|
}
|
||||||
|
|
||||||
|
XRRFreeScreenConfigInfo(screen_config);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nlwarning("3D: XRRGetScreenInfo failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // XRANDR
|
||||||
|
|
||||||
|
#ifdef XF86VIDMODE
|
||||||
|
|
||||||
|
if (!found && _xvidmode_version > 0)
|
||||||
|
{
|
||||||
|
sint pixelClock;
|
||||||
|
XF86VidModeModeLine xmode;
|
||||||
|
|
||||||
|
if (XF86VidModeGetModeLine(_dpy, screen, &pixelClock, &xmode))
|
||||||
|
{
|
||||||
|
mode.Windowed = !_FullScreen;
|
||||||
|
mode.OffScreen = false;
|
||||||
|
mode.Depth = (uint) DefaultDepth(_dpy, screen);
|
||||||
|
mode.Frequency = 1000 * pixelClock / (xmode.htotal * xmode.vtotal) ;
|
||||||
|
mode.Width = xmode.hdisplay;
|
||||||
|
mode.Height = xmode.vdisplay;
|
||||||
|
nlinfo("3D: Current XF86VidMode mode: %dx%d, %d Hz, %dbit", mode.Width, mode.Height, mode.Frequency, mode.Depth);
|
||||||
|
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nlwarning("3D: XF86VidModeGetModeLine failed, cannot get current video mode");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
mode.Windowed = !_FullScreen;
|
||||||
|
mode.OffScreen = _OffScreen;
|
||||||
|
mode.Depth = (uint) DefaultDepth(_dpy, screen);
|
||||||
|
mode.Frequency = 0;
|
||||||
|
mode.Width = DisplayWidth(_dpy, screen);
|
||||||
|
mode.Height = DisplayHeight(_dpy, screen);
|
||||||
|
|
||||||
|
found = true;
|
||||||
|
|
||||||
|
nldebug("Current mode: %dx%d, %d Hz, %dbit", mode.Width, mode.Height, mode.Frequency, mode.Depth);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
|
@ -1649,19 +1904,8 @@ void CDriverGL::setWindowSize(uint32 width, uint32 height)
|
||||||
|
|
||||||
XSetWMNormalHints(_dpy, _win, &size_hints);
|
XSetWMNormalHints(_dpy, _win, &size_hints);
|
||||||
|
|
||||||
// set position to (0, 0) if fullscreen
|
// resize the window
|
||||||
if (_FullScreen)
|
XResizeWindow(_dpy, _win, width, height);
|
||||||
{
|
|
||||||
// move and resize the window
|
|
||||||
XMoveResizeWindow(_dpy, _win, 0, 0, width, height);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// resize the window
|
|
||||||
XResizeWindow(_dpy, _win, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
// XMapWindow(_dpy, _win);
|
|
||||||
|
|
||||||
_WindowWidth = width;
|
_WindowWidth = width;
|
||||||
_WindowHeight = height;
|
_WindowHeight = height;
|
||||||
|
|
Loading…
Reference in a new issue