///////////////////////////////////////////////////////
| 1799 | |
| 1800 | //////////////////////////////////////////////////////////// |
| 1801 | bool WindowImplX11::processEvent(XEvent& windowEvent) |
| 1802 | { |
| 1803 | using namespace WindowImplX11Impl; |
| 1804 | |
| 1805 | // Convert the X11 event to a sf::Event |
| 1806 | switch (windowEvent.type) |
| 1807 | { |
| 1808 | // Destroy event |
| 1809 | case DestroyNotify: |
| 1810 | { |
| 1811 | // The window is about to be destroyed: we must cleanup resources |
| 1812 | cleanup(); |
| 1813 | break; |
| 1814 | } |
| 1815 | |
| 1816 | // Gain focus event |
| 1817 | case FocusIn: |
| 1818 | { |
| 1819 | // Update the input context |
| 1820 | if (m_inputContext) |
| 1821 | XSetICFocus(m_inputContext); |
| 1822 | |
| 1823 | // Grab cursor |
| 1824 | if (m_cursorGrabbed) |
| 1825 | { |
| 1826 | // Try multiple times to grab the cursor |
| 1827 | for (unsigned int trial = 0; trial < maxTrialsCount; ++trial) |
| 1828 | { |
| 1829 | const int result = XGrabPointer(m_display.get(), |
| 1830 | m_window, |
| 1831 | True, |
| 1832 | None, |
| 1833 | GrabModeAsync, |
| 1834 | GrabModeAsync, |
| 1835 | m_window, |
| 1836 | None, |
| 1837 | CurrentTime); |
| 1838 | |
| 1839 | if (result == GrabSuccess) |
| 1840 | { |
| 1841 | m_cursorGrabbed = true; |
| 1842 | break; |
| 1843 | } |
| 1844 | |
| 1845 | // The cursor grab failed, trying again after a small sleep |
| 1846 | sf::sleep(sf::milliseconds(50)); |
| 1847 | } |
| 1848 | |
| 1849 | if (!m_cursorGrabbed) |
| 1850 | err() << "Failed to grab mouse cursor" << std::endl; |
| 1851 | } |
| 1852 | |
| 1853 | pushEvent(Event::FocusGained{}); |
| 1854 | |
| 1855 | // If the window has been previously marked urgent (notification) as a result of a focus request, undo that |
| 1856 | const auto hints = X11Ptr<XWMHints>(XGetWMHints(m_display.get(), m_window)); |
| 1857 | if (hints != nullptr) |
| 1858 | { |