From e2ff29ecdad0a58c9d134a6b0b08628b78fde517 Mon Sep 17 00:00:00 2001 From: mantognini Date: Tue, 30 Nov 2010 22:55:23 +0000 Subject: [PATCH] fix event with fullscreen mode git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1730 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Window/CMakeLists.txt | 2 + src/SFML/Window/OSX/SFWindow.h | 46 +++++++++++++++++++++++ src/SFML/Window/OSX/SFWindow.m | 45 ++++++++++++++++++++++ src/SFML/Window/OSX/SFWindowController.h | 1 + src/SFML/Window/OSX/SFWindowController.mm | 45 +++++++++++----------- 5 files changed, 116 insertions(+), 23 deletions(-) create mode 100644 src/SFML/Window/OSX/SFWindow.h create mode 100644 src/SFML/Window/OSX/SFWindow.m diff --git a/src/SFML/Window/CMakeLists.txt b/src/SFML/Window/CMakeLists.txt index 9d50e5aea..d8b8b0842 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 000000000..7575a06a4 --- /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 000000000..3c5b61e42 --- /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 488a71c2b..c229a2cde 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 ea179da16..1565f97d9 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;