#!/bin/sh
# regreet-session.sh — greetd session command: run ReGreet inside a cage kiosk.
#
# greetd runs this as the unprivileged `greeter` user. cage is a minimal
# wlroots/Wayland compositor; `-s` allows VT switching (so Ctrl+Alt+F-keys still
# reach a console). Env here tunes the greeter's look/behaviour before ReGreet starts.
#
# Scaling: cage renders at output scale 1. Bump XCURSOR_SIZE for a larger cursor;
# uncomment GDK_SCALE to integer-scale the whole greeter (careful on mixed-DPI
# multi-monitor — it scales every output). Prefer regreet.toml's font_name for
# finer control.

export XCURSOR_SIZE=32
# export GDK_SCALE=2

# ── Multi-GPU: pin the greeter to a DRM card that actually drives a monitor ─────
# On a dual-GPU box (dGPU + iGPU) wlroots enumerates both cards and may pick the
# display-less one, giving a blank or input-frozen greeter. Hand it only the first
# card that has a connected output. Evaluated live, so it stays portable across
# boots and machines (no hard-coded PCI path).
for _status in /sys/class/drm/card[0-9]*-*/status; do
    [ "$(cat "$_status" 2>/dev/null)" = "connected" ] || continue
    _card="/dev/dri/$(basename "$(dirname "$_status")" | cut -d- -f1)"
    [ -e "$_card" ] && { WLR_DRM_DEVICES="$_card"; export WLR_DRM_DEVICES; break; }
done

# amdgpu hardware cursors can freeze on this hardware (the cursor sticks and input
# feels dead); software cursors are reliable.
export WLR_NO_HARDWARE_CURSORS=1

# cage's default is "-m extend", which stretches one canvas across every monitor and
# leaves ReGreet's login card floating in the middle of the whole multi-monitor span.
# "-m last" renders on a single output instead, so the card is centred on one screen.
exec cage -s -m last -- regreet
