From 4155b2e449e1448ccbe7a1c958e5cd686b1aba11 Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Thu, 29 May 2014 11:39:04 +0200 Subject: [PATCH] Changed Window::requestFocus() return type from bool to void Reasons: * Consistent with other sf::Window methods * User can test whether focus succeeded by subsequent hasFocus() call * Implementation would have to call hasFocus() anyway on some systems Also: minor code style change in Window::hasFocus() --- include/SFML/Window/Window.hpp | 3 +-- src/SFML/Window/OSX/SFViewController.mm | 4 +--- src/SFML/Window/OSX/SFWindowController.mm | 4 +--- src/SFML/Window/OSX/WindowImplCocoa.hpp | 4 +--- src/SFML/Window/OSX/WindowImplCocoa.mm | 4 ++-- src/SFML/Window/OSX/WindowImplDelegateProtocol.h | 4 +--- src/SFML/Window/Unix/WindowImplX11.cpp | 3 +-- src/SFML/Window/Unix/WindowImplX11.hpp | 4 +--- src/SFML/Window/Win32/WindowImplWin32.cpp | 4 ++-- src/SFML/Window/Win32/WindowImplWin32.hpp | 4 +--- src/SFML/Window/Window.cpp | 9 +++------ src/SFML/Window/WindowImpl.hpp | 4 +--- 12 files changed, 16 insertions(+), 35 deletions(-) diff --git a/include/SFML/Window/Window.hpp b/include/SFML/Window/Window.hpp index 0ba0477b..6d4ecf79 100644 --- a/include/SFML/Window/Window.hpp +++ b/include/SFML/Window/Window.hpp @@ -423,11 +423,10 @@ public: /// is free to deny the request. /// This is not to be confused with setActive(). /// - /// \return True if operation was successful, false otherwise /// \see hasFocus /// //////////////////////////////////////////////////////////// - bool requestFocus(); + void requestFocus(); //////////////////////////////////////////////////////////// /// \brief Check whether the window has the input focus diff --git a/src/SFML/Window/OSX/SFViewController.mm b/src/SFML/Window/OSX/SFViewController.mm index a2898da8..ba2e8a0f 100644 --- a/src/SFML/Window/OSX/SFViewController.mm +++ b/src/SFML/Window/OSX/SFViewController.mm @@ -188,7 +188,7 @@ //////////////////////////////////////////////////////// --(BOOL)requestFocus +-(void)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 @@ -197,8 +197,6 @@ // In case the app is not active, make its dock icon bounce for one sec [NSApp requestUserAttention:NSInformationalRequest]; - - return [self hasFocus]; } diff --git a/src/SFML/Window/OSX/SFWindowController.mm b/src/SFML/Window/OSX/SFWindowController.mm index 2fae9259..afdd3187 100644 --- a/src/SFML/Window/OSX/SFWindowController.mm +++ b/src/SFML/Window/OSX/SFWindowController.mm @@ -452,14 +452,12 @@ //////////////////////////////////////////////////////// --(BOOL)requestFocus +-(void)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]; } diff --git a/src/SFML/Window/OSX/WindowImplCocoa.hpp b/src/SFML/Window/OSX/WindowImplCocoa.hpp index 1dfc680f..4a66d743 100644 --- a/src/SFML/Window/OSX/WindowImplCocoa.hpp +++ b/src/SFML/Window/OSX/WindowImplCocoa.hpp @@ -324,10 +324,8 @@ public: /// \brief Request the current window to be made the active /// foreground window /// - /// \return True if operation was successful, false otherwise - /// //////////////////////////////////////////////////////////// - virtual bool requestFocus(); + virtual void requestFocus(); //////////////////////////////////////////////////////////// /// \brief Check whether the window has the input focus diff --git a/src/SFML/Window/OSX/WindowImplCocoa.mm b/src/SFML/Window/OSX/WindowImplCocoa.mm index 5dbf0f46..0ddfa78f 100644 --- a/src/SFML/Window/OSX/WindowImplCocoa.mm +++ b/src/SFML/Window/OSX/WindowImplCocoa.mm @@ -553,9 +553,9 @@ void WindowImplCocoa::setKeyRepeatEnabled(bool enabled) //////////////////////////////////////////////////////////// -bool WindowImplCocoa::requestFocus() +void WindowImplCocoa::requestFocus() { - return [m_delegate requestFocus]; + [m_delegate requestFocus]; } diff --git a/src/SFML/Window/OSX/WindowImplDelegateProtocol.h b/src/SFML/Window/OSX/WindowImplDelegateProtocol.h index 6c38f590..0132f401 100644 --- a/src/SFML/Window/OSX/WindowImplDelegateProtocol.h +++ b/src/SFML/Window/OSX/WindowImplDelegateProtocol.h @@ -170,10 +170,8 @@ namespace sf { /// \brief Request the current window to be made the active /// foreground window /// -/// \return True if operation was successful, false otherwise -/// //////////////////////////////////////////////////////////// --(BOOL)requestFocus; +-(void)requestFocus; //////////////////////////////////////////////////////////// /// \brief Check whether the window has the input focus diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index 7efacc19..f43644df 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -484,11 +484,10 @@ void WindowImplX11::setKeyRepeatEnabled(bool enabled) //////////////////////////////////////////////////////////// -bool WindowImplX11::requestFocus() +void WindowImplX11::requestFocus() { XRaiseWindow(m_display, m_window); XSetInputFocus(m_display, m_window, RevertToPointerRoot, CurrentTime); - return true; } diff --git a/src/SFML/Window/Unix/WindowImplX11.hpp b/src/SFML/Window/Unix/WindowImplX11.hpp index 9f354e9f..19de32f0 100644 --- a/src/SFML/Window/Unix/WindowImplX11.hpp +++ b/src/SFML/Window/Unix/WindowImplX11.hpp @@ -158,10 +158,8 @@ public: /// \brief Request the current window to be made the active /// foreground window /// - /// \return True if operation was successful, false otherwise - /// //////////////////////////////////////////////////////////// - virtual bool requestFocus(); + virtual void requestFocus(); //////////////////////////////////////////////////////////// /// \brief Check whether the window has the input focus diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index 32aec6da..5dcfc3e0 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -367,9 +367,9 @@ void WindowImplWin32::setKeyRepeatEnabled(bool enabled) //////////////////////////////////////////////////////////// -bool WindowImplWin32::requestFocus() +void WindowImplWin32::requestFocus() { - return SetForegroundWindow(m_handle); + SetForegroundWindow(m_handle); } diff --git a/src/SFML/Window/Win32/WindowImplWin32.hpp b/src/SFML/Window/Win32/WindowImplWin32.hpp index d06aae77..0bb3ce84 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.hpp +++ b/src/SFML/Window/Win32/WindowImplWin32.hpp @@ -157,10 +157,8 @@ public: /// \brief Request the current window to be made the active /// foreground window /// - /// \return True if operation was successful, false otherwise - /// //////////////////////////////////////////////////////////// - virtual bool requestFocus(); + virtual void requestFocus(); //////////////////////////////////////////////////////////// /// \brief Check whether the window has the input focus diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index 574c0549..7487ea6e 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -337,20 +337,17 @@ bool Window::setActive(bool active) const //////////////////////////////////////////////////////////// -bool Window::requestFocus() +void Window::requestFocus() { if (m_impl) - return m_impl->requestFocus(); - return false; + m_impl->requestFocus(); } //////////////////////////////////////////////////////////// bool Window::hasFocus() const { - if (m_impl) - return m_impl->hasFocus(); - return false; + return m_impl && m_impl->hasFocus(); } diff --git a/src/SFML/Window/WindowImpl.hpp b/src/SFML/Window/WindowImpl.hpp index 1b5251e8..dbf7170d 100644 --- a/src/SFML/Window/WindowImpl.hpp +++ b/src/SFML/Window/WindowImpl.hpp @@ -198,10 +198,8 @@ public: /// \brief Request the current window to be made the active /// foreground window /// - /// \return True if operation was successful, false otherwise - /// //////////////////////////////////////////////////////////// - virtual bool requestFocus() = 0; + virtual void requestFocus() = 0; //////////////////////////////////////////////////////////// /// \brief Check whether the window has the input focus