diff --git a/source/main.cpp b/source/main.cpp index a7b2b6fad4..fa785b6a11 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -90,6 +90,18 @@ static InReaction MainInputHandler(const SDL_Event_* ev) { switch(ev->ev.type) { + case SDL_ACTIVEEVENT: + if (ev->ev.active.state == SDL_APPMOUSEFOCUS) + { + // Tell renderer not to render cursor if mouse focus is lost + // this restores system cursor, until/if focus is regained + if (!ev->ev.active.gain) + RenderCursor(false); + else + RenderCursor(true); + } + break; + case SDL_QUIT: kill_mainloop(); break; diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index 43a231342d..5ec7b6ad0f 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -114,6 +114,7 @@ ERROR_TYPE(System, RequiredExtensionsMissing); bool g_DoRenderGui = true; bool g_DoRenderLogger = true; +bool g_DoRenderCursor = true; static const int SANE_TEX_QUALITY_DEFAULT = 5; // keep in sync with code @@ -273,15 +274,18 @@ void Render() ogl_WarnIfError(); // Draw the cursor (or set the Windows cursor, on Windows) - CStrW cursorName = g_CursorName; - if (cursorName.empty()) + if (g_DoRenderCursor) { - cursor_draw(g_VFS, NULL, g_mouse_x, g_yres-g_mouse_y); - } - else - { - if (cursor_draw(g_VFS, cursorName.c_str(), g_mouse_x, g_yres-g_mouse_y) < 0) - LOGWARNING(L"Failed to draw cursor '%ls'", cursorName.c_str()); + CStrW cursorName = g_CursorName; + if (cursorName.empty()) + { + cursor_draw(g_VFS, NULL, g_mouse_x, g_yres-g_mouse_y); + } + else + { + if (cursor_draw(g_VFS, cursorName.c_str(), g_mouse_x, g_yres-g_mouse_y) < 0) + LOGWARNING(L"Failed to draw cursor '%ls'", cursorName.c_str()); + } } // restore @@ -884,6 +888,11 @@ void RenderLogger(bool RenderingState) g_DoRenderLogger = RenderingState; } +void RenderCursor(bool RenderingState) +{ + g_DoRenderCursor = RenderingState; +} + static bool Autostart(const CmdLineArgs& args) { /* diff --git a/source/ps/GameSetup/GameSetup.h b/source/ps/GameSetup/GameSetup.h index 60073e8871..4e78f47cca 100644 --- a/source/ps/GameSetup/GameSetup.h +++ b/source/ps/GameSetup/GameSetup.h @@ -51,6 +51,12 @@ enum InitFlags extern void RenderGui(bool RenderingState); extern void RenderLogger(bool RenderingState); +/** + * enable/disable rendering of the cursor - this does not hide cursor, but reverts to OS style + */ +extern void RenderCursor(bool RenderingState); + + class CmdLineArgs; extern void Init(const CmdLineArgs& args, int flags); extern void InitGraphics(const CmdLineArgs& args, int flags);