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>
|
From Colin MacDonald, "In my application I have a custom graphics context class, derived from
osg::GraphicsContext, in order to give good integration with the
application's GUI toolkit. This works really well.
However, I need to share OpenGL texture resources with the standard
osgViewer GraphicsContext implementations, in particular the
PixelBuffers. This is essential for my application to conserve graphics
memory on low-end hardware. Currently the standard osg implementations
will not share resources with another derived osg::GraphicsContext,
other than the pre-defined osgViewer classes e.g. PixelBufferX11 is
hardcoded to only share resources with GraphicsWindowX11 and
PixelBufferX11 objects, and no other osg::GraphicsContext object.
To address this in the cleanest way I could think of, I have moved the
OpenGL handle variables for each platform into a small utility class,
e.g. GraphicsHandleX11 for unix. Then GraphicsWindowX11, PixelBufferX11
and any other derived osg::GraphicsContext class can inherit from
GraphicsHandleX11 to share OpenGL resources.
I have updated the X11, Win32 and Carbon implementations to use this.
The changes are minor. I haven't touched the Cocoa implmentation as
I'm not familiar with it at all and couldn't test it - it will work
unchanged.
Without this I had some horrible hacks in my application, this greatly
simplifies things for me. It also simplifies the osgViewer
implementations slightly. Perhaps it may help with other users'
desires to share resources with external graphics contexts, as was
discussed on the user list recently."
Notes from Robert Osfield, adapted Colin's submission to work with the new EGL related changes.
2009-11-22 00:41:02 +08:00
|
|
|
#include <osgViewer/api/X11/GraphicsHandleX11>
|
2009-10-30 23:17:38 +08:00
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
From Colin MacDonald, "In my application I have a custom graphics context class, derived from
osg::GraphicsContext, in order to give good integration with the
application's GUI toolkit. This works really well.
However, I need to share OpenGL texture resources with the standard
osgViewer GraphicsContext implementations, in particular the
PixelBuffers. This is essential for my application to conserve graphics
memory on low-end hardware. Currently the standard osg implementations
will not share resources with another derived osg::GraphicsContext,
other than the pre-defined osgViewer classes e.g. PixelBufferX11 is
hardcoded to only share resources with GraphicsWindowX11 and
PixelBufferX11 objects, and no other osg::GraphicsContext object.
To address this in the cleanest way I could think of, I have moved the
OpenGL handle variables for each platform into a small utility class,
e.g. GraphicsHandleX11 for unix. Then GraphicsWindowX11, PixelBufferX11
and any other derived osg::GraphicsContext class can inherit from
GraphicsHandleX11 to share OpenGL resources.
I have updated the X11, Win32 and Carbon implementations to use this.
The changes are minor. I haven't touched the Cocoa implmentation as
I'm not familiar with it at all and couldn't test it - it will work
unchanged.
Without this I had some horrible hacks in my application, this greatly
simplifies things for me. It also simplifies the osgViewer
implementations slightly. Perhaps it may help with other users'
desires to share resources with external graphics contexts, as was
discussed on the user list recently."
Notes from Robert Osfield, adapted Colin's submission to work with the new EGL related changes.
2009-11-22 00:41:02 +08:00
|
|
|
class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow, public osgViewer::GraphicsHandleX11
|
2006-12-20 00:00:51 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
GraphicsWindowX11(osg::GraphicsContext::Traits* traits):
|
2006-12-25 00:40:19 +08:00
|
|
|
_valid(false),
|
2007-02-09 21:51:28 +08:00
|
|
|
_eventDisplay(0),
|
2006-12-20 00:00:51 +08:00
|
|
|
_parent(0),
|
|
|
|
_window(0),
|
|
|
|
_visualInfo(0),
|
2009-10-30 23:17:38 +08:00
|
|
|
#ifdef OSG_USE_EGL
|
2009-11-01 17:04:41 +08:00
|
|
|
_eglDisplay(0),
|
|
|
|
_eglSurface(0),
|
2009-10-30 23:17:38 +08:00
|
|
|
#endif
|
2006-12-20 00:00:51 +08:00
|
|
|
_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),
|
From Melchoir Franz, "osgViewer toggled the NumLock state correctly when pressing the NumLock
key, but it didn't pick up the initial state. So, if NumLock was on for
the OS at startup (LED on), it was still off for OSG. And the first
keypress turned the LED off, and NumLock on for OSG. The attached fix
picks up the state on every FocusIn, just like it was done in the last
commits for CapsLock. The difference is, that the NumLock mask isn't
standardized (e.g. 0x10 for Linux, and 0x80 for AIX), so we have to do
a reverse lookup (::rescanModifierMapping()).
Note that I could not reproduce the problem on my system, but someone
else confirmed it twice on his, and the patch fixed it for him.
Changed files:
./include/osgViewer/api/X11/GraphicsWindowX11
./src/osgViewer/GraphicsWindowX11.cpp
"
2008-03-20 05:05:38 +08:00
|
|
|
_modifierState(0),
|
|
|
|
_numLockMask(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
|
|
|
|
2012-09-06 05:03:41 +08:00
|
|
|
if (_traits.valid() && _traits->sharedContext.valid())
|
2007-02-15 04:14:45 +08:00
|
|
|
{
|
|
|
|
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.*/
|
2013-05-24 17:35:58 +08:00
|
|
|
virtual bool checkEvents();
|
2006-12-21 05:13:29 +08:00
|
|
|
|
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();
|
|
|
|
|
2008-08-16 01:32:26 +08:00
|
|
|
/** Raise specified window */
|
|
|
|
virtual void raiseWindow();
|
|
|
|
|
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:
|
|
|
|
|
2011-01-13 01:39:35 +08:00
|
|
|
// X11 specific access functions
|
2007-01-02 20:50:57 +08:00
|
|
|
|
2007-04-13 21:22:52 +08:00
|
|
|
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; }
|
2009-10-30 23:17:38 +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);
|
2011-01-28 00:23:48 +08:00
|
|
|
void adaptKey(XKeyEvent& keyevent, int& keySymbol, int& unmodifiedKeySymbol);
|
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 forceKey(int key, double time, bool state);
|
From Melchoir Franz, "osgViewer toggled the NumLock state correctly when pressing the NumLock
key, but it didn't pick up the initial state. So, if NumLock was on for
the OS at startup (LED on), it was still off for OSG. And the first
keypress turned the LED off, and NumLock on for OSG. The attached fix
picks up the state on every FocusIn, just like it was done in the last
commits for CapsLock. The difference is, that the NumLock mask isn't
standardized (e.g. 0x10 for Linux, and 0x80 for AIX), so we have to do
a reverse lookup (::rescanModifierMapping()).
Note that I could not reproduce the problem on my system, but someone
else confirmed it twice on his, and the patch fixed it for him.
Changed files:
./include/osgViewer/api/X11/GraphicsWindowX11
./src/osgViewer/GraphicsWindowX11.cpp
"
2008-03-20 05:05:38 +08:00
|
|
|
void rescanModifierMapping();
|
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 getModifierMap(char* keymap) const;
|
|
|
|
int getModifierMask() const;
|
From Melchoir Franz, "osgViewer toggled the NumLock state correctly when pressing the NumLock
key, but it didn't pick up the initial state. So, if NumLock was on for
the OS at startup (LED on), it was still off for OSG. And the first
keypress turned the LED off, and NumLock on for OSG. The attached fix
picks up the state on every FocusIn, just like it was done in the last
commits for CapsLock. The difference is, that the NumLock mask isn't
standardized (e.g. 0x10 for Linux, and 0x80 for AIX), so we have to do
a reverse lookup (::rescanModifierMapping()).
Note that I could not reproduce the problem on my system, but someone
else confirmed it twice on his, and the patch fixed it for him.
Changed files:
./include/osgViewer/api/X11/GraphicsWindowX11
./src/osgViewer/GraphicsWindowX11.cpp
"
2008-03-20 05:05:38 +08:00
|
|
|
void syncLocks();
|
From Melchior Franz, "In KDE I switch desktops with Super-Tab, and occasionally I
get an excess Tab key report when switching back to an OSG
application (usually FlightGear :-). Although KDE has consumed
the Tab, it's sometimes still in the XKeymapEvent's key_vector,
and followed by a Tab KeyRelease event.
Avoid this artifact by
- asking for a "fresh" keymap (via XQueryKeymap()), rather than
using the unreliable(?) XKeymapEvent's key_vector, and by
- flushing all key events on focus-in (to avoid the KeyRelease)
After Super-press, Tab-press, Super-release, Tab-release (note
the wrong release order!) I still get an extra Tab event. But
this is not surprising and not exactly wrong either. Also it's
hard to avoid, as we can't see what happened to the keyboard
before we regained focus.
Files changed:
src/osgViewer/GraphicsWindowX11.cpp
include/osgViewer/api/X11/GraphicsWindowX11"
2008-05-09 00:45:59 +08:00
|
|
|
void flushKeyEvents();
|
2006-12-20 00:00:51 +08:00
|
|
|
|
2006-12-25 00:40:19 +08:00
|
|
|
bool _valid;
|
2007-02-09 21:51:28 +08:00
|
|
|
Display* _eventDisplay;
|
2006-12-20 00:00:51 +08:00
|
|
|
Window _parent;
|
|
|
|
Window _window;
|
|
|
|
XVisualInfo* _visualInfo;
|
2009-10-30 23:17:38 +08:00
|
|
|
|
|
|
|
#ifdef OSG_USE_EGL
|
2009-11-01 17:04:41 +08:00
|
|
|
EGLDisplay _eglDisplay;
|
|
|
|
EGLSurface _eglSurface;
|
2009-10-30 23:17:38 +08:00
|
|
|
#endif
|
2006-12-20 00:00:51 +08:00
|
|
|
|
|
|
|
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;
|
From Melchoir Franz, "osgViewer toggled the NumLock state correctly when pressing the NumLock
key, but it didn't pick up the initial state. So, if NumLock was on for
the OS at startup (LED on), it was still off for OSG. And the first
keypress turned the LED off, and NumLock on for OSG. The attached fix
picks up the state on every FocusIn, just like it was done in the last
commits for CapsLock. The difference is, that the NumLock mask isn't
standardized (e.g. 0x10 for Linux, and 0x80 for AIX), so we have to do
a reverse lookup (::rescanModifierMapping()).
Note that I could not reproduce the problem on my system, but someone
else confirmed it twice on his, and the patch fixed it for him.
Changed files:
./include/osgViewer/api/X11/GraphicsWindowX11
./src/osgViewer/GraphicsWindowX11.cpp
"
2008-03-20 05:05:38 +08:00
|
|
|
int _modifierState;
|
|
|
|
int _numLockMask;
|
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
|