Skip to content

Ignore mouse motion events when the window does not have keyboard focus #509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static Uint32 sdl_foreground;
static Uint32 sdl_background;
static int sdl_bytesperpixel;
static SDL_PixelFormat *sdl_pixelformat;

static int sdl_window_focusp = 0;
extern void kb_trans(u_short keycode, u_short upflg);
extern int error(const char *s);

Expand Down Expand Up @@ -625,6 +625,14 @@ void process_SDLevents() {
sdl_windowheight = event.window.data2;
sdl_update_viewport(sdl_windowwidth, sdl_windowheight);
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
sdl_window_focusp = 1;
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
sdl_window_focusp = 0;
break;
default:
break;
}
break;
#else
Expand All @@ -634,6 +642,12 @@ void process_SDLevents() {
sdl_windowheight = event.window.data2;
sdl_update_viewport(sdl_windowwidth, sdl_windowheight);
break;
case SDL_EVENT_WINDOW_FOCUS_GAINED:
sdl_window_focusp = 1;
break;
case SDL_EVENT_WINDOW_FOCUS_LOST:
sdl_window_focusp = 0;
break;
#endif
#if SDL_MAJOR_VERSION == 2
case SDL_KEYDOWN:
Expand Down Expand Up @@ -673,6 +687,7 @@ void process_SDLevents() {
int ix, iy;
float x, y;
#endif
if (!sdl_window_focusp) break;
SDL_GetMouseState(&x, &y);
x /= sdl_pixelscale;
y /= sdl_pixelscale;
Expand Down