#!/bin/bash set -e COMPOSITOR="" COMPOSITOR_CONFIG="" DMS_PATH="dms-greeter" CACHE_DIR="/var/cache/dms-greeter" show_help() { cat << EOF dms-greeter - DankMaterialShell greeter launcher Usage: dms-greeter --command COMPOSITOR [OPTIONS] Required: --command COMPOSITOR Compositor to use (niri, hyprland, or sway) Options: -C, --config PATH Custom compositor config file -p, --path PATH DMS path (config name or absolute path) (default: dms-greeter) --cache-dir PATH Cache directory for greeter data (default: /var/cache/dms-greeter) -h, --help Show this help message Examples: dms-greeter --command niri dms-greeter --command hyprland -C /etc/greetd/custom-hypr.conf dms-greeter --command sway -p /home/user/.config/quickshell/custom-dms dms-greeter --command niri --cache-dir /tmp/dmsgreeter EOF } while [[ $# -gt 0 ]]; do case $1 in --command) COMPOSITOR="$2" shift 2 ;; -C|--config) COMPOSITOR_CONFIG="$2" shift 2 ;; -p|--path) DMS_PATH="$2" shift 2 ;; --cache-dir) CACHE_DIR="$2" shift 2 ;; -h|--help) show_help exit 0 ;; *) echo "Unknown option: $1" >&2 show_help exit 1 ;; esac done if [[ -z "$COMPOSITOR" ]]; then echo "Error: --command COMPOSITOR is required" >&2 show_help exit 1 fi locate_dms_config() { local config_name="$1" local search_paths=() local config_home="${XDG_CONFIG_HOME:-$HOME/.config}" search_paths+=("$config_home/quickshell/$config_name") search_paths+=("/usr/share/quickshell/$config_name") local config_dirs="${XDG_CONFIG_DIRS:-/etc/xdg}" IFS=':' read -ra dirs <<< "$config_dirs" for dir in "${dirs[@]}"; do if [[ -n "$dir" ]]; then search_paths+=("$dir/quickshell/$config_name") fi done for path in "${search_paths[@]}"; do if [[ -f "$path/shell.qml" ]]; then echo "$path" return 0 fi done return 1 } export XDG_SESSION_TYPE=wayland export QT_QPA_PLATFORM=wayland export QT_WAYLAND_DISABLE_WINDOWDECORATION=1 export EGL_PLATFORM=gbm export DMS_RUN_GREETER=1 export DMS_GREET_CFG_DIR="$CACHE_DIR" mkdir -p "$CACHE_DIR" QS_CMD="qs" if [[ "$DMS_PATH" == /* ]]; then QS_CMD="qs -p $DMS_PATH" else RESOLVED_PATH=$(locate_dms_config "$DMS_PATH") if [[ $? -eq 0 && -n "$RESOLVED_PATH" ]]; then echo "Located DMS config at: $RESOLVED_PATH" >&2 QS_CMD="qs -p $RESOLVED_PATH" else echo "Error: Could not find DMS config '$DMS_PATH' (shell.qml) in any valid config path" >&2 exit 1 fi fi case "$COMPOSITOR" in niri) if [[ -z "$COMPOSITOR_CONFIG" ]]; then TEMP_CONFIG=$(mktemp) cat > "$TEMP_CONFIG" << NIRI_EOF hotkey-overlay { skip-at-startup } environment { DMS_RUN_GREETER "1" } spawn-at-startup "sh" "-c" "$QS_CMD; niri msg action quit --skip-confirmation" debug { keep-max-bpc-unchanged } gestures { hot-corners { off } } layout { background-color "#000000" } NIRI_EOF COMPOSITOR_CONFIG="$TEMP_CONFIG" else TEMP_CONFIG=$(mktemp) cat "$COMPOSITOR_CONFIG" > "$TEMP_CONFIG" cat >> "$TEMP_CONFIG" << NIRI_EOF spawn-at-startup "sh" "-c" "$QS_CMD; niri msg action quit --skip-confirmation" NIRI_EOF COMPOSITOR_CONFIG="$TEMP_CONFIG" fi exec niri -c "$COMPOSITOR_CONFIG" ;; hyprland) if [[ -z "$COMPOSITOR_CONFIG" ]]; then TEMP_CONFIG=$(mktemp) cat > "$TEMP_CONFIG" << HYPRLAND_EOF env = DMS_RUN_GREETER,1 misc { disable_hyprland_logo = true } exec = sh -c "$QS_CMD; hyprctl dispatch exit" HYPRLAND_EOF COMPOSITOR_CONFIG="$TEMP_CONFIG" else TEMP_CONFIG=$(mktemp) cat "$COMPOSITOR_CONFIG" > "$TEMP_CONFIG" cat >> "$TEMP_CONFIG" << HYPRLAND_EOF exec = sh -c "$QS_CMD; hyprctl dispatch exit" HYPRLAND_EOF COMPOSITOR_CONFIG="$TEMP_CONFIG" fi exec Hyprland -c "$COMPOSITOR_CONFIG" ;; sway) if [[ -z "$COMPOSITOR_CONFIG" ]]; then TEMP_CONFIG=$(mktemp) cat > "$TEMP_CONFIG" << SWAY_EOF exec "$QS_CMD; swaymsg exit" SWAY_EOF COMPOSITOR_CONFIG="$TEMP_CONFIG" else TEMP_CONFIG=$(mktemp) cat "$COMPOSITOR_CONFIG" > "$TEMP_CONFIG" cat >> "$TEMP_CONFIG" << SWAY_EOF exec "$QS_CMD; swaymsg exit" SWAY_EOF COMPOSITOR_CONFIG="$TEMP_CONFIG" fi exec sway -c "$COMPOSITOR_CONFIG" ;; *) echo "Error: Unsupported compositor: $COMPOSITOR" >&2 echo "Supported compositors: niri, hyprland, sway" >&2 exit 1 ;; esac