From 350119fd45bf86d02aef853f12d8007428c388e2 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 9 Jan 2010 10:50:49 +0000 Subject: [PATCH] Support querying the available display modes in X11 --- dtool/Config.pp | 9 +++++- dtool/pptempl/Global.pp | 7 +++++ makepanda/makepanda.py | 10 +++++-- panda/src/x11display/Sources.pp | 2 +- panda/src/x11display/x11GraphicsPipe.cxx | 37 ++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 5 deletions(-) diff --git a/dtool/Config.pp b/dtool/Config.pp index 07cd0bf2d6..abdca7011b 100644 --- a/dtool/Config.pp +++ b/dtool/Config.pp @@ -691,12 +691,19 @@ #defer HAVE_X11 $[and $[IS_LINUX],$[libtest $[X11_LPATH],$[X11_LIBS]]] // This defines if we have XF86DGA installed. This enables smooth -// FPS-style mouse in glxdisplay, when mouse mode M_relative is used. +// FPS-style mouse in x11display, when mouse mode M_relative is used. #define XF86DGA_IPATH /usr/include/X11/extensions #define XF86DGA_LPATH /usr/lib #define XF86DGA_LIBS Xxf86dga #defer HAVE_XF86DGA $[libtest $[XF86DGA_LPATH],$[XF86DGA_LIBS]] +// This defines if we have XF86DGA installed. This +// enables resolution switching in x11display. +#define XRANDR_IPATH /usr/include/X11/extensions +#define XRANDR_LPATH /usr/lib +#define XRANDR_LIBS Xrandr +#defer HAVE_XRANDR $[libtest $[XRANDR_LPATH],$[XRANDR_LIBS]] + // How about GLX? #define GLX_IPATH #define GLX_LPATH diff --git a/dtool/pptempl/Global.pp b/dtool/pptempl/Global.pp index 91c316ffd6..da264c2dfe 100644 --- a/dtool/pptempl/Global.pp +++ b/dtool/pptempl/Global.pp @@ -164,6 +164,13 @@ #define xf86dga_libs $[XF86DGA_LIBS] #endif +#if $[HAVE_XRANDR] + #define xrandr_ipath $[wildcard $[XRANDR_IPATH]] + #define xrandr_lpath $[wildcard $[XRANDR_LPATH]] + #define xrandr_cflags $[XRANDR_CFLAGS] + #define xrandr_libs $[XRANDR_LIBS] +#endif + #if $[HAVE_MESA] #define mesa_ipath $[wildcard $[MESA_IPATH]] #define mesa_lpath $[wildcard $[MESA_LPATH]] diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index 5698da4c27..2ed9bcf7f3 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -54,7 +54,7 @@ PkgListSet(MAYAVERSIONS + MAXVERSIONS + DXVERSIONS + [ "FMODEX","OPENAL","NVIDIACG","OPENSSL","FREETYPE","WX", "FFTW","ARTOOLKIT","SQUISH","ODE","DIRECTCAM","NPAPI", "OPENCV","FFMPEG","SWSCALE","FCOLLADA","GTK2","OPENGL", - "X11","XF86DGA","PHYSX","PANDATOOL","CONTRIB", + "X11","XF86DGA","XRANDR","PHYSX","PANDATOOL","CONTRIB", ]) CheckPandaSourceTree() @@ -309,6 +309,7 @@ else: if (COMPILER=="MSVC"): PkgDisable("X11") + PkgDisable("XRANDR") PkgDisable("XF86DGA") if (PkgSkip("PYTHON")==0): IncDirectory("ALWAYS", SDK["PYTHON"] + "/include") @@ -484,6 +485,7 @@ if (COMPILER=="LINUX"): SmartPkgEnable("CGGL", "", ("CgGL"), "Cg/cgGL.h") SmartPkgEnable("X11", "x11", "X11", ("X11", "X11/Xlib.h")) if (not RUNTIME): + SmartPkgEnable("XRANDR", "xrandr", "Xrandr", "X11/extensions/Xrandr.h") SmartPkgEnable("XF86DGA", "xxf86dga", "Xxf86dga", "X11/extensions/xf86dga.h") if (RUNTIME): @@ -1284,6 +1286,7 @@ DTOOL_CONFIG=[ ("PHAVE_UCONTEXT_H", 'UNDEF', '1'), ("HAVE_RTTI", '1', '1'), ("HAVE_X11", 'UNDEF', '1'), + ("HAVE_XRANDR", 'UNDEF', '1'), ("HAVE_XF86DGA", 'UNDEF', '1'), ("IS_LINUX", 'UNDEF', '1'), ("IS_OSX", 'UNDEF', 'UNDEF'), @@ -1387,6 +1390,7 @@ def WriteConfigSettings(): dtool_config["PHAVE_SYS_MALLOC_H"] = '1' dtool_config["HAVE_OPENAL_FRAMEWORK"] = '1' dtool_config["HAVE_X11"] = 'UNDEF' # We might have X11, but we don't need it. + dtool_config["HAVE_XRANDR"] = 'UNDEF' dtool_config["HAVE_XF86DGA"] = 'UNDEF' dtool_config["HAVE_GLX"] = 'UNDEF' dtool_config["IS_LINUX"] = 'UNDEF' @@ -3055,7 +3059,7 @@ if (sys.platform != "win32" and sys.platform != "darwin" and PkgSkip("OPENGL")== TargetAdd('libpandagl.dll', input='libp3glstuff.dll') TargetAdd('libpandagl.dll', input='libpandafx.dll') TargetAdd('libpandagl.dll', input=COMMON_PANDA_LIBS) - TargetAdd('libpandagl.dll', opts=['MODULE', 'OPENGL', 'NVIDIACG', 'CGGL', 'X11', 'XF86DGA']) + TargetAdd('libpandagl.dll', opts=['MODULE', 'OPENGL', 'NVIDIACG', 'CGGL', 'X11', 'XRANDR', 'XF86DGA']) # # DIRECTORY: panda/src/osxdisplay/ @@ -3249,7 +3253,7 @@ if (not RUNTIME and (sys.platform == "win32" or sys.platform == "darwin" or PkgS TargetAdd('libtinydisplay.dll', opts=['WINIMM', 'WINGDI', 'WINKERNEL', 'WINOLDNAMES', 'WINUSER', 'WINMM']) else: TargetAdd('libtinydisplay.dll', input='x11display_composite.obj') - TargetAdd('libtinydisplay.dll', opts=['X11', 'XF86DGA']) + TargetAdd('libtinydisplay.dll', opts=['X11', 'XRANDR', 'XF86DGA']) TargetAdd('libtinydisplay.dll', input='tinydisplay_composite1.obj') TargetAdd('libtinydisplay.dll', input='tinydisplay_composite2.obj') TargetAdd('libtinydisplay.dll', input='tinydisplay_ztriangle_1.obj') diff --git a/panda/src/x11display/Sources.pp b/panda/src/x11display/Sources.pp index b63ab4c070..2b8213e8f6 100644 --- a/panda/src/x11display/Sources.pp +++ b/panda/src/x11display/Sources.pp @@ -2,7 +2,7 @@ #define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \ dtoolutil:c dtoolbase:c dtool:m -#define USE_PACKAGES x11 xf86dga +#define USE_PACKAGES x11 xf86dga xrandr #begin lib_target #define TARGET x11display diff --git a/panda/src/x11display/x11GraphicsPipe.cxx b/panda/src/x11display/x11GraphicsPipe.cxx index 1e91fadaef..951887a398 100644 --- a/panda/src/x11display/x11GraphicsPipe.cxx +++ b/panda/src/x11display/x11GraphicsPipe.cxx @@ -17,6 +17,16 @@ #include "config_x11display.h" #include "frameBufferProperties.h" +#ifdef HAVE_XRANDR +// Ugly workaround around the conflicting definition +// of Connection that randr.h provides. +#define _RANDR_H_ +typedef unsigned short Rotation; +typedef unsigned short SizeID; +typedef unsigned short SubpixelOrder; +#include +#endif + TypeHandle x11GraphicsPipe::_type_handle; bool x11GraphicsPipe::_error_handlers_installed = false; @@ -81,6 +91,33 @@ x11GraphicsPipe(const string &display) { _display_height = DisplayHeight(_display, _screen); _is_valid = true; +#ifdef HAVE_XRANDR + // Use Xrandr to fill in the supported resolution list. + int num_sizes, num_rates; + XRRScreenSize *xrrs; + xrrs = XRRSizes(_display, 0, &num_sizes); + _display_information->_total_display_modes = 0; + for (int i = 0; i < num_sizes; ++i) { + XRRRates(_display, 0, i, &num_rates); + _display_information->_total_display_modes += num_rates; + } + + short *rates; + short counter = 0; + _display_information->_display_mode_array = new DisplayMode[_display_information->_total_display_modes]; + for (int i = 0; i < num_sizes; ++i) { + int num_rates; + rates = XRRRates(_display, 0, i, &num_rates); + for (int j = 0; j < num_rates; ++j) { + DisplayMode* dm = _display_information->_display_mode_array + counter; + dm->width = xrrs[i].width; + dm->height = xrrs[i].height; + dm->refresh_rate = rates[j]; + ++counter; + } + } +#endif + // Connect to an input method for supporting international text // entry. _im = XOpenIM(_display, NULL, NULL, NULL);