1 // Copyright (c) 2013 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <Aspect_DisplayConnection.hxx>
20 #include <Aspect_DisplayConnectionDefinitionError.hxx>
21 #include <OSD_Environment.hxx>
23 IMPLEMENT_STANDARD_HANDLE (Aspect_DisplayConnection, Standard_Transient)
24 IMPLEMENT_STANDARD_RTTIEXT(Aspect_DisplayConnection, Standard_Transient)
26 // =======================================================================
27 // function : Aspect_DisplayConnection
29 // =======================================================================
30 Aspect_DisplayConnection::Aspect_DisplayConnection()
32 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
33 OSD_Environment anEnv ("DISPLAY");
34 myDisplayName = anEnv.Value();
39 // =======================================================================
40 // function : ~Aspect_DisplayConnection
42 // =======================================================================
43 Aspect_DisplayConnection::~Aspect_DisplayConnection()
45 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
46 if (myDisplay != NULL)
48 XCloseDisplay (myDisplay);
53 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
54 // =======================================================================
55 // function : Aspect_DisplayConnection
57 // =======================================================================
58 Aspect_DisplayConnection::Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName)
60 myDisplayName = theDisplayName;
64 // =======================================================================
65 // function : GetDisplay
67 // =======================================================================
68 Display* Aspect_DisplayConnection::GetDisplay()
73 // =======================================================================
74 // function : GetDisplayName
76 // =======================================================================
77 TCollection_AsciiString Aspect_DisplayConnection::GetDisplayName()
82 // =======================================================================
85 // =======================================================================
86 void Aspect_DisplayConnection::Init()
88 myDisplay = XOpenDisplay (myDisplayName.ToCString());
89 myAtoms.Bind (Aspect_XA_DELETE_WINDOW, XInternAtom(myDisplay, "WM_DELETE_WINDOW", False));
91 if (myDisplay == NULL)
93 TCollection_AsciiString aMessage;
94 aMessage += "Can not connect to the server \"";
95 aMessage += myDisplayName + "\"";
96 Aspect_DisplayConnectionDefinitionError::Raise (aMessage.ToCString());
100 // =======================================================================
101 // function : GetAtom
103 // =======================================================================
104 Atom Aspect_DisplayConnection::GetAtom (const Aspect_XAtom theAtom) const
106 Atom anAtom = myAtoms.Find(theAtom);