NightLight

Struct NightLight 

Source
pub struct NightLight { /* private fields */ }

Implementations§

Source§

impl NightLight

Source

pub const MIN_NIGHT_COLOR_TEMP: u16 = 1_200u16

The lowest Kelvin value last known to be valid (as of Oct. 2023).

Source

pub const MAX_NIGHT_COLOR_TEMP: u16 = 6_500u16

Source

pub const WARMEST_NIGHT_COLOR_TEMP: u16 = 1_200u16

Alias for minimum.

Source

pub const COLDEST_NIGHT_COLOR_TEMP: u16 = 6_500u16

Alias for maximum.

Source

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.

Source

pub const DEFAULT_WARMTH: f32 = 0.471698105f32

Source

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.)

Source

pub const EXPIRATION_TIMEOUT: Duration

Duration after which an instance expires. May be shortened in future versions.

Source

pub fn from_reg() -> Result<Self, Error>

Creates a strict instance using Self::from_reg_with_strictness().

Source

pub fn from_reg_lenient() -> Result<Self, Error>

Source

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.

Source

pub fn from_bytes(bytes: NightLightBytes) -> Result<Self, ParseError>

Source

pub fn from_bytes_lenient(bytes: NightLightBytes) -> Result<Self, ParseError>

Source

pub fn from_bytes_with_strictness( bytes: NightLightBytes, strictness: Strictness, ) -> Result<Self, ParseError>

Source

pub fn lenient_fallback() -> Self

Source

pub fn init(delay: Duration, also_wait_after: bool) -> Result<(), Error>

Initializes with strict instances using Self::init_with_strictness().

Source

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.

Source

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.

Source

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.

Source

pub fn monitor<F, T, E>( stop_receiver: Option<Receiver<T>>, callback: F, ) -> Result<T, MonitorLoopError<E>>
where F: FnMut(RegValueId) -> Option<Result<T, E>>, T: Default,

Source

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.

Source

pub fn active(&self) -> bool

Whether night time color temperature is currently in effect, be it because manually chosen or by schedule.

Source

pub fn set_active(&mut self, active: bool)

Source

pub fn transition_cause(&self) -> TransitionCause

Source

pub fn state_modified_filetime(&self) -> i64

The state registry value’s modification timestamp as a FILETIME (always greater than 0).

Source

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).

Source

pub fn schedule_active(&self) -> bool

Source

pub fn set_schedule_active(&mut self, schedule_active: bool)

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn scheduled_night(&self) -> ClockTimeFrame

The clock times defining the explicit schedule.

Source

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.

Source

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.

Source

pub fn night_color_temp_in_range(&self) -> Option<u16>

The color temperature guaranteed to be in the range of the constants.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn set_night_preview_active(&mut self, night_preview_active: bool)

Source

pub fn set_uses_12_hour_clock(&mut self, uses_12_hour_clock: bool)

Only for display purposes.

Source

pub fn to_json(&self) -> String

Source

pub fn write_to_reg(self) -> Result<(), Error>

Writes the data to the registry values, which immediately applies it.

Trait Implementations§

Source§

impl Debug for NightLight

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for NightLight

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MapSelf for T

Source§

fn map_self<O, T>(self, op: O) -> T
where O: FnOnce(Self) -> T, Self: Sized,

Example: Read more
Source§

fn map_self_or_keep<O>(self, op: O) -> Self
where O: FnOnce(&Self) -> Option<Self>, Self: Sized,

Example: Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.