diff --git a/src/SFML/Window/OSX/SFViewController.mm b/src/SFML/Window/OSX/SFViewController.mm index 2b7676914..a2898da84 100644 --- a/src/SFML/Window/OSX/SFViewController.mm +++ b/src/SFML/Window/OSX/SFViewController.mm @@ -187,6 +187,28 @@ } +//////////////////////////////////////////////////////// +-(BOOL)requestFocus +{ + // Note: this doesn't imply that the view will get any event. + // The user has to make sure events are forwarded to the view + // with the usual responder chain. + [[m_view window] makeKeyAndOrderFront:nil]; + + // In case the app is not active, make its dock icon bounce for one sec + [NSApp requestUserAttention:NSInformationalRequest]; + + return [self hasFocus]; +} + + +//////////////////////////////////////////////////////////// +-(BOOL)hasFocus +{ + return [NSApp keyWindow] == [m_view window]; +} + + //////////////////////////////////////////////////////// -(void)enableKeyRepeat { diff --git a/src/SFML/Window/OSX/SFWindowController.mm b/src/SFML/Window/OSX/SFWindowController.mm index 1b0a0de7c..2fae92592 100644 --- a/src/SFML/Window/OSX/SFWindowController.mm +++ b/src/SFML/Window/OSX/SFWindowController.mm @@ -451,6 +451,25 @@ } +//////////////////////////////////////////////////////// +-(BOOL)requestFocus +{ + [m_window makeKeyAndOrderFront:nil]; + + // In case the app is not active, make its dock icon bounce for one sec + [NSApp requestUserAttention:NSInformationalRequest]; + + return [self hasFocus]; +} + + +//////////////////////////////////////////////////////////// +-(BOOL)hasFocus +{ + return [NSApp keyWindow] == m_window; +} + + //////////////////////////////////////////////////////// -(void)enableKeyRepeat { diff --git a/src/SFML/Window/OSX/WindowImplDelegateProtocol.h b/src/SFML/Window/OSX/WindowImplDelegateProtocol.h index b43805a64..e33f91a1b 100644 --- a/src/SFML/Window/OSX/WindowImplDelegateProtocol.h +++ b/src/SFML/Window/OSX/WindowImplDelegateProtocol.h @@ -166,6 +166,23 @@ namespace sf { //////////////////////////////////////////////////////////// -(void)closeWindow; +//////////////////////////////////////////////////////////// +/// \brief Request the current window to be made the active +/// foreground window +/// +/// \return True if operation was successful, false otherwise +/// +//////////////////////////////////////////////////////////// +-(BOOL)requestFocus; + +//////////////////////////////////////////////////////////// +/// \brief Determine whether the window has the input focus +/// +/// \return True if window has focus, false otherwise +/// +//////////////////////////////////////////////////////////// +-(BOOL)hasFocus; + //////////////////////////////////////////////////////////// /// \brief Enable key repeat ///