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>
20 IMPLEMENT_STANDARD_RTTIEXT(Aspect_DisplayConnection,Standard_Transient)
22 // =======================================================================
23 // function : Aspect_DisplayConnection
25 // =======================================================================
26 Aspect_DisplayConnection::Aspect_DisplayConnection()
28 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__) && !defined(__EMSCRIPTEN__)
30 myIsOwnDisplay = false;
31 OSD_Environment anEnv ("DISPLAY");
32 myDisplayName = anEnv.Value();
37 // =======================================================================
38 // function : ~Aspect_DisplayConnection
40 // =======================================================================
41 Aspect_DisplayConnection::~Aspect_DisplayConnection()
43 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__) && !defined(__EMSCRIPTEN__)
47 XCloseDisplay (myDisplay);
52 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__) && !defined(__EMSCRIPTEN__)
53 // =======================================================================
54 // function : Aspect_DisplayConnection
56 // =======================================================================
57 Aspect_DisplayConnection::Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName)
59 myIsOwnDisplay (false)
61 myDisplayName = theDisplayName;
65 // =======================================================================
66 // function : Aspect_DisplayConnection
68 // =======================================================================
69 Aspect_DisplayConnection::Aspect_DisplayConnection (Display* theDisplay)
71 myIsOwnDisplay (false)
76 // =======================================================================
79 // =======================================================================
80 void Aspect_DisplayConnection::Init (Display* theDisplay)
85 XCloseDisplay (myDisplay);
87 myIsOwnDisplay = false;
90 myDisplay = theDisplay != NULL ? theDisplay : XOpenDisplay (myDisplayName.ToCString());
91 if (myDisplay == NULL)
93 TCollection_AsciiString aMessage;
94 aMessage += "Can not connect to the server \"";
95 aMessage += myDisplayName + "\"";
96 throw Aspect_DisplayConnectionDefinitionError(aMessage.ToCString());
100 myIsOwnDisplay = theDisplay == NULL;
101 myAtoms.Bind (Aspect_XA_DELETE_WINDOW, XInternAtom(myDisplay, "WM_DELETE_WINDOW", False));
105 // =======================================================================
106 // function : GetAtom
108 // =======================================================================
109 Atom Aspect_DisplayConnection::GetAtom (const Aspect_XAtom theAtom) const
111 Atom anAtom = myAtoms.Find(theAtom);