From fdac401a5aabebedf71239f4999ef865967555c7 Mon Sep 17 00:00:00 2001 From: nigel <> Date: Thu, 30 May 2002 12:50:21 +0000 Subject: [PATCH] Sheet and fullscreen-safe input processing, small tidyup --- BasiliskII/src/MacOSX/Controller.h | 2 +- BasiliskII/src/MacOSX/Controller.mm | 69 +++++++++++++++++++++-------- 2 files changed, 51 insertions(+), 20 deletions(-) diff --git a/BasiliskII/src/MacOSX/Controller.h b/BasiliskII/src/MacOSX/Controller.h index 3253cd36..0073bd8b 100644 --- a/BasiliskII/src/MacOSX/Controller.h +++ b/BasiliskII/src/MacOSX/Controller.h @@ -26,7 +26,6 @@ // If the application supports multiple windows, define this: // #define ENABLE_MULTIPLE -//@interface Controller : NSObject @interface Controller : NSApplication { #ifdef ENABLE_MULTIPLE @@ -48,6 +47,7 @@ - (IBAction) TerminateAll: (id)sender; #endif +- (BOOL) isAnyEmulatorDisplayingSheets; - (BOOL) isAnyEmulatorRunning; - (short) emulatorCreatedCount; // If any emulator environments have been setup, count how many diff --git a/BasiliskII/src/MacOSX/Controller.mm b/BasiliskII/src/MacOSX/Controller.mm index 89472bf2..55a6367b 100644 --- a/BasiliskII/src/MacOSX/Controller.mm +++ b/BasiliskII/src/MacOSX/Controller.mm @@ -66,14 +66,19 @@ - (void) sendEvent: (NSEvent *)event; { - NSEventType type = [event type]; - - if ( type == NSKeyUp || type == NSKeyDown || type == NSFlagsChanged ) - [self dispatchKeyEvent: event - type: type]; + if ( [self isAnyEmulatorDisplayingSheets] || ! [self isAnyEmulatorRunning] ) + [super sendEvent: event]; else - [self dispatchEvent: event - type: type]; + { + NSEventType type = [event type]; + + if ( type == NSKeyUp || type == NSKeyDown || type == NSFlagsChanged ) + [self dispatchKeyEvent: event + type: type]; + else + [self dispatchEvent: event + type: type]; + } } // NSApplication methods which are invoked through delegation @@ -144,18 +149,22 @@ for ( tmp = 0; tmp < [emulators count], ++tmp ) { theEmulator = [emulators objectAtIndex: tmp]; - if ( [ theEmulator isRunning ] && [[theEmulator window] isKeyWindow ] ) + view = [theEmulator screen]; + + if ( [ theEmulator isRunning ] && + ( [[theEmulator window] isKeyWindow] || [view isFullScreen] ) ) break; } if ( tmp < [emulators count] ) // i.e. if we exited the for loop #else - if ( FULLSCREEN || - [theEmulator isRunning] && [[theEmulator window] isKeyWindow ] ) + view = [theEmulator screen]; + + if ( [theEmulator isRunning] && + ( [[theEmulator window] isKeyWindow] || [view isFullScreen] ) ) #endif { - view = [theEmulator screen]; -NSLog(@"Got a key event - %d\n", [event keyCode]); + D(NSLog(@"Got a key event - %d\n", [event keyCode])); switch ( type ) { case NSKeyUp: @@ -182,6 +191,8 @@ NSLog(@"Got a key event - %d\n", [event keyCode]); - (void) dispatchEvent: (NSEvent *)event type: (NSEventType)type { + EmulatorView *view; + #ifdef ENABLE_MULTIPLE // We need to work out what window's Emulator should receive these messages @@ -191,20 +202,22 @@ NSLog(@"Got a key event - %d\n", [event keyCode]); for ( tmp = 0; tmp < [emulators count], ++tmp ) { theEmulator = [emulators objectAtIndex: tmp]; - if ( [ theEmulator isRunning ] && [[theEmulator window] isMainWindow ] ) + view = [theEmulator screen]; + + if ( [theEmulator isRunning] && + ( [[theEmulator window] isMainWindow] || [view isFullScreen] ) ) break; } if ( tmp < [emulators count] ) // i.e. if we exited the for loop #else - if ( FULLSCREEN || - ( [theEmulator isRunning] && [[theEmulator window] isMainWindow ] ) ) + view = [theEmulator screen]; + + if ( [theEmulator isRunning] && + ( [[theEmulator window] isMainWindow] || [view isFullScreen] ) ) #endif { - EmulatorView *view = [theEmulator screen]; - -// if ( [view mouseInView] ) - if ( [view mouseInView: event] || FULLSCREEN ) + if ( [view mouseInView: event] ) { switch ( type ) { @@ -278,6 +291,24 @@ NSLog(@"Got a key event - %d\n", [event keyCode]); #endif +- (BOOL) isAnyEmulatorDisplayingSheets +{ +#ifdef ENABLE_MULTIPLE + int tmp; + + for ( tmp = 0; tmp < [emulators count], ++tmp ) + if ( [[[emulators objectAtIndex: tmp] window] attachedSheet] ) + break; + + if ( tmp < [emulators count] ) // i.e. if we exited the for loop +#else + if ( [[theEmulator window] attachedSheet] ) +#endif + return TRUE; + + return FALSE; +} + - (BOOL) isAnyEmulatorRunning { #ifdef ENABLE_MULTIPLE