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 | |
b69e576a |
19 | #if defined(HAVE_XLIB) |
20 | #include <X11/Xlib.h> |
21 | #include <X11/Xutil.h> |
b69e576a |
22 | #endif |
23 | |
92efcf78 |
24 | IMPLEMENT_STANDARD_RTTIEXT(Aspect_DisplayConnection,Standard_Transient) |
25 | |
dc3fe572 |
26 | // ======================================================================= |
27 | // function : Aspect_DisplayConnection |
28 | // purpose : |
29 | // ======================================================================= |
30 | Aspect_DisplayConnection::Aspect_DisplayConnection() |
31 | { |
b69e576a |
32 | #if defined(HAVE_XLIB) |
9c0787df |
33 | myDisplay = NULL; |
3ae8c60b |
34 | myDefVisualInfo = NULL; |
35 | myDefFBConfig = NULL; |
9c0787df |
36 | myIsOwnDisplay = false; |
dc3fe572 |
37 | OSD_Environment anEnv ("DISPLAY"); |
38 | myDisplayName = anEnv.Value(); |
9c0787df |
39 | Init (NULL); |
dc3fe572 |
40 | #endif |
41 | } |
42 | |
43 | // ======================================================================= |
44 | // function : ~Aspect_DisplayConnection |
45 | // purpose : |
46 | // ======================================================================= |
47 | Aspect_DisplayConnection::~Aspect_DisplayConnection() |
48 | { |
b69e576a |
49 | #if defined(HAVE_XLIB) |
3ae8c60b |
50 | if (myDefVisualInfo != NULL) |
51 | { |
52 | XFree (myDefVisualInfo); |
53 | } |
9c0787df |
54 | if (myDisplay != NULL |
55 | && myIsOwnDisplay) |
dc3fe572 |
56 | { |
b69e576a |
57 | XCloseDisplay ((Display* )myDisplay); |
dc3fe572 |
58 | } |
59 | #endif |
60 | } |
61 | |
dc3fe572 |
62 | // ======================================================================= |
63 | // function : Aspect_DisplayConnection |
64 | // purpose : |
65 | // ======================================================================= |
66 | Aspect_DisplayConnection::Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName) |
9c0787df |
67 | : myDisplay (NULL), |
3ae8c60b |
68 | myDefVisualInfo (NULL), |
69 | myDefFBConfig (NULL), |
9c0787df |
70 | myIsOwnDisplay (false) |
dc3fe572 |
71 | { |
72 | myDisplayName = theDisplayName; |
9c0787df |
73 | Init (NULL); |
dc3fe572 |
74 | } |
75 | |
76 | // ======================================================================= |
9c0787df |
77 | // function : Aspect_DisplayConnection |
dc3fe572 |
78 | // purpose : |
79 | // ======================================================================= |
b69e576a |
80 | Aspect_DisplayConnection::Aspect_DisplayConnection (Aspect_XDisplay* theDisplay) |
9c0787df |
81 | : myDisplay (NULL), |
3ae8c60b |
82 | myDefVisualInfo (NULL), |
83 | myDefFBConfig (NULL), |
9c0787df |
84 | myIsOwnDisplay (false) |
dc3fe572 |
85 | { |
9c0787df |
86 | Init (theDisplay); |
dc3fe572 |
87 | } |
88 | |
3ae8c60b |
89 | // ======================================================================= |
90 | // function : SetDefaultVisualInfo |
91 | // purpose : |
92 | // ======================================================================= |
b69e576a |
93 | void Aspect_DisplayConnection::SetDefaultVisualInfo (Aspect_XVisualInfo* theVisual, |
3ae8c60b |
94 | Aspect_FBConfig theFBConfig) |
95 | { |
96 | if (myDefVisualInfo != NULL) |
97 | { |
b69e576a |
98 | #if defined(HAVE_XLIB) |
3ae8c60b |
99 | XFree (myDefVisualInfo); |
b69e576a |
100 | #endif |
3ae8c60b |
101 | } |
102 | myDefVisualInfo = theVisual; |
103 | myDefFBConfig = theFBConfig; |
104 | } |
105 | |
dc3fe572 |
106 | // ======================================================================= |
107 | // function : Init |
108 | // purpose : |
109 | // ======================================================================= |
b69e576a |
110 | void Aspect_DisplayConnection::Init (Aspect_XDisplay* theDisplay) |
dc3fe572 |
111 | { |
b69e576a |
112 | #if defined(HAVE_XLIB) |
9c0787df |
113 | if (myDisplay != NULL |
114 | && myIsOwnDisplay) |
115 | { |
b69e576a |
116 | XCloseDisplay ((Display* )myDisplay); |
9c0787df |
117 | } |
118 | myIsOwnDisplay = false; |
119 | myAtoms.Clear(); |
120 | |
b69e576a |
121 | myDisplay = theDisplay != NULL ? theDisplay : (Aspect_XDisplay* )XOpenDisplay (myDisplayName.ToCString()); |
dc3fe572 |
122 | if (myDisplay == NULL) |
123 | { |
124 | TCollection_AsciiString aMessage; |
125 | aMessage += "Can not connect to the server \""; |
126 | aMessage += myDisplayName + "\""; |
9775fa61 |
127 | throw Aspect_DisplayConnectionDefinitionError(aMessage.ToCString()); |
dc3fe572 |
128 | } |
9c0787df |
129 | else |
130 | { |
131 | myIsOwnDisplay = theDisplay == NULL; |
b69e576a |
132 | myAtoms.Bind (Aspect_XA_DELETE_WINDOW, (uint64_t )XInternAtom((Display* )myDisplay, "WM_DELETE_WINDOW", False)); |
9c0787df |
133 | } |
b69e576a |
134 | #else |
135 | myDisplay = theDisplay; |
136 | myIsOwnDisplay = theDisplay == NULL; |
dc3fe572 |
137 | #endif |
b69e576a |
138 | } |