I’m not sure if this is a bug or expected behaviour, but when setting relative mouse mode I get mouse motion events even if SDL window does not have focus. Also initially I get the events with an invalid window id, until window gains focus.
Here is a minimal example:
#include <stdio.h>
#include "SDL.h"
int main(int argc, char const* argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window* window = SDL_CreateWindow("window", 0,0, 0,0, 0);
SDL_SetRelativeMouseMode(SDL_TRUE);
SDL_bool run = SDL_TRUE;
while(run)
{
SDL_Event e;
while(SDL_PollEvent(&e))
{
switch(e.type)
{
case SDL_MOUSEBUTTONDOWN:
run = SDL_FALSE;
break;
case SDL_MOUSEMOTION:
printf("%d\n", e.motion.windowID);
break;
}
}
}
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
In this particular case when I run the program the window does not have focus and moving the mouse I get motion events with window id 0 (invalid, SDL_GetWindowFromID returns NULL), then if I alt-tab to the window I get them with id 2(ok, returns the created window), after alt-tabbing again away from the window - still get id 2.
If that’s normal behaviour can I generally consider id 0 a special NULL id? Or should I always set the relative mouse mode after acquiring focus (waiting for SDL_WINDOWEVENT_FOCUS_GAINED)?
I’m testing on a linux system with X11, and I tried SDL versions 2.0.0, 2.0.7 and the default mercurial branch.