openscenegraph
GraphicsWindowX11
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
27namespace osgViewer
28{
29
30class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow, public osgViewer::GraphicsHandleX11
31{
32 public:
33
34 GraphicsWindowX11(osg::GraphicsContext::Traits* traits):
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 #else
44 _fbConfig(0),
45 #endif
46 _currentCursor(0),
47 _initialized(false),
48 _realized(false),
49 _timeOfLastCheckEvents(-1.0),
50 _lastEventType(0),
51 _modifierState(0),
52 _numLockMask(0)
53 {
54 _traits = traits;
55 memset(_keyMap, 0, 32);
56
57 init();
58
59 if (valid())
60 {
61 setState( new osg::State );
62 getState()->setGraphicsContext(this);
63
64 if (_traits.valid() && _traits->sharedContext.valid())
65 {
66 getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
67 incrementContextIDUsageCount( getState()->getContextID() );
68 }
69 else
70 {
71 getState()->setContextID( osg::GraphicsContext::createNewContextID() );
72 }
73
74 }
75 }
76
77 virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const GraphicsWindowX11*>(object)!=0; }
78 virtual const char* libraryName() const { return "osgViewer"; }
79 virtual const char* className() const { return "GraphicsWindowX11"; }
80
81 virtual bool valid() const { return _valid; }
82
83 /** Realise the GraphicsContext.*/
84 virtual bool realizeImplementation();
85
86 /** Return true if the graphics context has been realised and is ready to use.*/
87 virtual bool isRealizedImplementation() const { return _realized; }
88
89 /** Close the graphics context.*/
90 virtual void closeImplementation();
91
92 /** Make this graphics context current.*/
93 virtual bool makeCurrentImplementation();
94
95 /** Release the graphics context.*/
96 virtual bool releaseContextImplementation();
97
98 /** Swap the front and back buffers.*/
99 virtual void swapBuffersImplementation();
100
101 /** Check to see if any events have been generated.*/
102 virtual bool checkEvents();
103
104 /** Set Window decoration.*/
105 virtual bool setWindowDecorationImplementation(bool flag);
106
107 /** Get focus.*/
108 virtual void grabFocus();
109
110 /** Get focus on if the pointer is in this window.*/
111 virtual void grabFocusIfPointerInWindow();
112
113 /** Raise specified window */
114 virtual void raiseWindow();
115
116 // Override from GUIActionAdapter
117 virtual void requestWarpPointer(float x,float y);
118
119 /** Set the window's position and size.*/
120 virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);
121
122 /** Set the name of the window */
123 virtual void setWindowName(const std::string& name);
124
125 /** Set mouse cursor to a specific shape.*/
126 virtual void setCursor(MouseCursor cursor);
127
128 /** WindowData is used to pass in the X11 window handle attached the GraphicsContext::Traits structure. */
129 struct WindowData : public osg::Referenced
130 {
131 WindowData(Window window):
132 _window(window) {}
133
134 Window _window;
135 };
136
137 public:
138
139 // X11 specific access functions
140
141 Display* getEventDisplay() const { return _eventDisplay; }
142 Display* getDisplayToUse() const ;
143
144
145 Window& getParent() { return _parent; }
146 Window& getWindow() { return _window; }
147
148 Cursor getCurrentCursor() { return _currentCursor; }
149
150 protected:
151
152 ~GraphicsWindowX11();
153
154 Cursor getOrCreateCursor(MouseCursor mouseShape);
155
156 bool createVisualInfo();
157
158 bool createWindow();
159
160 bool setWindow(Window window);
161
162 void init();
163
164 bool checkAndSendEventFullScreenIfNeeded(Display* display, int x, int y, int width, int height, bool windowDecoration);
165
166
167 void transformMouseXY(float& x, float& y);
168 void adaptKey(XKeyEvent& keyevent, int& keySymbol, int& unmodifiedKeySymbol);
169 void forceKey(int key, double time, bool state);
170 void rescanModifierMapping();
171 void getModifierMap(char* keymap) const;
172 int getModifierMask() const;
173 void syncLocks();
174 void flushKeyEvents();
175
176 bool _valid;
177 Display* _eventDisplay;
178 Window _parent;
179 Window _window;
180 XVisualInfo* _visualInfo;
181
182 #ifdef OSG_USE_EGL
183 EGLDisplay _eglDisplay;
184 EGLSurface _eglSurface;
185 #else
186 GLXFBConfig _fbConfig;
187 #endif
188
189 Cursor _currentCursor;
190
191 Atom _deleteWindow;
192
193 bool _initialized;
194 bool _realized;
195 bool _ownsWindow;
196
197 double _timeOfLastCheckEvents;
198 int _lastEventType;
199 int _modifierState;
200 int _numLockMask;
201
202 char _keyMap[32];
203 std::map<MouseCursor,Cursor> _mouseCursorMap;
204};
205
206}
207
208#endif