MCPcopy Create free account
hub / github.com/SFML/SFML / setVideoMode

Method setVideoMode

src/SFML/Window/Unix/WindowImplX11.cpp:1400–1486  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

1398
1399////////////////////////////////////////////////////////////
1400void WindowImplX11::setVideoMode(const VideoMode& mode)
1401{
1402 using namespace WindowImplX11Impl;
1403
1404 // Skip mode switching if the new mode is equal to the desktop mode
1405 if (mode == VideoMode::getDesktopMode())
1406 return;
1407
1408 // Check if the XRandR extension is present
1409 if (!checkXRandR())
1410 {
1411 // XRandR extension is not supported: we cannot use fullscreen mode
1412 err() << "Fullscreen is not supported, switching to window mode" << std::endl;
1413 return;
1414 }
1415
1416 // Get root window
1417 ::Window rootWindow = RootWindow(m_display.get(), m_screen);
1418
1419 // Get the screen resources
1420 const auto res = X11Ptr<XRRScreenResources>(XRRGetScreenResources(m_display.get(), rootWindow));
1421 if (!res)
1422 {
1423 err() << "Failed to get the current screen resources for fullscreen mode, switching to window mode" << std::endl;
1424 return;
1425 }
1426
1427 RROutput output = getOutputPrimary(rootWindow, res.get());
1428
1429 // Get output info from output
1430 const auto outputInfo = X11Ptr<XRROutputInfo>(XRRGetOutputInfo(m_display.get(), res.get(), output));
1431 if (!outputInfo || outputInfo->connection == RR_Disconnected)
1432 {
1433 err() << "Failed to get output info for fullscreen mode, switching to window mode" << std::endl;
1434 return;
1435 }
1436
1437 // Retrieve current RRMode, screen position and rotation
1438 const auto crtcInfo = X11Ptr<XRRCrtcInfo>(XRRGetCrtcInfo(m_display.get(), res.get(), outputInfo->crtc));
1439 if (!crtcInfo)
1440 {
1441 err() << "Failed to get crtc info for fullscreen mode, switching to window mode" << std::endl;
1442 return;
1443 }
1444
1445 // Find RRMode to set
1446 bool modeFound = false;
1447 RRMode xRandMode = 0;
1448
1449 for (int i = 0; (i < res->nmode) && !modeFound; ++i)
1450 {
1451 if (crtcInfo->rotation == RR_Rotate_90 || crtcInfo->rotation == RR_Rotate_270)
1452 std::swap(res->modes[i].height, res->modes[i].width);
1453
1454 // Check if screen size match
1455 if ((res->modes[i].width == mode.size.x) && (res->modes[i].height == mode.size.y))
1456 {
1457 xRandMode = res->modes[i].id;

Callers

nothing calls this directly

Calls 2

getMethod · 0.80
swapFunction · 0.50

Tested by

no test coverage detected