fix: show/hide cursors properly (#1829)

This commit is contained in:
briaguya 2022-11-01 22:58:09 -04:00 committed by GitHub
commit 2f96e28135
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 47 additions and 47 deletions

View file

@ -352,12 +352,21 @@ static void gfx_dxgi_set_fullscreen_changed_callback(void (*on_fullscreen_change
dxgi.on_fullscreen_changed = on_fullscreen_changed;
}
static void gfx_dxgi_show_cursor(bool hide) {
/**
* @bug When menubar is open in windowed mode and you toggle fullscreen
* ShowCursor no longer responds. Debugging shows the bool to be correct.
**/
ShowCursor(hide);
static void gfx_dxgi_set_cursor_visibility(bool visible) {
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showcursor
// https://devblogs.microsoft.com/oldnewthing/20091217-00/?p=15643
// ShowCursor uses a counter, not a boolean value, and increments or decrements that value when called
// This means we need to keep calling it until we get the value we want
int cursorVisibilityCounter;
if (visible) {
do {
cursorVisibilityCounter = ShowCursor(true);
} while (cursorVisibilityCounter < 0);
} else {
do {
cursorVisibilityCounter = ShowCursor(false);
} while (cursorVisibilityCounter >= 0);
}
}
static void gfx_dxgi_set_fullscreen(bool enable) {
@ -730,7 +739,7 @@ extern "C" struct GfxWindowManagerAPI gfx_dxgi_api = {
gfx_dxgi_set_keyboard_callbacks,
gfx_dxgi_set_fullscreen_changed_callback,
gfx_dxgi_set_fullscreen,
gfx_dxgi_show_cursor,
gfx_dxgi_set_cursor_visibility,
gfx_dxgi_main_loop,
gfx_dxgi_get_dimensions,
gfx_dxgi_handle_events,