#!/bin/sh
# WlasnyOS - Skrypt startowy Hyprland Wayland Compositor

echo "=== Uruchamianie Hyprland (WlasnyOS) ==="

# Konfiguracja katalogu XDG_RUNTIME_DIR
if [ -z "$XDG_RUNTIME_DIR" ]; then
    export XDG_RUNTIME_DIR="/tmp/runtime-$(id -u)"
    mkdir -p "$XDG_RUNTIME_DIR"
    chmod 0700 "$XDG_RUNTIME_DIR"
fi

# Kompatybilność z maszynami wirtualnymi (VirtualBox / QEMU / VMware)
export WLR_NO_HARDWARE_CURSORS=1
export WLR_RENDERER_ALLOW_SOFTWARE=1
export AQ_FORCE_BACKEND=drm

# Zapewnienie istnienia konfiguracji użytkownika
mkdir -p ~/.config/hypr
if [ ! -f ~/.config/hypr/hyprland.conf ]; then
    if [ -f /etc/xdg/hypr/hyprland.conf ]; then
        cp /etc/xdg/hypr/hyprland.conf ~/.config/hypr/hyprland.conf
    fi
fi

# Uruchomienie demona seatd (obsługa sesji i grafiki bez systemd)
if ! pidof seatd >/dev/null 2>&1; then
    seatd -u "$(whoami)" &
    sleep 1
fi

echo "Start kompozytora Hyprland..."
if command -v seatd-launch >/dev/null 2>&1; then
    exec seatd-launch Hyprland
else
    exec Hyprland
fi
