#!/bin/bash

# omarchy:summary=Lock the computer and turn off the display
# omarchy:group=system
# omarchy:name=lock
# omarchy:examples=omarchy system lock

omarchy-shell lock lock >/dev/null

# Set keyboard layout to default (first layout)
hyprctl switchxkblayout all 0 > /dev/null 2>&1

# Ensure 1password is locked
if pgrep -x "1password" >/dev/null; then
  1password --lock &
fi

# Avoid running screensaver when locked
pkill -f '[o]rg.omarchy.screensaver'

if [[ ${OMARCHY_LOCK_ONLY:-false} != "true" ]]; then
  (
    sleep 3
    [[ $(omarchy-shell lock isLocked 2>/dev/null) == "true" ]] || exit 0
    omarchy-brightness-keyboard off
    omarchy-brightness-display off
  ) &
fi
