mirror of
https://github.com/SFML/SFML.git
synced 2024-11-24 20:31:05 +08:00
Assume XrandR version >=1.3
As far as I can tell XrandR 1.3 was released in ~2009. It's safe to assume anyone using SFML 3 or newer will have this version installed.
This commit is contained in:
parent
ac620900ac
commit
7987d3cedc
@ -1274,9 +1274,7 @@ void WindowImplX11::setVideoMode(const VideoMode& mode)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Check if the XRandR extension is present
|
// Check if the XRandR extension is present
|
||||||
int xRandRMajor = 0;
|
if (!checkXRandR())
|
||||||
int xRandRMinor = 0;
|
|
||||||
if (!checkXRandR(xRandRMajor, xRandRMinor))
|
|
||||||
{
|
{
|
||||||
// XRandR extension is not supported: we cannot use fullscreen mode
|
// XRandR extension is not supported: we cannot use fullscreen mode
|
||||||
err() << "Fullscreen is not supported, switching to window mode" << std::endl;
|
err() << "Fullscreen is not supported, switching to window mode" << std::endl;
|
||||||
@ -1294,7 +1292,7 @@ void WindowImplX11::setVideoMode(const VideoMode& mode)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RROutput output = getOutputPrimary(rootWindow, res.get(), xRandRMajor, xRandRMinor);
|
RROutput output = getOutputPrimary(rootWindow, res.get());
|
||||||
|
|
||||||
// Get output info from output
|
// Get output info from output
|
||||||
const auto outputInfo = X11Ptr<XRROutputInfo>(XRRGetOutputInfo(m_display.get(), res.get(), output));
|
const auto outputInfo = X11Ptr<XRROutputInfo>(XRRGetOutputInfo(m_display.get(), res.get(), output));
|
||||||
@ -1365,9 +1363,7 @@ void WindowImplX11::resetVideoMode()
|
|||||||
{
|
{
|
||||||
// Try to set old configuration
|
// Try to set old configuration
|
||||||
// Check if the XRandR extension
|
// Check if the XRandR extension
|
||||||
int xRandRMajor = 0;
|
if (checkXRandR())
|
||||||
int xRandRMinor = 0;
|
|
||||||
if (checkXRandR(xRandRMajor, xRandRMinor))
|
|
||||||
{
|
{
|
||||||
const auto res = X11Ptr<XRRScreenResources>(
|
const auto res = X11Ptr<XRRScreenResources>(
|
||||||
XRRGetScreenResources(m_display.get(), DefaultRootWindow(m_display.get())));
|
XRRGetScreenResources(m_display.get(), DefaultRootWindow(m_display.get())));
|
||||||
@ -1385,21 +1381,12 @@ void WindowImplX11::resetVideoMode()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RROutput output = 0;
|
// Get the primary screen
|
||||||
|
RROutput output = XRRGetOutputPrimary(m_display.get(), DefaultRootWindow(m_display.get()));
|
||||||
|
|
||||||
// if version >= 1.3 get the primary screen else take the first screen
|
// Check if returned output is valid, otherwise use the first screen
|
||||||
if ((xRandRMajor == 1 && xRandRMinor >= 3) || xRandRMajor > 1)
|
if (output == None)
|
||||||
{
|
|
||||||
output = XRRGetOutputPrimary(m_display.get(), DefaultRootWindow(m_display.get()));
|
|
||||||
|
|
||||||
// Check if returned output is valid, otherwise use the first screen
|
|
||||||
if (output == None)
|
|
||||||
output = res->outputs[0];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
output = res->outputs[0];
|
output = res->outputs[0];
|
||||||
}
|
|
||||||
|
|
||||||
XRRSetCrtcConfig(m_display.get(),
|
XRRSetCrtcConfig(m_display.get(),
|
||||||
res.get(),
|
res.get(),
|
||||||
@ -2045,7 +2032,7 @@ bool WindowImplX11::processEvent(XEvent& windowEvent)
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool WindowImplX11::checkXRandR(int& xRandRMajor, int& xRandRMinor)
|
bool WindowImplX11::checkXRandR()
|
||||||
{
|
{
|
||||||
// Check if the XRandR extension is present
|
// Check if the XRandR extension is present
|
||||||
int version = 0;
|
int version = 0;
|
||||||
@ -2055,35 +2042,20 @@ bool WindowImplX11::checkXRandR(int& xRandRMajor, int& xRandRMinor)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check XRandR version, 1.2 required
|
|
||||||
if (!XRRQueryVersion(m_display.get(), &xRandRMajor, &xRandRMinor) || xRandRMajor < 1 ||
|
|
||||||
(xRandRMajor == 1 && xRandRMinor < 2))
|
|
||||||
{
|
|
||||||
err() << "XRandR is too old" << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
RROutput WindowImplX11::getOutputPrimary(::Window& rootWindow, XRRScreenResources* res, int xRandRMajor, int xRandRMinor)
|
RROutput WindowImplX11::getOutputPrimary(::Window& rootWindow, XRRScreenResources* res)
|
||||||
{
|
{
|
||||||
// if xRandR version >= 1.3 get the primary screen else take the first screen
|
const RROutput output = XRRGetOutputPrimary(m_display.get(), rootWindow);
|
||||||
if ((xRandRMajor == 1 && xRandRMinor >= 3) || xRandRMajor > 1)
|
|
||||||
{
|
|
||||||
const RROutput output = XRRGetOutputPrimary(m_display.get(), rootWindow);
|
|
||||||
|
|
||||||
// Check if returned output is valid, otherwise use the first screen
|
// Check if returned output is valid, otherwise use the first screen
|
||||||
if (output == None)
|
if (output == None)
|
||||||
return res->outputs[0];
|
return res->outputs[0];
|
||||||
else
|
else
|
||||||
return output;
|
return output;
|
||||||
}
|
|
||||||
|
|
||||||
// xRandr version can't get the primary screen, use the first screen
|
|
||||||
return res->outputs[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2103,13 +2075,7 @@ Vector2i WindowImplX11::getPrimaryMonitorPosition()
|
|||||||
return monitorPosition;
|
return monitorPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get xRandr version
|
const RROutput output = getOutputPrimary(rootWindow, res.get());
|
||||||
int xRandRMajor = 0;
|
|
||||||
int xRandRMinor = 0;
|
|
||||||
if (!checkXRandR(xRandRMajor, xRandRMinor))
|
|
||||||
xRandRMajor = xRandRMinor = 0;
|
|
||||||
|
|
||||||
const RROutput output = getOutputPrimary(rootWindow, res.get(), xRandRMajor, xRandRMinor);
|
|
||||||
|
|
||||||
// Get output info from output
|
// Get output info from output
|
||||||
const auto outputInfo = X11Ptr<XRROutputInfo>(XRRGetOutputInfo(m_display.get(), res.get(), output));
|
const auto outputInfo = X11Ptr<XRROutputInfo>(XRRGetOutputInfo(m_display.get(), res.get(), output));
|
||||||
|
@ -284,26 +284,21 @@ private:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Check if a valid version of XRandR extension is present
|
/// \brief Check if a valid version of XRandR extension is present
|
||||||
///
|
///
|
||||||
/// \param xRandRMajor XRandR major version
|
|
||||||
/// \param xRandRMinor XRandR minor version
|
|
||||||
///
|
|
||||||
/// \return True if a valid XRandR version found, false otherwise
|
/// \return True if a valid XRandR version found, false otherwise
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool checkXRandR(int& xRandRMajor, int& xRandRMinor);
|
bool checkXRandR();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get the RROutput of the primary monitor
|
/// \brief Get the RROutput of the primary monitor
|
||||||
///
|
///
|
||||||
/// \param rootWindow the root window
|
/// \param rootWindow the root window
|
||||||
/// \param res screen resources
|
/// \param res screen resources
|
||||||
/// \param xRandRMajor XRandR major version
|
|
||||||
/// \param xRandRMinor XRandR minor version
|
|
||||||
///
|
///
|
||||||
/// \return RROutput of the primary monitor
|
/// \return RROutput of the primary monitor
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
RROutput getOutputPrimary(::Window& rootWindow, XRRScreenResources* res, int xRandRMajor, int xRandRMinor);
|
RROutput getOutputPrimary(::Window& rootWindow, XRRScreenResources* res);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get coordinates of the primary monitor
|
/// \brief Get coordinates of the primary monitor
|
||||||
|
Loading…
Reference in New Issue
Block a user