mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0030429: Samples - add simple glfw 3D Viewer sample
Aspect_DisplayConnection now provides constructor wrapping existing X Display connection.
This commit is contained in:
@@ -26,9 +26,11 @@ IMPLEMENT_STANDARD_RTTIEXT(Aspect_DisplayConnection,Standard_Transient)
|
||||
Aspect_DisplayConnection::Aspect_DisplayConnection()
|
||||
{
|
||||
#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__)
|
||||
myDisplay = NULL;
|
||||
myIsOwnDisplay = false;
|
||||
OSD_Environment anEnv ("DISPLAY");
|
||||
myDisplayName = anEnv.Value();
|
||||
Init();
|
||||
Init (NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -39,7 +41,8 @@ Aspect_DisplayConnection::Aspect_DisplayConnection()
|
||||
Aspect_DisplayConnection::~Aspect_DisplayConnection()
|
||||
{
|
||||
#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__)
|
||||
if (myDisplay != NULL)
|
||||
if (myDisplay != NULL
|
||||
&& myIsOwnDisplay)
|
||||
{
|
||||
XCloseDisplay (myDisplay);
|
||||
}
|
||||
@@ -52,38 +55,39 @@ Aspect_DisplayConnection::~Aspect_DisplayConnection()
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Aspect_DisplayConnection::Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName)
|
||||
: myDisplay (NULL),
|
||||
myIsOwnDisplay (false)
|
||||
{
|
||||
myDisplayName = theDisplayName;
|
||||
Init();
|
||||
Init (NULL);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : GetDisplay
|
||||
// function : Aspect_DisplayConnection
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Display* Aspect_DisplayConnection::GetDisplay()
|
||||
Aspect_DisplayConnection::Aspect_DisplayConnection (Display* theDisplay)
|
||||
: myDisplay (NULL),
|
||||
myIsOwnDisplay (false)
|
||||
{
|
||||
return myDisplay;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : GetDisplayName
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
TCollection_AsciiString Aspect_DisplayConnection::GetDisplayName()
|
||||
{
|
||||
return myDisplayName;
|
||||
Init (theDisplay);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Init
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Aspect_DisplayConnection::Init()
|
||||
void Aspect_DisplayConnection::Init (Display* theDisplay)
|
||||
{
|
||||
myDisplay = XOpenDisplay (myDisplayName.ToCString());
|
||||
myAtoms.Bind (Aspect_XA_DELETE_WINDOW, XInternAtom(myDisplay, "WM_DELETE_WINDOW", False));
|
||||
|
||||
if (myDisplay != NULL
|
||||
&& myIsOwnDisplay)
|
||||
{
|
||||
XCloseDisplay (myDisplay);
|
||||
}
|
||||
myIsOwnDisplay = false;
|
||||
myAtoms.Clear();
|
||||
|
||||
myDisplay = theDisplay != NULL ? theDisplay : XOpenDisplay (myDisplayName.ToCString());
|
||||
if (myDisplay == NULL)
|
||||
{
|
||||
TCollection_AsciiString aMessage;
|
||||
@@ -91,6 +95,11 @@ void Aspect_DisplayConnection::Init()
|
||||
aMessage += myDisplayName + "\"";
|
||||
throw Aspect_DisplayConnectionDefinitionError(aMessage.ToCString());
|
||||
}
|
||||
else
|
||||
{
|
||||
myIsOwnDisplay = theDisplay == NULL;
|
||||
myAtoms.Bind (Aspect_XA_DELETE_WINDOW, XInternAtom(myDisplay, "WM_DELETE_WINDOW", False));
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
|
@@ -47,25 +47,37 @@ public:
|
||||
//! screen_number - Specifies the screen to be used on that server. Optional variable.
|
||||
Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName);
|
||||
|
||||
//! Constructor wrapping existing Display instance.
|
||||
//! WARNING! it is a responsibility of application to keep this pointer
|
||||
//! valid while Aspect_DisplayConnection is alive and to close Display when it is no more needed.
|
||||
Aspect_DisplayConnection (Display* theDisplay);
|
||||
|
||||
//! @return pointer to Display structure that serves as the connection to the X server.
|
||||
Display* GetDisplay();
|
||||
|
||||
Display* GetDisplay() { return myDisplay; }
|
||||
|
||||
//! @return TRUE if X Display has been allocated by this class
|
||||
Standard_Boolean IsOwnDisplay() const { return myIsOwnDisplay; }
|
||||
|
||||
//! @return identifier(atom) for custom named property associated with windows that use current connection to X server.
|
||||
Atom GetAtom (const Aspect_XAtom theAtom) const;
|
||||
|
||||
//! @return display name for this connection.
|
||||
TCollection_AsciiString GetDisplayName();
|
||||
const TCollection_AsciiString& GetDisplayName() { return myDisplayName; }
|
||||
|
||||
private:
|
||||
|
||||
//! Open connection with display specified in myDisplayName class field.
|
||||
void Init();
|
||||
//! Open connection with display specified in myDisplayName class field
|
||||
//! or takes theDisplay parameter when it is not NULL.
|
||||
//! WARNING! When external Display is specified, it is a responsibility of application
|
||||
//! to keep this pointer valid while Aspect_DisplayConnection is alive
|
||||
//! and to close Display when it is no more needed.
|
||||
//! @param theDisplay external pointer to allocated Display, or NULL if new connection should be created
|
||||
void Init (Display* theDisplay);
|
||||
|
||||
private:
|
||||
|
||||
Display* myDisplay;
|
||||
NCollection_DataMap<Aspect_XAtom, Atom> myAtoms;
|
||||
TCollection_AsciiString myDisplayName;
|
||||
Standard_Boolean myIsOwnDisplay;
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
Reference in New Issue
Block a user