mjdev-session 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/sh
  2. # mjdev desktop wayland session
  3. # started by the display manager via /usr/share/wayland-sessions/mjdev.desktop
  4. export XDG_CURRENT_DESKTOP=mjdev
  5. export XDG_SESSION_TYPE=wayland
  6. export MOZ_ENABLE_WAYLAND=1
  7. export QT_QPA_PLATFORM="wayland;xcb"
  8. export _JAVA_AWT_WM_NONREPARENTING=1
  9. # allow wlroots to start on llvmpipe (software GL). On real hardware mesa uses the
  10. # GPU and this is ignored; in a VM / headless box without GPU passthrough mesa falls
  11. # back to llvmpipe and wlroots otherwise refuses to create a renderer ("Software
  12. # rendering detected, please use WLR_RENDERER_ALLOW_SOFTWARE") and the compositor
  13. # exits immediately -> black screen + tty1 autologin crash-loop.
  14. export WLR_RENDERER_ALLOW_SOFTWARE=1
  15. # NOTE: SKIKO_RENDER_API is intentionally NOT set here. The compositor (mjdevc) detects at runtime
  16. # whether it got a hardware or software GL renderer and exports SKIKO_RENDER_API=SOFTWARE for the
  17. # shell only when GL is software (VM / no GPU) — so real GPUs use hardware GL automatically.
  18. # desktop shell binary - deb/appimage install location, gradle dev fallback
  19. SHELL_CMD="/opt/mjdev-desktop/bin/mjdev-desktop"
  20. if [ ! -x "$SHELL_CMD" ]; then
  21. SHELL_CMD="$HOME/.local/bin/mjdev-desktop"
  22. fi
  23. # compositor binary - /usr/bin (deb) or /usr/local/bin (manual install)
  24. MJDEVC="$(command -v mjdevc 2>/dev/null)"
  25. if [ -z "$MJDEVC" ]; then
  26. MJDEVC="/usr/bin/mjdevc"
  27. fi
  28. # clean up the activation environment the compositor exported into the
  29. # persistent systemd --user manager. with KillUserProcesses=no (the distro
  30. # default) that manager survives logout, so leaving a stale WAYLAND_DISPLAY /
  31. # DISPLAY behind poisons the next login - of any session, not just ours.
  32. # run on every exit path (normal exit, crash, signal) - no exec, so we get here.
  33. cleanup() {
  34. systemctl --user unset-environment \
  35. WAYLAND_DISPLAY DISPLAY XDG_CURRENT_DESKTOP XDG_SESSION_TYPE \
  36. 2>/dev/null || true
  37. }
  38. trap cleanup EXIT HUP INT TERM
  39. # log the compositor + shell output so a failed start is diagnosable (otherwise the
  40. # tty1 session just dies to a black screen with no trace). keep the previous run.
  41. LOG_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/mjdev-desktop"
  42. mkdir -p "$LOG_DIR"
  43. [ -f "$LOG_DIR/session.log" ] && mv -f "$LOG_DIR/session.log" "$LOG_DIR/session.log.1"
  44. "$MJDEVC" --session --shell-cmd "$SHELL_CMD" >"$LOG_DIR/session.log" 2>&1