hinoirisetr 1.6.2

A daemon to dim the screen at night
Documentation
日の入りsetr (hinoirisetr)
==========================

[![dependency status](https://deps.rs/repo/gitea/git.vavakado.xyz/vavakado/hinoirisetr/status.svg)](https://deps.rs/repo/gitea/git.vavakado.xyz/vavakado/hinoirisetr)

**hinoirisetr** is a lightweight daemon that automatically adjusts your
screen's color temperature and gamma based on the time of day. It helps reduce
eye strain and improve sleep quality by dimming the screen at night. The daemon
supports multiple backends for flexibility and can be controlled at runtime via
a Unix socket.


Features
--------

 -  **Automatic Screen Adjustment**: Adjusts screen temperature and gamma based
    on the time of day (e.g., warmer at night, cooler during the day).
 -  **Multiple Backends**: Supports various backends for controlling screen
    settings:
     -  `ddcutil`
     -  `hyprctl` (with `hyprsunset`)
     -  `wayland`
     -  `xsct`
     -  `acpi`
 -  **Runtime Control**: Use the CLI utility to enable, disable, toggle, or
    reload the configuration without restarting the daemon.
 -  **Configuration Reload**: Automatically reloads the configuration file when
    changes are detected.
 -  **Desktop Notifications**: Optionally send notifications with the current
    status.


Backends
--------

hinoirisetr uses backends to apply screen adjustments. You can choose different
backends for temperature and gamma control:

 -  **ddcutil**: Controls monitor settings via the DDC/CI protocol (useful for
    external monitors).
 -  **hyprctl**: Controls settings in the Hyprland compositor (requires
    `hyprsunset`).
 -  wayland:  Adjusts both screen color temperature and gamma.
 -  **xsct**: Adjusts both screen color temperature and gamma.
 -  **acpi**: Adjusts screen gamma, using native ACPI(laptop monitors)

Select the appropriate backend based on your system and preferences. Ensure the
required binaries are installed and available in your `PATH`.


Installation
------------

hinoirisetr is written in Rust. To build and install it:

1.  **Install Rust and Cargo** if you haven't already:

    ~~~~ sh
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    ~~~~

2.  **Install**:

    If you have `cargo-binstall`:

    ~~~~ sh
    cargo binstall hinoirisetr
    ~~~~

    (We do not sign builds yet)

    Built from sources:

    ~~~~ sh
    cargo install hinoirisetr
    ~~~~

    If you don't want to have the `wayland` backend:

    ~~~~ sh
    cargo install hinoirisetr --no-default-features
    ~~~~

Alternatively, if using Nix, you can use the provided flake:

~~~~ sh
nix profile add git+https://git.vavakado.xyz/me/hinoirisetr
~~~~

or just try it out temporarily:

~~~~ sh
nix run git+https://git.vavakado.xyz/me/hinoirisetr
~~~~


Configuration
-------------

hinoirisetr uses a TOML configuration file located at:

 -  `$XDG_CONFIG_HOME/hinoirisetr.toml` (if `XDG_CONFIG_HOME` is set)
 -  `~/.config/hinoirisetr.toml` (otherwise)

If no configuration file is found, the daemon will use default settings and log
a warning.

### Configuration Options

The configuration file supports the following options:

 -  **Global Options**:

     -  `notification_timeout`: Timeout in milliseconds for desktop
        notifications (default: 5000).
     -  `disable_timeout`: Timeout in seconds for disabling adjustments
        (default: 300).
     -  `gamma_backend`: Backend for gamma control (options: `hyprctl`,
        `ddcutil`, `xsct`, `wayland`, `acpi`, `none`).
     -  `temp_backend`: Backend for temperature control (options: `hyprctl`,
        `xsct`, `wayland`, `none`).

 -  **Section `[gamma]`**:

     -  `day`: Gamma percentage for daytime (0–100, default: 100).
     -  `night`: Gamma percentage for nighttime (0–100, default: 95).

 -  **Section `[temp]`**:

     -  `day`: Color temperature in Kelvin for daytime (1000–20000, default:
        6500).
     -  `night`: Color temperature in Kelvin for nighttime (1000–20000,
        default: 2500).

 -  **Section `[time]`**:
     -  `sunset_start`: Hour (0–23) when sunset starts.
     -  `sunset_end`: Hour (0–23) when sunset ends.
     -  `sunrise_start`: Hour (0–23) when sunrise starts.
     -  `sunrise_end`: Hour (0–23) when sunrise ends.
     -  `interpolation_temp`: Interpolation method for temperature (options:
        `linear`, `cubic`, `cubiceaseinout`, `cosine`, `exponential`).
     -  `interpolation_gamma`: Interpolation method for gamma (same options as
        above).

**Note**: The daemon will interpolate settings between day and night during
sunrise and sunset periods using the specified interpolation methods.

### Example Configuration

~~~~ toml
notification_timeout = 3000
gamma_backend = "xsct"
temp_backend = "xsct"

[gamma]
day = 100
night = 90

[temp]
day = 6500
night = 3500

[time]
sunset_start = 18
sunset_end = 21
sunrise_start = 5
sunrise_end = 8
interpolation_temp = "cubic"
interpolation_gamma = "linear"
~~~~


Usage
-----

### Starting the Daemon

To start the daemon, simply run:

~~~~ sh
hinoirisetr
~~~~

It will load the configuration, check for required backends, and start
adjusting the screen settings based on the current time.

### Runtime Control via Unix Socket / CLI

hinoirisetr listens on a Unix socket at `/tmp/hinoirisetr-$USER.sock` for
control commands. Available commands include:

 -  **status**: Prints the current status (e.g., “dimming - temp: 6500K, gamma:
    100%”).
 -  **status\_notify**: Sends the current status via a desktop notification.
 -  **enable**: Enables automatic adjustments.
 -  **disable**: Disables automatic adjustments and sets day settings.
 -  **toggle**: Toggles between enabled and disabled states.
 -  **enable\_temp**: Enables temperature adjustments.
 -  **disable\_temp**: Disables temperature adjustments.
 -  **toggle\_temp**: Toggles temperature adjustments.
 -  **enable\_gamma**: Enables gamma adjustments.
 -  **disable\_gamma**: Disables gamma adjustments.
 -  **toggle\_gamma**: Toggles gamma adjustments.
 -  **reload**: Reloads the configuration file.
 -  **reload\_full**: Reloads the configuration file and restarts backend.
    threads

To send a command, you can use `hinoirisetr` iteslf:

~~~~ sh
hinoirisetr toggle
~~~~

### Logging

Set the `RUST_LOG` environment variable to control log verbosity:

 -  `trace` (only on debug builds)
 -  `debug` (only on debug builds)
 -  `info` (default)
 -  `warn`
 -  `error`

For example:

~~~~ sh
RUST_LOG=debug hinoirisetr
~~~~


Dependencies
------------

 -  **Rust and Cargo**: Required for building the project.
 -  **Backends**: Depending on your configuration, you may need one or more of
    the following:
     -  `ddcutil`
     -  `hyprctl` (from `hyprsunset` for Hyprland)
     -  `xsct`
 -  **libnotify**: Optional, for desktop notifications.

Ensure that the required backends are installed and available in your `PATH`.


Contributing
------------

Contributions are welcome! Please submit issues or pull requests to the
repository at [forgejo].

[forgejo]: https://git.vavakado.xyz/me/hinoirisetr


License
-------

This project is licensed under the MIT License. See the <LICENSE> file for
details.