2424 */
2525
2626#import " shoeScreenView.h"
27+ #import " shoeScreenWindow.h"
2728#import " shoeAppDelegate.h"
2829#import " shoeApplication.h"
2930#import < Foundation/Foundation.h>
@@ -198,21 +199,6 @@ - (void)drawRect:(NSRect)rect
198199 [[self openGLContext ] flushBuffer ];
199200}
200201
201- - (void ) warpToCenter
202- {
203- // Convert the cocoa window frame to quartz global coordinates
204- NSRect winrect = [[self window ] frame ];
205- NSScreen *mainScreen = (NSScreen *)[[NSScreen screens ] objectAtIndex: 0 ];
206- winrect.origin .y = NSMaxY ([mainScreen frame ]) - NSMaxY (winrect);
207- CGRect cgwinrect = NSRectToCGRect (winrect);
208-
209- // Find the center of the window
210- cgwinrect.origin .x += cgwinrect.size .width / 2.0 ;
211- cgwinrect.origin .y += cgwinrect.size .height / 2.0 ;
212-
213- CGWarpMouseCursorPosition (cgwinrect.origin );
214- }
215-
216202- (void )viewDidMoveToWindow
217203{
218204 [[self window ] setAcceptsMouseMovedEvents: YES ];
@@ -229,22 +215,14 @@ - (void)mouseEntered:(NSEvent *)theEvent
229215- (void )mouseMoved : (NSEvent *)theEvent
230216{
231217 if (shoeApp->doCaptureMouse ) {
232- assert (shoeApp->isRunning );
233- // NSPoint point = [theEvent locationInWindow];
234- // NSPoint point = [self convertPoint:windowPoint fromView:self];
218+ shoeScreenWindow *win = (shoeScreenWindow*)[self window ];
235219
236- /* NSRect winFrame = [[self window] frame];
237- NSPoint winCenter;
238- winCenter.x = winFrame.size.width / 2.0;
239- winCenter.y = winFrame.size.height / 2.0;*/
220+ assert (shoeApp->isRunning );
240221
241- /* int32_t delta_x = (int32_t)(point.x - winCenter.x);
242- int32_t delta_y = -(int32_t)(point.y - winCenter.y);*/
243-
244222 int32_t delta_x, delta_y;
245223 CGGetLastMouseDelta (&delta_x, &delta_y);
246224 shoebill_mouse_move_delta (delta_x, delta_y);
247- [self warpToCenter ];
225+ [win warpToCenter ];
248226 }
249227}
250228
@@ -253,7 +231,7 @@ -(void)mouseDragged:(NSEvent *)theEvent
253231 [self mouseMoved: theEvent];
254232}
255233
256- - (void ) say : (NSString *)str
234+ /* - (void) say:(NSString*)str
257235{
258236 NSAlert *theAlert = [NSAlert
259237 alertWithMessageText:nil
@@ -263,21 +241,31 @@ - (void) say:(NSString*)str
263241 informativeTextWithFormat:@"%@", str
264242 ];
265243 [theAlert runModal];
266- }
244+ }*/
267245
268246- (void )mouseDown : (NSEvent *)theEvent
269247{
248+
270249 if (shoeApp->doCaptureMouse ) {
271250 assert (shoeApp->isRunning );
272- shoebill_mouse_click (1 );
273-
274- // Warp experiment
275-
276-
277251
278- // [self say:[NSString stringWithFormat:@"view origin x=%f, y=%f, window origin x=%f, y=%f", rect.origin.x, rect.origin.y, winrect.origin.x, winrect.origin.y]];
252+ // ctrl - left click doesn't get reported as rightMouseDown
253+ // on Mavericks (and maybe other OS X versions?)
254+ if ([theEvent modifierFlags ] & NSControlKeyMask ) {
255+ shoeScreenWindow *win = (shoeScreenWindow*)[self window ];
256+ [win uncaptureMouse ];
257+ }
258+ else
259+ shoebill_mouse_click (1 );
279260
280261 }
262+ else {
263+ shoeScreenWindow *win = (shoeScreenWindow*)[self window ];
264+ if ([win isKeyWindow ]) {
265+ shoeApp->doCaptureKeys = YES ;
266+ [win captureMouse ];
267+ }
268+ }
281269}
282270
283271- (void )mouseUp : (NSEvent *)theEvent
@@ -288,4 +276,12 @@ - (void)mouseUp:(NSEvent *)theEvent
288276 }
289277}
290278
279+ - (void )rightMouseDown : (NSEvent *)theEvent
280+ {
281+ if (shoeApp->doCaptureMouse ) {
282+ shoeScreenWindow *win = (shoeScreenWindow*)[self window ];
283+ [win uncaptureMouse ];
284+ }
285+ }
286+
291287@end
0 commit comments