1
General / SFML Window Loses Focus on Startup - Mouse Clicks Don't Regain Focus
« on: June 30, 2024, 02:54:20 pm »
Hello, I'm trying to build a SFML app (dictionary app)
I'm encountering an issue where my SFML window loses focus on startup, leading to unexpected behavior with mouse interactions.
Details:
Here is the relevant part of my code.
I'm encountering an issue where my SFML window loses focus on startup, leading to unexpected behavior with mouse interactions.
Details:
- Platform: macOS (apple silicon)
- SFML version: 2.6.1
- Behavior: The render window doesn't have focus. Some elements in the SFML window require double-clicking to respond, even though they are designed to work with a single-click. However, it is unable to regain focus when being clicked on (some how still able to poll double-click as two separate single-click event.) Also, the loading screen doesn't draw during startup, the drawLoadingScreen function only works after startup.
- Cause: This seems to happen if I click on the program icon in my dock while it's starting up (there is a heavy function call before the event loop). The SFML window appears to lose focus but still registers a double-click as two separate single-click events. Despite this, clicking the SFML window itself does not restore focus.
- Conditions: The problem is particularly noticeable when auto-save is enabled and the last save (serialized data) is large.
- Temporary workaround: Switching to another program and then switching back to the SFML window restores the expected behavior.
Here is the relevant part of my code.
void instance::operatePage1()
{
if (!loadedSave)
{
deleteWholeTrie(pRoot);
drawLoadingPage(); /* this is supposed to draw the loading page but it doesn't */
deserializeBinaryWrapper(pRoot); /* this is very slow and allow me to click on the executable`s icon in the dock during it`s startup */
loadedSave = true;
}
while (windowInstance.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
{
windowInstance.close();
}
case sf::Event::MouseButtonPressed:
{
This is the loading page function{
if (!loadedSave)
{
deleteWholeTrie(pRoot);
drawLoadingPage(); /* this is supposed to draw the loading page but it doesn't */
deserializeBinaryWrapper(pRoot); /* this is very slow and allow me to click on the executable`s icon in the dock during it`s startup */
loadedSave = true;
}
while (windowInstance.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
{
windowInstance.close();
}
case sf::Event::MouseButtonPressed:
{
void instance::drawLoadingPage()
{
windowInstance.clear();
windowInstance.draw(loadingSprite);
windowInstance.display();
}
{
windowInstance.clear();
windowInstance.draw(loadingSprite);
windowInstance.display();
}