Added s/getWindowRectangle to GraphicsWindow and implementation in GraphicsWindowX11
This commit is contained in:
@@ -42,18 +42,27 @@ class OSGVIEWER_EXPORT GraphicsWindow : public osg::GraphicsContext, public osgG
|
||||
const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); }
|
||||
|
||||
virtual void checkEvents() {}
|
||||
|
||||
/** Set the window's position and size.*/
|
||||
virtual void setWindowRectangle(int x, int y, int width, int height) { osg::notify(osg::NOTICE)<<"GraphicsWindow::setWindowRectangle(..) not implemented."<<std::endl; }
|
||||
|
||||
/** Get the window's position and size.*/
|
||||
virtual void getWindowRectangle(int& x, int& y, int& width, int& height) { if (_traits.valid()) { x = _traits->x; y = _traits->y; width = _traits->width; height = _traits->height; } }
|
||||
|
||||
/** Set Window decoration.*/
|
||||
virtual void setWindowDecoration(bool /*flag*/) {}
|
||||
virtual void setWindowDecoration(bool /*flag*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::setWindowDecoration(..) not implemented."<<std::endl; }
|
||||
|
||||
/** Set Window decoration.*/
|
||||
virtual bool getWindowDecoration() const { return _traits.valid() ? _traits->windowDecoration : false; }
|
||||
|
||||
/** Get focus.*/
|
||||
virtual void grabFocus() {}
|
||||
virtual void grabFocus() { osg::notify(osg::NOTICE)<<"GraphicsWindow::grabFocus(..) not implemented."<<std::endl; }
|
||||
|
||||
/** Get focus on if the pointer is in this window.*/
|
||||
virtual void grabFocusIfPointerInWindow() {}
|
||||
virtual void grabFocusIfPointerInWindow() { osg::notify(osg::NOTICE)<<"GraphicsWindow::grabFocusIfPointerInWindow(..) not implemented."<<std::endl; }
|
||||
|
||||
/** Switch on/off the cursor.*/
|
||||
virtual void useCursor(bool /*cursorOn*/) {}
|
||||
virtual void useCursor(bool /*cursorOn*/) { osg::notify(osg::NOTICE)<<"GraphicsWindow::useCursor(..) not implemented."<<std::endl; }
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@@ -105,6 +105,9 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow
|
||||
// Override from GUIActionAdapter
|
||||
virtual void requestWarpPointer(float x,float y);
|
||||
|
||||
/** Set the window's position and size.*/
|
||||
virtual void setWindowRectangle(int x, int y, int width, int height);
|
||||
|
||||
/** Switch on/off the cursor.*/
|
||||
virtual void useCursor(bool cursorOn);
|
||||
|
||||
@@ -121,8 +124,11 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow
|
||||
|
||||
// X11 specific aces functions
|
||||
|
||||
Display* getDisplay() { return _display; }
|
||||
Display* getEventDisplay() { return _eventDisplay; }
|
||||
Display* getDisplay() const { return _display; }
|
||||
Display* getEventDisplay() const { return _eventDisplay; }
|
||||
Display* getDisplayToUse() const ;
|
||||
|
||||
|
||||
Window& getParent() { return _parent; }
|
||||
Window& getWindow() { return _window; }
|
||||
GLXContext& getGLXContext() { return _glxContext; }
|
||||
@@ -130,6 +136,8 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow
|
||||
Cursor& getDefaultCursor() { return _defaultCursor; }
|
||||
Cursor& getNullCursor() { return _nullCursor; }
|
||||
Cursor& getCurrentCursor() { return _nullCursor; }
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -231,6 +231,23 @@ GraphicsWindowX11::~GraphicsWindowX11()
|
||||
close(true);
|
||||
}
|
||||
|
||||
Display* GraphicsWindowX11::getDisplayToUse() const
|
||||
{
|
||||
if (_threadOfLastMakeCurrent==0)
|
||||
{
|
||||
return _display;
|
||||
}
|
||||
|
||||
if (OpenThreads::Thread::CurrentThread()==_threadOfLastMakeCurrent)
|
||||
{
|
||||
return _display;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _eventDisplay;
|
||||
}
|
||||
}
|
||||
|
||||
bool GraphicsWindowX11::createVisualInfo()
|
||||
{
|
||||
typedef std::vector<int> Attributes;
|
||||
@@ -275,7 +292,7 @@ bool GraphicsWindowX11::createVisualInfo()
|
||||
|
||||
void GraphicsWindowX11::setWindowDecoration(bool flag)
|
||||
{
|
||||
Display* display = _display;
|
||||
Display* display = getDisplayToUse();
|
||||
|
||||
Atom atom;
|
||||
if( (atom = XInternAtom( display, "_MOTIF_WM_HINTS", 0 )) != None )
|
||||
@@ -343,9 +360,21 @@ void GraphicsWindowX11::setWindowDecoration(bool flag)
|
||||
osg::notify(osg::NOTICE)<<"Error: GraphicsWindowX11::setBorder(" << flag << ") - couldn't change decorations." << std::endl;
|
||||
}
|
||||
|
||||
void GraphicsWindowX11::setWindowRectangle(int x, int y, int width, int height)
|
||||
{
|
||||
if (!_realized) return;
|
||||
|
||||
Display* display = getDisplayToUse();
|
||||
|
||||
XMoveResizeWindow(display, _window, x, y, width, height);
|
||||
|
||||
XFlush(display);
|
||||
XSync(display, 0);
|
||||
}
|
||||
|
||||
void GraphicsWindowX11::useCursor(bool cursorOn)
|
||||
{
|
||||
Display* display = _display;
|
||||
Display* display = getDisplayToUse();
|
||||
|
||||
if (cursorOn)
|
||||
{
|
||||
@@ -444,6 +473,8 @@ void GraphicsWindowX11::init()
|
||||
return;
|
||||
}
|
||||
|
||||
_eventDisplay = XOpenDisplay(_traits->displayName().c_str());
|
||||
|
||||
_parent = RootWindow( _display, screen );
|
||||
|
||||
XWindowAttributes watt;
|
||||
@@ -482,8 +513,6 @@ void GraphicsWindowX11::init()
|
||||
return;
|
||||
}
|
||||
|
||||
_eventDisplay = XOpenDisplay(_traits->displayName().c_str());
|
||||
|
||||
|
||||
// This positions the window at _windowX, _windowY
|
||||
XSizeHints sh;
|
||||
@@ -498,11 +527,8 @@ void GraphicsWindowX11::init()
|
||||
sh.height = _traits->height;
|
||||
XSetStandardProperties( _display, _window, _traits->windowName.c_str(), _traits->windowName.c_str(), None, 0, 0, &sh);
|
||||
|
||||
#if 1
|
||||
setWindowDecoration(_traits->windowDecoration);
|
||||
#else
|
||||
setWindowDecoration(true);
|
||||
#endif
|
||||
|
||||
// Create default Cursor
|
||||
_defaultCursor = XCreateFontCursor( _display, XC_left_ptr );
|
||||
|
||||
@@ -678,7 +704,7 @@ void GraphicsWindowX11::checkEvents()
|
||||
{
|
||||
if (!_realized) return;
|
||||
|
||||
Display* display = _eventDisplay;
|
||||
Display* display = getDisplayToUse();
|
||||
|
||||
double baseTime = _timeOfLastCheckEvents;
|
||||
double eventTime = baseTime;
|
||||
@@ -940,8 +966,11 @@ void GraphicsWindowX11::checkEvents()
|
||||
|
||||
void GraphicsWindowX11::grabFocus()
|
||||
{
|
||||
XSetInputFocus( _eventDisplay, _window, RevertToNone, CurrentTime );
|
||||
XFlush(_eventDisplay); XSync(_eventDisplay,0);
|
||||
Display* display = getDisplayToUse();
|
||||
|
||||
XSetInputFocus( display, _window, RevertToNone, CurrentTime );
|
||||
XFlush(display);
|
||||
XSync(display,0);
|
||||
}
|
||||
|
||||
void GraphicsWindowX11::grabFocusIfPointerInWindow()
|
||||
@@ -950,7 +979,9 @@ void GraphicsWindowX11::grabFocusIfPointerInWindow()
|
||||
int wx, wy, rx, ry;
|
||||
unsigned int buttons;
|
||||
|
||||
if( XQueryPointer( _eventDisplay, _window,
|
||||
Display* display = getDisplayToUse();
|
||||
|
||||
if( XQueryPointer( display, _window,
|
||||
&root, &win, &rx, &ry, &wx, &wy, &buttons))
|
||||
{
|
||||
#if 0
|
||||
@@ -978,6 +1009,7 @@ void GraphicsWindowX11::transformMouseXY(float& x, float& y)
|
||||
|
||||
void GraphicsWindowX11::adaptKey(XKeyEvent& keyevent, int& keySymbol, unsigned int& modifierMask)
|
||||
{
|
||||
Display* display = getDisplayToUse();
|
||||
|
||||
static XComposeStatus state;
|
||||
unsigned char keybuf[32];
|
||||
@@ -1011,7 +1043,7 @@ void GraphicsWindowX11::adaptKey(XKeyEvent& keyevent, int& keySymbol, unsigned i
|
||||
|
||||
keySymbol = keybuf[0];
|
||||
|
||||
KeySym ks = XKeycodeToKeysym( _eventDisplay, keyevent.keycode, 0 );
|
||||
KeySym ks = XKeycodeToKeysym( display, keyevent.keycode, 0 );
|
||||
int remappedKey = remapX11Key(ks);
|
||||
if (remappedKey & 0xff00)
|
||||
{
|
||||
@@ -1029,14 +1061,16 @@ void GraphicsWindowX11::adaptKey(XKeyEvent& keyevent, int& keySymbol, unsigned i
|
||||
|
||||
void GraphicsWindowX11::requestWarpPointer(float x,float y)
|
||||
{
|
||||
XWarpPointer( _eventDisplay,
|
||||
Display* display = getDisplayToUse();
|
||||
|
||||
XWarpPointer( display,
|
||||
None,
|
||||
_window,
|
||||
0, 0, 0, 0,
|
||||
static_cast<int>(x), static_cast<int>(y) );
|
||||
|
||||
XFlush(_eventDisplay);
|
||||
XSync(_eventDisplay, 0);
|
||||
XFlush(display);
|
||||
XSync(display, 0);
|
||||
|
||||
getEventQueue()->mouseWarped(x,y);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user