From f3161c97a6eea885a9f162599d42d7ca85e2cfe3 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 28 May 2015 18:23:44 +1000 Subject: [PATCH] Ghost/X11: allow creating windows to fail Would exit, problematic for setting stereo3d modes which aren't always supported. --- intern/ghost/intern/GHOST_WindowX11.cpp | 56 ++++++++++++++----------- intern/ghost/intern/GHOST_WindowX11.h | 4 +- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/intern/ghost/intern/GHOST_WindowX11.cpp b/intern/ghost/intern/GHOST_WindowX11.cpp index a2d7303243a..bd0d6829e27 100644 --- a/intern/ghost/intern/GHOST_WindowX11.cpp +++ b/intern/ghost/intern/GHOST_WindowX11.cpp @@ -291,11 +291,17 @@ GHOST_WindowX11( m_visualInfo(NULL), m_normal_state(GHOST_kWindowStateNormal), m_system(system), - m_valid_setup(false), m_invalid_window(false), m_empty_cursor(None), m_custom_cursor(None), - m_visible_cursor(None) + m_visible_cursor(None), +#ifdef WITH_XDND + m_dropTarget(NULL), +#endif +#if defined(WITH_X11_XINPUT) && defined(X_HAVE_UTF8_STRING) + m_xic(NULL), +#endif + m_valid_setup(false) { if (type == GHOST_kDrawingContextTypeOpenGL) { m_visualInfo = x11_visualinfo_from_glx(m_display, stereoVisual, &m_wantNumOfAASamples); @@ -306,10 +312,10 @@ GHOST_WindowX11( m_visualInfo = XGetVisualInfo(m_display, 0, &tmp, &n); } - /* exit if this is the first window */ + /* caller needs to check 'getValid()' */ if (m_visualInfo == NULL) { - fprintf(stderr, "initial window could not find the GLX extension, exit!\n"); - exit(EXIT_FAILURE); + fprintf(stderr, "initial window could not find the GLX extension\n"); + return; } unsigned int xattributes_valuemask = 0; @@ -486,11 +492,6 @@ GHOST_WindowX11( } } -#if defined(WITH_X11_XINPUT) && defined(X_HAVE_UTF8_STRING) - m_xic = NULL; -#endif - - /* Set the window hints */ { XWMHints *xwmhints = XAllocWMHints(); @@ -1216,15 +1217,6 @@ validate() GHOST_WindowX11:: ~GHOST_WindowX11() { - static Atom Primary_atom, Clipboard_atom; - Window p_owner, c_owner; - /*Change the owner of the Atoms to None if we are the owner*/ - Primary_atom = XInternAtom(m_display, "PRIMARY", False); - Clipboard_atom = XInternAtom(m_display, "CLIPBOARD", False); - - p_owner = XGetSelectionOwner(m_display, Primary_atom); - c_owner = XGetSelectionOwner(m_display, Clipboard_atom); - std::map::iterator it = m_standard_cursors.begin(); for (; it != m_standard_cursors.end(); ++it) { XFreeCursor(m_display, it->second); @@ -1237,11 +1229,23 @@ GHOST_WindowX11:: XFreeCursor(m_display, m_custom_cursor); } - if (p_owner == m_window) { - XSetSelectionOwner(m_display, Primary_atom, None, CurrentTime); - } - if (c_owner == m_window) { - XSetSelectionOwner(m_display, Clipboard_atom, None, CurrentTime); + if (m_valid_setup) { + static Atom Primary_atom, Clipboard_atom; + Window p_owner, c_owner; + /*Change the owner of the Atoms to None if we are the owner*/ + Primary_atom = XInternAtom(m_display, "PRIMARY", False); + Clipboard_atom = XInternAtom(m_display, "CLIPBOARD", False); + + + p_owner = XGetSelectionOwner(m_display, Primary_atom); + c_owner = XGetSelectionOwner(m_display, Clipboard_atom); + + if (p_owner == m_window) { + XSetSelectionOwner(m_display, Primary_atom, None, CurrentTime); + } + if (c_owner == m_window) { + XSetSelectionOwner(m_display, Clipboard_atom, None, CurrentTime); + } } if (m_visualInfo) { @@ -1260,7 +1264,9 @@ GHOST_WindowX11:: releaseNativeHandles(); - XDestroyWindow(m_display, m_window); + if (m_valid_setup) { + XDestroyWindow(m_display, m_window); + } } diff --git a/intern/ghost/intern/GHOST_WindowX11.h b/intern/ghost/intern/GHOST_WindowX11.h index eaa8a5327f7..277afe38e19 100644 --- a/intern/ghost/intern/GHOST_WindowX11.h +++ b/intern/ghost/intern/GHOST_WindowX11.h @@ -327,8 +327,6 @@ private: /** A pointer to the typed system class. */ GHOST_SystemX11 *m_system; - bool m_valid_setup; - /** Used to concatenate calls to invalidate() on this window. */ bool m_invalid_window; @@ -356,6 +354,8 @@ private: XIC m_xic; #endif + bool m_valid_setup; + void icccmSetState(int state); int icccmGetState() const;