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 | |
92efcf78 |
20 | IMPLEMENT_STANDARD_RTTIEXT(Aspect_DisplayConnection,Standard_Transient) |
21 | |
dc3fe572 |
22 | // ======================================================================= |
23 | // function : Aspect_DisplayConnection |
24 | // purpose : |
25 | // ======================================================================= |
26 | Aspect_DisplayConnection::Aspect_DisplayConnection() |
27 | { |
d8d01f6e |
28 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__) |
dc3fe572 |
29 | OSD_Environment anEnv ("DISPLAY"); |
30 | myDisplayName = anEnv.Value(); |
31 | Init(); |
32 | #endif |
33 | } |
34 | |
35 | // ======================================================================= |
36 | // function : ~Aspect_DisplayConnection |
37 | // purpose : |
38 | // ======================================================================= |
39 | Aspect_DisplayConnection::~Aspect_DisplayConnection() |
40 | { |
d8d01f6e |
41 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__) |
dc3fe572 |
42 | if (myDisplay != NULL) |
43 | { |
44 | XCloseDisplay (myDisplay); |
45 | } |
46 | #endif |
47 | } |
48 | |
d8d01f6e |
49 | #if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__) |
dc3fe572 |
50 | // ======================================================================= |
51 | // function : Aspect_DisplayConnection |
52 | // purpose : |
53 | // ======================================================================= |
54 | Aspect_DisplayConnection::Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName) |
55 | { |
56 | myDisplayName = theDisplayName; |
57 | Init(); |
58 | } |
59 | |
60 | // ======================================================================= |
61 | // function : GetDisplay |
62 | // purpose : |
63 | // ======================================================================= |
64 | Display* Aspect_DisplayConnection::GetDisplay() |
65 | { |
66 | return myDisplay; |
67 | } |
68 | |
69 | // ======================================================================= |
70 | // function : GetDisplayName |
71 | // purpose : |
72 | // ======================================================================= |
73 | TCollection_AsciiString Aspect_DisplayConnection::GetDisplayName() |
74 | { |
75 | return myDisplayName; |
76 | } |
77 | |
78 | // ======================================================================= |
79 | // function : Init |
80 | // purpose : |
81 | // ======================================================================= |
82 | void Aspect_DisplayConnection::Init() |
83 | { |
84 | myDisplay = XOpenDisplay (myDisplayName.ToCString()); |
18d715bd |
85 | myAtoms.Bind (Aspect_XA_DELETE_WINDOW, XInternAtom(myDisplay, "WM_DELETE_WINDOW", False)); |
dc3fe572 |
86 | |
87 | if (myDisplay == NULL) |
88 | { |
89 | TCollection_AsciiString aMessage; |
90 | aMessage += "Can not connect to the server \""; |
91 | aMessage += myDisplayName + "\""; |
9775fa61 |
92 | throw Aspect_DisplayConnectionDefinitionError(aMessage.ToCString()); |
dc3fe572 |
93 | } |
94 | } |
18d715bd |
95 | |
96 | // ======================================================================= |
97 | // function : GetAtom |
98 | // purpose : |
99 | // ======================================================================= |
100 | Atom Aspect_DisplayConnection::GetAtom (const Aspect_XAtom theAtom) const |
101 | { |
102 | Atom anAtom = myAtoms.Find(theAtom); |
103 | return anAtom; |
104 | } |
105 | |
dc3fe572 |
106 | #endif |