Skip to content

Instantly share code, notes, and snippets.

@abodelot
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abodelot/37ad3a65521499a1462d to your computer and use it in GitHub Desktop.
Save abodelot/37ad3a65521499a1462d to your computer and use it in GitHub Desktop.
window gently requests focus instead of stealing it
diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp
index 4add01b..4cc2e7e 100644
--- a/src/SFML/Window/Unix/WindowImplX11.cpp
+++ b/src/SFML/Window/Unix/WindowImplX11.cpp
@@ -486,18 +486,18 @@ void WindowImplX11::setKeyRepeatEnabled(bool enabled)
////////////////////////////////////////////////////////////
void WindowImplX11::requestFocus()
{
- // Check if window is viewable (not on other desktop, minimized, ...)
- XWindowAttributes attributes;
- if (XGetWindowAttributes(m_display, m_window, &attributes) == 0)
- return; // error getting attribute
-
- // Not viewable: Can't set focus
- if (attributes.map_state != IsViewable)
- return;
+ // Ensure WM hints exist
+ XWMHints* hints = XGetWMHints(m_display, m_window);
+ if (hints == NULL)
+ hints = XAllocWMHints();
- // Bring window to the front and give it input focus
- XRaiseWindow(m_display, m_window);
- XSetInputFocus(m_display, m_window, RevertToPointerRoot, CurrentTime);
+ if (hints != NULL)
+ {
+ // Add Urgency Hint flag (visual notification)
+ hints->flags |= XUrgencyHint;
+ XSetWMHints(m_display, m_window, hints);
+ XFree(hints);
+ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment