diff --git a/src/SFML/Window/OSX/SFOpenGLView.h b/src/SFML/Window/OSX/SFOpenGLView.h index a09d0df56..50373cda0 100644 --- a/src/SFML/Window/OSX/SFOpenGLView.h +++ b/src/SFML/Window/OSX/SFOpenGLView.h @@ -41,7 +41,10 @@ namespace sf { /// /// Handle event and send them back to the requester. /// -/// NSTrackingArea is used to keep track of mouse events. +/// NSTrackingArea is used to keep track of mouse events. We also +/// need to be able to ignore mouse event when exiting fullscreen. +/// The SFWindowController should call -[SFOpenGLView exitFullscreen] +/// and -[SFOpenGLView enterFullscreen] when appropriate. /// /// In order to send correct mouse coordonate to the requester when /// the window is in fullscreen we use m_realSize to represent the @@ -72,6 +75,13 @@ namespace sf { //////////////////////////////////////////////////////////// -(id)initWithFrame:(NSRect)frameRect; +//////////////////////////////////////////////////////////// +/// Handle going in and out of fullscreen mode. +/// +//////////////////////////////////////////////////////////// +-(void)enterFullscreen; +-(void)exitFullscreen; + //////////////////////////////////////////////////////////// /// Apply the given resquester to the view. /// diff --git a/src/SFML/Window/OSX/SFOpenGLView.mm b/src/SFML/Window/OSX/SFOpenGLView.mm index 2f15524a9..b787e4866 100644 --- a/src/SFML/Window/OSX/SFOpenGLView.mm +++ b/src/SFML/Window/OSX/SFOpenGLView.mm @@ -128,6 +128,39 @@ BOOL isValidTextUnicode(NSEvent* event); } +//////////////////////////////////////////////////////// +-(void)enterFullscreen +{ + // Remove the tracking area first, + // just to be sure we don't add it twice! + [self removeTrackingArea:m_trackingArea]; + [self addTrackingArea:m_trackingArea]; + + // Fire an mouse entered event if needed + if (!m_mouseIsIn && m_requester != 0) { + m_requester->mouseMovedIn(); + } + + // Update status + m_mouseIsIn = YES; +} + + +//////////////////////////////////////////////////////// +-(void)exitFullscreen +{ + [self removeTrackingArea:m_trackingArea]; + + // Fire an mouse left event if needed + if (m_mouseIsIn && m_requester != 0) { + m_requester->mouseMovedOut(); + } + + // Update status + m_mouseIsIn = NO; +} + + //////////////////////////////////////////////////////// -(void)setRequesterTo:(sf::priv::WindowImplCocoa *)requester { diff --git a/src/SFML/Window/OSX/SFWindowController.mm b/src/SFML/Window/OSX/SFWindowController.mm index 777046d93..4f68c13f8 100644 --- a/src/SFML/Window/OSX/SFWindowController.mm +++ b/src/SFML/Window/OSX/SFWindowController.mm @@ -211,9 +211,15 @@ } // If a fullscreen window was requested... - if (style & sf::Style::Fullscreen && mode != sf::VideoMode::getDesktopMode()) { - /// ... we set the "real size" of the view (that is the back buffer size). - [m_oglView setRealSize:NSMakeSize(m_fullscreenMode->width, m_fullscreenMode->height)]; + if (style & sf::Style::Fullscreen) { + /// ... we tell the OpenGL view + [m_oglView enterFullscreen]; + + // ... and if the resolution is not the default one... + if (mode != sf::VideoMode::getDesktopMode()) { + // ... we set the "real size" of the view (that is the back buffer size). + [m_oglView setRealSize:NSMakeSize(m_fullscreenMode->width, m_fullscreenMode->height)]; + } } // Set the view to the window as its content view. @@ -496,6 +502,10 @@ if (m_requester == 0) return; m_requester->windowGainedFocus(); + + if (*m_fullscreenMode != sf::VideoMode()) { + [m_oglView enterFullscreen]; + } } @@ -506,6 +516,10 @@ if (m_requester == 0) return; m_requester->windowLostFocus(); + + if (*m_fullscreenMode != sf::VideoMode()) { + [m_oglView exitFullscreen]; + } }