#!/bin/bash

# Default to XWayland on Wayland sessions so manual window positioning works.
if [[ -z "${QT_QPA_PLATFORM:-}" ]]; then
  if [[ "${XDG_SESSION_TYPE:-}" == "wayland" || -n "${WAYLAND_DISPLAY:-}" ]]; then
    if [[ "${TYPHOON_WINDOW_POSITION_BACKEND:-xwayland}" != "native" \
       && "${TYPHOON_WINDOW_POSITION_BACKEND:-xwayland}" != "wayland" \
       && -n "${DISPLAY:-}" ]]; then
      export QT_QPA_PLATFORM=xcb
    fi
  fi
fi

if [[ -n "${SNAP:-}" ]]; then
  flags=" ${QTWEBENGINE_CHROMIUM_FLAGS:-} "
  if [[ "$flags" != *" --disable-dev-shm-usage "* ]]; then
    export QTWEBENGINE_CHROMIUM_FLAGS="${QTWEBENGINE_CHROMIUM_FLAGS:+$QTWEBENGINE_CHROMIUM_FLAGS }--disable-dev-shm-usage"
  fi
fi

/usr/bin/python3 /usr/share/typhoon/typhoon/typhoon_window.py
