diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp index 096309f15..b5423ca57 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.cpp @@ -251,12 +251,10 @@ bool CIrrDeviceLinux::restoreResolution() if (UseXRandR && CreationParams.Fullscreen && old_mode != BadRRMode) { XRRScreenResources* res = XRRGetScreenResources(display, DefaultRootWindow(display)); - if (!res) return false; XRROutputInfo* output = XRRGetOutputInfo(display, res, output_id); - if (!output || !output->crtc || output->connection == RR_Disconnected) { XRRFreeOutputInfo(output); @@ -264,10 +262,8 @@ bool CIrrDeviceLinux::restoreResolution() } XRRCrtcInfo* crtc = XRRGetCrtcInfo(display, res, output->crtc); - if (!crtc) { - XRRFreeCrtcInfo(crtc); XRRFreeOutputInfo(output); return false; } @@ -288,7 +284,7 @@ bool CIrrDeviceLinux::restoreResolution() } -bool CIrrDeviceLinux::switchToFullscreen() +bool CIrrDeviceLinux::changeResolution() { if (!CreationParams.Fullscreen) return true; @@ -356,22 +352,33 @@ bool CIrrDeviceLinux::switchToFullscreen() XFree(modes); } - else #endif #ifdef _IRR_LINUX_X11_RANDR_ - if (XRRQueryExtension(display, &eventbase, &errorbase)) + while (XRRQueryExtension(display, &eventbase, &errorbase)) { - XRRScreenResources* res = XRRGetScreenResources(display, DefaultRootWindow(display)); + if (output_id == BadRROutput) + break; - if (!res || output_id == BadRROutput) - { - os::Printer::log("Could not get video output. Try to run in windowed mode.", ELL_WARNING); - CreationParams.Fullscreen = false; - return CreationParams.Fullscreen; - } + XRRScreenResources* res = XRRGetScreenResources(display, DefaultRootWindow(display)); + if (!res) + break; XRROutputInfo* output = XRRGetOutputInfo(display, res, output_id); + if (!output || !output->crtc || output->connection == RR_Disconnected) + { + XRRFreeOutputInfo(output); + XRRFreeScreenResources(res); + break; + } + XRRCrtcInfo* crtc = XRRGetCrtcInfo(display, res, output->crtc); + if (!crtc) + { + XRRFreeOutputInfo(output); + XRRFreeScreenResources(res); + break; + } + float refresh_rate, refresh_rate_new; core::dimension2d mode0_size = core::dimension2d(0, 0); @@ -436,26 +443,22 @@ bool CIrrDeviceLinux::switchToFullscreen() Status s = XRRSetCrtcConfig(display, res, output->crtc, CurrentTime, crtc->x, crtc->y, output->modes[bestMode], crtc->rotation, &output_id, 1); + + if (s == Success) + UseXRandR = true; XRRFreeCrtcInfo(crtc); XRRFreeOutputInfo(output); XRRFreeScreenResources(res); - - if (s != Success) - { - CreationParams.Fullscreen = false; - return CreationParams.Fullscreen; - } - - UseXRandR=true; + break; } - else - #endif + + if (UseXRandR == false) { - os::Printer::log("VidMode or RandR extension must be installed to allow Irrlicht " - "to switch to fullscreen mode. Running in windowed mode instead.", ELL_WARNING); + os::Printer::log("Could not get video output. Try to run in windowed mode.", ELL_WARNING); CreationParams.Fullscreen = false; } + #endif return CreationParams.Fullscreen; } @@ -570,7 +573,7 @@ bool CIrrDeviceLinux::createWindow() screennr = DefaultScreen(display); - switchToFullscreen(); + changeResolution(); #ifdef _IRR_COMPILE_WITH_OPENGL_ @@ -1625,7 +1628,6 @@ video::IVideoModeList* CIrrDeviceLinux::getVideoModeList() crtc_x = crtc_y = -1; XRRScreenResources* res = XRRGetScreenResources(display, DefaultRootWindow(display)); - if (!res) break; @@ -1633,49 +1635,39 @@ video::IVideoModeList* CIrrDeviceLinux::getVideoModeList() for (int i = 0; i < res->noutput; i++) { - output = XRRGetOutputInfo(display, res, res->outputs[i]); - - if (!output || !output->crtc || output->connection == RR_Disconnected) + XRROutputInfo* output_tmp = XRRGetOutputInfo(display, res, res->outputs[i]); + if (!output_tmp || !output_tmp->crtc || output_tmp->connection == RR_Disconnected) { - XRRFreeOutputInfo(output); + XRRFreeOutputInfo(output_tmp); continue; } - crtc = XRRGetCrtcInfo(display, res, output->crtc); - - if (!crtc) + XRRCrtcInfo* crtc_tmp = XRRGetCrtcInfo(display, res, output_tmp->crtc); + if (!crtc_tmp) + { + XRRFreeOutputInfo(output_tmp); + continue; + } + + if (res->outputs[i] == primary_id || + output_id == BadRROutput || crtc_tmp->x < crtc->x || + (crtc_tmp->x == crtc->x && crtc_tmp->y < crtc->y)) { XRRFreeCrtcInfo(crtc); - XRRFreeOutputInfo(output); - continue; + XRRFreeOutputInfo(output); + + output = output_tmp; + crtc = crtc_tmp; + output_id = res->outputs[i]; + } + else + { + XRRFreeCrtcInfo(crtc_tmp); + XRRFreeOutputInfo(output_tmp); } if (res->outputs[i] == primary_id) - { - crtc_x = crtc->x; - crtc_y = crtc->y; - output_id = res->outputs[i]; - - XRRFreeCrtcInfo(crtc); - XRRFreeOutputInfo(output); break; - } - - if (crtc_x == -1 || crtc->x < crtc_x) - { - crtc_x = crtc->x; - crtc_y = crtc->y; - output_id = res->outputs[i]; - } - else if (crtc_x == crtc->x && crtc->y < crtc_y) - { - crtc_x = crtc->x; - crtc_y = crtc->y; - output_id = res->outputs[i]; - } - - XRRFreeCrtcInfo(crtc); - XRRFreeOutputInfo(output); } if (output_id == BadRROutput) @@ -1683,9 +1675,9 @@ video::IVideoModeList* CIrrDeviceLinux::getVideoModeList() os::Printer::log("Could not get video output.", ELL_WARNING); break; } - - output = XRRGetOutputInfo(display, res, output_id); - crtc = XRRGetCrtcInfo(display, res, output->crtc); + + crtc_x = crtc->x; + crtc_y = crtc->y; for (int i = 0; i < res->nmode; i++) { @@ -1719,8 +1711,7 @@ video::IVideoModeList* CIrrDeviceLinux::getVideoModeList() XRRFreeCrtcInfo(crtc); XRRFreeOutputInfo(output); - XRRFreeScreenResources(res); - + XRRFreeScreenResources(res); break; } #endif diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.h b/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.h index d2fd06899..c808b8ebd 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.h +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceLinux.h @@ -151,7 +151,7 @@ namespace irr void initXAtoms(); bool restoreResolution(); - bool switchToFullscreen(); + bool changeResolution(); //! Implementation of the linux cursor control class CCursorControl : public gui::ICursorControl