comparison src/video/quartz/SDL_QuartzEvents.m @ 3952:e3c28caea46d SDL-1.2

Better handling of multiple queued Cocoa mouse events. Thanks to Christian Walther for the patch. Fixes Bugzilla #353.
author Ryan C. Gordon <icculus@icculus.org>
date Mon, 04 Jun 2007 11:22:23 +0000
parents c5c3c772f5aa
children 1146681dbb74
comparison
equal deleted inserted replaced
3951:e1e525d96838 3952:e3c28caea46d
720 720
721 void QZ_PumpEvents (_THIS) 721 void QZ_PumpEvents (_THIS)
722 { 722 {
723 static Uint32 screensaverTicks = 0; 723 static Uint32 screensaverTicks = 0;
724 Uint32 nowTicks; 724 Uint32 nowTicks;
725 int firstMouseEvent;
726 CGMouseDelta dx, dy; 725 CGMouseDelta dx, dy;
727 726
728 NSDate *distantPast; 727 NSDate *distantPast;
729 NSEvent *event; 728 NSEvent *event;
730 NSRect winRect; 729 NSRect winRect;
746 pool = [ [ NSAutoreleasePool alloc ] init ]; 745 pool = [ [ NSAutoreleasePool alloc ] init ];
747 distantPast = [ NSDate distantPast ]; 746 distantPast = [ NSDate distantPast ];
748 747
749 winRect = NSMakeRect (0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h); 748 winRect = NSMakeRect (0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
750 749
751 /* send the first mouse event in absolute coordinates */ 750 /* while grabbed, accumulate all mouse moved events into one SDL mouse event */
752 firstMouseEvent = 1;
753
754 /* accumulate any additional mouse moved events into one SDL mouse event */
755 dx = 0; 751 dx = 0;
756 dy = 0; 752 dy = 0;
757 753
758 do { 754 do {
759 755
851 CGMouseDelta dx1, dy1; 847 CGMouseDelta dx1, dy1;
852 CGGetLastMouseDelta (&dx1, &dy1); 848 CGGetLastMouseDelta (&dx1, &dy1);
853 dx += dx1; 849 dx += dx1;
854 dy += dy1; 850 dy += dy1;
855 } 851 }
856 else if (firstMouseEvent) { 852 else {
857 853
858 /* 854 /*
859 Get the first mouse event in a possible 855 Get the absolute mouse location. This is not the
860 sequence of mouse moved events. Since we 856 mouse location after the currently processed event,
861 use absolute coordinates, this serves to 857 but the *current* mouse location, i.e. after all
862 compensate any inaccuracy in deltas, and 858 pending events. This means that if there are
863 provides the first known mouse position, 859 multiple mouse moved events in the queue, we make
864 since everything after this uses deltas 860 multiple identical calls to SDL_PrivateMouseMotion(),
861 but that's no problem since the latter only
862 generates SDL events for nonzero movements. In my
863 experience on PBG4/10.4.8, this rarely happens anyway.
865 */ 864 */
866 NSPoint p; 865 NSPoint p;
867 QZ_GetMouseLocation (this, &p); 866 QZ_GetMouseLocation (this, &p);
868 SDL_PrivateMouseMotion (0, 0, p.x, p.y); 867 SDL_PrivateMouseMotion (0, 0, p.x, p.y);
869 firstMouseEvent = 0;
870 }
871 else {
872
873 /*
874 Get the amount moved since the last drag or move event,
875 add it on for one big move event at the end.
876 */
877 dx += [ event deltaX ];
878 dy += [ event deltaY ];
879 } 868 }
880 869
881 /* 870 /*
882 Handle grab input+cursor visible by warping the cursor back 871 Handle grab input+cursor visible by warping the cursor back
883 into the game window. This still generates a mouse moved event, 872 into the game window. This still generates a mouse moved event,