Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ internal unsafe interface IInputRuntime
/// <summary>
/// Set delegate to call when the application changes focus.
/// </summary>
/// <seealso cref="Application.onFocusChanged"/>
/// <seealso cref="Application.focusChanged"/>
Action<bool> onPlayerFocusChanged { get; set; }
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/// <summary>
/// In editor this means the GameView has focus. In a built player this means the player has focus.
/// </summary>
ApplicationFocus = (1 << 0)
ApplicationFocus = (1 << 0),
Comment thread
VeraMommersteeg marked this conversation as resolved.
};

internal partial class InputManager
Expand All @@ -34,7 +34,7 @@

if (!m_Runtime.isInPlayMode)
{
focusState = focus ? FocusFlags.ApplicationFocus : FocusFlags.None;
SetRuntimeFocusState(focus);

Check warning on line 37 in Packages/com.unity.inputsystem/InputSystem/Runtime/InputManager.LegacyFocusHandling.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Runtime/InputManager.LegacyFocusHandling.cs#L37

Added line #L37 was not covered by tests
return;
}

Expand All @@ -59,7 +59,7 @@
{
// If runInBackground is true, no device changes should happen, even when focus is gained. So early out.
// If runInBackground is false, we still want to sync devices when focus is gained. So we need to continue further.
focusState = focus ? FocusFlags.ApplicationFocus : FocusFlags.None;
SetRuntimeFocusState(focus);

Check warning on line 62 in Packages/com.unity.inputsystem/InputSystem/Runtime/InputManager.LegacyFocusHandling.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Runtime/InputManager.LegacyFocusHandling.cs#L62

Added line #L62 was not covered by tests
return;
}

Expand Down Expand Up @@ -122,7 +122,7 @@
#endif

// We set this *after* the block above as defaultUpdateType is influenced by the setting.
focusState = focus ? FocusFlags.ApplicationFocus : FocusFlags.None;
SetRuntimeFocusState(focus);

Check warning on line 125 in Packages/com.unity.inputsystem/InputSystem/Runtime/InputManager.LegacyFocusHandling.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Runtime/InputManager.LegacyFocusHandling.cs#L125

Added line #L125 was not covered by tests
}

/// <summary>
Expand Down Expand Up @@ -150,8 +150,6 @@
/// <summary>
/// Determines if we should exit early from event processing without handling events.
/// </summary>
/// <param name="eventBuffer">The current event buffer</param>
/// <param name="canFlushBuffer">Whether the buffer can be flushed</param>
/// <param name="updateType">The current update type</param>
/// <returns>True if we should exit early, false otherwise.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
42 changes: 22 additions & 20 deletions Packages/com.unity.inputsystem/InputSystem/Runtime/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,20 +268,15 @@
{
get
{
#if UNITY_INPUTSYSTEM_SUPPORTS_FOCUS_EVENTS
return m_Runtime.focusState;
#else
return m_FocusState;
#endif
if (m_Runtime != null)
return m_Runtime.focusState;

return Application.isFocused ? FocusFlags.ApplicationFocus : FocusFlags.None;
Comment thread
VeraMommersteeg marked this conversation as resolved.
Outdated
}
set
{
#if UNITY_INPUTSYSTEM_SUPPORTS_FOCUS_EVENTS
if (m_Runtime != null)
m_Runtime.focusState = value;
#else
m_FocusState = value;
#endif
}
}

Expand Down Expand Up @@ -557,11 +552,11 @@
#else
true;
#endif
private bool applicationHasFocus => (focusState & FocusFlags.ApplicationFocus) != FocusFlags.None;
private bool applicationHasFocus => m_Runtime != null ? m_Runtime.isPlayerFocused : Application.isFocused;

private bool gameHasFocus =>
#if UNITY_EDITOR
m_RunPlayerUpdatesInEditMode || applicationHasFocus || gameShouldGetInputRegardlessOfFocus || isEditorEventPassthroughActive;
m_RunPlayerUpdatesInEditMode || applicationHasFocus || gameShouldGetInputRegardlessOfFocus || isEditorEventPassthroughActive;
#else
applicationHasFocus || gameShouldGetInputRegardlessOfFocus;
#endif
Expand Down Expand Up @@ -2027,11 +2022,6 @@
// we don't know which one the user is going to use. The user
// can manually turn off one of them to optimize operation.
m_UpdateMask = InputUpdateType.Dynamic | InputUpdateType.Fixed;
#if !UNITY_INPUTSYSTEM_SUPPORTS_FOCUS_EVENTS
m_FocusState = Application.isFocused
? m_FocusState | FocusFlags.ApplicationFocus
: m_FocusState & ~FocusFlags.ApplicationFocus;
#endif
#if UNITY_EDITOR
m_EditorIsActive = true;
m_UpdateMask |= InputUpdateType.Editor;
Expand Down Expand Up @@ -2277,9 +2267,7 @@
#endif
m_Runtime.pollingFrequency = pollingFrequency;

focusState = m_Runtime.isPlayerFocused
? focusState | FocusFlags.ApplicationFocus
: focusState & ~FocusFlags.ApplicationFocus;
SetRuntimeFocusState(Application.isFocused);

Check warning on line 2270 in Packages/com.unity.inputsystem/InputSystem/Runtime/InputManager.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Runtime/InputManager.cs#L2270

Added line #L2270 was not covered by tests
Comment thread
chris-massie marked this conversation as resolved.
Outdated

// We only hook NativeInputSystem.onBeforeUpdate if necessary.
if (m_BeforeUpdateListeners.length > 0 || m_HaveDevicesWithStateCallbackReceivers)
Expand Down Expand Up @@ -2451,7 +2439,6 @@
private bool m_NativeBeforeUpdateHooked;
private bool m_HaveDevicesWithStateCallbackReceivers;
#if !UNITY_INPUTSYSTEM_SUPPORTS_FOCUS_EVENTS
private FocusFlags m_FocusState = FocusFlags.ApplicationFocus;
private bool m_DiscardOutOfFocusEvents;
private double m_FocusRegainedTime;
#endif
Expand Down Expand Up @@ -4059,6 +4046,21 @@

#endif // UNITY_INPUTSYSTEM_SUPPORTS_FOCUS_EVENTS

/// <summary>
/// Set the focus state of the runtime, converting from the given boolean to either setting or clearing the focus flag.
/// </summary>
/// <param name="applicationFocus">The application focus state.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetRuntimeFocusState(bool applicationFocus)
{
if (m_Runtime != null)
{
m_Runtime.focusState = applicationFocus
? m_Runtime.focusState | FocusFlags.ApplicationFocus
: m_Runtime.focusState & ~FocusFlags.ApplicationFocus;
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void FinalizeUpdate(InputUpdateType updateType)
{
Expand Down
Loading