[PATCH] Allow mouse warp only when window in focus + debug for window events |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
- Subject: [PATCH] Allow mouse warp only when window in focus + debug for window events
- From: Eero Tamminen <oak@xxxxxxxxxxxxxx>
- Date: Sat, 9 Nov 2019 00:59:54 +0200
---
src/main.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 53 insertions(+), 9 deletions(-)
diff --git a/src/main.c b/src/main.c
index e1a6f191..1bfb1207 100644
--- a/src/main.c
+++ b/src/main.c
@@ -80,7 +80,9 @@ static int nVBLSlowdown = 1; /* host VBL wait multiplier */
static bool bEmulationActive = true; /* Run emulation when started */
static bool bAccurateDelays; /* Host system has an accurate SDL_Delay()? */
+
static bool bIgnoreNextMouseMotion = false; /* Next mouse motion will be ignored (needed after SDL_WarpMouse) */
+static bool bWinInFocus; /* whether window has focus */
/*-----------------------------------------------------------------------*/
/**
@@ -435,12 +437,17 @@ static void Main_CheckForAccurateDelays(void)
* Set mouse pointer to new x,y coordinates and set flag to ignore
* the mouse event that is generated by SDL_WarpMouse().
*
- * Skip the request is it's not position restore and mouse warping is disabled.
+ * Skip the request if:
+ * - it's not position restore and mouse warping is disabled, or
+ * - window doesn't include mouse or have keyboard focus
+ * (i.e. user isn't interacting with it)
*/
void Main_WarpMouse(int x, int y, bool restore)
{
if (!(restore || ConfigureParams.Screen.bMouseWarp))
return;
+ if (!bWinInFocus)
+ return;
#if WITH_SDL2
SDL_WarpMouseInWindow(sdlWindow, x, y);
#else
@@ -505,6 +512,7 @@ void Main_EventHandler(void)
SDL_Event event;
int events;
int remotepause;
+ const char *evname;
do
{
@@ -635,15 +643,51 @@ void Main_EventHandler(void)
break;
case SDL_WINDOWEVENT:
- if (event.window.event == SDL_WINDOWEVENT_EXPOSED
- && !ConfigureParams.Screen.bUseSdlRenderer)
- {
- /* Hack: Redraw screen here when going into
- * fullscreen mode without SDL renderer */
- sdlscrn = SDL_GetWindowSurface(sdlWindow);
- Screen_SetFullUpdate();
- Statusbar_Init(sdlscrn);
+ switch(event.window.event) {
+ case SDL_WINDOWEVENT_EXPOSED:
+ evname = "EXPOSED";
+ if (!ConfigureParams.Screen.bUseSdlRenderer)
+ {
+ /* Hack: Redraw screen here when going into
+ * fullscreen mode without SDL renderer */
+ sdlscrn = SDL_GetWindowSurface(sdlWindow);
+ Screen_SetFullUpdate();
+ Statusbar_Init(sdlscrn);
+ }
+ break;
+ /* keyboard focus */
+ case SDL_WINDOWEVENT_FOCUS_GAINED:
+ evname = "FOCUS_GAINED";
+ bWinInFocus = true;
+ break;
+ case SDL_WINDOWEVENT_FOCUS_LOST:
+ evname = "FOCUS_LOST";
+ bWinInFocus = false;
+ break;
+ /* mouse focus */
+ case SDL_WINDOWEVENT_ENTER:
+ evname = "ENTER";
+ bWinInFocus = true;
+ break;
+ case SDL_WINDOWEVENT_LEAVE:
+ evname = "LEAVE";
+ bWinInFocus = false;
+ break;
+ /* rest of window events */
+ case SDL_WINDOWEVENT_SIZE_CHANGED: evname = "SIZE_CHANGED"; break;
+ case SDL_WINDOWEVENT_TAKE_FOCUS:evname = "TAKE_FOCUS"; break;
+ case SDL_WINDOWEVENT_MOVED: evname = "MOVED"; break;
+ case SDL_WINDOWEVENT_RESIZED: evname = "RESIZED"; break;
+ case SDL_WINDOWEVENT_RESTORED: evname = "RESTORED"; break;
+ case SDL_WINDOWEVENT_MAXIMIZED: evname = "MAXIMIZED"; break;
+ case SDL_WINDOWEVENT_MINIMIZED: evname = "MINIMIZED"; break;
+ case SDL_WINDOWEVENT_SHOWN: evname = "SHOWN"; break;
+ case SDL_WINDOWEVENT_HIDDEN: evname = "HIDDEN"; break;
+ case SDL_WINDOWEVENT_CLOSE: evname = "CLOSE"; break;
+ default: evname = "Unknown";
}
+ Log_Printf(LOG_DEBUG, "Window event: %s\n", evname);
+
/* Note: any changes here should most likely be done
* also in sdlgui.c::SDLGui_DoDialog()
*/
--
2.20.1
--------------05BFFFEBD505E9D8E6925037--