diff --git a/include/osgViewer/GraphicsWindow b/include/osgViewer/GraphicsWindow index 1ab711eae..464861939 100644 --- a/include/osgViewer/GraphicsWindow +++ b/include/osgViewer/GraphicsWindow @@ -22,6 +22,7 @@ #include + extern "C" { typedef void (* CGraphicsWindowFunction) (void); @@ -113,6 +114,13 @@ class OSGVIEWER_EXPORT GraphicsWindow : public osg::GraphicsContext, public osgG BottomRightCorner, BottomLeftCorner }; + + /** Set the name of the window */ + virtual void setWindowName(const std::string& /*name*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::setWindowName(..) not implemented."<windowName : ""; } + /** Switch on/off the cursor.*/ virtual void useCursor(bool cursorOn) { setCursor(cursorOn ? InheritCursor : NoCursor); } diff --git a/include/osgViewer/api/Win32/GraphicsWindowWin32 b/include/osgViewer/api/Win32/GraphicsWindowWin32 index 69c8d6e31..c24f81ee2 100644 --- a/include/osgViewer/api/Win32/GraphicsWindowWin32 +++ b/include/osgViewer/api/Win32/GraphicsWindowWin32 @@ -78,6 +78,9 @@ class OSGVIEWER_EXPORT GraphicsWindowWin32 : public osgViewer::GraphicsWindow /** Override from GUIActionAdapter.*/ virtual void requestWarpPointer(float x,float y); + + /** Set the name of the window */ + virtual void setWindowName(const std::string& /*name*/); /** Switch on/off the cursor.*/ virtual void useCursor(bool /*cursorOn*/); diff --git a/include/osgViewer/api/X11/GraphicsWindowX11 b/include/osgViewer/api/X11/GraphicsWindowX11 index d344753c9..ad08a9eea 100644 --- a/include/osgViewer/api/X11/GraphicsWindowX11 +++ b/include/osgViewer/api/X11/GraphicsWindowX11 @@ -110,6 +110,9 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow /** Set the window's position and size.*/ virtual bool setWindowRectangleImplementation(int x, int y, int width, int height); + /** Set the name of the window */ + virtual void setWindowName(const std::string& name); + /** Set mouse cursor to a specific shape.*/ virtual void setCursor(MouseCursor cursor); @@ -144,6 +147,10 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow Cursor getOrCreateCursor(MouseCursor mouseShape); bool createVisualInfo(); + + bool createWindow(); + + bool setWindow(Window window); void init(); @@ -164,6 +171,7 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow bool _initialized; bool _realized; + bool _ownsWindow; double _timeOfLastCheckEvents; diff --git a/src/osgViewer/GraphicsWindowWin32.cpp b/src/osgViewer/GraphicsWindowWin32.cpp index f0e1b97a2..78e3117c0 100644 --- a/src/osgViewer/GraphicsWindowWin32.cpp +++ b/src/osgViewer/GraphicsWindowWin32.cpp @@ -1777,6 +1777,12 @@ bool GraphicsWindowWin32::setWindowRectangleImplementation(int x, int y, int wid return true; } +void GraphicsWindowWin32::setWindowName( const std::string & name ) +{ + _traits->windowName = name; + SetWindowText(_hwnd, name.c_str()); +} + void GraphicsWindowWin32::useCursor( bool cursorOn ) { _traits->useCursor = cursorOn; diff --git a/src/osgViewer/GraphicsWindowX11.cpp b/src/osgViewer/GraphicsWindowX11.cpp index d2db12925..15a92e3c9 100644 --- a/src/osgViewer/GraphicsWindowX11.cpp +++ b/src/osgViewer/GraphicsWindowX11.cpp @@ -194,42 +194,55 @@ Display* GraphicsWindowX11::getDisplayToUse() const bool GraphicsWindowX11::createVisualInfo() { - typedef std::vector Attributes; - Attributes attributes; - - attributes.push_back(GLX_USE_GL); - - attributes.push_back(GLX_RGBA); - - if (_traits->doubleBuffer) attributes.push_back(GLX_DOUBLEBUFFER); - - if (_traits->quadBufferStereo) attributes.push_back(GLX_STEREO); - - attributes.push_back(GLX_RED_SIZE); attributes.push_back(_traits->red); - attributes.push_back(GLX_GREEN_SIZE); attributes.push_back(_traits->green); - attributes.push_back(GLX_BLUE_SIZE); attributes.push_back(_traits->blue); - attributes.push_back(GLX_DEPTH_SIZE); attributes.push_back(_traits->depth); - - if (_traits->alpha) { attributes.push_back(GLX_ALPHA_SIZE); attributes.push_back(_traits->alpha); } - - if (_traits->stencil) { attributes.push_back(GLX_STENCIL_SIZE); attributes.push_back(_traits->stencil); } + if( _window != 0 ) + { + XWindowAttributes watt; + XGetWindowAttributes( _display, _window, &watt ); + XVisualInfo temp; + temp.visualid = XVisualIDFromVisual(watt.visual); + int n; + _visualInfo = XGetVisualInfo( _display, VisualIDMask, &temp, &n ); + } + else + { -#if defined(GLX_SAMPLE_BUFFERS) && defined (GLX_SAMPLES) - - if (_traits->sampleBuffers) { attributes.push_back(GLX_SAMPLE_BUFFERS); attributes.push_back(_traits->sampleBuffers); } - if (_traits->sampleBuffers) { attributes.push_back(GLX_SAMPLES); attributes.push_back(_traits->samples); } - -#endif - // TODO - // GLX_AUX_BUFFERS - // GLX_ACCUM_RED_SIZE - // GLX_ACCUM_GREEN_SIZE - // GLX_SAMPLE_BUFFERS - // GLX_SAMPLES + typedef std::vector Attributes; + Attributes attributes; + + attributes.push_back(GLX_USE_GL); + + attributes.push_back(GLX_RGBA); + + if (_traits->doubleBuffer) attributes.push_back(GLX_DOUBLEBUFFER); + + if (_traits->quadBufferStereo) attributes.push_back(GLX_STEREO); + + attributes.push_back(GLX_RED_SIZE); attributes.push_back(_traits->red); + attributes.push_back(GLX_GREEN_SIZE); attributes.push_back(_traits->green); + attributes.push_back(GLX_BLUE_SIZE); attributes.push_back(_traits->blue); + attributes.push_back(GLX_DEPTH_SIZE); attributes.push_back(_traits->depth); + + if (_traits->alpha) { attributes.push_back(GLX_ALPHA_SIZE); attributes.push_back(_traits->alpha); } + + if (_traits->stencil) { attributes.push_back(GLX_STENCIL_SIZE); attributes.push_back(_traits->stencil); } - attributes.push_back(None); + #if defined(GLX_SAMPLE_BUFFERS) && defined (GLX_SAMPLES) - _visualInfo = glXChooseVisual( _display, _traits->screenNum, &(attributes.front()) ); + if (_traits->sampleBuffers) { attributes.push_back(GLX_SAMPLE_BUFFERS); attributes.push_back(_traits->sampleBuffers); } + if (_traits->sampleBuffers) { attributes.push_back(GLX_SAMPLES); attributes.push_back(_traits->samples); } + + #endif + // TODO + // GLX_AUX_BUFFERS + // GLX_ACCUM_RED_SIZE + // GLX_ACCUM_GREEN_SIZE + // GLX_SAMPLE_BUFFERS + // GLX_SAMPLES + + attributes.push_back(None); + + _visualInfo = glXChooseVisual( _display, _traits->screenNum, &(attributes.front()) ); + } return _visualInfo != 0; } @@ -337,6 +350,26 @@ bool GraphicsWindowX11::setWindowRectangleImplementation(int x, int y, int width return true; } +void GraphicsWindowX11::setWindowName(const std::string& name) +{ + if( _window ) return; + + // char *slist[] = { name.c_str(), 0L }; + // XTextProperty xtp; + + // XStringListToTextProperty( slist, 1, &xtp ); + + Display* display = getDisplayToUse(); + if( !display ) return; + + // XSetWMName( display, _window, &xtp ); + XStoreName( display, _window, name.c_str() ); + XSetIconName( display, _window, name.c_str() ); + + XFlush(display); + XSync(display,0); +} + void GraphicsWindowX11::setCursor(MouseCursor mouseCursor) { Cursor newCursor = getOrCreateCursor(mouseCursor); @@ -454,14 +487,17 @@ void GraphicsWindowX11::init() _valid = false; return; } - + getEventQueue()->setCurrentEventState(osgGA::GUIEventAdapter::getAccumulatedEventState().get()); - - // WindowData* inheritedWindowData = dynamic_cast(_traits->inheritedWindowData.get()); + + WindowData* inheritedWindowData = dynamic_cast(_traits->inheritedWindowData.get()); + Window windowHandle = inheritedWindowData ? inheritedWindowData->_window : 0; + + _ownsWindow = windowHandle == 0; + + _display = XOpenDisplay(_traits->displayName().c_str()); - - unsigned int screen = _traits->screenNum; if (!_display) { @@ -470,7 +506,7 @@ void GraphicsWindowX11::init() return; } - // Query for GLX extension + // Query for GLX extension int errorBase, eventBase; if( glXQueryExtension( _display, &errorBase, &eventBase) == False ) { @@ -481,7 +517,7 @@ void GraphicsWindowX11::init() _valid = false; return; } - + // osg::notify(osg::NOTICE)<<"GLX extension, errorBase="<windowName); + XFlush( _eventDisplay ); XSync( _eventDisplay, 0 ); - _valid = true; - _initialized = true; + return true; +} + +bool GraphicsWindowX11::setWindow(Window window) +{ + if (_initialized) + { + osg::notify(osg::NOTICE) << "GraphicsWindowX11::setWindow() - Window already created; it cannot be changed"; + return false; + } + + if (window==0) + { + osg::notify(osg::NOTICE) << "GraphicsWindowX11::setWindow() - Invalid window handle passed "; + return false; + } + + _window = window; + if (_window==0) + { + osg::notify(osg::NOTICE) << "GraphicsWindowX11::setWindow() - Unable to retrieve native window handle"; + return false; + } + + XWindowAttributes watt; + XGetWindowAttributes( _display, _window, &watt ); + _traits->x = watt.x; + _traits->y = watt.y; + _traits->width = watt.width; + _traits->height = watt.height; + + _parent = DefaultRootWindow( _display ); + + //_traits->supportsResize = false; + _traits->windowDecoration = false; + _eventDisplay = XOpenDisplay(_traits->displayName().c_str()); + + XFlush( _eventDisplay ); + XSync( _eventDisplay, 0 ); + + return true; } bool GraphicsWindowX11::realizeImplementation() @@ -725,7 +812,7 @@ void GraphicsWindowX11::swapBuffersImplementation() // osg::notify(osg::NOTICE)<<"swapBuffersImplementation "<(ev.xclient.data.l[0]) == _deleteWindow) { osg::notify(osg::NOTICE)<<"DeleteWindow event recieved"<closeWindow(eventTime); } @@ -1058,7 +1146,6 @@ void GraphicsWindowX11::grabFocusIfPointerInWindow() } } - void GraphicsWindowX11::transformMouseXY(float& x, float& y) { if (getEventQueue()->getUseFixedMouseInputRange())