Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML doesnt catch all window Resized events +focusLost doesn't fire in some case  (Read 3479 times)

0 Members and 1 Guest are viewing this topic.

Phanoo

  • Full Member
  • ***
  • Posts: 136
    • View Profile
hello, some problems I have, not sure if they are SFML bugs :
  • I have a program that keeps fixed-size contents no matter the window size (the UI elements are of the same size when the window is bigger). This is done by resizing the view size on Window Resize event. But sometimes on Windows, when I mess with window switching, it doesnt work properly, the whole content get scaled, like if the Resized event wasnt triggered. (or maybe triggered but with the old width/height value)
  • LostFocus event doesn't work when another window get the focus itself (not a user action). I found that with League of Legends, the game laucher brings itself to the foreground, and my app don't get any LostFocus event so i cant disable mouse clicks..

I know my post needs more testing, but it was to see if other people noticed the same problems
« Last Edit: December 05, 2017, 01:50:11 pm by ratatax »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
If you post a complete and minimal example that reproduces the problem(s), then maybe more people can test it and check if it's a SFML bug.
Laurent Gomila - SFML developer

Phanoo

  • Full Member
  • ***
  • Posts: 136
    • View Profile
100 % reproductible, two programs, the first request to get to the front, the second checks if it lost focus :

Requester, brings window to foreground every 2sec, using windows api
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>

#include <windows.h>

int main(){
        sf::RenderWindow window(sf::VideoMode(200, 200), "request focus");

        sf::Event evt;

        while(window.isOpen()){
                while (window.pollEvent(evt)){
                }
                sf::sleep(sf::seconds(2));
                SwitchToThisWindow(window.getSystemHandle(),0);
                window.clear();
                window.display();
        }


       
        return 0;
}


Focus checker, displays a green window when it has focus, red if it hasn't

#include <SFML/Graphics.hpp>

int main(){
        sf::RenderWindow window(sf::VideoMode(200, 200), "focus checker");
       
        sf::Event evt;

        sf::Color c(0,255,0);

        while(window.isOpen()){
                while (window.pollEvent(evt)){
                        switch(evt.type){
                                case sf::Event::LostFocus:
                                        c = sf::Color(255,0,0);
                                        break;
                                case sf::Event::GainedFocus:
                                        c = sf::Color(0,255,0);
                                        break;
                        }
                }

                window.clear(c);
                window.display();
        }


        return 0;
}


Run both programs, you'll see the focus checker stays green when the requester gets to the foreground. No problem when the user switch window or click outside, it seems to happen only when another window takes the focus by itself.

See compiled test in attachment. It doesn't check for window close event so you have to kill them using task manager
« Last Edit: December 12, 2017, 02:45:34 am by ratatax »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Works fine for me (SFML 2.4, Windows 10).
Laurent Gomila - SFML developer

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Isn't that how the behavior of focus is defined in Windows? A program can be in the foreground, but it doesn't have focus until the user interacts with it? (ie: I can use my mouse's scroll wheel in one window, but be typing in another window)

Looking at the documentation for SwitchToThisWindow
Quote
[This function is not intended for general use. It may be altered or unavailable in subsequent versions of Windows.]
and
Quote
This function is typically called to maintain window z-ordering.
That makes me think it might not do quite what the name says it would.

Does using SetFocus instead change the behavior of your example?
(Also, it's documentation specifically references the events that SFML listens for, WM_KILLFOCUS and WM_SETFOCUS)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
What's your version of Windows and what's your version of SFML?

What if you set fAltTab (second parameter) to true?

In the end, if the OS isn't providing us the required events, then there's little we can do without introducing ugly or performance impacting hacks.
We know that focus can potentially be a bit unstable, which is why we introduced an event independent focus checking and focus requesting function.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything