From 41e9c20c04bde872c794e2a8287baba627bedc25 Mon Sep 17 00:00:00 2001
From: Monster Iestyn <iestynjealous@ntlworld.com>
Date: Mon, 28 May 2018 21:29:46 +0100
Subject: [PATCH] Ignore mouse button events if the mouse's focus is not
 actually on the window at the moment.

This should hopefully kill the F12 getting stuck issue once and for all.
---
 src/sdl/i_video.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c
index 87ce84158e..4eab0ae3cc 100644
--- a/src/sdl/i_video.c
+++ b/src/sdl/i_video.c
@@ -658,6 +658,14 @@ static void Impl_HandleMouseButtonEvent(SDL_MouseButtonEvent evt, Uint32 type)
 
 	SDL_memset(&event, 0, sizeof(event_t));
 
+	// Ignore the event if the mouse is not actually focused on the window.
+	// This can happen if you used the mouse to restore keyboard focus;
+	// this apparently makes a mouse button down event but not a mouse button up event,
+	// resulting in whatever key was pressed down getting "stuck" if we don't ignore it.
+	// -- Monster Iestyn (28/05/18)
+	if (SDL_GetMouseFocus() != window)
+		return;
+
 	/// \todo inputEvent.button.which
 	if (USE_MOUSEINPUT)
 	{
-- 
GitLab