From 85291debb45b907630ed36e86c30da435e1bf46d Mon Sep 17 00:00:00 2001 From: Marco Antognini Date: Wed, 23 Apr 2014 11:26:44 +0200 Subject: [PATCH] Added OS X impl of requestFocus and hasFocus Signed-off-by: Foaly Signed-off-by: Jan Haller --- src/SFML/Window/OSX/SFViewController.mm | 22 +++++++++++++++++++ src/SFML/Window/OSX/SFWindowController.mm | 19 ++++++++++++++++ .../Window/OSX/WindowImplDelegateProtocol.h | 17 ++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/src/SFML/Window/OSX/SFViewController.mm b/src/SFML/Window/OSX/SFViewController.mm index 2b767691..a2898da8 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 1b0a0de7..2fae9259 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 b43805a6..e33f91a1 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 ///