|
|
@@ -0,0 +1,67 @@
|
|
|
+#!/usr/bin/env bash
|
|
|
+
|
|
|
+set -u
|
|
|
+
|
|
|
+SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
+LOG_FILE="${SCRIPT_DIR}/gaming-mode.log"
|
|
|
+
|
|
|
+log() {
|
|
|
+ printf '[%s] [LEAVE] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$*" >> "${LOG_FILE}"
|
|
|
+}
|
|
|
+
|
|
|
+import_xfce_environment() {
|
|
|
+ local session_pid
|
|
|
+ local entry
|
|
|
+
|
|
|
+ session_pid="$(pgrep -u "$(id -u)" -x xfce4-session | head -n 1 || true)"
|
|
|
+
|
|
|
+ if [[ -n "${session_pid}" && -r "/proc/${session_pid}/environ" ]]; then
|
|
|
+ while IFS= read -r -d '' entry; do
|
|
|
+ case "${entry}" in
|
|
|
+ DISPLAY=*|XAUTHORITY=*|DBUS_SESSION_BUS_ADDRESS=*|XDG_RUNTIME_DIR=*)
|
|
|
+ export "${entry}"
|
|
|
+ ;;
|
|
|
+ esac
|
|
|
+ done < "/proc/${session_pid}/environ"
|
|
|
+ fi
|
|
|
+}
|
|
|
+
|
|
|
+import_xfce_environment
|
|
|
+
|
|
|
+export DISPLAY="${DISPLAY:-:20}"
|
|
|
+
|
|
|
+STATE_DIR="${XDG_RUNTIME_DIR:-/tmp}/sunshine-gaming-mode"
|
|
|
+STATE_FILE="${STATE_DIR}/xfce-state"
|
|
|
+
|
|
|
+desktop_was_running=1
|
|
|
+panel_was_running=1
|
|
|
+
|
|
|
+if [[ -f "${STATE_FILE}" ]]; then
|
|
|
+ source "${STATE_FILE}"
|
|
|
+fi
|
|
|
+
|
|
|
+log "Leaving gaming mode on DISPLAY=${DISPLAY}"
|
|
|
+
|
|
|
+if [[ "${desktop_was_running}" == "1" ]] &&
|
|
|
+ ! pgrep -u "$(id -u)" -x xfdesktop >/dev/null 2>&1; then
|
|
|
+
|
|
|
+ log "Starting xfdesktop"
|
|
|
+
|
|
|
+ nohup xfdesktop --disable-wm-check \
|
|
|
+ >> "${LOG_FILE}" 2>&1 &
|
|
|
+fi
|
|
|
+
|
|
|
+if [[ "${panel_was_running}" == "1" ]] &&
|
|
|
+ ! pgrep -u "$(id -u)" -x xfce4-panel >/dev/null 2>&1; then
|
|
|
+
|
|
|
+ log "Starting xfce4-panel"
|
|
|
+
|
|
|
+ nohup xfce4-panel \
|
|
|
+ >> "${LOG_FILE}" 2>&1 &
|
|
|
+fi
|
|
|
+
|
|
|
+rm -f "${STATE_FILE}"
|
|
|
+
|
|
|
+log "XFCE desktop restored"
|
|
|
+
|
|
|
+exit 0
|