2006-12-20 00:47:15 +08:00
|
|
|
/* -*-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.
|
|
|
|
*/
|
|
|
|
|
2006-12-21 05:13:29 +08:00
|
|
|
#ifndef OSGVIEWER_GRAPHICSWINDOWX11
|
|
|
|
#define OSGVIEWER_GRAPHICSWINDOWX11 1
|
|
|
|
|
2006-12-21 20:24:20 +08:00
|
|
|
#include <osgViewer/GraphicsWindow>
|
2006-12-20 00:00:51 +08:00
|
|
|
|
|
|
|
#define GLX_GLXEXT_PROTOTYPES 1
|
2006-12-21 20:24:20 +08:00
|
|
|
|
|
|
|
#include <X11/X.h>
|
2006-12-20 00:00:51 +08:00
|
|
|
#include <GL/glx.h>
|
2008-03-14 19:01:54 +08:00
|
|
|
#include <string.h>
|
2006-12-20 00:00:51 +08:00
|
|
|
|
2006-12-21 05:13:29 +08:00
|
|
|
namespace osgViewer
|
|
|
|
{
|
|
|
|
|
2007-06-20 01:12:05 +08:00
|
|
|
class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow
|
2006-12-20 00:00:51 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
GraphicsWindowX11(osg::GraphicsContext::Traits* traits):
|
2006-12-25 00:40:19 +08:00
|
|
|
_valid(false),
|
2006-12-20 00:00:51 +08:00
|
|
|
_display(0),
|
2007-02-09 21:51:28 +08:00
|
|
|
_eventDisplay(0),
|
2006-12-20 00:00:51 +08:00
|
|
|
_parent(0),
|
|
|
|
_window(0),
|
|
|
|
_visualInfo(0),
|
|
|
|
_glxContext(0),
|
|
|
|
_currentCursor(0),
|
|
|
|
_initialized(false),
|
2007-01-05 21:01:08 +08:00
|
|
|
_realized(false),
|
From Franz Melchior, "When switching virtual desktops or minimizing a window, keys
remain in pressed state after revealing, even if they are no
longer pressed on the keyboard. This can have bad effects,
especially if the stuck keys are modifier keys. One has to
press and release the stuck keys again to reset the wrong state.
The fix keeps track of all key presses and releases. On FocusOut
and UnmapNotify it releases all keys that are in pressed state,
and on KeymapNotify (following a FocusIn), it sets the currently
pressed keys again. To avoid confusion in the OSG-using application
normal keys are always reported released /before/ and pressed
/after/ modifier keys.
As current key states are returned as char[32] keymap by
XQueryKeymap and XKeymapEvent, this format is also used to
recognize modifier keys and for maintaining the current
internal key state. Functions to set/clear/query bits in
such a keymap are added.
The patch was extensively tested with osgkeyboard and
FlightGear under KDE and fvwm2. It was not tested on a
Xinerama setup or with multiple windows, but as _eventDisplay
is used throughout, there should be no problems. The patch also
makes the following changes:
- removes old and obsolete handling of modifier keys in ::adaptKey().
This wasn't only unused, but also wrong (and for that reason commented
out in revision 7066). The modifier states are actually handled
in ./src/osgGA/EventQueue.cpp (EventQueue::keyPress/keyRelease).
- fixes some spelling"
2008-02-26 00:50:28 +08:00
|
|
|
_timeOfLastCheckEvents(-1.0),
|
2008-03-14 00:12:46 +08:00
|
|
|
_lastEventType(0),
|
|
|
|
_lockMask(0)
|
2006-12-20 00:00:51 +08:00
|
|
|
{
|
|
|
|
_traits = traits;
|
From Franz Melchior, "When switching virtual desktops or minimizing a window, keys
remain in pressed state after revealing, even if they are no
longer pressed on the keyboard. This can have bad effects,
especially if the stuck keys are modifier keys. One has to
press and release the stuck keys again to reset the wrong state.
The fix keeps track of all key presses and releases. On FocusOut
and UnmapNotify it releases all keys that are in pressed state,
and on KeymapNotify (following a FocusIn), it sets the currently
pressed keys again. To avoid confusion in the OSG-using application
normal keys are always reported released /before/ and pressed
/after/ modifier keys.
As current key states are returned as char[32] keymap by
XQueryKeymap and XKeymapEvent, this format is also used to
recognize modifier keys and for maintaining the current
internal key state. Functions to set/clear/query bits in
such a keymap are added.
The patch was extensively tested with osgkeyboard and
FlightGear under KDE and fvwm2. It was not tested on a
Xinerama setup or with multiple windows, but as _eventDisplay
is used throughout, there should be no problems. The patch also
makes the following changes:
- removes old and obsolete handling of modifier keys in ::adaptKey().
This wasn't only unused, but also wrong (and for that reason commented
out in revision 7066). The modifier states are actually handled
in ./src/osgGA/EventQueue.cpp (EventQueue::keyPress/keyRelease).
- fixes some spelling"
2008-02-26 00:50:28 +08:00
|
|
|
memset(_keyMap, 0, 32);
|
2006-12-20 00:00:51 +08:00
|
|
|
|
2007-03-27 00:28:26 +08:00
|
|
|
init();
|
2006-12-25 00:40:19 +08:00
|
|
|
|
|
|
|
if (valid())
|
|
|
|
{
|
|
|
|
setState( new osg::State );
|
2007-02-15 01:28:33 +08:00
|
|
|
getState()->setGraphicsContext(this);
|
2007-02-15 04:14:45 +08:00
|
|
|
|
|
|
|
if (_traits.valid() && _traits->sharedContext)
|
|
|
|
{
|
|
|
|
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
|
|
|
incrementContextIDUsageCount( getState()->getContextID() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
getState()->setContextID( osg::GraphicsContext::createNewContextID() );
|
|
|
|
}
|
|
|
|
|
2006-12-25 00:40:19 +08:00
|
|
|
}
|
2006-12-20 00:00:51 +08:00
|
|
|
}
|
|
|
|
|
2007-06-12 23:32:04 +08:00
|
|
|
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"; }
|
|
|
|
|
2006-12-25 00:40:19 +08:00
|
|
|
virtual bool valid() const { return _valid; }
|
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
/** Realise the GraphicsContext.*/
|
|
|
|
virtual bool realizeImplementation();
|
|
|
|
|
|
|
|
/** Return true if the graphics context has been realised and is ready to use.*/
|
|
|
|
virtual bool isRealizedImplementation() const { return _realized; }
|
|
|
|
|
|
|
|
/** Close the graphics context.*/
|
|
|
|
virtual void closeImplementation();
|
|
|
|
|
|
|
|
/** Make this graphics context current.*/
|
2007-01-09 03:29:59 +08:00
|
|
|
virtual bool makeCurrentImplementation();
|
|
|
|
|
|
|
|
/** Release the graphics context.*/
|
|
|
|
virtual bool releaseContextImplementation();
|
2006-12-20 00:00:51 +08:00
|
|
|
|
2006-12-21 05:13:29 +08:00
|
|
|
/** Swap the front and back buffers.*/
|
2006-12-20 00:00:51 +08:00
|
|
|
virtual void swapBuffersImplementation();
|
|
|
|
|
2006-12-21 05:13:29 +08:00
|
|
|
/** Check to see if any events have been generated.*/
|
|
|
|
virtual void checkEvents();
|
|
|
|
|
2006-12-21 19:20:42 +08:00
|
|
|
/** Set Window decoration.*/
|
2007-06-11 03:53:18 +08:00
|
|
|
virtual bool setWindowDecorationImplementation(bool flag);
|
2006-12-21 19:20:42 +08:00
|
|
|
|
|
|
|
/** Get focus.*/
|
|
|
|
virtual void grabFocus();
|
|
|
|
|
|
|
|
/** Get focus on if the pointer is in this window.*/
|
|
|
|
virtual void grabFocusIfPointerInWindow();
|
|
|
|
|
2007-01-02 02:20:10 +08:00
|
|
|
// Override from GUIActionAdapter
|
|
|
|
virtual void requestWarpPointer(float x,float y);
|
|
|
|
|
2007-04-13 21:22:52 +08:00
|
|
|
/** Set the window's position and size.*/
|
2007-06-11 03:53:18 +08:00
|
|
|
virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);
|
2007-04-13 21:22:52 +08:00
|
|
|
|
2007-09-26 17:50:32 +08:00
|
|
|
/** Set the name of the window */
|
|
|
|
virtual void setWindowName(const std::string& name);
|
|
|
|
|
2007-06-02 03:43:28 +08:00
|
|
|
/** Set mouse cursor to a specific shape.*/
|
|
|
|
virtual void setCursor(MouseCursor cursor);
|
|
|
|
|
2007-03-16 21:22:05 +08:00
|
|
|
/** WindowData is used to pass in the X11 window handle attached the GraphicsContext::Traits structure. */
|
|
|
|
struct WindowData : public osg::Referenced
|
|
|
|
{
|
|
|
|
WindowData(Window window):
|
|
|
|
_window(window) {}
|
|
|
|
|
|
|
|
Window _window;
|
|
|
|
};
|
|
|
|
|
2007-01-02 20:50:57 +08:00
|
|
|
public:
|
|
|
|
|
|
|
|
// X11 specific aces functions
|
|
|
|
|
2007-04-13 21:22:52 +08:00
|
|
|
Display* getDisplay() const { return _display; }
|
|
|
|
Display* getEventDisplay() const { return _eventDisplay; }
|
|
|
|
Display* getDisplayToUse() const ;
|
2007-06-02 03:43:28 +08:00
|
|
|
|
2007-04-13 21:22:52 +08:00
|
|
|
|
2007-01-02 20:50:57 +08:00
|
|
|
Window& getParent() { return _parent; }
|
|
|
|
Window& getWindow() { return _window; }
|
2007-02-15 20:24:04 +08:00
|
|
|
GLXContext& getGLXContext() { return _glxContext; }
|
2007-01-02 20:50:57 +08:00
|
|
|
|
2007-06-02 03:43:28 +08:00
|
|
|
Cursor getCurrentCursor() { return _currentCursor; }
|
2007-01-02 20:50:57 +08:00
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
protected:
|
|
|
|
|
2007-01-04 00:06:12 +08:00
|
|
|
~GraphicsWindowX11();
|
|
|
|
|
2007-06-02 03:43:28 +08:00
|
|
|
Cursor getOrCreateCursor(MouseCursor mouseShape);
|
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
bool createVisualInfo();
|
2007-09-26 17:50:32 +08:00
|
|
|
|
|
|
|
bool createWindow();
|
|
|
|
|
|
|
|
bool setWindow(Window window);
|
2007-03-16 21:22:05 +08:00
|
|
|
|
2007-03-27 00:28:26 +08:00
|
|
|
void init();
|
2006-12-21 05:13:29 +08:00
|
|
|
|
2007-12-07 01:28:29 +08:00
|
|
|
bool checkAndSendEventFullScreenIfNeeded(Display* display, int x, int y, int width, int height, bool windowDecoration);
|
|
|
|
|
|
|
|
|
2006-12-21 05:13:29 +08:00
|
|
|
void transformMouseXY(float& x, float& y);
|
From Franz Melchior, "When switching virtual desktops or minimizing a window, keys
remain in pressed state after revealing, even if they are no
longer pressed on the keyboard. This can have bad effects,
especially if the stuck keys are modifier keys. One has to
press and release the stuck keys again to reset the wrong state.
The fix keeps track of all key presses and releases. On FocusOut
and UnmapNotify it releases all keys that are in pressed state,
and on KeymapNotify (following a FocusIn), it sets the currently
pressed keys again. To avoid confusion in the OSG-using application
normal keys are always reported released /before/ and pressed
/after/ modifier keys.
As current key states are returned as char[32] keymap by
XQueryKeymap and XKeymapEvent, this format is also used to
recognize modifier keys and for maintaining the current
internal key state. Functions to set/clear/query bits in
such a keymap are added.
The patch was extensively tested with osgkeyboard and
FlightGear under KDE and fvwm2. It was not tested on a
Xinerama setup or with multiple windows, but as _eventDisplay
is used throughout, there should be no problems. The patch also
makes the following changes:
- removes old and obsolete handling of modifier keys in ::adaptKey().
This wasn't only unused, but also wrong (and for that reason commented
out in revision 7066). The modifier states are actually handled
in ./src/osgGA/EventQueue.cpp (EventQueue::keyPress/keyRelease).
- fixes some spelling"
2008-02-26 00:50:28 +08:00
|
|
|
void adaptKey(XKeyEvent& keyevent, int& keySymbol);
|
|
|
|
void forceKey(int key, double time, bool state);
|
|
|
|
void getModifierMap(char* keymap) const;
|
|
|
|
int getModifierMask() const;
|
2006-12-20 00:00:51 +08:00
|
|
|
|
2006-12-25 00:40:19 +08:00
|
|
|
bool _valid;
|
2006-12-20 00:00:51 +08:00
|
|
|
Display* _display;
|
2007-02-09 21:51:28 +08:00
|
|
|
Display* _eventDisplay;
|
2006-12-20 00:00:51 +08:00
|
|
|
Window _parent;
|
|
|
|
Window _window;
|
|
|
|
XVisualInfo* _visualInfo;
|
|
|
|
GLXContext _glxContext;
|
|
|
|
|
|
|
|
Cursor _currentCursor;
|
2007-01-04 07:00:05 +08:00
|
|
|
|
|
|
|
Atom _deleteWindow;
|
2006-12-20 00:00:51 +08:00
|
|
|
|
|
|
|
bool _initialized;
|
|
|
|
bool _realized;
|
2007-09-26 17:50:32 +08:00
|
|
|
bool _ownsWindow;
|
2007-01-05 21:01:08 +08:00
|
|
|
|
|
|
|
double _timeOfLastCheckEvents;
|
From Franz Melchior, "When switching virtual desktops or minimizing a window, keys
remain in pressed state after revealing, even if they are no
longer pressed on the keyboard. This can have bad effects,
especially if the stuck keys are modifier keys. One has to
press and release the stuck keys again to reset the wrong state.
The fix keeps track of all key presses and releases. On FocusOut
and UnmapNotify it releases all keys that are in pressed state,
and on KeymapNotify (following a FocusIn), it sets the currently
pressed keys again. To avoid confusion in the OSG-using application
normal keys are always reported released /before/ and pressed
/after/ modifier keys.
As current key states are returned as char[32] keymap by
XQueryKeymap and XKeymapEvent, this format is also used to
recognize modifier keys and for maintaining the current
internal key state. Functions to set/clear/query bits in
such a keymap are added.
The patch was extensively tested with osgkeyboard and
FlightGear under KDE and fvwm2. It was not tested on a
Xinerama setup or with multiple windows, but as _eventDisplay
is used throughout, there should be no problems. The patch also
makes the following changes:
- removes old and obsolete handling of modifier keys in ::adaptKey().
This wasn't only unused, but also wrong (and for that reason commented
out in revision 7066). The modifier states are actually handled
in ./src/osgGA/EventQueue.cpp (EventQueue::keyPress/keyRelease).
- fixes some spelling"
2008-02-26 00:50:28 +08:00
|
|
|
int _lastEventType;
|
2008-03-14 00:12:46 +08:00
|
|
|
int _lockMask;
|
2007-06-02 03:43:28 +08:00
|
|
|
|
From Franz Melchior, "When switching virtual desktops or minimizing a window, keys
remain in pressed state after revealing, even if they are no
longer pressed on the keyboard. This can have bad effects,
especially if the stuck keys are modifier keys. One has to
press and release the stuck keys again to reset the wrong state.
The fix keeps track of all key presses and releases. On FocusOut
and UnmapNotify it releases all keys that are in pressed state,
and on KeymapNotify (following a FocusIn), it sets the currently
pressed keys again. To avoid confusion in the OSG-using application
normal keys are always reported released /before/ and pressed
/after/ modifier keys.
As current key states are returned as char[32] keymap by
XQueryKeymap and XKeymapEvent, this format is also used to
recognize modifier keys and for maintaining the current
internal key state. Functions to set/clear/query bits in
such a keymap are added.
The patch was extensively tested with osgkeyboard and
FlightGear under KDE and fvwm2. It was not tested on a
Xinerama setup or with multiple windows, but as _eventDisplay
is used throughout, there should be no problems. The patch also
makes the following changes:
- removes old and obsolete handling of modifier keys in ::adaptKey().
This wasn't only unused, but also wrong (and for that reason commented
out in revision 7066). The modifier states are actually handled
in ./src/osgGA/EventQueue.cpp (EventQueue::keyPress/keyRelease).
- fixes some spelling"
2008-02-26 00:50:28 +08:00
|
|
|
char _keyMap[32];
|
2007-06-02 03:43:28 +08:00
|
|
|
std::map<MouseCursor,Cursor> _mouseCursorMap;
|
2006-12-20 00:00:51 +08:00
|
|
|
};
|
|
|
|
|
2006-12-21 05:13:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|