diff --git a/core/global/launch_manager.gd b/core/global/launch_manager.gd index dbd743b36..4d4590c93 100644 --- a/core/global/launch_manager.gd +++ b/core/global/launch_manager.gd @@ -251,6 +251,8 @@ func _launch(app: LibraryLaunchItem) -> RunningApp: var user_env = settings_manager.get_value(section, env_key, {}) if user_env and user_env is Dictionary and not (user_env as Dictionary).is_empty(): env = user_env + var inherit_environment_key := ".".join(["inherit_parent_environment", app._provider_id]) + var inherit_environment := settings_manager.get_value(section, inherit_environment_key, true) as bool var sandboxing_key := ".".join(["use_sandboxing", app._provider_id]) var use_sandboxing := settings_manager.get_value(section, sandboxing_key, false) as bool @@ -264,6 +266,15 @@ func _launch(app: LibraryLaunchItem) -> RunningApp: # Set the OGUI ID environment variable env["OGUI_ID"] = app.name + # Set certain environment variables when not inheriting the parent environment + if not inherit_environment: + if not "HOME" in env: + env["HOME"] = OS.get_environment("HOME") + if not "XDG_SESSION_TYPE" in env: + env["XDG_SESSION_TYPE"] = "x11" + if not "XDG_RUNTIME_DIR" in env: + env["XDG_RUNTIME_DIR"] = OS.get_environment("XDG_RUNTIME_DIR") + # Build any environment variables to include in the command var env_vars := PackedStringArray() for key in env.keys(): @@ -277,6 +288,8 @@ func _launch(app: LibraryLaunchItem) -> RunningApp: # Build the launch command to run var exec := "env" var command := ["-C", cwd] + if not inherit_environment: + command.push_front("-i") command.append_array(env_vars) command.append_array(sandbox) command.append(cmd) diff --git a/core/ui/common/launch/game_launch_settings.gd b/core/ui/common/launch/game_launch_settings.gd index a49aae2c5..ef0e8301a 100644 --- a/core/ui/common/launch/game_launch_settings.gd +++ b/core/ui/common/launch/game_launch_settings.gd @@ -20,6 +20,7 @@ var provider_id: String @onready var cwd_input := $%CWDTextInput @onready var env_input := $%EnvTextInput @onready var sandbox_toggle := $%UseSandboxToggle as Toggle +@onready var inherit_env_toggle := $%InheritEnvironmentToggle as Toggle # Called when the node enters the scene tree for the first time. @@ -31,6 +32,7 @@ func _ready() -> void: cwd_input.focus_exited.connect(_on_input_update.bind(cwd_input, "cwd")) env_input.focus_exited.connect(_on_input_update.bind(env_input, "env", UPDATE.DICT)) sandbox_toggle.toggled.connect(_on_toggle_update.bind(sandbox_toggle, "use_sandboxing")) + inherit_env_toggle.toggled.connect(_on_toggle_update.bind(inherit_env_toggle, "inherit_parent_environment")) func _on_game_settings_entered(_from: State) -> void: @@ -98,6 +100,8 @@ func _on_provider_selected(idx: int) -> void: sandbox_toggle.button_pressed = use_sandboxing else: sandbox_toggle.button_pressed = true + var inherit_env := settings_manager.get_value(settings_section, ".".join(["inherit_parent_environment", provider_id]), true) as bool + inherit_env_toggle.button_pressed = inherit_env # Converts the given dictionary into a string representation. E.g. foo=bar diff --git a/core/ui/common/launch/game_launch_settings.tscn b/core/ui/common/launch/game_launch_settings.tscn index aa9b16b6f..79ab0f622 100644 --- a/core/ui/common/launch/game_launch_settings.tscn +++ b/core/ui/common/launch/game_launch_settings.tscn @@ -72,6 +72,13 @@ layout_mode = 2 title = "Environment Variables" description = "Environment variables to use when launching the game" +[node name="InheritEnvironmentToggle" parent="MarginContainer/VBoxContainer" instance=ExtResource("7_5wp75")] +unique_name_in_owner = true +layout_mode = 2 +text = "Inherit Parent Environment" +separator_visible = false +description = "Whether or not environment variables should be inherited from the current session" + [node name="SandboxSettingsLabel" parent="MarginContainer/VBoxContainer" instance=ExtResource("4_m05uu")] layout_mode = 2 text = "Sandbox Settings"