# =============================================================================
# hypridle.conf — Idle management daemon configuration
#
# hypridle watches for user inactivity and triggers actions (lock, suspend)
# after configurable timeouts. It integrates with the presence-detection daemon
# (presence-detect.sh) which resets the idle timer every ~2 minutes while the
# webcam detects a person, so these timeouts only fire when the user has truly
# stepped away from the machine.
#
# Reference: https://wiki.hypr.land/Hypr-Ecosystem/hypridle/
# =============================================================================

general {
    # Command to run when the lock screen should be shown.
    # `pidof hyprlock || hyprlock` first checks if hyprlock is already running
    # (pidof returns 0 if found) and only launches a new instance if it is not.
    # This prevents stacking multiple lock screen instances on repeated trigger.
    lock_cmd         = pidof hyprlock || hyprlock

    # Lock the session immediately when the system is about to suspend.
    # loginctl lock-session sends the Lock D-Bus signal to the session manager,
    # which hyprlock listens to, ensuring the screen is locked before the
    # display blanks during suspend.
    before_sleep_cmd = loginctl lock-session

    # fprintd restart ensures fingerprint sensor is ready after resume
    # Turn the display back on after the system wakes from suspend.
    # `hyprctl dispatch dpms on` sends DPMS power-on to all connected monitors.
    after_sleep_cmd  = hyprctl dispatch dpms on

    # ignore_dbus_inhibit = false means hypridle honours D-Bus idle-inhibit locks.
    # This allows systemd-inhibit (used by the presence-detect daemon and the
    # caffeine script) to pause the idle timer while they are active.
    ignore_dbus_inhibit = false   # respect systemd-inhibit locks (presence-detect, caffeine)
}

# Presence detection resets the idle timer every 2 minutes while you're visible,
# so these timeouts only run when you've actually stepped away.

# First idle listener: lock the screen after 2.5 minutes of inactivity.
# 150 seconds is long enough to avoid triggering during short pauses (reading,
# thinking) but short enough to protect the session if you leave unexpectedly.
listener {
    timeout = 150   # 2.5 min — lock screen
    # loginctl lock-session triggers the session lock signal; hyprlock picks it up.
    on-timeout = loginctl lock-session
}

# Second idle listener: suspend (then hibernate) after 10 minutes of inactivity.
# This fires only if the lock screen has already been active for ~7.5 minutes,
# meaning the user is confirmed away. suspend-then-hibernate first suspends to RAM
# for fast resume; after the hibernate delay (configured in systemd-sleep.conf)
# it writes the RAM image to disk for power-off safety.
listener {
    timeout = 600   # 10 min — suspend
    on-timeout = systemctl suspend-then-hibernate
}
