first mouse click in window after window creation not registered

@GuildedDoughnut oh, the message box was only for debuggign purpose, it should pop up when the click is found in polling events. I used this because printf (on an allocated console) led the window to actually register the first click inside.
Perhaps the issue is that the window didn’t start focused, but you can read all I tried in my op and the first click never was registered. Only using the fake click, the first user click is registered.
Perhaps i do try to create a mre but i don’t want to spend time on this now.

OK, thank you and sorry for my misunderstanding.

As a work-around, have you tried capturing this in your event loop:

case SDL_WINDOWEVENT:
    switch(event->window.event)
    {
        case SDL_WINDOWEVENT_FOCUS_GAINED:
           int x, y;
           SDL_GetMouseState(&x, &y);
           // Now you know where the mouse is near the time of the focus gained event.
        break;
    }
break;

No, I haven’t. I thought it “too risky” to get the mouse state in case the user did make the window focused by other means (eg. Alt + Tab), also I thought the window was actually focused initially, only not taking the first mouse click. I would have to replace my workaorund and test. I might do this later. Keyboard input is registered initially btw… But I learned from the Win32 doc from Microsoft during researching a solution for this problem that input focus for keyboard and mouse are different.

Edit: i tested switching window focus away and back and clicking then: this works. It only was the first click after creation which did not.

This is what was discussed in the thread:

SDL_SetHint("SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH", "1");

However SDL_HINT_* is the define name in the code. It shouldn’t be quoted as a string.

The string (and environment variable name) does not have “HINT_” in it.

Maybe try:

SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
4 Likes

@zturtleman this did help !

I thank you !

I’ll retract the bug report.

1 Like