Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Adds a cursor auto-hide option for when the cursor has been idle for at least two seconds and is over the game window, and the application is focused. Currently only implemented via the Cocoa UI on macOS in hiro.
To
hiro/core/window
, thehidesCursor
stored property is added, along with a setter, so a window knows whether it should use the auto-hide behavior. Todesktop-ui/settings/settings
, theautoHideCursor
property is added togeneral
, and a corresponding option has been added under a new Miscellaneous header under "Options" in the Configuration window. An option is also added to the main menu bar viadesktop-ui/presentation/presentation.cpp
and state there is kept in sync with the Configuration window option.Toggling the option calls out to specifically the presentation window, calling
setHidesCursor()
. Correspondly, during initialization, the option only is referenced when starting up the presentation window (desktop-ui/presentation/presentation.cpp:230
), as other windows should never auto-hide the cursor.On the concrete implementation side, in Cocoa,
hidesCursor
defaults tofalse
(hiro/cocoa/window.cpp:9
).Important
Future implementations for other UIs should initialize
hidesCursor
in the concretewindow.cpp
implementation asfalse
, so the cursor is never hidden over non-game windows.The Cocoa implementation is fairly straightforward; on window initialization, an
NSTimer
is added to the run loop that ticks every second and callshideCursor()
, and anNSTrackingArea
is created for the bounds of the window on every size event.hideCursor()
hides the cursor ifhidesCursor
is true, at least 2 seconds idle have elapsed, and the cursor is within the tracking area for the window. Cursor presence in the window is tracked with-(void)mouseEntered:(NSEvent *)
and-(void)mouseExited:(NSEvent *)
and thecursorIsInWindow
property. Cursor is hidden simply via[NSCursor setHiddenUntilMouseMoves:YES];
Motivation
Hiding the mouse cursor when it falls idle over the game window is typical for most games and emulators, and is probably behavior that users will generally want.
Discussion / Possible Issues
Currently, the option is only implemented on macOS, and so the configuration window and menu bar options are currently hidden behind a simple
#ifdef PLATFORM_MACOS
. I am not sure if I will be able to effectively test this for other platforms and UIs since my only machine is Apple Silicon (though I will try), so I wanted to go ahead and get this in flight for review as is just in case.In terms of UI/UX, I am not sure if the current location is the best place for the option to live in the Configuration window. Currently, the option lives both there as well as the menu bar. I considered only having the option in the menu bar as well, which might fit better. Currently there are no other options in ares that are settable both via the menu bar as well as the Configuration window. I will of course defer to maintainers' thoughts on this.