Search
lxdream.org :: lxdream/src/drivers/video_osx.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/video_osx.c
changeset 780:4e4ea322cb84
prev770:429ff505c450
next781:88d48559380a
author nkeynes
date Mon Jul 28 10:13:13 2008 +0000 (11 years ago)
permissions -rw-r--r--
last change Move grab management to window
Clear grab if the window loses key focus (probably a good idea in general)
file annotate diff log raw
1.1 --- a/src/drivers/video_osx.c Mon Jul 28 03:41:25 2008 +0000
1.2 +++ b/src/drivers/video_osx.c Mon Jul 28 10:13:13 2008 +0000
1.3 @@ -54,18 +54,29 @@
1.4
1.5 #define MAX_MASK_KEYCODE 128
1.6
1.7 -@interface LxdreamVideoView : NSView
1.8 +@interface LxdreamOSXView : LxdreamVideoView
1.9 {
1.10 - BOOL isGrabbed;
1.11 int buttonMask;
1.12 int flagsMask[MAX_MASK_KEYCODE];
1.13 }
1.14 -- (BOOL)isOpaque;
1.15 -- (BOOL)isFlipped;
1.16 -- (void)drawRect: (NSRect) rect;
1.17 @end
1.18
1.19 @implementation LxdreamVideoView
1.20 +- (void)setIsGrabbed: (BOOL)grabbed
1.21 +{
1.22 + isGrabbed = grabbed;
1.23 +}
1.24 +- (void) setDelegate: (id)other
1.25 +{
1.26 + delegate = other;
1.27 +}
1.28 +- (id)delegate
1.29 +{
1.30 + return delegate;
1.31 +}
1.32 +@end
1.33 +
1.34 +@implementation LxdreamOSXView
1.35 //--------------------------------------------------------------------
1.36 - (id)initWithFrame: (NSRect)contentRect
1.37 {
1.38 @@ -80,6 +91,16 @@
1.39 }
1.40 return nil;
1.41 }
1.42 +- (void)requestGrab
1.43 +{
1.44 + if( delegate && [delegate respondsToSelector: @selector(viewRequestedGrab:)] )
1.45 + [delegate performSelector: @selector(viewRequestedGrab:) withObject: self];
1.46 +}
1.47 +- (void)requestUngrab
1.48 +{
1.49 + if( delegate && [delegate respondsToSelector: @selector(viewRequestedUngrab:)] )
1.50 + [delegate performSelector: @selector(viewRequestedUngrab:) withObject: self];
1.51 +}
1.52 - (BOOL)isOpaque
1.53 {
1.54 return YES;
1.55 @@ -116,12 +137,8 @@
1.56 - (void)flagsChanged: (NSEvent *) event
1.57 {
1.58 int keycode = [event keyCode];
1.59 - if ( isGrabbed && ([event modifierFlags] & NSControlKeyMask) && ([event modifierFlags] & NSAlternateKeyMask) ) {
1.60 - // Release the display grab
1.61 - isGrabbed = NO;
1.62 - [NSCursor unhide];
1.63 - CGAssociateMouseAndMouseCursorPosition(YES);
1.64 - [((LxdreamMainWindow *)[self window]) setIsGrabbed: NO];
1.65 + if( ([event modifierFlags] & NSControlKeyMask) && ([event modifierFlags] & NSAlternateKeyMask) ) {
1.66 + [self requestUngrab];
1.67 }
1.68
1.69 if( flagsMask[keycode] == 0 ) {
1.70 @@ -137,11 +154,8 @@
1.71 if( isGrabbed ) {
1.72 buttonMask |= 1;
1.73 input_event_mouse( buttonMask, 0, 0 );
1.74 - } else { // take display grab
1.75 - isGrabbed = YES;
1.76 - [NSCursor hide];
1.77 - CGAssociateMouseAndMouseCursorPosition(NO);
1.78 - [((LxdreamMainWindow *)[self window]) setIsGrabbed: YES];
1.79 + } else {
1.80 + [self requestGrab];
1.81 }
1.82 }
1.83 - (void)mouseUp: (NSEvent *)event
1.84 @@ -200,7 +214,7 @@
1.85 NSView *video_osx_create_drawable()
1.86 {
1.87 NSRect contentRect = {{0,0},{640,480}};
1.88 - video_view = [[LxdreamVideoView alloc] initWithFrame: contentRect];
1.89 + video_view = [[LxdreamOSXView alloc] initWithFrame: contentRect];
1.90 [video_view setAutoresizingMask: (NSViewWidthSizable|NSViewHeightSizable)];
1.91 return video_view;
1.92 }
.