1 // Copyright (c) 2013 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
6 // under the terms of the GNU Lesser General Public 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_HANDLE (Aspect_DisplayConnection, Standard_Transient)
20 IMPLEMENT_STANDARD_RTTIEXT(Aspect_DisplayConnection, Standard_Transient)
22 // =======================================================================
23 // function : Aspect_DisplayConnection
25 // =======================================================================
26 Aspect_DisplayConnection::Aspect_DisplayConnection()
28 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
29 OSD_Environment anEnv ("DISPLAY");
30 myDisplayName = anEnv.Value();
35 // =======================================================================
36 // function : ~Aspect_DisplayConnection
38 // =======================================================================
39 Aspect_DisplayConnection::~Aspect_DisplayConnection()
41 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
42 if (myDisplay != NULL)
44 XCloseDisplay (myDisplay);
49 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
50 // =======================================================================
51 // function : Aspect_DisplayConnection
53 // =======================================================================
54 Aspect_DisplayConnection::Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName)
56 myDisplayName = theDisplayName;
60 // =======================================================================
61 // function : GetDisplay
63 // =======================================================================
64 Display* Aspect_DisplayConnection::GetDisplay()
69 // =======================================================================
70 // function : GetDisplayName
72 // =======================================================================
73 TCollection_AsciiString Aspect_DisplayConnection::GetDisplayName()
78 // =======================================================================
81 // =======================================================================
82 void Aspect_DisplayConnection::Init()
84 myDisplay = XOpenDisplay (myDisplayName.ToCString());
85 myAtoms.Bind (Aspect_XA_DELETE_WINDOW, XInternAtom(myDisplay, "WM_DELETE_WINDOW", False));
87 if (myDisplay == NULL)
89 TCollection_AsciiString aMessage;
90 aMessage += "Can not connect to the server \"";
91 aMessage += myDisplayName + "\"";
92 Aspect_DisplayConnectionDefinitionError::Raise (aMessage.ToCString());
96 // =======================================================================
99 // =======================================================================
100 Atom Aspect_DisplayConnection::GetAtom (const Aspect_XAtom theAtom) const
102 Atom anAtom = myAtoms.Find(theAtom);