sokol icon indicating copy to clipboard operation
sokol copied to clipboard

sokol_app.h: clean up mouse-locking behaviur on Windows.

Open floooh opened this issue 10 months ago • 0 comments

Ticket https://github.com/floooh/sokol/issues/1211 has uncovered a couple of issues which are not completely fixed (most notably, the locked mouse cursor may remain visible after switching back from the task manager to the application window).

New attempt to make that more robust should look like this:

  • calling sapp_lock_mouse() only sets an 'intended state' flag instead of locking/unlocking the mouse immeditably
  • Q: should sapp_mouse_locked() return the intended state or the actual state?
  • once per frame:
    • if mouse is unlocked but intended state is locked:
      • if we're the foreground window: lock mouse
      • if we're not the foreground window: ignore
    • if mouse is locked and intended state is unlocked: unlock the mouse
    • if mouse is locked and we're currrently not the foreground window => unlock the mouse

Also implement the same for cursor visibilty:

  • maintain two flags: intended vs actual cursor visibility
  • once per frame if intended != actual:
    • call GetCursorInfo once to determine current visibility
    • if still intended != actual:
      • call ShowCursor(TRUE) or ShowCursor(FALSE)
  • note that GetCursorInfo() cannot be called in a loop with ShowCursor(), GetCursorInfo() will not update after ShowCursor is called

floooh avatar Mar 09 '25 16:03 floooh