From 3bd6b0eccced25a6d4d53b3d77545ba2fb437711 Mon Sep 17 00:00:00 2001 From: waltje Date: Fri, 15 Dec 2017 00:42:10 -0500 Subject: [PATCH] Hopefully correct setting of host mouse cursor in window and fullscreen modes. --- src/win/win.c | 5 ++++- src/win/win.h | 3 ++- src/win/win_ui.c | 28 ++++++++++++++++++++++------ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/win/win.c b/src/win/win.c index e3d787be5..42cd60050 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -8,7 +8,7 @@ * * Platform main support module for Windows. * - * Version: @(#)win.c 1.0.41 2017/12/13 + * Version: @(#)win.c 1.0.42 2017/12/15 * * Authors: Sarah Walker, * Miran Grca, @@ -740,6 +740,9 @@ doit: /* Release video and make it redraw the screen. */ endblit(); device_force_redraw(); + + /* Finally, handle the host's mouse cursor. */ + show_cursor(video_fullscreen ? 0 : -1); } diff --git a/src/win/win.h b/src/win/win.h index ef6ee67d3..0453ae88a 100644 --- a/src/win/win.h +++ b/src/win/win.h @@ -8,7 +8,7 @@ * * Platform support defintions for Win32. * - * Version: @(#)win.h 1.0.12 2017/12/13 + * Version: @(#)win.h 1.0.13 2017/12/15 * * Authors: Sarah Walker, * Miran Grca, @@ -78,6 +78,7 @@ extern void do_stop(void); /* Internal platform support functions. */ extern void set_language(int id); extern int get_vidpause(void); +extern void show_cursor(int); extern void keyboard_getkeymap(void); extern void keyboard_handle(LPARAM lParam, int infocus); diff --git a/src/win/win_ui.c b/src/win/win_ui.c index ccb118b4b..5632a083a 100644 --- a/src/win/win_ui.c +++ b/src/win/win_ui.c @@ -8,7 +8,7 @@ * * user Interface module for WinAPI on Windows. * - * Version: @(#)win_ui.c 1.0.8 2017/12/15 + * Version: @(#)win_ui.c 1.0.9 2017/12/15 * * Authors: Sarah Walker, * Miran Grca, @@ -64,6 +64,25 @@ static int hook_enabled = 0; static int save_window_pos = 0; +/* Set host cursor visible or not. */ +void +show_cursor(int val) +{ + static int old = -1, vis = -1; + + if (vis == val) return; + + if (val < 0) + val = old; + + old = vis; + while (1) { + if (ShowCursor((val == 0) ? FALSE : TRUE) < 0) break; + } + vis = val; +} + + HICON LoadIconEx(PCTSTR pszIconName) { @@ -938,15 +957,12 @@ plat_mouse_capture(int on) GetClipCursor(&oldclip); GetWindowRect(hwndRender, &rect); ClipCursor(&rect); - while (1) { - if (ShowCursor(FALSE) < 0) break; - } - + show_cursor(0); mouse_capture = 1; } else if (!on && mouse_capture) { /* Disable the in-app mouse. */ ClipCursor(&oldclip); - ShowCursor(TRUE); + show_cursor(1); mouse_capture = 0; }