dc3fe572 |
1 | // Copyright (c) 2013 OPEN CASCADE SAS |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
dc3fe572 |
4 | // |
973c2be1 |
5 | // This library is free software; you can redistribute it and / or modify it |
6 | // under the terms of the GNU Lesser General Public 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. |
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 | #ifndef _Aspect_DisplayConnection_H__ |
15 | #define _Aspect_DisplayConnection_H__ |
16 | |
17 | #include <Standard_Transient.hxx> |
18 | #include <Aspect_DisplayConnection_Handle.hxx> |
18d715bd |
19 | #include <Aspect_XAtom.hxx> |
dc3fe572 |
20 | |
21 | #include <TCollection_AsciiString.hxx> |
18d715bd |
22 | #include <NCollection_DataMap.hxx> |
dc3fe572 |
23 | |
24 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
25 | #include <X11/Xlib.h> |
26 | #endif |
27 | |
28 | //! This class creates and provides connection with X server. |
29 | //! Raises exception if can not connect to X server. |
30 | //! On Windows and Mac OS X (in case when Cocoa used) platforms this class do nothing. |
31 | //! WARRNING: Do not close display connection manualy! |
32 | |
33 | class Aspect_DisplayConnection : public Standard_Transient |
34 | { |
35 | public: |
36 | |
37 | //! Default constructor. Creates connection with display name taken from "DISPLAY" environment variable |
38 | Standard_EXPORT Aspect_DisplayConnection(); |
39 | |
40 | //! Destructor. Close opened connection. |
41 | Standard_EXPORT ~Aspect_DisplayConnection(); |
42 | |
43 | #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
44 | //! Constructor. Creates connection with display specified in theDisplayName. |
45 | //! Display name should be in format "hostname:number" or "hostname:number.screen_number", where: |
46 | //! hostname - Specifies the name of the host machine on which the display is physically attached. |
47 | //! number - Specifies the number of the display server on that host machine. |
48 | //! screen_number - Specifies the screen to be used on that server. Optional variable. |
49 | Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName); |
50 | |
51 | //! @return pointer to Display structure that serves as the connection to the X server. |
52 | Display* GetDisplay(); |
18d715bd |
53 | |
54 | //! @return identifier(atom) for custom named property associated with windows that use current connection to X server. |
55 | Atom GetAtom (const Aspect_XAtom theAtom) const; |
dc3fe572 |
56 | |
57 | //! @return display name for this connection. |
58 | TCollection_AsciiString GetDisplayName(); |
59 | |
60 | private: |
61 | |
62 | //! Open connection with display specified in myDisplayName class field. |
63 | void Init(); |
64 | |
65 | private: |
66 | |
18d715bd |
67 | Display* myDisplay; |
68 | NCollection_DataMap<Aspect_XAtom, Atom> myAtoms; |
69 | TCollection_AsciiString myDisplayName; |
dc3fe572 |
70 | #endif |
71 | |
72 | private: |
73 | |
74 | //! To protect the connection from closing copying allowed only through the handles. |
75 | Aspect_DisplayConnection (const Aspect_DisplayConnection& ); |
76 | Aspect_DisplayConnection& operator= (const Aspect_DisplayConnection& ); |
77 | |
78 | public: |
79 | |
80 | DEFINE_STANDARD_RTTI(Aspect_DisplayConnection) // Type definition |
81 | |
82 | }; |
83 | |
84 | #endif // _Aspect_DisplayConnection_H__ |