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

Method setMouseCursorGrabbed

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

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

Source from the content-addressed store, hash-verified

1242
1243////////////////////////////////////////////////////////////
1244void WindowImplX11::setMouseCursorGrabbed(bool grabbed)
1245{
1246 using namespace WindowImplX11Impl;
1247
1248 // This has no effect in fullscreen mode
1249 if (m_fullscreen || (m_cursorGrabbed == grabbed))
1250 return;
1251
1252 if (grabbed)
1253 {
1254 // Try multiple times to grab the cursor
1255 for (unsigned int trial = 0; trial < maxTrialsCount; ++trial)
1256 {
1257 const int result = XGrabPointer(m_display.get(), m_window, True, None, GrabModeAsync, GrabModeAsync, m_window, None, CurrentTime);
1258
1259 if (result == GrabSuccess)
1260 {
1261 m_cursorGrabbed = true;
1262 break;
1263 }
1264
1265 // The cursor grab failed, trying again after a small sleep
1266 sf::sleep(sf::milliseconds(50));
1267 }
1268
1269 if (!m_cursorGrabbed)
1270 err() << "Failed to grab mouse cursor" << std::endl;
1271 }
1272 else
1273 {
1274 // Release the cursor from the window and disable cursor grabbing
1275 XUngrabPointer(m_display.get(), CurrentTime);
1276 m_cursorGrabbed = false;
1277 }
1278}
1279
1280
1281////////////////////////////////////////////////////////////

Callers

nothing calls this directly

Calls 2

sleepFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected