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>
19 #if defined(HAVE_XLIB)
21 #include <X11/Xutil.h>
24 IMPLEMENT_STANDARD_RTTIEXT(Aspect_DisplayConnection,Standard_Transient)
26 // =======================================================================
27 // function : Aspect_DisplayConnection
29 // =======================================================================
30 Aspect_DisplayConnection::Aspect_DisplayConnection()
32 #if defined(HAVE_XLIB)
34 myDefVisualInfo = NULL;
36 myIsOwnDisplay = false;
37 OSD_Environment anEnv ("DISPLAY");
38 myDisplayName = anEnv.Value();
43 // =======================================================================
44 // function : ~Aspect_DisplayConnection
46 // =======================================================================
47 Aspect_DisplayConnection::~Aspect_DisplayConnection()
49 #if defined(HAVE_XLIB)
50 if (myDefVisualInfo != NULL)
52 XFree (myDefVisualInfo);
57 XCloseDisplay ((Display* )myDisplay);
62 // =======================================================================
63 // function : Aspect_DisplayConnection
65 // =======================================================================
66 Aspect_DisplayConnection::Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName)
68 myDefVisualInfo (NULL),
70 myIsOwnDisplay (false)
72 myDisplayName = theDisplayName;
76 // =======================================================================
77 // function : Aspect_DisplayConnection
79 // =======================================================================
80 Aspect_DisplayConnection::Aspect_DisplayConnection (Aspect_XDisplay* theDisplay)
82 myDefVisualInfo (NULL),
84 myIsOwnDisplay (false)
89 // =======================================================================
90 // function : SetDefaultVisualInfo
92 // =======================================================================
93 void Aspect_DisplayConnection::SetDefaultVisualInfo (Aspect_XVisualInfo* theVisual,
94 Aspect_FBConfig theFBConfig)
96 if (myDefVisualInfo != NULL)
98 #if defined(HAVE_XLIB)
99 XFree (myDefVisualInfo);
102 myDefVisualInfo = theVisual;
103 myDefFBConfig = theFBConfig;
106 // =======================================================================
109 // =======================================================================
110 void Aspect_DisplayConnection::Init (Aspect_XDisplay* theDisplay)
112 #if defined(HAVE_XLIB)
113 if (myDisplay != NULL
116 XCloseDisplay ((Display* )myDisplay);
118 myIsOwnDisplay = false;
121 myDisplay = theDisplay != NULL ? theDisplay : (Aspect_XDisplay* )XOpenDisplay (myDisplayName.ToCString());
122 if (myDisplay == NULL)
124 TCollection_AsciiString aMessage;
125 aMessage += "Can not connect to the server \"";
126 aMessage += myDisplayName + "\"";
127 throw Aspect_DisplayConnectionDefinitionError(aMessage.ToCString());
131 myIsOwnDisplay = theDisplay == NULL;
132 myAtoms.Bind (Aspect_XA_DELETE_WINDOW, (uint64_t )XInternAtom((Display* )myDisplay, "WM_DELETE_WINDOW", False));
135 myDisplay = theDisplay;
136 myIsOwnDisplay = theDisplay == NULL;