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

libobs: Always explicitly check modifiers in macOS hotkey event handler #11100

Merged
merged 1 commit into from
Aug 10, 2024

Conversation

jcm93
Copy link
Contributor

@jcm93 jcm93 commented Aug 8, 2024

Description

Changes the macOS hotkey system event handler to always explicitly register the state of the modifier keys, regardless of the event type that was received.

Motivation and Context

It turns out that applications will not always receive a "flags changed" NSEvent from the system when a modifier key status is either pressed or let go of. These events seem particularly likely to be eaten by the system or other applications if the modifier is released, and that action results in the application losing focus (Command + Tab, for example), though it can also happen under some other circumstances. This means that OBS can often spuriously think that a modifier key is held when it is not, or, more rarely, that a modifier is not held when it is. This will in turn cause OBS's hotkey system to fail to properly register hotkey events.

Explicitly checking and registering the state of these modifier keys on every monitored keypress is slightly less efficient, but removes all reliance on these events, and means that OBS will always know accurately what modifier keys are held.

Should resolve #4126, #9023, possibly others.

How Has This Been Tested?

Tested on Apple Silicon, macOS 15. Verified that both one-shot and "push-to" hotkeys now work much more reliably with OBS focused and unfocused, particularly when tabbing into and out of OBS.

Other

I thought about possibly basing this off of #9583, in order to take advantage of the better TCC granularity of CGEventTap at the same time as fixing this bug. If maintainers think that that is a good idea, would be happy to rewrite this from there, or we could maybe even just merge this fix on top of that PR instead (@gxalpha @PatTheMav thoughts?)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

@PatTheMav
Copy link
Member

I'm currently working on a refactor of the entire implementation, so it should be good enough to just fix the issue currently affecting users and ponder an alternative implementation separately.

Copy link
Member

@PatTheMav PatTheMav left a comment

Choose a reason for hiding this comment

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

I think this should be sufficient, as the modifier value is kept for as long as the corresponding keys are held (i.e., the modifier value does not reset for the key down/key up event).

@WizardCM WizardCM added Bug Fix Non-breaking change which fixes an issue macOS Affects macOS labels Aug 10, 2024
@WizardCM WizardCM merged commit 66ff8cb into obsproject:master Aug 10, 2024
15 checks passed
@RytoEX RytoEX added this to the OBS Studio 31 milestone Aug 11, 2024
@JRemitz
Copy link

JRemitz commented Dec 29, 2024

This change has been working great, however I still have a handful of instances where the hotkey registration is lost and stop working during an active stream. My only workaround is to reregister the desired hotkeys while streaming for a one-time use.

I'm not sure how to collect information to give as feedback. Is there a way that I can forcibly restart the registration listener during a stream? Or any way to collect information when I see it happen again to give as feedback?

@jcm93
Copy link
Contributor Author

jcm93 commented Dec 29, 2024

Any remaining reliability issues are likely due to the issue resolved by #11663

If anything calls InputMethodChangedProc, hotkeys will stop working for the duration of the session; this can happen under a variety of circumstances.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Fix Non-breaking change which fixes an issue macOS Affects macOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MacBook M1 hotkey issues - not working when not in focus and erratically when in focus.
5 participants