xrandr: Simplify code a bit.
Fixed some memory leaks.
This commit is contained in:
parent
4a62fd7968
commit
db53dd6767
@ -251,12 +251,10 @@ bool CIrrDeviceLinux::restoreResolution()
|
|||||||
if (UseXRandR && CreationParams.Fullscreen && old_mode != BadRRMode)
|
if (UseXRandR && CreationParams.Fullscreen && old_mode != BadRRMode)
|
||||||
{
|
{
|
||||||
XRRScreenResources* res = XRRGetScreenResources(display, DefaultRootWindow(display));
|
XRRScreenResources* res = XRRGetScreenResources(display, DefaultRootWindow(display));
|
||||||
|
|
||||||
if (!res)
|
if (!res)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
XRROutputInfo* output = XRRGetOutputInfo(display, res, output_id);
|
XRROutputInfo* output = XRRGetOutputInfo(display, res, output_id);
|
||||||
|
|
||||||
if (!output || !output->crtc || output->connection == RR_Disconnected)
|
if (!output || !output->crtc || output->connection == RR_Disconnected)
|
||||||
{
|
{
|
||||||
XRRFreeOutputInfo(output);
|
XRRFreeOutputInfo(output);
|
||||||
@ -264,10 +262,8 @@ bool CIrrDeviceLinux::restoreResolution()
|
|||||||
}
|
}
|
||||||
|
|
||||||
XRRCrtcInfo* crtc = XRRGetCrtcInfo(display, res, output->crtc);
|
XRRCrtcInfo* crtc = XRRGetCrtcInfo(display, res, output->crtc);
|
||||||
|
|
||||||
if (!crtc)
|
if (!crtc)
|
||||||
{
|
{
|
||||||
XRRFreeCrtcInfo(crtc);
|
|
||||||
XRRFreeOutputInfo(output);
|
XRRFreeOutputInfo(output);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -288,7 +284,7 @@ bool CIrrDeviceLinux::restoreResolution()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CIrrDeviceLinux::switchToFullscreen()
|
bool CIrrDeviceLinux::changeResolution()
|
||||||
{
|
{
|
||||||
if (!CreationParams.Fullscreen)
|
if (!CreationParams.Fullscreen)
|
||||||
return true;
|
return true;
|
||||||
@ -356,22 +352,33 @@ bool CIrrDeviceLinux::switchToFullscreen()
|
|||||||
|
|
||||||
XFree(modes);
|
XFree(modes);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef _IRR_LINUX_X11_RANDR_
|
#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)
|
XRRScreenResources* res = XRRGetScreenResources(display, DefaultRootWindow(display));
|
||||||
{
|
if (!res)
|
||||||
os::Printer::log("Could not get video output. Try to run in windowed mode.", ELL_WARNING);
|
break;
|
||||||
CreationParams.Fullscreen = false;
|
|
||||||
return CreationParams.Fullscreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
XRROutputInfo* output = XRRGetOutputInfo(display, res, output_id);
|
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);
|
XRRCrtcInfo* crtc = XRRGetCrtcInfo(display, res, output->crtc);
|
||||||
|
if (!crtc)
|
||||||
|
{
|
||||||
|
XRRFreeOutputInfo(output);
|
||||||
|
XRRFreeScreenResources(res);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
float refresh_rate, refresh_rate_new;
|
float refresh_rate, refresh_rate_new;
|
||||||
core::dimension2d<u32> mode0_size = core::dimension2d<u32>(0, 0);
|
core::dimension2d<u32> mode0_size = core::dimension2d<u32>(0, 0);
|
||||||
|
|
||||||
@ -436,26 +443,22 @@ bool CIrrDeviceLinux::switchToFullscreen()
|
|||||||
Status s = XRRSetCrtcConfig(display, res, output->crtc, CurrentTime,
|
Status s = XRRSetCrtcConfig(display, res, output->crtc, CurrentTime,
|
||||||
crtc->x, crtc->y, output->modes[bestMode],
|
crtc->x, crtc->y, output->modes[bestMode],
|
||||||
crtc->rotation, &output_id, 1);
|
crtc->rotation, &output_id, 1);
|
||||||
|
|
||||||
|
if (s == Success)
|
||||||
|
UseXRandR = true;
|
||||||
|
|
||||||
XRRFreeCrtcInfo(crtc);
|
XRRFreeCrtcInfo(crtc);
|
||||||
XRRFreeOutputInfo(output);
|
XRRFreeOutputInfo(output);
|
||||||
XRRFreeScreenResources(res);
|
XRRFreeScreenResources(res);
|
||||||
|
break;
|
||||||
if (s != Success)
|
|
||||||
{
|
|
||||||
CreationParams.Fullscreen = false;
|
|
||||||
return CreationParams.Fullscreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
UseXRandR=true;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
#endif
|
if (UseXRandR == false)
|
||||||
{
|
{
|
||||||
os::Printer::log("VidMode or RandR extension must be installed to allow Irrlicht "
|
os::Printer::log("Could not get video output. Try to run in windowed mode.", ELL_WARNING);
|
||||||
"to switch to fullscreen mode. Running in windowed mode instead.", ELL_WARNING);
|
|
||||||
CreationParams.Fullscreen = false;
|
CreationParams.Fullscreen = false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return CreationParams.Fullscreen;
|
return CreationParams.Fullscreen;
|
||||||
}
|
}
|
||||||
@ -570,7 +573,7 @@ bool CIrrDeviceLinux::createWindow()
|
|||||||
|
|
||||||
screennr = DefaultScreen(display);
|
screennr = DefaultScreen(display);
|
||||||
|
|
||||||
switchToFullscreen();
|
changeResolution();
|
||||||
|
|
||||||
#ifdef _IRR_COMPILE_WITH_OPENGL_
|
#ifdef _IRR_COMPILE_WITH_OPENGL_
|
||||||
|
|
||||||
@ -1625,7 +1628,6 @@ video::IVideoModeList* CIrrDeviceLinux::getVideoModeList()
|
|||||||
crtc_x = crtc_y = -1;
|
crtc_x = crtc_y = -1;
|
||||||
|
|
||||||
XRRScreenResources* res = XRRGetScreenResources(display, DefaultRootWindow(display));
|
XRRScreenResources* res = XRRGetScreenResources(display, DefaultRootWindow(display));
|
||||||
|
|
||||||
if (!res)
|
if (!res)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1633,49 +1635,39 @@ video::IVideoModeList* CIrrDeviceLinux::getVideoModeList()
|
|||||||
|
|
||||||
for (int i = 0; i < res->noutput; i++)
|
for (int i = 0; i < res->noutput; i++)
|
||||||
{
|
{
|
||||||
output = XRRGetOutputInfo(display, res, res->outputs[i]);
|
XRROutputInfo* output_tmp = XRRGetOutputInfo(display, res, res->outputs[i]);
|
||||||
|
if (!output_tmp || !output_tmp->crtc || output_tmp->connection == RR_Disconnected)
|
||||||
if (!output || !output->crtc || output->connection == RR_Disconnected)
|
|
||||||
{
|
{
|
||||||
XRRFreeOutputInfo(output);
|
XRRFreeOutputInfo(output_tmp);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
crtc = XRRGetCrtcInfo(display, res, output->crtc);
|
XRRCrtcInfo* crtc_tmp = XRRGetCrtcInfo(display, res, output_tmp->crtc);
|
||||||
|
if (!crtc_tmp)
|
||||||
if (!crtc)
|
{
|
||||||
|
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);
|
XRRFreeCrtcInfo(crtc);
|
||||||
XRRFreeOutputInfo(output);
|
XRRFreeOutputInfo(output);
|
||||||
continue;
|
|
||||||
|
output = output_tmp;
|
||||||
|
crtc = crtc_tmp;
|
||||||
|
output_id = res->outputs[i];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
XRRFreeCrtcInfo(crtc_tmp);
|
||||||
|
XRRFreeOutputInfo(output_tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res->outputs[i] == primary_id)
|
if (res->outputs[i] == primary_id)
|
||||||
{
|
|
||||||
crtc_x = crtc->x;
|
|
||||||
crtc_y = crtc->y;
|
|
||||||
output_id = res->outputs[i];
|
|
||||||
|
|
||||||
XRRFreeCrtcInfo(crtc);
|
|
||||||
XRRFreeOutputInfo(output);
|
|
||||||
break;
|
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)
|
if (output_id == BadRROutput)
|
||||||
@ -1683,9 +1675,9 @@ video::IVideoModeList* CIrrDeviceLinux::getVideoModeList()
|
|||||||
os::Printer::log("Could not get video output.", ELL_WARNING);
|
os::Printer::log("Could not get video output.", ELL_WARNING);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
output = XRRGetOutputInfo(display, res, output_id);
|
crtc_x = crtc->x;
|
||||||
crtc = XRRGetCrtcInfo(display, res, output->crtc);
|
crtc_y = crtc->y;
|
||||||
|
|
||||||
for (int i = 0; i < res->nmode; i++)
|
for (int i = 0; i < res->nmode; i++)
|
||||||
{
|
{
|
||||||
@ -1719,8 +1711,7 @@ video::IVideoModeList* CIrrDeviceLinux::getVideoModeList()
|
|||||||
|
|
||||||
XRRFreeCrtcInfo(crtc);
|
XRRFreeCrtcInfo(crtc);
|
||||||
XRRFreeOutputInfo(output);
|
XRRFreeOutputInfo(output);
|
||||||
XRRFreeScreenResources(res);
|
XRRFreeScreenResources(res);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -151,7 +151,7 @@ namespace irr
|
|||||||
void initXAtoms();
|
void initXAtoms();
|
||||||
|
|
||||||
bool restoreResolution();
|
bool restoreResolution();
|
||||||
bool switchToFullscreen();
|
bool changeResolution();
|
||||||
|
|
||||||
//! Implementation of the linux cursor control
|
//! Implementation of the linux cursor control
|
||||||
class CCursorControl : public gui::ICursorControl
|
class CCursorControl : public gui::ICursorControl
|
||||||
|
Loading…
x
Reference in New Issue
Block a user