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

Author Topic: Generate "FocusLost" event when window is grabbed and moved?  (Read 3253 times)

0 Members and 1 Guest are viewing this topic.

TheWehe

  • Guest
Generate "FocusLost" event when window is grabbed and moved?
« on: February 22, 2015, 01:58:17 pm »
Hi :)
When the user grabs the window and moves it, the message loop freezes, but there's no "FocusLost" event generated. Thereby it's not possible to stop the timer and as soon as the movement ends the app does a big jump depending on how long the window movement has last.
Actually the window doesn't lose the focus, but anyways, I think it would be useful to integrate that.

The only work-around I know is (like Rickety Racquet does) preventing the user completely from using the mouse. He's not able to move the window until he opens up the menu then.

I hope you understand what I mean, I'm a German pupil and I don't have that much experience using English practically.  ::)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Generate "FocusLost" event when window is grabbed and moved?
« Reply #1 on: February 22, 2015, 03:55:11 pm »
How would you process the LostFocus event if the whole message loop, and thus the whole thread that contains it (which means your complete app if it's single-threaded) is frozen?

Quote
The only work-around I know is (like Rickety Racquet does) preventing the user completely from using the mouse. He's not able to move the window until he opens up the menu then.
I don't understand this suggestion. What menu are you talking about, and how would disabling the mouse be any kind of solution?

Note that a typical solution to this problem is to handle events in a separate thread, so that the rest of the program is not blocked.
Laurent Gomila - SFML developer

TheWehe

  • Guest
Re: Generate "FocusLost" event when window is grabbed and moved?
« Reply #2 on: February 22, 2015, 06:46:00 pm »
Isn't it possible to send "LostFocus" when the user clicks on the titlebar and "GainedFocus" when he releases it? In right these moments I should be able to call pollEvent, or am I wrong?
By the way the same behaviour apperas while resizing windows.

The multithreaded way isn't a solution for my problem, because although the event loop is handled seperately I'm simply not able to detect if the user has started to move the window.

Rickety Raquet prevents the mouse to get out of the window, but as soon as a menu (main, in-game) is opened the mouse is free. With this, the user is not able to start moving/resizing the window, because he simply can't reach the titlebar.

Maybe I'm in the wrong sub-forum:D

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Generate "FocusLost" event when window is grabbed and moved?
« Reply #3 on: February 22, 2015, 08:49:36 pm »
Quote
Isn't it possible to send "LostFocus" when the user clicks on the titlebar and "GainedFocus" when he releases it? In right these moments I should be able to call pollEvent, or am I wrong?
It's already too late. When the OS tells you that it starts moving/resizing the window, there's nothing else you can do (with SFML) until it's finished.

Quote
The multithreaded way isn't a solution for my problem, because although the event loop is handled seperately I'm simply not able to detect if the user has started to move the window.
There could be a workaround with a continuous check on the window position / size.

Quote
Rickety Raquet prevents the mouse to get out of the window, but as soon as a menu (main, in-game) is opened the mouse is free.
You can perfectly implement this behaviour yourself.
Laurent Gomila - SFML developer

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Generate "FocusLost" event when window is grabbed and moved?
« Reply #4 on: February 23, 2015, 01:59:11 pm »
The window is never losing focus while dragging, so triggering the events would be misleading and a bug.

Easy workaround #1:

Limit the amount of time you update between two render calls.

For example, if you're using fixed timesteps, don't update more than 10 times per iteration.

If you're using dynamic timesteps, limit your delta time to something like 100 ms.

That way you're able to counter framerate drops, but at the same time you're not leaving the player with "infinite speed" after moving the window.

More complicated workaround #2:
Don't use the window manager's border and titlebar. Instead draw your own and handle drag&drop inside your program. This way you've got full control and know if/when the user starts or stops dragging.

TheWehe

  • Guest
Re: Generate "FocusLost" event when window is grabbed and moved?
« Reply #5 on: February 23, 2015, 03:01:25 pm »
Ok, I understand it now why there's no event for this. Thanks:)

Quote
The window is never losing focus while dragging, so triggering the events would be misleading and a bug.
Yeah, I know, my main idea behind this post was to ask for a fitting event. But as Laurent explained me, it is not possible through the OS without workarounds.

I'll try both. Thank you:)