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

Author Topic: Windows gains focus only at borded  (Read 16196 times)

0 Members and 1 Guest are viewing this topic.

Melascry

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Windows gains focus only at borded
« Reply #15 on: June 30, 2014, 10:07:32 pm »
Just to add my solution.
This is a Windows only solution.

I actually found a coding solution which just gets around this problem. I don't know if it has been solved yet, but it was not working with my actual version for SFML, 2.1, less than a week old.

So to still get the sf::Event::GainedFocus when clicking in the middle of the window, is used an other event. The sf::Event::MouseEntered event.
It gets trigerred whether or not the window is on focus.
So all that is left is to detect the mouseClick Event.
Which is again trigerred even if the window isn't the focus.

Then to make the window the focus. No function from sfml is provided to force the focus on the window. But there is a win32 api call that does the trick. SetFocus(HWND HandleToTheWindow).

case sf::Event::MouseEntered:
{
        // Retrieving when the mouse gets in the window.
        mouseInScreen = true;
        break;
}
case sf::Event::MouseButtonReleased:
{
        if(mouseInScreen)
        {
                // make the window the current focus.
                SetFocus(this->window->getSystemHandle());
        }
}
 

The only downside, if considered one, is that it will send a lose focus event before sending the GainedFocus event.

I hope this helps anyone having this problem again. Or maybe giving the SFML guys some clue about how to get this fixed. :)

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Windows gains focus only at borded
« Reply #16 on: June 30, 2014, 10:26:22 pm »
I'm pretty sure that got fixed a while ago: https://github.com/SFML/SFML/pull/457

Also, 2.1 is a lot older than a week.

Melascry

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Windows gains focus only at borded
« Reply #17 on: July 01, 2014, 10:52:43 am »
Oh yeah that's not what I meant by a week old ^^'.

I downloaded the 2.1 libs less than a week ago, and that wasn't fix for me :/

Maybe someone can check on their version.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Windows gains focus only at borded
« Reply #18 on: July 01, 2014, 11:01:22 am »
SFML 2.1 doesn't have the fix. You can download the package as often as you want, it just doesn't have it. ;)

If you want a version with the fix, then get the source from GitHub and build SFML yourself. There are no official binaries available as of now.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Melascry

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Windows gains focus only at borded
« Reply #19 on: July 01, 2014, 11:02:41 am »
OOOOk that's why ^^

Thanks then, I'll do this ASAP :)

zzymyn

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Windows gains focus only at borded
« Reply #20 on: August 07, 2014, 09:11:47 am »
There's a workaround here if you don't/can't build SFML 2.2:

You'll need to #include <CommCtrl.h> and link to Comctl32.lib.

Add this function somewhere:

#if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR == 1
        LRESULT CALLBACK GameWindowHook(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
        {
                if (uMsg == WM_MOUSEMOVE)
                {
                        // Supress mouse move events if the window doesn't have the focus:
                        if (GetActiveWindow() != hWnd)
                                return DefWindowProc(hWnd, uMsg, wParam, lParam);
                }
                return DefSubclassProc(hWnd, uMsg, wParam, lParam);
        }
#endif

And add this after you create your SFML window:

#if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR == 1
        SetWindowSubclass(window.getSystemHandle(), &GameWindowHook, 0, 0);
#endif

I haven't thoroughly tested this or anything so I don't recomment putting it in a release build.
« Last Edit: August 07, 2014, 09:20:47 am by zzymyn »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Windows gains focus only at borded
« Reply #21 on: August 07, 2014, 03:19:03 pm »
There are a number of hacks like yours around this problem that 2.1 has.

However, if you can't build the latest version from source yourself, there very little reason why you can't download a pre-built version from the Nightly Builds.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

zzymyn

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Windows gains focus only at borded
« Reply #22 on: August 07, 2014, 03:27:04 pm »
Thanks Hapax. I didn't see this workaround in the bug thread or via a Google search, so I thought it may be useful to people who Google the bug.

It may sound weird, but I prefer to workaround bugs and stick to the stable versions of libraries rather than use nightlies. Better the devil you know, or something.  :P

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Windows gains focus only at borded
« Reply #23 on: August 07, 2014, 03:29:30 pm »
Fair enough but the "stable" release is over a year old now so I would say that there are fewer problems in the latest version than that release  ;D
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Gobbles

  • Full Member
  • ***
  • Posts: 132
    • View Profile
    • Email
Re: Windows gains focus only at borded
« Reply #24 on: August 07, 2014, 03:48:49 pm »
Also I think your logic is a bit backwards. 'Hacks' require you putting in code to deal with the problem, but you never really know what other systems they might affect, hence why they are a hack. The nightlies are at least tested by a multitude of people before and after they are posted, so they are to a degree stable, unofficially anyways.

Or maybe the SFML Team just throws all the code in there and hopes for the best.. you never know with those guys.

select_this

  • Full Member
  • ***
  • Posts: 130
  • Current mood: just ate a pinecone
    • View Profile
    • darrenferrie.com
Re: Windows gains focus only at borded
« Reply #25 on: August 07, 2014, 03:50:57 pm »
Or maybe the SFML Team just throws all the code in there and hopes for the best.. you never know with those guys.

:o
Follow me on Twitter, why don'tcha? @select_this

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Windows gains focus only at borded
« Reply #26 on: August 07, 2014, 05:18:30 pm »
Or maybe the SFML Team just throws all the code in there and hopes for the best.. you never know with those guys.
I assume (hope) that this comment is intended as a bad joke.
In my experience the SFML team is quite careful about what they commit to the master branch and it is generally quite stable. They most certainly don't just throw everything in there and hope for the best.

I really don't get why people attach so much import to a tagged release - it's just a commit at some semi-random point in the commit history where someone decided that "yeah, seems OK now; let's call this version x.y".  Sure, for some projects it may mean that the release has gone through some formal testing and acceptance criteria. But outside the realm of regulated and ISO certified commercial software I doubt that's the case very often.
In any case, the current tip of the master branch of the SFML library is (IMHO) a lot better than the tagged 2.1 release.

Gobbles

  • Full Member
  • ***
  • Posts: 132
    • View Profile
    • Email
Re: Windows gains focus only at borded
« Reply #27 on: August 07, 2014, 06:53:17 pm »
I assume (hope) that this comment is intended as a bad joke.
In my experience the SFML team is quite careful about what they commit to the master branch and it is generally quite stable. They most certainly don't just throw everything in there and hope for the best.

Yes, it was a joke. Really is a no humor zone around here isn't it.