GraphicsWindowX11
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
/* Note, elements of GraphicsWindowX11 have used Prodcer/RenderSurface_X11.cpp as both
* a guide to use of X11/GLX and copiying directly in the case of setBorder().
* These elements are license under OSGPL as above, with Copyright (C) 2001-2004 Don Burns.
*/
#ifndef OSGVIEWER_GRAPHICSWINDOWX11
#define OSGVIEWER_GRAPHICSWINDOWX11 1
#include <osgViewer/GraphicsWindow>
#include <osgViewer/api/X11/GraphicsHandleX11>
#include <string.h>
namespace osgViewer
{
class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow, public osgViewer::GraphicsHandleX11
{
public:
GraphicsWindowX11(osg::GraphicsContext::Traits* traits):
_valid(false),
_eventDisplay(0),
_parent(0),
_window(0),
_visualInfo(0),
#ifdef OSG_USE_EGL
_eglDisplay(0),
_eglSurface(0),
#else
_fbConfig(0),
#endif
_currentCursor(0),
_initialized(false),
_realized(false),
_timeOfLastCheckEvents(-1.0),
_lastEventType(0),
_modifierState(0),
_numLockMask(0)
{
_traits = traits;
memset(_keyMap, 0, 32);
init();
if (valid())
{
setState( new osg::State );
getState()->setGraphicsContext(this);
if (_traits.valid() && _traits->sharedContext.valid())
{
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
incrementContextIDUsageCount( getState()->getContextID() );
}
else
{
getState()->setContextID( osg::GraphicsContext::createNewContextID() );
}
}
}
virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const GraphicsWindowX11*>(object)!=0; }
virtual const char* libraryName() const { return "osgViewer"; }
virtual const char* className() const { return "GraphicsWindowX11"; }
virtual bool valid() const { return _valid; }
virtual bool realizeImplementation();
virtual bool isRealizedImplementation() const { return _realized; }
virtual void closeImplementation();
virtual bool makeCurrentImplementation();
virtual bool releaseContextImplementation();
virtual void swapBuffersImplementation();
virtual bool checkEvents();
virtual bool setWindowDecorationImplementation(bool flag);
virtual void grabFocus();
virtual void grabFocusIfPointerInWindow();
virtual void raiseWindow();
// Override from GUIActionAdapter
virtual void requestWarpPointer(float x,float y);
virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);
virtual void setWindowName(const std::string& name);
virtual void setCursor(MouseCursor cursor);
struct WindowData : public osg::Referenced
{
WindowData(Window window):
_window(window) {}
Window _window;
};
public:
// X11 specific access functions
Display* getEventDisplay() const { return _eventDisplay; }
Display* getDisplayToUse() const ;
Window& getParent() { return _parent; }
Window& getWindow() { return _window; }
Cursor getCurrentCursor() { return _currentCursor; }
protected:
~GraphicsWindowX11();
Cursor getOrCreateCursor(MouseCursor mouseShape);
bool createVisualInfo();
bool createWindow();
bool setWindow(Window window);
void init();
bool checkAndSendEventFullScreenIfNeeded(Display* display, int x, int y, int width, int height, bool windowDecoration);
void transformMouseXY(float& x, float& y);
void adaptKey(XKeyEvent& keyevent, int& keySymbol, int& unmodifiedKeySymbol);
void forceKey(int key, double time, bool state);
void rescanModifierMapping();
void getModifierMap(char* keymap) const;
int getModifierMask() const;
void syncLocks();
void flushKeyEvents();
bool _valid;
Display* _eventDisplay;
Window _parent;
Window _window;
XVisualInfo* _visualInfo;
#ifdef OSG_USE_EGL
EGLDisplay _eglDisplay;
EGLSurface _eglSurface;
#else
GLXFBConfig _fbConfig;
#endif
Cursor _currentCursor;
Atom _deleteWindow;
bool _initialized;
bool _realized;
bool _ownsWindow;
double _timeOfLastCheckEvents;
int _lastEventType;
int _modifierState;
int _numLockMask;
char _keyMap[32];
std::map<MouseCursor,Cursor> _mouseCursorMap;
};
}
#endif
GraphicsHandleX11
GraphicsWindow
osgViewer::GraphicsHandleX11
Definition GraphicsHandleX11:45
osgViewer::GraphicsWindowX11::_numLockMask
int _numLockMask
Definition GraphicsWindowX11:200
osgViewer::GraphicsWindowX11::_valid
bool _valid
Definition GraphicsWindowX11:176
osgViewer::GraphicsWindowX11::isRealizedImplementation
virtual bool isRealizedImplementation() const
Definition GraphicsWindowX11:87
osgViewer::GraphicsWindowX11::adaptKey
void adaptKey(XKeyEvent &keyevent, int &keySymbol, int &unmodifiedKeySymbol)
osgViewer::GraphicsWindowX11::checkEvents
virtual bool checkEvents()
osgViewer::GraphicsWindowX11::setWindowRectangleImplementation
virtual bool setWindowRectangleImplementation(int x, int y, int width, int height)
osgViewer::GraphicsWindowX11::syncLocks
void syncLocks()
osgViewer::GraphicsWindowX11::~GraphicsWindowX11
~GraphicsWindowX11()
osgViewer::GraphicsWindowX11::_timeOfLastCheckEvents
double _timeOfLastCheckEvents
Definition GraphicsWindowX11:197
osgViewer::GraphicsWindowX11::_ownsWindow
bool _ownsWindow
Definition GraphicsWindowX11:195
osgViewer::GraphicsWindowX11::init
void init()
osgViewer::GraphicsWindowX11::requestWarpPointer
virtual void requestWarpPointer(float x, float y)
osgViewer::GraphicsWindowX11::createWindow
bool createWindow()
osgViewer::GraphicsWindowX11::getDisplayToUse
Display * getDisplayToUse() const
osgViewer::GraphicsWindowX11::getModifierMask
int getModifierMask() const
osgViewer::GraphicsWindowX11::_initialized
bool _initialized
Definition GraphicsWindowX11:193
osgViewer::GraphicsWindowX11::getEventDisplay
Display * getEventDisplay() const
Definition GraphicsWindowX11:141
osgViewer::GraphicsWindowX11::_lastEventType
int _lastEventType
Definition GraphicsWindowX11:198
osgViewer::GraphicsWindowX11::_fbConfig
GLXFBConfig _fbConfig
Definition GraphicsWindowX11:186
osgViewer::GraphicsWindowX11::createVisualInfo
bool createVisualInfo()
osgViewer::GraphicsWindowX11::checkAndSendEventFullScreenIfNeeded
bool checkAndSendEventFullScreenIfNeeded(Display *display, int x, int y, int width, int height, bool windowDecoration)
osgViewer::GraphicsWindowX11::rescanModifierMapping
void rescanModifierMapping()
osgViewer::GraphicsWindowX11::_keyMap
char _keyMap[32]
Definition GraphicsWindowX11:202
osgViewer::GraphicsWindowX11::_modifierState
int _modifierState
Definition GraphicsWindowX11:199
osgViewer::GraphicsWindowX11::releaseContextImplementation
virtual bool releaseContextImplementation()
osgViewer::GraphicsWindowX11::_parent
Window _parent
Definition GraphicsWindowX11:178
osgViewer::GraphicsWindowX11::grabFocusIfPointerInWindow
virtual void grabFocusIfPointerInWindow()
osgViewer::GraphicsWindowX11::_window
Window _window
Definition GraphicsWindowX11:179
osgViewer::GraphicsWindowX11::GraphicsWindowX11
GraphicsWindowX11(osg::GraphicsContext::Traits *traits)
Definition GraphicsWindowX11:34
osgViewer::GraphicsWindowX11::realizeImplementation
virtual bool realizeImplementation()
osgViewer::GraphicsWindowX11::swapBuffersImplementation
virtual void swapBuffersImplementation()
osgViewer::GraphicsWindowX11::libraryName
virtual const char * libraryName() const
Definition GraphicsWindowX11:78
osgViewer::GraphicsWindowX11::_mouseCursorMap
std::map< MouseCursor, Cursor > _mouseCursorMap
Definition GraphicsWindowX11:203
osgViewer::GraphicsWindowX11::makeCurrentImplementation
virtual bool makeCurrentImplementation()
osgViewer::GraphicsWindowX11::forceKey
void forceKey(int key, double time, bool state)
osgViewer::GraphicsWindowX11::getOrCreateCursor
Cursor getOrCreateCursor(MouseCursor mouseShape)
osgViewer::GraphicsWindowX11::_realized
bool _realized
Definition GraphicsWindowX11:194
osgViewer::GraphicsWindowX11::_currentCursor
Cursor _currentCursor
Definition GraphicsWindowX11:189
osgViewer::GraphicsWindowX11::valid
virtual bool valid() const
Definition GraphicsWindowX11:81
osgViewer::GraphicsWindowX11::setWindowDecorationImplementation
virtual bool setWindowDecorationImplementation(bool flag)
osgViewer::GraphicsWindowX11::_deleteWindow
Atom _deleteWindow
Definition GraphicsWindowX11:191
osgViewer::GraphicsWindowX11::getWindow
Window & getWindow()
Definition GraphicsWindowX11:146
osgViewer::GraphicsWindowX11::getParent
Window & getParent()
Definition GraphicsWindowX11:145
osgViewer::GraphicsWindowX11::getCurrentCursor
Cursor getCurrentCursor()
Definition GraphicsWindowX11:148
osgViewer::GraphicsWindowX11::transformMouseXY
void transformMouseXY(float &x, float &y)
osgViewer::GraphicsWindowX11::getModifierMap
void getModifierMap(char *keymap) const
osgViewer::GraphicsWindowX11::isSameKindAs
virtual bool isSameKindAs(const Object *object) const
Definition GraphicsWindowX11:77
osgViewer::GraphicsWindowX11::_visualInfo
XVisualInfo * _visualInfo
Definition GraphicsWindowX11:180
osgViewer::GraphicsWindowX11::setWindowName
virtual void setWindowName(const std::string &name)
osgViewer::GraphicsWindowX11::setWindow
bool setWindow(Window window)
osgViewer::GraphicsWindowX11::setCursor
virtual void setCursor(MouseCursor cursor)
osgViewer::GraphicsWindowX11::grabFocus
virtual void grabFocus()
osgViewer::GraphicsWindowX11::closeImplementation
virtual void closeImplementation()
osgViewer::GraphicsWindowX11::raiseWindow
virtual void raiseWindow()
osgViewer::GraphicsWindowX11::_eventDisplay
Display * _eventDisplay
Definition GraphicsWindowX11:177
osgViewer::GraphicsWindowX11::flushKeyEvents
void flushKeyEvents()
osgViewer::GraphicsWindowX11::className
virtual const char * className() const
Definition GraphicsWindowX11:79
osgViewer::GraphicsWindow
Definition GraphicsWindow:43
osgViewer::GraphicsWindow::MouseCursor
MouseCursor
Definition GraphicsWindow:100
osg::GraphicsContext::_traits
ref_ptr< Traits > _traits
Definition GraphicsContext:544
osg::GraphicsContext::createNewContextID
static unsigned int createNewContextID()
osg::GraphicsContext::incrementContextIDUsageCount
static void incrementContextIDUsageCount(unsigned int contextID)
osg::GraphicsContext::setState
void setState(State *state)
Definition GraphicsContext:331
osg::GraphicsContext::getState
State * getState()
Definition GraphicsContext:334
osg::Object::Object
Object()
Definition Object:69
osg::Referenced
Definition Referenced:44
osg::State
Definition State:80
osgViewer
OSGVIEWER_EXPORT
#define OSGVIEWER_EXPORT
Definition osgViewer/Export:40
osgViewer::GraphicsWindowX11::WindowData::_window
Window _window
Definition GraphicsWindowX11:134
osgViewer::GraphicsWindowX11::WindowData::WindowData
WindowData(Window window)
Definition GraphicsWindowX11:131
osg::GraphicsContext::Traits
Definition GraphicsContext:70