0024023: Revamp the OCCT Handle -- ambiguity
[occt.git] / src / Aspect / Aspect_DisplayConnection.cxx
CommitLineData
d5f74e42 1// Copyright (c) 2013-2014 OPEN CASCADE SAS
dc3fe572 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
dc3fe572 4//
d5f74e42 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
973c2be1 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.
dc3fe572 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
dc3fe572 13
14#include <Aspect_DisplayConnection.hxx>
15
16#include <Aspect_DisplayConnectionDefinitionError.hxx>
17#include <OSD_Environment.hxx>
18
dc3fe572 19
20// =======================================================================
21// function : Aspect_DisplayConnection
22// purpose :
23// =======================================================================
24Aspect_DisplayConnection::Aspect_DisplayConnection()
25{
0304f711 26#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__)
dc3fe572 27 OSD_Environment anEnv ("DISPLAY");
28 myDisplayName = anEnv.Value();
29 Init();
30#endif
31}
32
33// =======================================================================
34// function : ~Aspect_DisplayConnection
35// purpose :
36// =======================================================================
37Aspect_DisplayConnection::~Aspect_DisplayConnection()
38{
0304f711 39#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__)
dc3fe572 40 if (myDisplay != NULL)
41 {
42 XCloseDisplay (myDisplay);
43 }
44#endif
45}
46
0304f711 47#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__)
dc3fe572 48// =======================================================================
49// function : Aspect_DisplayConnection
50// purpose :
51// =======================================================================
52Aspect_DisplayConnection::Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName)
53{
54 myDisplayName = theDisplayName;
55 Init();
56}
57
58// =======================================================================
59// function : GetDisplay
60// purpose :
61// =======================================================================
62Display* Aspect_DisplayConnection::GetDisplay()
63{
64 return myDisplay;
65}
66
67// =======================================================================
68// function : GetDisplayName
69// purpose :
70// =======================================================================
71TCollection_AsciiString Aspect_DisplayConnection::GetDisplayName()
72{
73 return myDisplayName;
74}
75
76// =======================================================================
77// function : Init
78// purpose :
79// =======================================================================
80void Aspect_DisplayConnection::Init()
81{
82 myDisplay = XOpenDisplay (myDisplayName.ToCString());
18d715bd 83 myAtoms.Bind (Aspect_XA_DELETE_WINDOW, XInternAtom(myDisplay, "WM_DELETE_WINDOW", False));
dc3fe572 84
85 if (myDisplay == NULL)
86 {
87 TCollection_AsciiString aMessage;
88 aMessage += "Can not connect to the server \"";
89 aMessage += myDisplayName + "\"";
90 Aspect_DisplayConnectionDefinitionError::Raise (aMessage.ToCString());
91 }
92}
18d715bd 93
94// =======================================================================
95// function : GetAtom
96// purpose :
97// =======================================================================
98Atom Aspect_DisplayConnection::GetAtom (const Aspect_XAtom theAtom) const
99{
100 Atom anAtom = myAtoms.Find(theAtom);
101 return anAtom;
102}
103
dc3fe572 104#endif