From c1ce16f4d6272936e51c554c17c532926ffef8da Mon Sep 17 00:00:00 2001
From: Marco Antognini <antognini.marco@gmail.com>
Date: Wed, 18 May 2011 21:47:17 +0200
Subject: [PATCH] Improved SetCursorPosition on Mac (fixes issue #46)

---
 src/SFML/Window/OSX/SFWindowController.mm | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/src/SFML/Window/OSX/SFWindowController.mm b/src/SFML/Window/OSX/SFWindowController.mm
index 38536625..4be3b0e9 100644
--- a/src/SFML/Window/OSX/SFWindowController.mm
+++ b/src/SFML/Window/OSX/SFWindowController.mm
@@ -281,9 +281,6 @@
 {
     if (myRequester == 0) return;
     
-    // Create a SFML event.
-    myRequester->MouseMovedAt(x, y);
-    
     // Flip for SFML window coordinate system
     y = NSHeight([myWindow frame]) - y;
     
@@ -297,16 +294,15 @@
     float const screenHeight = NSHeight([[myWindow screen] frame]);
     screenCoord.y = screenHeight - screenCoord.y;
     
-    CGDirectDisplayID screenNumber = (CGDirectDisplayID)[[[[myWindow screen] deviceDescription] valueForKey:@"NSScreenNumber"] intValue];
-    
     // Place the cursor.
-    CGDisplayMoveCursorToPoint(screenNumber, CGPointMake(screenCoord.x, screenCoord.y));
-    /*
-     CGDisplayMoveCursorToPoint -- Discussion :
-     
-     No events are generated as a result of this move. 
-     Points that lie outside the desktop are clipped to the desktop.
-     */
+    CGEventRef event = CGEventCreateMouseEvent(NULL, 
+                                               kCGEventMouseMoved, 
+                                               CGPointMake(screenCoord.x, screenCoord.y), 
+                                               /*we don't care about this : */0);
+    CGEventPost(kCGHIDEventTap, event);
+    CFRelease(event);
+    // This is a workaround to deprecated CGSetLocalEventsSuppressionInterval.
+    // The event produced will be catched by SFML in sf::Window::FilterEvent.
 }