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

Author Topic: Unexpected GainedFocus event  (Read 3530 times)

0 Members and 1 Guest are viewing this topic.

maly

  • Newbie
  • *
  • Posts: 14
    • View Profile
Unexpected GainedFocus event
« on: June 27, 2014, 10:59:53 am »
When I click on other window(LostFocus) setSize and setPosition gives me GainedFocus.
SFML 2.1 on Windows XP.
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    sf::Window app(sf::VideoMode(100, 100), "SFML window");
    //sf::RenderWindow app(sf::VideoMode(100, 100), "SFML window");

    while (app.isOpen())
    {
        //app.setPosition(app.getPosition());
        app.setSize(app.getSize());

        sf::Event event;
        while (app.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                app.close();
            else if(event.type == sf::Event::LostFocus)
                std::cout << "LostFocus" << std::endl;
            else if(event.type == sf::Event::GainedFocus)
                std::cout << "GainedFocus" << std::endl;
        }
    }
    return 0;
}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Unexpected GainedFocus event
« Reply #1 on: June 27, 2014, 11:12:28 am »
Does it just trigger the event or do you actually get focus on the window?
If the window gets the focus, everything works as expected. The window manager decides whether it gives focus to the window up on resizing or repositioning.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

maly

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Unexpected GainedFocus event
« Reply #2 on: June 27, 2014, 12:49:14 pm »
It just trigger GainedFocus event when losing focus.
 
My solution is add flag SWP_NOACTIVATE but I have no idea, if it's good idea.
void WindowImplWin32::setPosition(const Vector2i& position)
{
        SetWindowPos(m_handle, NULL, position.x, position.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
}

void WindowImplWin32::setSize(const Vector2u& size)
{
    // SetWindowPos wants the total size of the window (including title bar and borders),
    // so we have to compute it
    RECT rectangle = {0, 0, static_cast<long>(size.x), static_cast<long>(size.y)};
    AdjustWindowRect(&rectangle, GetWindowLong(m_handle, GWL_STYLE), false);
    int width  = rectangle.right - rectangle.left;
    int height = rectangle.bottom - rectangle.top;

    SetWindowPos(m_handle, NULL, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Unexpected GainedFocus event
« Reply #3 on: June 27, 2014, 01:14:29 pm »
It just trigger GainedFocus event when losing focus.
You might want to express yourself better...

Am I understanding you right, that if the window has lost the focus and you call setPosition or setSize the event GainedFocus will get triggered, but the window doesn't get the focus?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

maly

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Unexpected GainedFocus event
« Reply #4 on: February 09, 2015, 09:25:43 am »
I was reminded of this problem.

I'll explain it as simply as I can.

Expected result
Code: [Select]
click outside the window LostFocus
click inside the window GainedFocus

But result is
Code: [Select]
click outside the window LostFocus and GainedFocus
click inside the window ??? nothing

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Unexpected GainedFocus event
« Reply #5 on: February 09, 2015, 09:32:40 am »
Hehe that lag. :D

What version of SFML are you using?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

maly

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Unexpected GainedFocus event
« Reply #6 on: February 09, 2015, 10:23:09 am »
Today compiled from the master.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Unexpected GainedFocus event
« Reply #7 on: February 13, 2015, 09:31:46 am »
Never tried resizing while the window is active, but the flags sound reasonable (assuming using them there is viable/allowed, which I haven't checked yet).

 

anything