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 // =======================================================================
21 // function : Aspect_DisplayConnection
23 // =======================================================================
24 Aspect_DisplayConnection::Aspect_DisplayConnection()
26 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__)
27 OSD_Environment anEnv ("DISPLAY");
28 myDisplayName = anEnv.Value();
33 // =======================================================================
34 // function : ~Aspect_DisplayConnection
36 // =======================================================================
37 Aspect_DisplayConnection::~Aspect_DisplayConnection()
39 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__)
40 if (myDisplay != NULL)
42 XCloseDisplay (myDisplay);
47 #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__)
48 // =======================================================================
49 // function : Aspect_DisplayConnection
51 // =======================================================================
52 Aspect_DisplayConnection::Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName)
54 myDisplayName = theDisplayName;
58 // =======================================================================
59 // function : GetDisplay
61 // =======================================================================
62 Display* Aspect_DisplayConnection::GetDisplay()
67 // =======================================================================
68 // function : GetDisplayName
70 // =======================================================================
71 TCollection_AsciiString Aspect_DisplayConnection::GetDisplayName()
76 // =======================================================================
79 // =======================================================================
80 void Aspect_DisplayConnection::Init()
82 myDisplay = XOpenDisplay (myDisplayName.ToCString());
83 myAtoms.Bind (Aspect_XA_DELETE_WINDOW, XInternAtom(myDisplay, "WM_DELETE_WINDOW", False));
85 if (myDisplay == NULL)
87 TCollection_AsciiString aMessage;
88 aMessage += "Can not connect to the server \"";
89 aMessage += myDisplayName + "\"";
90 Aspect_DisplayConnectionDefinitionError::Raise (aMessage.ToCString());
94 // =======================================================================
97 // =======================================================================
98 Atom Aspect_DisplayConnection::GetAtom (const Aspect_XAtom theAtom) const
100 Atom anAtom = myAtoms.Find(theAtom);