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

Author Topic: [Linux with Fluxbox] Weird Focus Gain/Lose on Alt-Tab / Alt-F4  (Read 2567 times)

0 Members and 1 Guest are viewing this topic.

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
[Linux with Fluxbox] Weird Focus Gain/Lose on Alt-Tab / Alt-F4
« on: February 24, 2015, 03:25:15 pm »
Hi, I'm using Linux (Ubuntu Trusty) with fluxbox (1.3.5) as window manager. When alt-tab'ing, my program behaves weird referring to GainFocus and LostFocus. Here's the Code:

#include <iostream>
#include <SFML/Graphics.hpp>

int main() {
    sf::RenderWindow window(sf::VideoMode(320, 240), "Test");

        window.clear();
        while (window.isOpen()) {
                sf::Event event;
                while (window.pollEvent(event)) {
                        switch (event.type) {
                                case sf::Event::Closed:
                                        window.close();
                                        break;
                                case sf::Event::LostFocus:
                                        std::cout << "Focus Lost" << std::endl;
                                        break;
                                case sf::Event::GainedFocus:
                                        std::cout << "Focus Gained" << std::endl;
                                        break;
                                default:
                                        break;
                        }
                }
                window.display();
        }
}

  • On startup it gains focus (ok).
  • Alt-Tab'ing to unfocus the window causes "Lost, Gained, Lost, Lost"
  • Alt-Tab'ing to refocus the window causes "Gained, Gained"

I think that's weird! Is the problem fluxbox's fault?
I also attached a very short video showing that the behavior can be reproduced.

Kind regards

/EDIT: Changing focus by clicking behaves as expected. Closing by Alt-F4 causes "Lost, Lost, Gained".
« Last Edit: February 24, 2015, 03:36:51 pm by Glocke »
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Weird Focus Gain/Lose on Alt-Tab / Alt-F4
« Reply #1 on: February 24, 2015, 03:33:04 pm »
Would be great if you of someone else could test the same thing with another WM.
Laurent Gomila - SFML developer

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: Weird Focus Gain/Lose on Alt-Tab / Alt-F4
« Reply #2 on: February 24, 2015, 03:47:42 pm »
A friend of mine just tested it with the Gnome Desktop: Alt-Tab works as expected, but moving the window around triggers events. Moving the window inside fluxbox doesn't.
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10226
    • View Profile
    • development blog
    • Email
AW: [Linux with Fluxbox] Weird Focus Gain/Lose on Alt-Tab / Alt-F4
« Reply #3 on: February 24, 2015, 08:58:15 pm »
What version of SFML are you using?
Does the following PR change anything? https://github.com/SFML/SFML/pull/780
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: [Linux with Fluxbox] Weird Focus Gain/Lose on Alt-Tab / Alt-F4
« Reply #4 on: February 24, 2015, 09:44:34 pm »
I just tested the posted example code on my system (CentOS 7 with xfce4) and it behaves reasonably OK although it's slightly odd that whenever I "ALT-tab" away from the program window I get 2 FocusLost events and when I "ALT-tab" back I get 2 FocusGained events. I would have expected 1 event in each case.

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: AW: [Linux with Fluxbox] Weird Focus Gain/Lose on Alt-Tab / Alt-F4
« Reply #5 on: February 25, 2015, 08:26:34 am »
What version of SFML are you using?
2.2

Does the following PR change anything? https://github.com/SFML/SFML/pull/780
Haven't tested yet. I don't have the time to recompile SFML, yet :(
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10226
    • View Profile
    • development blog
    • Email
Re: [Linux with Fluxbox] Weird Focus Gain/Lose on Alt-Tab / Alt-F4
« Reply #6 on: February 25, 2015, 09:03:18 am »
If you use 2.2 you might want to try the latest master since we switched to XCB.
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: [Linux with Fluxbox] Weird Focus Gain/Lose on Alt-Tab / Alt-F4
« Reply #7 on: February 25, 2015, 10:10:05 am »
If you use 2.2 you might want to try the latest master since we switched to XCB.

Well, I just pulled, installed all missing dev-packages, compiled sfml, recompiled my test code with using the new headers and shared objects, but the behavior is still weird :S

/EDIT: Just tested "Openbox": Gain Focus works as expected but Lose Focus causes "Gain, Lose, Gain, Lose"
« Last Edit: February 25, 2015, 11:28:05 am by Glocke »
Current project: Racod's Lair - Rogue-inspired Coop Action RPG