diff --git a/core/systems/ipc/pipe_manager.gd b/core/systems/ipc/pipe_manager.gd index 7b751f7b5..b2da1ce60 100644 --- a/core/systems/ipc/pipe_manager.gd +++ b/core/systems/ipc/pipe_manager.gd @@ -4,12 +4,11 @@ class_name PipeManager ## Class for managing control messages sent through a named pipe ## -## The [PipeManager] creates a named pipe in `/run/user//opengamepadui` +## The [PipeManager] creates a named pipe in `$XDG_RUNTIME_DIR/opengamepadui` ## that can be used as a communication mechanism to send OpenGamepadUI commands ## from another process. This is mostly done to handle custom `ogui://` URIs ## which can be used to react in different ways. -const RUN_FOLDER: String = "/run/user/{}/opengamepadui" const URI_PREFIX: String = "ogui://" signal line_written(line: String) @@ -26,6 +25,9 @@ var logger := Log.get_logger("PipeManager", Log.LEVEL.DEBUG) func _ready() -> void: # Ensure the run directory exists var run_path := get_run_path() + if run_path.is_empty(): + logger.error("$XDG_RUNTIME_DIR is not set; unable to create named pipe") + return DirAccess.make_dir_recursive_absolute(run_path) # Create a unix named pipe @@ -52,25 +54,16 @@ func get_pipe_path() -> String: ## Returns the run path for the current user (e.g. /run/user/1000/opengamepadui) func get_run_path() -> String: - var uid := get_uid() - if uid < 0: + var runtime_dir := get_runtime_dir() + if runtime_dir.is_empty(): return "" - var run_folder := RUN_FOLDER.format([uid], "{}") - - return run_folder + return "/".join([runtime_dir, "opengamepadui"]) -## Returns the current user id (e.g. 1000) -func get_uid() -> int: - var output: Array = [] - if OS.execute("id", ["-u"], output) != OK: - return -1 - if output.is_empty(): - return -1 - var data := output[0] as String - var uid := data.to_int() - return uid +## Returns the XDG runtime directory (e.g. /run/user/1000) +func get_runtime_dir() -> String: + return OS.get_environment("XDG_RUNTIME_DIR") func _on_line_written(line: String) -> void: diff --git a/docs/class-reference/PipeManager.md b/docs/class-reference/PipeManager.md index 1f3e99245..e13d3fd28 100644 --- a/docs/class-reference/PipeManager.md +++ b/docs/class-reference/PipeManager.md @@ -5,7 +5,7 @@ Class for managing control messages sent through a named pipe ## Description -The [PipeManager](../PipeManager) creates a named pipe in `/run/user//opengamepadui` that can be used as a communication mechanism to send OpenGamepadUI commands from another process. This is mostly done to handle custom `ogui://` URIs which can be used to react in different ways. +The [PipeManager](../PipeManager) creates a named pipe in `$XDG_RUNTIME_DIR/opengamepadui` that can be used as a communication mechanism to send OpenGamepadUI commands from another process. This is mostly done to handle custom `ogui://` URIs which can be used to react in different ways. ## Properties | Type | Name | Default | diff --git a/rootfs/usr/bin/opengamepadui b/rootfs/usr/bin/opengamepadui index 19e23f7ef..8f8e6d59c 100755 --- a/rootfs/usr/bin/opengamepadui +++ b/rootfs/usr/bin/opengamepadui @@ -5,17 +5,18 @@ ARCH=$(uname -m) OGUI_BIN=${OGUI_BIN:-"${PREFIX}/share/opengamepadui/opengamepad-ui.${ARCH}"} GAMESCOPE_CMD=${GAMESCOPE_CMD:-gamescope -e -w 1920 -h 1080 -f --xwayland-count 2} +RUNTIME_DIR=${XDG_RUNTIME_DIR} # Check to see if a URI is being sent if [[ "$1" == ogui://* ]]; then - if ls /run/user/${UID}/opengamepadui/opengamepadui-0 >/dev/null 2>&1; then - echo "$1" >/run/user/${UID}/opengamepadui/opengamepadui-0 + if ls "${RUNTIME_DIR}/opengamepadui/opengamepadui-0" >/dev/null 2>&1; then + echo "$1" >"${RUNTIME_DIR}/opengamepadui/opengamepadui-0" exit 0 fi fi # Launch normally if gamescope is already running -if ls /run/user/${UID}/gamescope* >/dev/null 2>&1; then +if ls "${RUNTIME_DIR}"/gamescope* >/dev/null 2>&1; then echo "Executing: ${OGUI_BIN}" "$@" exec ${OGUI_BIN} "$@" fi