From 2a9d2bb25a75196382b776d3f6c6b8a931130b32 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 9 Feb 2007 13:51:28 +0000 Subject: [PATCH] Changed GraphicsWindowX11 so that it creates two Display* connextions to the Xserver, one for the graphics thread, one for the main thread that querries events --- include/osgViewer/GraphicsWindowX11 | 3 + src/osgViewer/GraphicsWindowX11.cpp | 132 +++++++++++++++++++--------- 2 files changed, 95 insertions(+), 40 deletions(-) diff --git a/include/osgViewer/GraphicsWindowX11 b/include/osgViewer/GraphicsWindowX11 index b60a2a454..436559be1 100644 --- a/include/osgViewer/GraphicsWindowX11 +++ b/include/osgViewer/GraphicsWindowX11 @@ -36,6 +36,7 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow GraphicsWindowX11(osg::GraphicsContext::Traits* traits): _valid(false), _display(0), + _eventDisplay(0), _parent(0), _window(0), _visualInfo(0), @@ -101,6 +102,7 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow // X11 specific aces functions Display* getDisplay() { return _display; } + Display* getEventDisplay() { return _eventDisplay; } Window& getParent() { return _parent; } Window& getWindow() { return _window; } @@ -120,6 +122,7 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow bool _valid; Display* _display; + Display* _eventDisplay; Window _parent; Window _window; XVisualInfo* _visualInfo; diff --git a/src/osgViewer/GraphicsWindowX11.cpp b/src/osgViewer/GraphicsWindowX11.cpp index 01a4e2a30..ca66cba0b 100644 --- a/src/osgViewer/GraphicsWindowX11.cpp +++ b/src/osgViewer/GraphicsWindowX11.cpp @@ -275,8 +275,10 @@ bool GraphicsWindowX11::createVisualInfo() void GraphicsWindowX11::setWindowDecoration(bool flag) { + Display* display = _display; + Atom atom; - if( (atom = XInternAtom( _display, "_MOTIF_WM_HINTS", 0 )) != None ) + if( (atom = XInternAtom( display, "_MOTIF_WM_HINTS", 0 )) != None ) { // Hack for sending 64 bit atom to Xserver #if defined( _MIPS_SIM) && (_MIPS_SIM == _MIPS_SIM_ABI64) || defined ( __ia64 ) || defined (__amd64 ) || defined(__x86_64__) @@ -322,16 +324,16 @@ void GraphicsWindowX11::setWindowDecoration(bool flag) wmHints.input_mode = 0; #endif - XUnmapWindow(_display, _window ); - XChangeProperty( _display, _window, atom, atom, 32, PropModeReplace, (unsigned char *)&wmHints, 5 ); - XMapWindow(_display, _window ); + XUnmapWindow(display, _window ); + XChangeProperty( display, _window, atom, atom, 32, PropModeReplace, (unsigned char *)&wmHints, 5 ); + XMapWindow(display, _window ); - XFlush(_display); - XSync(_display,0); + XFlush(display); + XSync(display,0); #if 0 // now update the window dimensions to account for any size changes made by the window manager, - XGetWindowAttributes( _display, _window, &watt ); + XGetWindowAttributes( display, _window, &watt ); _traits->width = watt.width; _traits->height = watt.height; #endif @@ -343,6 +345,8 @@ void GraphicsWindowX11::setWindowDecoration(bool flag) void GraphicsWindowX11::useCursor(bool cursorOn) { + Display* display = _display; + if (cursorOn) { _currentCursor = _defaultCursor; @@ -352,11 +356,11 @@ void GraphicsWindowX11::useCursor(bool cursorOn) _currentCursor = _nullCursor; } - if (_display && _window) + if (display && _window) { - XDefineCursor( _display, _window, _currentCursor ); - XFlush(_display); - XSync(_display,0); + XDefineCursor( display, _window, _currentCursor ); + XFlush(display); + XSync(display,0); } _traits->useCursor = cursorOn; @@ -470,6 +474,9 @@ void GraphicsWindowX11::init() return; } + _eventDisplay = XOpenDisplay(_traits->displayName().c_str()); + + // This positions the window at _windowX, _windowY XSizeHints sh; sh.flags = 0; @@ -504,9 +511,9 @@ void GraphicsWindowX11::init() useCursor(_traits->useCursor); - XSelectInput( _display, _window, ExposureMask | StructureNotifyMask | - KeyPressMask | KeyReleaseMask | - PointerMotionMask | ButtonPressMask | ButtonReleaseMask); + _deleteWindow = XInternAtom (_display, "WM_DELETE_WINDOW", False); + XSetWMProtocols(_display, _window, &_deleteWindow, 1); + XFlush( _display ); XSync( _display, 0 ); @@ -521,8 +528,13 @@ void GraphicsWindowX11::init() //osg::notify(osg::NOTICE)<<"After sync apply.x = "<(ev.xclient.data.l[0]) == _deleteWindow) + { + osg::notify(osg::INFO)<<"DeleteWindow event recieved"<closeWindow(); + } + } + } + } } void GraphicsWindowX11::checkEvents() { if (!_realized) return; + Display* display = _eventDisplay; + double baseTime = _timeOfLastCheckEvents; double eventTime = baseTime; double resizeTime = eventTime; @@ -645,18 +688,19 @@ void GraphicsWindowX11::checkEvents() Time firstEventTime = 0; // osg::notify(osg::NOTICE)<<"Check events"<(ev.xclient.data.l[0]) == _deleteWindow) { - osg::notify(osg::INFO)<<"DeleteWindow event recieved"<closeWindow(eventTime); } @@ -678,7 +722,7 @@ void GraphicsWindowX11::checkEvents() break; case DestroyNotify : - osg::notify(osg::INFO)<<"DestroyNotify event recieved"<