We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5116 - Tabbing out when cursor is within SDL window bounds and then covered up doesn't update mouse focus
Summary: Tabbing out when cursor is within SDL window bounds and then covered up doesn...
Status: ASSIGNED
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: don't know
Hardware: x86_64 Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.16
Depends on:
Blocks:
 
Reported: 2020-04-30 03:09 UTC by Jeff
Modified: 2020-07-16 18:29 UTC (History)
0 users

See Also:


Attachments
Red cross shows where cursor is located before alt-tabbing (46.98 KB, image/png)
2020-04-30 03:09 UTC, Jeff
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jeff 2020-04-30 03:09:38 UTC
Created attachment 4326 [details]
Red cross shows where cursor is located before alt-tabbing

On Linux if you have an active SDL window and the mouse is within the bounds of the window SDL_GetWindowsFlags reports SDL_WINDOW_MOUSE_FOCUS.  However if while the mouse is within bounds the user alt-tabs to another applications window which overlaps the SDL window (including the current cursor position) the SDL_GetWindowsFlags continues to report SDL_WINDOW_MOUSE_FOCUS.  

It then doesn't update itself until the cursor leaves the bounds of the other application, and crosses into the bounds of the visible portion of the SDL Window.

Using the included C code (it's fairly rudimentary as I usually access SDL from a .NET context via a C# wrapper), it shows white when the window reports Mouse Focus, and Black when it does not.  The picture I have attached shows with a red cross where the cursor is before alt tabbing from the active SDL window to in this case a terminal.

I have confirmed this is still an issue on the latest commit to default, running on XUbuntu 18.04 with the reported video driver being X11.


#include <stdio.h>
#include <SDL2/SDL.h>

int main(int argc, char *argv[])
{
    if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) != 0) {
      SDL_Log("Unable to initialize SDL: %s", SDL_GetError());
      return 1;
    }

    printf("Current: %s\n", SDL_GetCurrentVideoDriver());
    SDL_Window *window = SDL_CreateWindow("Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, 0);
    SDL_Surface *surface = NULL;
    surface = SDL_GetWindowSurface(window);
    SDL_bool poll = SDL_TRUE;    
    while (poll) {
      SDL_Event event;
      while (SDL_PollEvent(&event)) {
        if (event.type == SDL_QUIT) {
          poll = SDL_FALSE;
          break;
        }  
      }

      if (SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_FOCUS) {
        SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF));    
      } else {
        SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, 0x00, 0x00, 0x00));
      }
      SDL_UpdateWindowSurface(window);
      SDL_Delay(500);
    }

    SDL_DestroyWindow(window);

    SDL_Quit();
    return 0;
}