Search
lxdream.org :: lxdream :: r780:4e4ea322cb84
lxdream 0.9.1
released Jun 29
Download Now
changeset780:4e4ea322cb84
parent779:a60e47313e7b
child781:88d48559380a
authornkeynes
dateMon Jul 28 10:13:13 2008 +0000 (11 years ago)
Move grab management to window
Clear grab if the window loses key focus (probably a good idea in general)
src/cocoaui/cocoa_win.c
src/cocoaui/cocoaui.c
src/cocoaui/cocoaui.h
src/drivers/video_osx.c
1.1 --- a/src/cocoaui/cocoa_win.c Mon Jul 28 10:10:13 2008 +0000
1.2 +++ b/src/cocoaui/cocoa_win.c Mon Jul 28 10:13:13 2008 +0000
1.3 @@ -131,8 +131,9 @@
1.4 return nil;
1.5 } else {
1.6 isGrabbed = NO;
1.7 - video = video_osx_create_drawable();
1.8 + video = (LxdreamVideoView *)video_osx_create_drawable();
1.9 [video setFrameOrigin: NSMakePoint(0.0,STATUSBAR_HEIGHT)];
1.10 + [video setDelegate: self];
1.11
1.12 status =
1.13 [[NSTextField alloc] initWithFrame: NSMakeRect(0.0,0.0,videoRect.size.width,STATUS_TEXT_HEIGHT)];
1.14 @@ -198,9 +199,25 @@
1.15 if( grab != isGrabbed ) {
1.16 isGrabbed = grab;
1.17 [self setRunning: dreamcast_is_running() ? YES : NO];
1.18 +
1.19 + if( isGrabbed ) {
1.20 + [NSCursor hide];
1.21 + CGAssociateMouseAndMouseCursorPosition(NO);
1.22 + } else {
1.23 + [NSCursor unhide];
1.24 + CGAssociateMouseAndMouseCursorPosition(YES);
1.25 + }
1.26 + [video setIsGrabbed: isGrabbed];
1.27 }
1.28 }
1.29 -
1.30 +- (void)viewRequestedGrab: (id)sender
1.31 +{
1.32 + [self setIsGrabbed: YES];
1.33 +}
1.34 +- (void)viewRequestedUngrab: (id)sender
1.35 +{
1.36 + [self setIsGrabbed: NO];
1.37 +}
1.38 @end
1.39
1.40 NSWindow *cocoa_gui_create_main_window()
2.1 --- a/src/cocoaui/cocoaui.c Mon Jul 28 10:10:13 2008 +0000
2.2 +++ b/src/cocoaui/cocoaui.c Mon Jul 28 10:13:13 2008 +0000
2.3 @@ -157,6 +157,15 @@
2.4 cocoa_gui_run_later();
2.5 }
2.6 }
2.7 +- (void)windowDidBecomeKey: (NSNotification *)notice
2.8 +{
2.9 + display_set_focused( TRUE );
2.10 +}
2.11 +- (void)windowDidResignKey: (NSNotification *)notice
2.12 +{
2.13 + display_set_focused( FALSE );
2.14 + [((LxdreamMainWindow *)[NSApp mainWindow]) setIsGrabbed: NO];
2.15 +}
2.16 - (void) about_action: (id)sender
2.17 {
2.18 NSArray *keys = [NSArray arrayWithObjects: @"Version", @"Copyright", nil];
3.1 --- a/src/cocoaui/cocoaui.h Mon Jul 28 10:10:13 2008 +0000
3.2 +++ b/src/cocoaui/cocoaui.h Mon Jul 28 10:13:13 2008 +0000
3.3 @@ -15,7 +15,7 @@
3.4 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3.5 * GNU General Public License for more details.
3.6 */
3.7 -
3.8 +
3.9 #ifndef lxdream_cocoaui_H
3.10 #define lxdream_cocoaui_H
3.11
3.12 @@ -46,9 +46,19 @@
3.13 */
3.14 NSTextField *cocoa_gui_add_label(NSView *parent, NSString *title, NSRect frame);
3.15
3.16 +@interface LxdreamVideoView : NSView
3.17 +{
3.18 + BOOL isGrabbed;
3.19 + id delegate;
3.20 +}
3.21 +- (void) setDelegate: (id)other;
3.22 +- (id)delegate;
3.23 +- (void) setIsGrabbed: (BOOL)grabbed;
3.24 +@end
3.25 +
3.26 @interface LxdreamMainWindow : NSWindow
3.27 {
3.28 - NSView *video;
3.29 + LxdreamVideoView *video;
3.30 NSTextField *status;
3.31 BOOL isGrabbed;
3.32 }
4.1 --- a/src/drivers/video_osx.c Mon Jul 28 10:10:13 2008 +0000
4.2 +++ b/src/drivers/video_osx.c Mon Jul 28 10:13:13 2008 +0000
4.3 @@ -54,18 +54,29 @@
4.4
4.5 #define MAX_MASK_KEYCODE 128
4.6
4.7 -@interface LxdreamVideoView : NSView
4.8 +@interface LxdreamOSXView : LxdreamVideoView
4.9 {
4.10 - BOOL isGrabbed;
4.11 int buttonMask;
4.12 int flagsMask[MAX_MASK_KEYCODE];
4.13 }
4.14 -- (BOOL)isOpaque;
4.15 -- (BOOL)isFlipped;
4.16 -- (void)drawRect: (NSRect) rect;
4.17 @end
4.18
4.19 @implementation LxdreamVideoView
4.20 +- (void)setIsGrabbed: (BOOL)grabbed
4.21 +{
4.22 + isGrabbed = grabbed;
4.23 +}
4.24 +- (void) setDelegate: (id)other
4.25 +{
4.26 + delegate = other;
4.27 +}
4.28 +- (id)delegate
4.29 +{
4.30 + return delegate;
4.31 +}
4.32 +@end
4.33 +
4.34 +@implementation LxdreamOSXView
4.35 //--------------------------------------------------------------------
4.36 - (id)initWithFrame: (NSRect)contentRect
4.37 {
4.38 @@ -80,6 +91,16 @@
4.39 }
4.40 return nil;
4.41 }
4.42 +- (void)requestGrab
4.43 +{
4.44 + if( delegate && [delegate respondsToSelector: @selector(viewRequestedGrab:)] )
4.45 + [delegate performSelector: @selector(viewRequestedGrab:) withObject: self];
4.46 +}
4.47 +- (void)requestUngrab
4.48 +{
4.49 + if( delegate && [delegate respondsToSelector: @selector(viewRequestedUngrab:)] )
4.50 + [delegate performSelector: @selector(viewRequestedUngrab:) withObject: self];
4.51 +}
4.52 - (BOOL)isOpaque
4.53 {
4.54 return YES;
4.55 @@ -116,12 +137,8 @@
4.56 - (void)flagsChanged: (NSEvent *) event
4.57 {
4.58 int keycode = [event keyCode];
4.59 - if ( isGrabbed && ([event modifierFlags] & NSControlKeyMask) && ([event modifierFlags] & NSAlternateKeyMask) ) {
4.60 - // Release the display grab
4.61 - isGrabbed = NO;
4.62 - [NSCursor unhide];
4.63 - CGAssociateMouseAndMouseCursorPosition(YES);
4.64 - [((LxdreamMainWindow *)[self window]) setIsGrabbed: NO];
4.65 + if( ([event modifierFlags] & NSControlKeyMask) && ([event modifierFlags] & NSAlternateKeyMask) ) {
4.66 + [self requestUngrab];
4.67 }
4.68
4.69 if( flagsMask[keycode] == 0 ) {
4.70 @@ -137,11 +154,8 @@
4.71 if( isGrabbed ) {
4.72 buttonMask |= 1;
4.73 input_event_mouse( buttonMask, 0, 0 );
4.74 - } else { // take display grab
4.75 - isGrabbed = YES;
4.76 - [NSCursor hide];
4.77 - CGAssociateMouseAndMouseCursorPosition(NO);
4.78 - [((LxdreamMainWindow *)[self window]) setIsGrabbed: YES];
4.79 + } else {
4.80 + [self requestGrab];
4.81 }
4.82 }
4.83 - (void)mouseUp: (NSEvent *)event
4.84 @@ -200,7 +214,7 @@
4.85 NSView *video_osx_create_drawable()
4.86 {
4.87 NSRect contentRect = {{0,0},{640,480}};
4.88 - video_view = [[LxdreamVideoView alloc] initWithFrame: contentRect];
4.89 + video_view = [[LxdreamOSXView alloc] initWithFrame: contentRect];
4.90 [video_view setAutoresizingMask: (NSViewWidthSizable|NSViewHeightSizable)];
4.91 return video_view;
4.92 }
.