Skip to content

'instant' KEYDOWN event on a background process when the foreground process is killed #4432

@wraitii

Description

@wraitii

I've encountered a rather peculiar issue.
When an app gains focus, it seems to re-trigger Keydown events (without repeat) incorrectly. This is confirmed only on Linux with X11.

Here's a toy example reproducing the issue:

  • start two instances (distinct processes)
  • Alt-F4 the first
  • It gets killed via SDL_Quit
  • The second gets killed as well, by receiving the keydown events sent to the first window.
    The latter behaviour is incorrect and appears to only happen on linux (we've not been able to reproduce on MacOS/Windows).
    The keydown events that the 2nd process receives have repeat == 0 and no way to distinguish them from real keydown events, as far as I can tell.
#include <SDL2/SDL.h>
 
#include <cstdio>
 
int main(int argc, char ** argv)
{
	// variables
 
	SDL_Init(SDL_INIT_VIDEO);
	SDL_Window * window = SDL_CreateWindow("Test",
		SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0);
 
	bool quit = false;
	SDL_Event event;
 
	bool alt = false;
	bool f4 = false;
	while (!quit)
	{
		SDL_WaitEvent(&event);
 		printf("event: %i\n", event.type);
		switch (event.type)
		{
		case SDL_QUIT:
			quit = true;
			break;
		case SDL_KEYDOWN:
		{
			printf("keydown: %i, repeat %i\n", event.key.keysym.scancode, event.key.repeat);
			if (event.key.keysym.scancode == SDL_SCANCODE_LALT)
				alt = true;
			else if (event.key.keysym.scancode == SDL_SCANCODE_F4)
				f4 = true;
			break;
		}
		case SDL_KEYUP:
		{	
			if (event.key.keysym.scancode == SDL_SCANCODE_LALT)
				alt = false;
			else if (event.key.keysym.scancode == SDL_SCANCODE_F4)
				f4 = false;
			break;
		}
		}
		if (alt && f4)
			break;
	}
 
	SDL_DestroyWindow(window);
	SDL_Quit();
 
	return 0;
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions