Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mouse grab/lock feature when PCSX2 is in focus #12239

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Gonzalosilvalde
Copy link

Description of Changes

This PR adds a new "Mouse Grab" feature to lock the mouse cursor within the PCSX2 window when it is in focus. This functionality is particularly useful for lightgun games that require shooting off the screen to reload, especially when PCSX2 is running in windowed mode or on multi-monitor setups.

The main changes include:

1. Added a new option "Enable Mouse Grab" in the Settings/Interface menu to enable/disable mouse grab.

2. Implemented a QTimer to check the mouse position and keep it within the window bounds when mouse grab is active.

3. Logic to determine when the mouse should be grabbed based on the window state, emulation state, and user settings.

Rationale behind Changes

This feature was requested in issue #11902 to improve the experience for lightgun games, particularly in multi-monitor environments or when PCSX2 is running in windowed mode.

Mouse grab is a common feature in other emulators like RPCS3, Dolphin, and MAME. Implementing it in PCSX2 will provide users with a more consistent and accurate experience for games that rely on this mechanic.

Key Logic for Mouse Grab

The mouse grab feature is enabled only under the following conditions:

1. The "Enable Mouse Grab" setting (located in Settings/Interface) is turned on.

2. PCSX2 is emulating a game.

3. All auxiliary windows (debugger, controller settings, and settings windows) are either closed or hidden.

4. The PCSX2 window is either active or rendering in fullscreen mode .

If any of these conditions are not met, the mouse grab feature is automatically disabled.

Suggested Testing Steps

1. Navigate to Settings/Interface and enable the "Enable Mouse Grab" option.

2. Run PCSX2 in windowed mode and verify that the mouse cursor cannot leave the window bounds while emulation is active.

3. Test it with several games and check that the cursor behaves as it should with the option enabled.

4. Ensure that mouse grab is properly disabled in the following scenarios:

    · The emulator is paused or in an invalid state.

    · The "Enable Mouse Grab" setting is turned off.

    · Auxiliary windows (e.g., debugger, controller settings, or settings windows) are open.

    · The PCSX2 window loses focus or is minimized.

5. Test in multi-monitor setups in fullscreen to confirm that the cursor does not escape to other monitors.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for submitting a contribution to PCSX2

As this is your first pull request, please be aware of the contributing guidelines.

Additionally, as per recent changes in GitHub Actions, your pull request will need to be approved by a maintainer before GitHub Actions can run against it. You can find more information about this change here.

Please be patient until this happens. In the meantime if you'd like to confirm the builds are passing, you have the option of opening a PR on your own fork, just make sure your fork's master branch is up to date!

@F0bes
Copy link
Member

F0bes commented Feb 12, 2025

Can you add prefixes to the names of your commits?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: Mouse grab / lock when PCSX2 is in focus
3 participants