1 // Copyright (c) 2013-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <Aspect_DisplayConnection.hxx>
16 #include <Aspect_DisplayConnectionDefinitionError.hxx>
17 #include <OSD_Environment.hxx>
19 IMPLEMENT_STANDARD_RTTIEXT(Aspect_DisplayConnection,Standard_Transient)
21 // =======================================================================
22 // function : Aspect_DisplayConnection
24 // =======================================================================
25 Aspect_DisplayConnection::Aspect_DisplayConnection()
27 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__) && !defined(__EMSCRIPTEN__)
29 myDefVisualInfo = NULL;
31 myIsOwnDisplay = false;
32 OSD_Environment anEnv ("DISPLAY");
33 myDisplayName = anEnv.Value();
38 // =======================================================================
39 // function : ~Aspect_DisplayConnection
41 // =======================================================================
42 Aspect_DisplayConnection::~Aspect_DisplayConnection()
44 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__) && !defined(__EMSCRIPTEN__)
45 if (myDefVisualInfo != NULL)
47 XFree (myDefVisualInfo);
52 XCloseDisplay (myDisplay);
57 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__) && !defined(__EMSCRIPTEN__)
58 // =======================================================================
59 // function : Aspect_DisplayConnection
61 // =======================================================================
62 Aspect_DisplayConnection::Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName)
64 myDefVisualInfo (NULL),
66 myIsOwnDisplay (false)
68 myDisplayName = theDisplayName;
72 // =======================================================================
73 // function : Aspect_DisplayConnection
75 // =======================================================================
76 Aspect_DisplayConnection::Aspect_DisplayConnection (Display* theDisplay)
78 myDefVisualInfo (NULL),
80 myIsOwnDisplay (false)
85 // =======================================================================
86 // function : SetDefaultVisualInfo
88 // =======================================================================
89 void Aspect_DisplayConnection::SetDefaultVisualInfo (XVisualInfo* theVisual,
90 Aspect_FBConfig theFBConfig)
92 if (myDefVisualInfo != NULL)
94 XFree (myDefVisualInfo);
96 myDefVisualInfo = theVisual;
97 myDefFBConfig = theFBConfig;
100 // =======================================================================
103 // =======================================================================
104 void Aspect_DisplayConnection::Init (Display* theDisplay)
106 if (myDisplay != NULL
109 XCloseDisplay (myDisplay);
111 myIsOwnDisplay = false;
114 myDisplay = theDisplay != NULL ? theDisplay : XOpenDisplay (myDisplayName.ToCString());
115 if (myDisplay == NULL)
117 TCollection_AsciiString aMessage;
118 aMessage += "Can not connect to the server \"";
119 aMessage += myDisplayName + "\"";
120 throw Aspect_DisplayConnectionDefinitionError(aMessage.ToCString());
124 myIsOwnDisplay = theDisplay == NULL;
125 myAtoms.Bind (Aspect_XA_DELETE_WINDOW, XInternAtom(myDisplay, "WM_DELETE_WINDOW", False));
129 // =======================================================================
130 // function : GetAtom
132 // =======================================================================
133 Atom Aspect_DisplayConnection::GetAtom (const Aspect_XAtom theAtom) const
135 Atom anAtom = myAtoms.Find(theAtom);