TermUI.Focus.Tracker (TermUI v0.2.0)
View SourceFocus state tracker with action registration.
Maintains focus state and executes registered actions when focus changes. Supports optimization hooks for reducing work when the application is backgrounded.
Usage
{:ok, tracker} = Focus.Tracker.start_link()
# Register focus actions
Focus.Tracker.on_focus_lost(tracker, fn ->
save_state()
end)
Focus.Tracker.on_focus_gained(tracker, fn ->
refresh_content()
end)
# Update focus state
Focus.Tracker.set_focus(tracker, true)
# Query focus state
Focus.Tracker.has_focus?(tracker)
Summary
Functions
Returns a specification to start this module under a supervisor.
Clears all registered actions.
Enables automatic pause when focus is lost.
Enables automatic framerate reduction when focus is lost.
Returns true if the application has focus.
Registers an action to execute when focus is gained.
Registers an action to execute when focus is lost.
Returns true if animations should be paused.
Returns true if framerate should be reduced.
Sets the focus state.
Sets the paused state manually.
Sets the reduced framerate state manually.
Starts the focus tracker.
Types
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clear_actions(GenServer.server()) :: :ok
Clears all registered actions.
@spec enable_auto_pause(GenServer.server()) :: :ok
Enables automatic pause when focus is lost.
@spec enable_auto_reduce_framerate(GenServer.server()) :: :ok
Enables automatic framerate reduction when focus is lost.
@spec has_focus?(GenServer.server()) :: boolean()
Returns true if the application has focus.
@spec on_focus_gained(GenServer.server(), (-> any())) :: :ok
Registers an action to execute when focus is gained.
@spec on_focus_lost(GenServer.server(), (-> any())) :: :ok
Registers an action to execute when focus is lost.
@spec paused?(GenServer.server()) :: boolean()
Returns true if animations should be paused.
This is set when focus is lost and auto_pause is enabled.
@spec reduced_framerate?(GenServer.server()) :: boolean()
Returns true if framerate should be reduced.
This is set when focus is lost and auto_reduce_framerate is enabled.
@spec set_focus(GenServer.server(), boolean()) :: :ok
Sets the focus state.
@spec set_paused(GenServer.server(), boolean()) :: :ok
Sets the paused state manually.
@spec set_reduced_framerate(GenServer.server(), boolean()) :: :ok
Sets the reduced framerate state manually.
@spec start_link(keyword()) :: GenServer.on_start()
Starts the focus tracker.