From 4122b9a305074fbb7447a6232e5fa3f92e1444a2 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Fri, 31 Jul 2026 20:37:03 +0545 Subject: [PATCH] fix: launch desktop apps from home dir, not Modus cwd GIO inherits the caller's working directory when a desktop file has no Path= entry, so terminals and file managers opened in the Modus project dir. chdir to the desktop file's Path= or $HOME before launching. --- src/window/globalmenu/launch.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/window/globalmenu/launch.py b/src/window/globalmenu/launch.py index 8d8fbb1..005ff12 100644 --- a/src/window/globalmenu/launch.py +++ b/src/window/globalmenu/launch.py @@ -18,6 +18,7 @@ Two launch paths are supported: import os import re +from pathlib import Path from fabric.utils import exec_shell_command_async, logger @@ -63,8 +64,34 @@ def launch_command(command_line: str) -> None: ) +def _launch_workdir(app) -> str | None: + """Working directory for the launched app: the desktop file's ``Path=`` + if set, else the user's home directory. + + GIO inherits the calling process's cwd when the desktop file has no + ``Path=`` entry, so without this terminals and file managers would open in + Modus's own working directory. + """ + app_path = getattr(app, "_app", None) + path = app_path.get_string("Path") if app_path is not None else None + if path: + return str(path) + return str(Path.home()) + + def launch_desktop_app(app) -> None: """Launch a :class:`fabric.utils.DesktopApp`, injecting the GTK3 shim if needed.""" + workdir = _launch_workdir(app) + cwd = os.getcwd() + + def launch() -> None: + if workdir: + os.chdir(workdir) + try: + app.launch() + finally: + os.chdir(cwd) + shim_env = shim_env_for_executable(getattr(app, "executable", None)) if shim_env: prev = os.environ.get("LD_PRELOAD") @@ -74,11 +101,11 @@ def launch_desktop_app(app) -> None: f"{getattr(app, 'display_name', app)}" ) try: - app.launch() + launch() finally: if prev is None: os.environ.pop("LD_PRELOAD", None) else: os.environ["LD_PRELOAD"] = prev else: - app.launch() + launch()