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 #ifndef Aspect_DisplayConnection_HeaderFile
15 #define Aspect_DisplayConnection_HeaderFile
17 #include <Standard_Transient.hxx>
18 #include <Aspect_XAtom.hxx>
19 #include <Aspect_FBConfig.hxx>
21 #include <TCollection_AsciiString.hxx>
22 #include <NCollection_DataMap.hxx>
24 struct Aspect_XDisplay;
25 struct Aspect_XVisualInfo;
27 //! This class creates and provides connection with X server.
28 //! Raises exception if can not connect to X server.
29 //! On Windows and Mac OS X (in case when Cocoa used) platforms this class does nothing.
30 //! WARRNING: Do not close display connection manually!
31 class Aspect_DisplayConnection : public Standard_Transient
33 DEFINE_STANDARD_RTTIEXT(Aspect_DisplayConnection, Standard_Transient)
36 //! Default constructor. Creates connection with display name taken from "DISPLAY" environment variable
37 Standard_EXPORT Aspect_DisplayConnection();
39 //! Destructor. Close opened connection.
40 Standard_EXPORT virtual ~Aspect_DisplayConnection();
42 //! Constructor. Creates connection with display specified in theDisplayName.
43 //! Display name should be in format "hostname:number" or "hostname:number.screen_number", where:
44 //! hostname - Specifies the name of the host machine on which the display is physically attached.
45 //! number - Specifies the number of the display server on that host machine.
46 //! screen_number - Specifies the screen to be used on that server. Optional variable.
47 Standard_EXPORT Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName);
49 //! Constructor wrapping existing Display instance.
50 //! WARNING! it is a responsibility of application to keep this pointer
51 //! valid while Aspect_DisplayConnection is alive and to close Display when it is no more needed.
52 Standard_EXPORT Aspect_DisplayConnection (Aspect_XDisplay* theDisplay);
54 //! @return pointer to Display structure that serves as the connection to the X server.
55 Aspect_XDisplay* GetDisplayAspect() { return myDisplay; }
57 //! @return TRUE if X Display has been allocated by this class
58 Standard_Boolean IsOwnDisplay() const { return myIsOwnDisplay; }
60 //! @return identifier(atom) for custom named property associated with windows that use current connection to X server.
61 uint64_t GetAtom (const Aspect_XAtom theAtom) const
63 return myAtoms.Find (theAtom);
66 //! @return display name for this connection.
67 const TCollection_AsciiString& GetDisplayName() { return myDisplayName; }
69 //! Open connection with display specified in myDisplayName class field
70 //! or takes theDisplay parameter when it is not NULL.
71 //! WARNING! When external Display is specified, it is a responsibility of application
72 //! to keep this pointer valid while Aspect_DisplayConnection is alive
73 //! and to close Display when it is no more needed.
74 //! @param theDisplay external pointer to allocated Display, or NULL if new connection should be created
75 Standard_EXPORT void Init (Aspect_XDisplay* theDisplay);
77 //! Return default window visual or NULL when undefined.
78 Aspect_XVisualInfo* GetDefaultVisualInfo() const { return myDefVisualInfo; }
80 //! @return native Window FB config (GLXFBConfig on Xlib)
81 Aspect_FBConfig GetDefaultFBConfig() const { return myDefFBConfig; }
83 //! Set default window visual; the visual will be deallocated using XFree().
84 Standard_EXPORT void SetDefaultVisualInfo (Aspect_XVisualInfo* theVisual,
85 Aspect_FBConfig theFBConfig);
88 //! Constructor wrapping existing Display instance.
89 //! WARNING! it is a responsibility of application to keep this pointer
90 //! valid while Aspect_DisplayConnection is alive and to close Display when it is no more needed.
91 Aspect_DisplayConnection (Display* theDisplay)
92 : Aspect_DisplayConnection ((Aspect_XDisplay* )theDisplay) {}
94 //! @return pointer to Display structure that serves as the connection to the X server.
95 Display* GetDisplay() { return (Display* )myDisplay; }
97 //! Return default window visual or NULL when undefined.
98 XVisualInfo* GetDefaultVisualInfoX() const { return (XVisualInfo* )myDefVisualInfo; }
100 //! Set default window visual; the visual will be deallocated using XFree().
101 void SetDefaultVisualInfo (XVisualInfo* theVisual,
102 Aspect_FBConfig theFBConfig)
104 SetDefaultVisualInfo ((Aspect_XVisualInfo* )theVisual, theFBConfig);
107 //! @return identifier(atom) for custom named property associated with windows that use current connection to X server.
108 Atom GetAtomX (const Aspect_XAtom theAtom) const
110 return (Atom )GetAtom (theAtom);
113 //! Open connection with display specified in myDisplayName class field
114 //! or takes theDisplay parameter when it is not NULL.
115 void Init (Display* theDisplay)
117 Init ((Aspect_XDisplay* )theDisplay);
123 Aspect_XDisplay* myDisplay;
124 Aspect_XVisualInfo* myDefVisualInfo;
125 Aspect_FBConfig myDefFBConfig;
126 NCollection_DataMap<Aspect_XAtom, uint64_t> myAtoms;
127 TCollection_AsciiString myDisplayName;
128 Standard_Boolean myIsOwnDisplay;
132 //! To protect the connection from closing copying allowed only through the handles.
133 Aspect_DisplayConnection (const Aspect_DisplayConnection& );
134 Aspect_DisplayConnection& operator= (const Aspect_DisplayConnection& );
138 DEFINE_STANDARD_HANDLE (Aspect_DisplayConnection, Standard_Transient)
140 #endif // _Aspect_DisplayConnection_H__