Index: include/nel/misc/events.h =================================================================== --- include/nel/misc/events.h (révision 1625) +++ include/nel/misc/events.h (copie de travail) @@ -250,6 +250,7 @@ altButton =0x20 }; +// TODO list altGr ? enum TKeyButton { noKeyButton =0x0, @@ -279,7 +280,7 @@ /** * CEventKeyDown - * Send when a key is push down. The key type is Key and FirstTime is true if the previous key state wasn't pushed. + * Send when a key is pushed down. The key type is Key and FirstTime is true if the previous key state wasn't pushed. */ class CEventKeyDown : public CEventKey { Index: include/nel/misc/mutex.h =================================================================== --- include/nel/misc/mutex.h (révision 1625) +++ include/nel/misc/mutex.h (copie de travail) @@ -196,7 +196,7 @@ * \date 2002, 2003 */ #ifdef __ppc__ -// on ppc, use fait mutex because we don't have ppc implementation of fast mutex +// on ppc, use fair mutex because we don't have ppc implementation of fast mutex # define CFastMutex CFairMutex #else @@ -253,7 +253,7 @@ // Enter critical section __forceinline void enter () volatile { - //std::cout << "Entering, Lock=" << _Lock << std::endl; +// std::cout << "Entering, Lock=" << _Lock << std::endl; if (atomic_swap (&_Lock)) { // First test @@ -278,7 +278,7 @@ #ifdef NL_OS_WINDOWS Sleep (wait_time); #else - //std::cout << "Sleeping i=" << i << std::endl; +// std::cout << "Sleeping i=" << i << std::endl; usleep( wait_time*1000 ); #endif } @@ -289,7 +289,7 @@ __forceinline void leave () volatile { _Lock = 0; - //std::cout << "Leave" << std::endl; +// std::cout << "Leave" << std::endl; } private: Index: src/misc/win_event_emitter.cpp =================================================================== --- src/misc/win_event_emitter.cpp (révision 1625) +++ src/misc/win_event_emitter.cpp (copie de travail) @@ -127,7 +127,7 @@ case WM_SYSKEYDOWN: if (_KeyboardEventsEnabled) { - // Ctrl, shit or alt ? + // Ctrl, shift or alt ? if ((int)wParam==VK_MENU) _AltButton=true; if ((int)wParam==VK_CONTROL) Index: src/3d/driver/opengl/driver_opengl.cpp =================================================================== --- src/3d/driver/opengl/driver_opengl.cpp (révision 1625) +++ src/3d/driver/opengl/driver_opengl.cpp (copie de travail) @@ -277,6 +277,7 @@ #ifdef XF86VIDMODE // zero the old screen mode memset(&_OldScreenMode, 0, sizeof(_OldScreenMode)); + _capture = false ; #endif //XF86VIDMODE #endif // NL_OS_UNIX @@ -458,7 +459,6 @@ { nldebug("3D: XOpenDisplay on '%s' OK", getenv("DISPLAY")); } - #endif return true; } @@ -533,8 +533,8 @@ { H_AUTO_OGL(CDriverGL_setDisplay) - uint width = mode.Width; - uint height = mode.Height; + uint width = _WindowWidth = mode.Width; + uint height = _WindowHeight = mode.Height; #ifdef NL_OS_WINDOWS @@ -1103,14 +1103,14 @@ XTextProperty text_property; // FIXME char*s are created as const char*, but that doesn't work // with XStringListToTextProperty()'s char** ... - char *title="NeL window"; + char *title = "NeL window"; XStringListToTextProperty(&title, 1, &text_property); XSetWMProperties (dpy, win, &text_property, &text_property, 0, 0, &size_hints, 0, 0); glXMakeCurrent (dpy, win, ctx); XMapRaised (dpy, win); - XSelectInput (dpy, win, KeyPressMask|KeyReleaseMask|ButtonPressMask|ButtonReleaseMask|PointerMotionMask); + XSelectInput (dpy, win, KeyPressMask|KeyReleaseMask|ButtonPressMask|ButtonReleaseMask|PointerMotionMask|StructureNotifyMask); XMapWindow(dpy, win); @@ -1938,7 +1938,35 @@ // flush direct input messages if any NLMISC::safe_cast(_EventEmitter.getEmitter(1))->poll(); } -#endif +#else // NL_OS_WINDOWS + if (_capture) + { + sint mouseX, mouseY, tmp, newX, newY ; + uint utmp ; + Window root, fromroot, tmpwin; + + // retrive the root window + root = DefaultRootWindow(dpy); + + _WindowX = _EventEmitter.getWindowPosX() ; + _WindowY = _EventEmitter.getWindowPosY() ; + + nldebug("%d %d", _WindowWidth, _WindowHeight) ; + + // gets the mouse position even if it is outside the window + XQueryPointer(dpy, root, &fromroot, &tmpwin, &mouseX, &mouseY, &tmp, &tmp, &utmp); + + newX = mouseX ; + newY = mouseY ; + + clamp(newX, _WindowX, _WindowX + _WindowWidth - 1); + clamp(newY, _WindowY, _WindowY + _WindowHeight - 1); + + if (newX - mouseX || newY - mouseY) // mouse has to be moved ? + // move the new position + XWarpPointer( dpy, None, fromroot, 0, 0, 0, 0, newX, newY) ; + } +#endif // !NL_OS_WINDOWS if (!_WndActive) { @@ -2460,7 +2488,8 @@ } } #elif defined (NL_OS_UNIX) - x = y = 0; + x = _EventEmitter.getWindowPosX() ; + y = _EventEmitter.getWindowPosY() ; #endif // NL_OS_UNIX } @@ -2537,8 +2566,7 @@ #elif defined (NL_OS_UNIX) - nlwarning("LINUXTODO: This method is not implemented under linux"); - // TODO for Linux : implement it (clipRect with the window dimensions ?) + _capture = b ; #endif // NL_OS_UNIX } Index: src/3d/driver/opengl/driver_opengl.h =================================================================== --- src/3d/driver/opengl/driver_opengl.h (révision 1625) +++ src/3d/driver/opengl/driver_opengl.h (copie de travail) @@ -699,6 +699,7 @@ int _OldDotClock; // old dotclock XF86VidModeModeLine _OldScreenMode; // old modeline int _OldX, _OldY; //Viewport settings + bool _capture ; #endif //XF86VIDMODE #endif // NL_OS_UNIX Index: src/3d/driver/opengl/unix_event_emitter.cpp =================================================================== --- src/3d/driver/opengl/unix_event_emitter.cpp (révision 1625) +++ src/3d/driver/opengl/unix_event_emitter.cpp (copie de travail) @@ -43,9 +43,11 @@ { _dpy = dpy; _win = win; + _posX = 0 ; + _posY = 0 ; } -void CUnixEventEmitter::submitEvents(CEventServer & server, bool allWindows) +void CUnixEventEmitter::submitEvents(CEventServer & server, bool /*allWindows*/) { while (XPending(_dpy)) { @@ -224,11 +226,11 @@ break; Case(ButtonPress) { - //nlinfo("%d %d %d", event.xbutton.button, event.xbutton.x, event.xbutton.y); XWindowAttributes xwa; XGetWindowAttributes (_dpy, _win, &xwa); float fX = (float) event.xbutton.x / (float) xwa.width; float fY = 1.0f - (float) event.xbutton.y / (float) xwa.height; + TMouseButton button=getMouseButton(event.xbutton.state); switch(event.xbutton.button) { @@ -252,11 +254,11 @@ } Case(ButtonRelease) { - //nlinfo("%d %d %d", event.xbutton.button, event.xbutton.x, event.xbutton.y); XWindowAttributes xwa; XGetWindowAttributes (_dpy, _win, &xwa); float fX = (float) event.xbutton.x / (float) xwa.width; float fY = 1.0f - (float) event.xbutton.y / (float) xwa.height; + switch(event.xbutton.button) { case Button1: @@ -327,11 +329,8 @@ Case(DestroyNotify) break; Case(ConfigureNotify) - /* if (event.xconfigure.width==gmaxx && event.xconfigure.height==gmaxy) { - UpdateGWin(); - } else { - XResizeWindow(display, gwindow, gmaxx, gmaxy); - } */ + _posX = event.xconfigure.x ; + _posY = event.xconfigure.y ; break; default: nlinfo("UnknownEvent"); Index: src/3d/driver/opengl/unix_event_emitter.h =================================================================== --- src/3d/driver/opengl/unix_event_emitter.h (révision 1625) +++ src/3d/driver/opengl/unix_event_emitter.h (copie de travail) @@ -45,11 +45,11 @@ { public: - /// Constructor - CUnixEventEmitter(); + /// Constructor + CUnixEventEmitter(); + + void init (Display *dpy, Window win); - void init (Display *dpy, Window win); - /** * sends all events to server * (should call CEventServer method postEvent() ) @@ -59,13 +59,29 @@ public: void processMessage (XEvent &event, CEventServer &server); + sint getWindowPosX() const ; + sint getWindowPosY() const ; private: Display *_dpy; Window _win; + + // position of the window, retrieved on configure events + sint _posX ; + sint _posY ; }; +/* Inline code */ +inline sint CUnixEventEmitter::getWindowPosX() const +{ + return _posX ; +} +inline sint CUnixEventEmitter::getWindowPosY() const +{ + return _posY ; +} + } // NLMISC #endif // NL_OS_UNIX