diff --git a/src/SFML/Window/CMakeLists.txt b/src/SFML/Window/CMakeLists.txt index 9d50e5ae..d8b8b084 100644 --- a/src/SFML/Window/CMakeLists.txt +++ b/src/SFML/Window/CMakeLists.txt @@ -60,6 +60,8 @@ else() # MACOSX ${SRCROOT}/OSX/SFContext.mm ${SRCROOT}/OSX/SFOpenGLView.h ${SRCROOT}/OSX/SFOpenGLView.mm + ${SRCROOT}/OSX/SFWindow.h + ${SRCROOT}/OSX/SFWindow.m ${SRCROOT}/OSX/SFWindowController.h ${SRCROOT}/OSX/SFWindowController.mm ${SRCROOT}/OSX/VideoModeImpl.cpp diff --git a/src/SFML/Window/OSX/SFWindow.h b/src/SFML/Window/OSX/SFWindow.h new file mode 100644 index 00000000..7575a06a --- /dev/null +++ b/src/SFML/Window/OSX/SFWindow.h @@ -0,0 +1,46 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com), +// Laurent Gomila (laurent.gom@gmail.com), +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#import + +//////////////////////////////////////////////////////////// +/// Here we redefine some methods to allow grabing fullscreen events. +//////////////////////////////////////////////////////////// +@interface SFWindow : NSWindow { + +} + +/* + These two methods must return YES to grab fullscreen events. + See http://stackoverflow.com/questions/999464/fullscreen-key-down-actions + for more informations + */ +-(BOOL)acceptsFirstResponder; +-(BOOL)canBecomeKeyWindow; + +@end diff --git a/src/SFML/Window/OSX/SFWindow.m b/src/SFML/Window/OSX/SFWindow.m new file mode 100644 index 00000000..3c5b61e4 --- /dev/null +++ b/src/SFML/Window/OSX/SFWindow.m @@ -0,0 +1,45 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2010 Marco Antognini (antognini.marco@gmail.com), +// Laurent Gomila (laurent.gom@gmail.com), +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#import "SFWindow.h" + + +@implementation SFWindow + +//////////////////////////////////////////////////////// +-(BOOL)acceptsFirstResponder { + return YES; +} + + +//////////////////////////////////////////////////////// +-(BOOL)canBecomeKeyWindow { + return YES; +} + +@end diff --git a/src/SFML/Window/OSX/SFWindowController.h b/src/SFML/Window/OSX/SFWindowController.h index 488a71c2..c229a2cd 100644 --- a/src/SFML/Window/OSX/SFWindowController.h +++ b/src/SFML/Window/OSX/SFWindowController.h @@ -28,6 +28,7 @@ //////////////////////////////////////////////////////////// #import + //////////////////////////////////////////////////////////// /// Predefine some classes //////////////////////////////////////////////////////////// diff --git a/src/SFML/Window/OSX/SFWindowController.mm b/src/SFML/Window/OSX/SFWindowController.mm index ea179da1..1565f97d 100644 --- a/src/SFML/Window/OSX/SFWindowController.mm +++ b/src/SFML/Window/OSX/SFWindowController.mm @@ -35,6 +35,7 @@ #import #import #import +#import @implementation SFWindowController @@ -103,7 +104,7 @@ } // Create the window. - myWindow = [[NSWindow alloc] initWithContentRect:rect + myWindow = [[SFWindow alloc] initWithContentRect:rect styleMask:nsStyle backing:NSBackingStoreBuffered defer:NO]; @@ -127,6 +128,26 @@ return self; } + // Apply special feature for fullscreen window. + if (style & sf::Style::Fullscreen) { + // We place the window above everything else. + [myWindow setLevel:NSMainMenuWindowLevel+1]; + [myWindow setOpaque:YES]; + [myWindow setHidesOnDeactivate:YES]; + + /* --------------------------- + * | Note for future version | + * --------------------------- + * + * starting with OS 10.5 NSView provides + * a new method -enterFullScreenMode:withOptions: + * which could be a good alternative. + */ + } else { + // Center the window to be cool =) + [myWindow center]; + } + // Create the view. myOGLView = [[SFOpenGLView alloc] initWithFrame:[[myWindow contentView] frame]]; @@ -151,28 +172,6 @@ // And some other things... [myWindow setAutodisplay:YES]; [myWindow setReleasedWhenClosed:NO]; - - // Apply special feature for fullscreen window. - if (style & sf::Style::Fullscreen) { - - // We place the window above everything else. - [myWindow setLevel:NSMainMenuWindowLevel+1]; - [myWindow setOpaque:YES]; - [myWindow setHidesOnDeactivate:YES]; - - /* --------------------------- - * | Note for future version | - * --------------------------- - * - * starting with OS 10.5 NSView provides - * a new method -enterFullScreenMode:withOptions: - * which could be a good alternative. - */ - } - - // Center the window to be cool =) - [myWindow center]; - } // if super init ok return self;