diff --git a/doomsday/engine/portable/include/window.h b/doomsday/engine/portable/include/window.h index 48158a6ae7..cc262cd905 100644 --- a/doomsday/engine/portable/include/window.h +++ b/doomsday/engine/portable/include/window.h @@ -291,12 +291,18 @@ void Window_RestoreState(Window* wnd); /** * Activates or deactivates the window mouse trap. When trapped, the mouse cursor is * not visible and all mouse motions are interpreted as deltas. + * + * @param wnd Window instance. + * @param enable @c true, if the mouse is to be trapped in the window. + * + * @note This is a C wrapper for Canvas::trapMouse(). */ void Window_TrapMouse(const Window* wnd, boolean enable); void* Window_NativeHandle(const Window* wnd); #ifdef _DEBUG +/// @todo Get rid of this; libdeng2 should do debug output. void debugPrint(const char* msg); #endif diff --git a/doomsday/engine/portable/src/canvas.cpp b/doomsday/engine/portable/src/canvas.cpp index c6df87e807..b3a6fecaee 100644 --- a/doomsday/engine/portable/src/canvas.cpp +++ b/doomsday/engine/portable/src/canvas.cpp @@ -70,25 +70,33 @@ struct Canvas::Instance { if(mouseGrabbed) return; + // Tell the mouse driver that the mouse is supposed to be trapped now. mouseGrabbed = true; + Mouse_Trap(true); - // Start grabbing the mouse now. +#ifndef WIN32 + // Start tracking the mouse now. QCursor::setPos(self->mapToGlobal(self->rect().center())); self->grabMouse(); self->setCursor(QCursor(Qt::BlankCursor)); qApp->setOverrideCursor(QCursor(Qt::BlankCursor)); - QTimer::singleShot(1, self, SLOT(trackMousePosition())); +#endif } void ungrabMouse() { if(!mouseGrabbed) return; - mouseGrabbed = false; +#ifndef WIN32 self->releaseMouse(); qApp->restoreOverrideCursor(); self->setCursor(QCursor(Qt::ArrowCursor)); // Default cursor. +#endif + + // Tell the mouse driver that the mouse is untrapepd. + mouseGrabbed = false; + Mouse_Trap(false); } }; @@ -339,7 +347,7 @@ void Canvas::mouseReleaseEvent(QMouseEvent* ev) if(!d->mouseGrabbed) { // Start grabbing after a click. - Mouse_Trap(true); + trapMouse(); return; } diff --git a/doomsday/engine/portable/src/mouse_qt.c b/doomsday/engine/portable/src/mouse_qt.c index fef50e23fc..78290828e1 100644 --- a/doomsday/engine/portable/src/mouse_qt.c +++ b/doomsday/engine/portable/src/mouse_qt.c @@ -21,6 +21,7 @@ * 02110-1301 USA */ +#include "dd_share.h" #include "sys_input.h" #include "window.h" #include @@ -75,7 +76,8 @@ static void Mouse_Qt_GetState(mousestate_t *state) static void Mouse_Qt_Trap(boolean enabled) { - Window_TrapMouse(Window_Main(), enabled); + // nothing to do -- the window will submit input to us when trapped + DENG_UNUSED(enabled); } void Mouse_Qt_SubmitButton(int button, boolean isDown) diff --git a/doomsday/engine/portable/src/window.cpp b/doomsday/engine/portable/src/window.cpp index bcf7f07329..443621edae 100644 --- a/doomsday/engine/portable/src/window.cpp +++ b/doomsday/engine/portable/src/window.cpp @@ -184,7 +184,7 @@ struct ddwindow_s { if(DisplayMode_Change(mode, true /* fullscreen: capture */)) { - Mouse_Trap(true); + Window_TrapMouse(this, true); geometry.size.width = DisplayMode_Current()->width; geometry.size.height = DisplayMode_Current()->height; @@ -899,7 +899,7 @@ static void windowFocusChanged(Canvas& canvas, bool focus) { DD_ClearEvents(); I_ResetAllDevices(); - Mouse_Trap(false); + Window_TrapMouse(wnd, false); } #if 0