From 0999cf406abc3989b8a5216d86c468e251c1bdb6 Mon Sep 17 00:00:00 2001 From: Diego Borghetti Date: Mon, 4 May 2009 15:31:28 +0000 Subject: Fix crash because XSetInputFocus fail. Some WM send a WM_TAKE_FOCUS event before the window is really mapped (for example, change from virtual desktop), because of this, the call to XSetInputFocus fail and close Blender. --- intern/ghost/intern/GHOST_SystemX11.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'intern') diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp index 02dfdc2e25c..bfa5f35d312 100644 --- a/intern/ghost/intern/GHOST_SystemX11.cpp +++ b/intern/ghost/intern/GHOST_SystemX11.cpp @@ -515,11 +515,28 @@ GHOST_SystemX11::processEvent(XEvent *xe) window, data); } } else if (((Atom)xcme.data.l[0]) == m_wm_take_focus) { + XWindowAttributes attr; + Window fwin; + int revert_to; + /* as ICCCM say, we need reply this event * with a SetInputFocus, the data[1] have * the valid timestamp (send by the wm). + * + * Some WM send this event before the + * window is really mapped (for example + * change from virtual desktop), so we need + * to be sure that our windows is mapped + * or this call fail and close blender. */ - XSetInputFocus(m_display, xcme.window, RevertToParent, xcme.data.l[1]); + if (XGetWindowAttributes(m_display, xcme.window, &attr) == True) { + if (XGetInputFocus(m_display, &fwin, &revert_to) == True) { + if (attr.map_state == IsViewable) { + if (fwin != xcme.window) + XSetInputFocus(m_display, xcme.window, RevertToParent, xcme.data.l[1]); + } + } + } } else { /* Unknown client message, ignore */ } -- cgit v1.2.3