#!/bin/bash
export PATH=$PATH:/sbin
export XDG_SESSION_TYPE=wayland
export XDG_SESSION_DESKTOP=Deepin
export DDE_CURRENT_COMPOSITOR=GXWM
export KYWC_USE_LAYOUT_MANAGER=1  # 设置环境变量这个才会使用配置文件里的分辨率
unset QT_QPA_PLATFORM
unset DTK2_XWAYLAND

# If all DTK5/6 applications keeps crashing, uncomment the line below this
# comment block.
# Note that DTK5/6 graphic effect (blur, border, shadows) will also be gone.
# -----------------------------------------------------------------------------
# 若所有DTK5/6程序不停崩溃，拒绝启动，取消本注释块下方代码的注释
# 请注意，DTK5/6的图形特效（模糊、边框、阴影）也会随之消失。

# export GXWM_DONOT_BROADCAST_TLPM=ON

# The logic of libseat is that seatd is the 1st priority backend, and then
# logind. We are currently using LightDM with logind (The current developing
# GXDE Display manager is based on SDDM, which is also using logind), and hence
# we are forcing the backend to logind.
#
# Unfortunately, we're unable to auto detect which one to use automatically.
#
# Don't be overwhelmed if you are a seatd user. If you are really using seatd,
# You may simply comment out the following if block.
# -----------------------------------------------------------------------------
# libseat的逻辑如下：在有Seatd的情况下优先使用seatd，而GXDE（无论是当前GXDE正在使用的
# LightDM还是正在开发的基于SDDM的GXDE Display Manager）都使用logind。故而我们强制使用
# logind作为后端。
#
# 不幸的是，我们无法自动检测应该使用哪个后端。
#
# 如果您是seatd用户，您也无须担心，只需要注释掉下方这个if块即可。
if [ -z "$LIBSEAT_BACKEND" ] && [ -n "$XDG_SESSION_ID" ] && [ -d /run/systemd/seats ]; then
    export LIBSEAT_BACKEND=logind
fi

# export GDK_BACKEND=wayland
# export WLR_DRM_NO_ATOMIC=1

# === kirin 9000c 芯片走 hisi 硬件桌面 ===
# 检测到麒麟 9000c 内核且安装了 gxde-hisi-9000c-gpu-compat
# （提供 /usr/bin/startgxde_wlcom_9000c，hisi Maleoon 910 硬件加速启动器）
# 时，跳转到硬件加速启动；未安装则继续默认软件启动流程。
if uname -r | grep -q 9000c && [ -x /usr/bin/startgxde_wlcom_9000c ]; then
    # hisi 会话所需的最小环境（详细配置由 startgxde_wlcom_9000c 负责）
    export WLR_BACKENDS=drm,libinput
    exec /usr/bin/startgxde_wlcom_9000c "$@"
fi

exec /usr/bin/gxde-wlcom -s /usr/bin/startdde "$@"
