///////////////////////////////////////////////////////
| 1287 | |
| 1288 | //////////////////////////////////////////////////////////// |
| 1289 | void WindowImplX11::requestFocus() |
| 1290 | { |
| 1291 | using namespace WindowImplX11Impl; |
| 1292 | |
| 1293 | // Focus is only stolen among SFML windows, not between applications |
| 1294 | // Check the global list of windows to find out whether an SFML window has the focus |
| 1295 | // Note: can't handle console and other non-SFML windows belonging to the application. |
| 1296 | bool sfmlWindowFocused = false; |
| 1297 | |
| 1298 | { |
| 1299 | const std::lock_guard lock(allWindowsMutex); |
| 1300 | for (sf::priv::WindowImplX11* windowPtr : allWindows) |
| 1301 | { |
| 1302 | if (windowPtr->hasFocus()) |
| 1303 | { |
| 1304 | sfmlWindowFocused = true; |
| 1305 | break; |
| 1306 | } |
| 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | // Check if window is viewable (not on other desktop, ...) |
| 1311 | // TODO: Check also if minimized |
| 1312 | XWindowAttributes attributes; |
| 1313 | if (XGetWindowAttributes(m_display.get(), m_window, &attributes) == 0) |
| 1314 | { |
| 1315 | err() << "Failed to check if window is viewable while requesting focus" << std::endl; |
| 1316 | return; // error getting attribute |
| 1317 | } |
| 1318 | |
| 1319 | const bool windowViewable = (attributes.map_state == IsViewable); |
| 1320 | |
| 1321 | if (sfmlWindowFocused && windowViewable) |
| 1322 | { |
| 1323 | // Another SFML window of this application has the focus and the current window is viewable: |
| 1324 | // steal focus (i.e. bring window to the front and give it input focus) |
| 1325 | grabFocus(); |
| 1326 | } |
| 1327 | else |
| 1328 | { |
| 1329 | // Otherwise: display urgency hint (flashing application logo) |
| 1330 | // Ensure WM hints exist, allocate if necessary |
| 1331 | auto hints = X11Ptr<XWMHints>(XGetWMHints(m_display.get(), m_window)); |
| 1332 | if (hints == nullptr) |
| 1333 | hints.reset(XAllocWMHints()); |
| 1334 | |
| 1335 | // Add urgency (notification) flag to hints |
| 1336 | hints->flags |= XUrgencyHint; |
| 1337 | XSetWMHints(m_display.get(), m_window, hints.get()); |
| 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | |
| 1342 | //////////////////////////////////////////////////////////// |