Skip to content

Commit

Permalink
Fixed|Mac OS X: Mouse input in OS X 10.4
Browse files Browse the repository at this point in the history
No suppression interval must be used or otherwise the mouse movement will
stop for 250 ms when warping the cursor back to the center.

Another way would be to disassocate the mouse position from the cursor
and handle the native Mac mouse events to get the deltas.
  • Loading branch information
skyjake committed Apr 28, 2012
1 parent 370525f commit 13f573d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
8 changes: 7 additions & 1 deletion doomsday/engine/portable/include/canvas.h
Expand Up @@ -27,10 +27,14 @@ struct image_s; // see image.h
#include <QGLWidget>

#ifdef Q_WS_X11
//#define LIBDENG_CANVAS_TRACK_WITH_MOUSE_MOVE_EVENTS
//# define LIBDENG_CANVAS_TRACK_WITH_MOUSE_MOVE_EVENTS
//# define LIBDENG_CANVAS_XWARPPOINTER
#endif

#ifdef MACOS_10_4
# define LIBDENG_CANVAS_TRACK_WITH_MOUSE_MOVE_EVENTS
#endif

/**
* Drawing canvas with an OpenGL context and window surface. Each CanvasWindow
* creates one Canvas instance on which to draw. Buffer swapping must be done
Expand Down Expand Up @@ -133,6 +137,8 @@ protected slots:
void notifyInit();
#ifndef LIBDENG_CANVAS_TRACK_WITH_MOUSE_MOVE_EVENTS
void trackMousePosition(bool keepTracking = true);
#else
void recenterMouse();
#endif

private:
Expand Down
37 changes: 32 additions & 5 deletions doomsday/engine/portable/src/canvas.cpp
Expand Up @@ -47,11 +47,15 @@
#include "keycode.h"
#include "canvas.h"

#ifdef MACOS_10_4
# include <ApplicationServices/ApplicationServices.h>
#endif

#if (QT_VERSION < QT_VERSION_CHECK(4, 7, 0))
# define constBits bits
#endif

#ifdef LIBDENG_CANVAS_XWARPPOINTER
#if defined(LIBDENG_CANVAS_XWARPPOINTER) || defined(MACOS_10_4)
static const int MOUSE_TRACK_INTERVAL = 10; // ms
#else
static const int MOUSE_TRACK_INTERVAL = 1; // ms
Expand Down Expand Up @@ -102,6 +106,10 @@ struct Canvas::Instance
#ifndef LIBDENG_CANVAS_TRACK_WITH_MOUSE_MOVE_EVENTS
QTimer::singleShot(MOUSE_TRACK_INTERVAL, self, SLOT(trackMousePosition()));
#endif
#endif

#ifdef MACOSX
//CGAssociateMouseAndMouseCursorPosition(false);
#endif
}

Expand All @@ -116,7 +124,9 @@ struct Canvas::Instance
qApp->restoreOverrideCursor();
self->setCursor(QCursor(Qt::ArrowCursor)); // Default cursor.
#endif

#ifdef MACOSX
//CGAssociateMouseAndMouseCursorPosition(true);
#endif
// Tell the mouse driver that the mouse is untrapepd.
mouseGrabbed = false;
Mouse_Trap(false);
Expand Down Expand Up @@ -443,12 +453,29 @@ void Canvas::mouseMoveEvent(QMouseEvent* ev)
if(!delta.isNull())
{
Mouse_Qt_SubmitMotion(IMA_POINTER, delta.x(), delta.y());
}

QCursor::setPos(mapToGlobal(rect().center()));
d->prevMousePos = ev->pos();

QTimer::singleShot(1, this, SLOT(recenterMouse()));
}
}

void Canvas::recenterMouse()
{
// Ignore the next event, which is caused by the forced cursor move.
d->prevMousePos = QPoint();
d->prevMousePos = QPoint();

QPoint screenPoint = mapToGlobal(rect().center());

#ifdef MACOS_10_4
CGSetLocalEventsSuppressionInterval(0.0);
#endif

QCursor::setPos(screenPoint);

#ifdef MACOS_10_4
CGSetLocalEventsSuppressionInterval(0.25);
#endif
}
#endif

Expand Down

0 comments on commit 13f573d

Please sign in to comment.