Just to add my solution.
This is a Windows only solution.
I actually found a coding solution which just gets around this problem. I don't know if it has been solved yet, but it was not working with my actual version for SFML, 2.1, less than a week old.
So to still get the sf::Event::GainedFocus when clicking in the middle of the window, is used an other event. The sf::Event::MouseEntered event.
It gets trigerred whether or not the window is on focus.
So all that is left is to detect the mouseClick Event.
Which is again trigerred even if the window isn't the focus.
Then to make the window the focus. No function from sfml is provided to force the focus on the window. But there is a win32 api call that does the trick. SetFocus(HWND HandleToTheWindow).
case sf::Event::MouseEntered:
{
// Retrieving when the mouse gets in the window.
mouseInScreen = true;
break;
}
case sf::Event::MouseButtonReleased:
{
if(mouseInScreen)
{
// make the window the current focus.
SetFocus(this->window->getSystemHandle());
}
}
The only downside, if considered one, is that it will send a lose focus event before sending the GainedFocus event.
I hope this helps anyone having this problem again. Or maybe giving the SFML guys some clue about how to get this fixed.