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

Method grabFocus

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

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

Source from the content-addressed store, hash-verified

1352
1353////////////////////////////////////////////////////////////
1354void WindowImplX11::grabFocus()
1355{
1356 using namespace WindowImplX11Impl;
1357
1358 // Only try to grab focus if the window is mapped
1359 XWindowAttributes attr;
1360
1361 XGetWindowAttributes(m_display.get(), m_window, &attr);
1362
1363 if (attr.map_state == IsUnmapped)
1364 return;
1365
1366 static const auto netActiveWindow = isFeatureSupported("_NET_ACTIVE_WINDOW") ? getAtom("_NET_ACTIVE_WINDOW") : None;
1367
1368 if (netActiveWindow)
1369 {
1370 auto event = XEvent();
1371 event.type = ClientMessage;
1372 event.xclient.window = m_window;
1373 event.xclient.format = 32;
1374 event.xclient.message_type = netActiveWindow;
1375 event.xclient.data.l[0] = 1; // Normal application
1376 event.xclient.data.l[1] = static_cast<long>(m_lastInputTime);
1377 event.xclient.data.l[2] = 0; // We don't know the currently active window
1378
1379 const int result = XSendEvent(m_display.get(),
1380 DefaultRootWindow(m_display.get()),
1381 False,
1382 SubstructureNotifyMask | SubstructureRedirectMask,
1383 &event);
1384
1385 XFlush(m_display.get());
1386
1387 if (!result)
1388 err() << "Setting fullscreen failed, could not send \"_NET_ACTIVE_WINDOW\" event" << std::endl;
1389 }
1390 else
1391 {
1392 XRaiseWindow(m_display.get(), m_window);
1393 XSetInputFocus(m_display.get(), m_window, RevertToPointerRoot, CurrentTime);
1394 XFlush(m_display.get());
1395 }
1396}
1397
1398
1399////////////////////////////////////////////////////////////

Callers

nothing calls this directly

Calls 3

isFeatureSupportedFunction · 0.85
getAtomFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected