OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GraphicsWindowX11.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 /* Note, elements of GraphicsWindowX11 have used Prodcer/RenderSurface_X11.cpp as both
15  * a guide to use of X11/GLX and copiying directly in the case of setBorder().
16  * These elements are license under OSGPL as above, with Copyright (C) 2001-2004 Don Burns.
17  */
18 
19 #ifndef OSGVIEWER_GRAPHICSWINDOWX11
20 #define OSGVIEWER_GRAPHICSWINDOWX11 1
21 
22 #include <osgViewer/GraphicsWindow>
23 #include <osgViewer/api/X11/GraphicsHandleX11>
24 
25 #include <string.h>
26 
27 namespace osgViewer
28 {
29 
31 {
32  public:
33 
35  _valid(false),
36  _eventDisplay(0),
37  _parent(0),
38  _window(0),
39  _visualInfo(0),
40  #ifdef OSG_USE_EGL
41  _eglDisplay(0),
42  _eglSurface(0),
43  #endif
44  _currentCursor(0),
45  _initialized(false),
46  _realized(false),
47  _timeOfLastCheckEvents(-1.0),
48  _lastEventType(0),
49  _modifierState(0),
50  _numLockMask(0)
51  {
52  _traits = traits;
53  memset(_keyMap, 0, 32);
54 
55  init();
56 
57  if (valid())
58  {
59  setState( new osg::State );
60  getState()->setGraphicsContext(this);
61 
62  if (_traits.valid() && _traits->sharedContext.valid())
63  {
64  getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
65  incrementContextIDUsageCount( getState()->getContextID() );
66  }
67  else
68  {
69  getState()->setContextID( osg::GraphicsContext::createNewContextID() );
70  }
71 
72  }
73  }
74 
75  virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const GraphicsWindowX11*>(object)!=0; }
76  virtual const char* libraryName() const { return "osgViewer"; }
77  virtual const char* className() const { return "GraphicsWindowX11"; }
78 
79  virtual bool valid() const { return _valid; }
80 
82  virtual bool realizeImplementation();
83 
85  virtual bool isRealizedImplementation() const { return _realized; }
86 
88  virtual void closeImplementation();
89 
91  virtual bool makeCurrentImplementation();
92 
94  virtual bool releaseContextImplementation();
95 
97  virtual void swapBuffersImplementation();
98 
100  virtual bool checkEvents();
101 
103  virtual bool setWindowDecorationImplementation(bool flag);
104 
106  virtual void grabFocus();
107 
109  virtual void grabFocusIfPointerInWindow();
110 
112  virtual void raiseWindow();
113 
114  // Override from GUIActionAdapter
115  virtual void requestWarpPointer(float x,float y);
116 
118  virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);
119 
121  virtual void setWindowName(const std::string& name);
122 
124  virtual void setCursor(MouseCursor cursor);
125 
127  struct WindowData : public osg::Referenced
128  {
129  WindowData(Window window):
130  _window(window) {}
131 
132  Window _window;
133  };
134 
135  public:
136 
137  // X11 specific access functions
138 
139  Display* getEventDisplay() const { return _eventDisplay; }
140  Display* getDisplayToUse() const ;
141 
142 
143  Window& getParent() { return _parent; }
144  Window& getWindow() { return _window; }
145 
146  Cursor getCurrentCursor() { return _currentCursor; }
147 
148  protected:
149 
151 
152  Cursor getOrCreateCursor(MouseCursor mouseShape);
153 
154  bool createVisualInfo();
155 
156  bool createWindow();
157 
158  bool setWindow(Window window);
159 
160  void init();
161 
162  bool checkAndSendEventFullScreenIfNeeded(Display* display, int x, int y, int width, int height, bool windowDecoration);
163 
164 
165  void transformMouseXY(float& x, float& y);
166  void adaptKey(XKeyEvent& keyevent, int& keySymbol, int& unmodifiedKeySymbol);
167  void forceKey(int key, double time, bool state);
168  void rescanModifierMapping();
169  void getModifierMap(char* keymap) const;
170  int getModifierMask() const;
171  void syncLocks();
172  void flushKeyEvents();
173 
174  bool _valid;
175  Display* _eventDisplay;
176  Window _parent;
177  Window _window;
178  XVisualInfo* _visualInfo;
179 
180  #ifdef OSG_USE_EGL
181  EGLDisplay _eglDisplay;
182  EGLSurface _eglSurface;
183  #endif
184 
186 
188 
190  bool _realized;
192 
197 
198  char _keyMap[32];
199  std::map<MouseCursor,Cursor> _mouseCursorMap;
200 };
201 
202 }
203 
204 #endif
GraphicsWindowX11(osg::GraphicsContext::Traits *traits)
virtual const char * className() const
Display * getEventDisplay() const
virtual bool isRealizedImplementation() const
virtual bool isSameKindAs(const Object *object) const
#define OSGVIEWER_EXPORT
Definition: Export.h:40
std::map< MouseCursor, Cursor > _mouseCursorMap
GLint GLenum GLsizei width
Definition: GLU.h:71
static unsigned int createNewContextID()
GLint GLenum GLsizei GLsizei height
Definition: GLU.h:71
virtual bool valid() const
virtual const char * libraryName() const