pub struct NightLight { /* private fields */ }Implementations§
Source§impl NightLight
impl NightLight
Sourcepub const MIN_NIGHT_COLOR_TEMP: u16 = 1_200u16
pub const MIN_NIGHT_COLOR_TEMP: u16 = 1_200u16
The lowest Kelvin value last known to be valid (as of Oct. 2023).
pub const MAX_NIGHT_COLOR_TEMP: u16 = 6_500u16
Sourcepub const WARMEST_NIGHT_COLOR_TEMP: u16 = 1_200u16
pub const WARMEST_NIGHT_COLOR_TEMP: u16 = 1_200u16
Alias for minimum.
Sourcepub const COLDEST_NIGHT_COLOR_TEMP: u16 = 6_500u16
pub const COLDEST_NIGHT_COLOR_TEMP: u16 = 6_500u16
Alias for maximum.
Sourcepub const DEFAULT_NIGHT_COLOR_TEMP: u16 = 4_000u16
pub const DEFAULT_NIGHT_COLOR_TEMP: u16 = 4_000u16
Official default as of Dec. 2023. Found out by alternatingly setting the warmth factor to None and a concrete value until no difference could be visually perceived anymore, then snapping to a plausible round number.
Sourcepub const DEFAULT_WARMTH: f32 = 0.471698105f32
pub const DEFAULT_WARMTH: f32 = 0.471698105f32
Equivalent of Self::DEFAULT_NIGHT_COLOR_TEMP. See Self::warmth().
Sourcepub const REASONABLE_INIT_DELAY: Duration
pub const REASONABLE_INIT_DELAY: Duration
The delay Self::init_with_strictness() should wait for, if no better information is available. (Defined as a common animation duration.)
Sourcepub const EXPIRATION_TIMEOUT: Duration
pub const EXPIRATION_TIMEOUT: Duration
Duration after which an instance expires. May be shortened in future versions.
Sourcepub fn from_reg() -> Result<Self, Error>
pub fn from_reg() -> Result<Self, Error>
Creates a strict instance using Self::from_reg_with_strictness().
pub fn from_reg_lenient() -> Result<Self, Error>
Sourcepub fn from_reg_with_strictness(strictness: Strictness) -> Result<Self, Error>
pub fn from_reg_with_strictness(strictness: Strictness) -> Result<Self, Error>
Returns a fallback instance if one of the registry values doesn’t exist in lenient mode.
pub fn from_bytes(bytes: NightLightBytes) -> Result<Self, ParseError>
pub fn from_bytes_lenient(bytes: NightLightBytes) -> Result<Self, ParseError>
pub fn from_bytes_with_strictness( bytes: NightLightBytes, strictness: Strictness, ) -> Result<Self, ParseError>
pub fn lenient_fallback() -> Self
Sourcepub fn init(delay: Duration, also_wait_after: bool) -> Result<(), Error>
pub fn init(delay: Duration, also_wait_after: bool) -> Result<(), Error>
Initializes with strict instances using Self::init_with_strictness().
Sourcepub fn init_with_strictness(
delay: Duration,
also_wait_after: bool,
strictness: Strictness,
) -> Result<(), Error>
pub fn init_with_strictness( delay: Duration, also_wait_after: bool, strictness: Strictness, ) -> Result<(), Error>
Performs actions that are necessary after OS log-on to be able to change the color temperature without activating one of the boolean states. Also restores a warm color temperature after turning the screen back on. (As of Dec. 2023.)
Concretely, it activates preview mode, waits for the delay duration, and deactivates it again. Doesn’t write a registry value and wait, if preview mode was already active. To make the intermediate previewing as invisible as possible, the color temperature is temporarily set to the coldest possible, if Night Light is inactive.
Normally to be used with Self::REASONABLE_INIT_DELAY. Additionally waiting after the last write can be activated in a command line context, if the user plans to follow the action up with another write.
Sourcepub fn export_reg<T: AsRef<Path>>(file_path: T) -> Result<(), Error>
pub fn export_reg<T: AsRef<Path>>(file_path: T) -> Result<(), Error>
Writes the Night Light registry values to a file in .reg file format.
Sourcepub fn delete_reg() -> Result<(), Error>
pub fn delete_reg() -> Result<(), Error>
Deletes the Night Light registry values to reset the Windows feature. May help when they’ve been corrupted and Night Light became unusable. User should restart or at least log-off after deletion.
pub fn monitor<F, T, E>( stop_receiver: Option<Receiver<T>>, callback: F, ) -> Result<T, MonitorLoopError<E>>
Sourcepub fn sunset_to_sunrise_possible() -> Option<bool>
pub fn sunset_to_sunrise_possible() -> Option<bool>
Whether the “Sunset to sunrise” option is available, because location services are turned on. If not, the explicit schedule is the fallback. Returns None on registry access failure.
Sourcepub fn active(&self) -> bool
pub fn active(&self) -> bool
Whether night time color temperature is currently in effect, be it because manually chosen or by schedule.
pub fn set_active(&mut self, active: bool)
pub fn transition_cause(&self) -> TransitionCause
Sourcepub fn state_modified_filetime(&self) -> i64
pub fn state_modified_filetime(&self) -> i64
The state registry value’s modification timestamp as a FILETIME (always greater than 0).
Sourcepub fn latest_possible_settings_modified_epoch_secs(&self) -> u32
pub fn latest_possible_settings_modified_epoch_secs(&self) -> u32
The settings registry value’s modification timestamp, or a value somewhat later when many changes were performed in quick succession (e.g., by moving the slider in the official settings).
pub fn schedule_active(&self) -> bool
pub fn set_schedule_active(&mut self, schedule_active: bool)
Sourcepub fn schedule_type(&self) -> ScheduleType
pub fn schedule_type(&self) -> ScheduleType
The theoretical schedule type. The one really in effect also depends on the state of location services. See also other getter.
Sourcepub fn effective_schedule_type(&self) -> Option<ScheduleType>
pub fn effective_schedule_type(&self) -> Option<ScheduleType>
The schedule type really in effect, which also depends on location services being turned on or off. It’s unknown how Windows behaves when location services are turned on, but the location still can’t be retrieved for a longer period of time. Returns None on schedule type “Sunset to sunrise”, if Self::sunset_to_sunrise_possible() did.
Sourcepub fn set_schedule_type(&mut self, schedule_type: ScheduleType)
pub fn set_schedule_type(&mut self, schedule_type: ScheduleType)
Because the explicit schedule is the fallback of “Sunset to sunrise”, there won’t be a change of the effective schedule type in the official Night Light settings when location services are off. The change is still perfomed however - just that it can only become effective when location services are turned on.
Sourcepub fn sunset_to_sunrise(&self) -> Option<ClockTimeFrame>
pub fn sunset_to_sunrise(&self) -> Option<ClockTimeFrame>
Returns None, if all of the respective hour and minute values in the registry value were zero.
Sourcepub fn scheduled_night(&self) -> ClockTimeFrame
pub fn scheduled_night(&self) -> ClockTimeFrame
The clock times defining the explicit schedule.
Sourcepub fn set_scheduled_night(&mut self, scheduled_night: ClockTimeFrame)
pub fn set_scheduled_night(&mut self, scheduled_night: ClockTimeFrame)
You can use any combination of clock times precise to the minute, and it will be adhered to. The time pickers in the official Night Light settings, however, will just display the times with 15-minute accuracy, rounded down. Two times the same clock time means zero-length night.
Sourcepub fn night_color_temp(&self) -> Option<u16>
pub fn night_color_temp(&self) -> Option<u16>
The night time color temperature in Kelvin. May possibly be out of the range of the constants, if Microsoft changed them. Returns None, if the information wasn’t present in the registry value, in which case Windows applies the default.
Sourcepub fn night_color_temp_in_range(&self) -> Option<u16>
pub fn night_color_temp_in_range(&self) -> Option<u16>
The color temperature guaranteed to be in the range of the constants.
Sourcepub fn set_night_color_temp(&mut self, night_color_temp: Option<u16>)
pub fn set_night_color_temp(&mut self, night_color_temp: Option<u16>)
Windows corrects the value to lie in the valid range. None makes Windows apply the default.
Sourcepub fn warmth(&self) -> Option<f32>
pub fn warmth(&self) -> Option<f32>
A factor in the range from 0 to 1, based on the color temperature range constants. May return None like the color temperature getter. Corresponds to the “Strength” slider in the official Night Light settings, which shows a percentage.
Sourcepub fn set_warmth(&mut self, warmth: Option<f32>)
pub fn set_warmth(&mut self, warmth: Option<f32>)
Steps in the upper range are perceived as more intense, which is why they should be smaller to achieve the same step in perception as larger steps in the lower range. There isn’t a one-size-fits-all correction curve, since color temperature perception also depends on light intensity (see https://en.wikipedia.org/wiki/Kruithof_curve). But gamma correction (exponentiation) still seems suitable.
§Panics
Panics on NaN.
Sourcepub fn night_preview_active(&self) -> bool
pub fn night_preview_active(&self) -> bool
Whether preview mode with a hard change (as opposed to a smooth transition) to night color temperature is in effect. The official Night Light settings activate this while moving the color temperature slider.
pub fn set_night_preview_active(&mut self, night_preview_active: bool)
Sourcepub fn set_uses_12_hour_clock(&mut self, uses_12_hour_clock: bool)
pub fn set_uses_12_hour_clock(&mut self, uses_12_hour_clock: bool)
Only for display purposes.
pub fn to_json(&self) -> String
Sourcepub fn write_to_reg(self) -> Result<(), Error>
pub fn write_to_reg(self) -> Result<(), Error>
Writes the data to the registry values, which immediately applies it.