From 49ae73022c9f187e1d47fe7b1576ac3523b17199 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Mon, 2 Aug 2021 15:48:58 +0200 Subject: [PATCH] Taskbar: Set chdir to the home directory when opening applications Although the chdir was set up for the applications opened from the quick launch, the regular application list hadn't do this. This meant that you could open a Terminal or HackStudio project in the root directory, which isn't so bad, but it's better to stick to the user home directory. --- Userland/Services/Taskbar/main.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Userland/Services/Taskbar/main.cpp b/Userland/Services/Taskbar/main.cpp index 9dc465f9d1..b8c15f5ab3 100644 --- a/Userland/Services/Taskbar/main.cpp +++ b/Userland/Services/Taskbar/main.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -190,13 +191,20 @@ NonnullRefPtr build_system_menu() } else { argv[0] = app.executable.characters(); } + + posix_spawn_file_actions_t spawn_actions; + posix_spawn_file_actions_init(&spawn_actions); + auto home_directory = Core::StandardPaths::home_directory(); + posix_spawn_file_actions_addchdir(&spawn_actions, home_directory.characters()); + pid_t child_pid; - if ((errno = posix_spawn(&child_pid, argv[0], nullptr, nullptr, const_cast(argv), environ))) { + if ((errno = posix_spawn(&child_pid, argv[0], &spawn_actions, nullptr, const_cast(argv), environ))) { perror("posix_spawn"); } else { if (disown(child_pid) < 0) perror("disown"); } + posix_spawn_file_actions_destroy(&spawn_actions); })); ++app_identifier; } @@ -261,14 +269,21 @@ NonnullRefPtr build_system_menu() } })); system_menu->add_action(GUI::Action::create("Run...", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-run.png"), [](auto&) { + posix_spawn_file_actions_t spawn_actions; + posix_spawn_file_actions_init(&spawn_actions); + auto home_directory = Core::StandardPaths::home_directory(); + posix_spawn_file_actions_addchdir(&spawn_actions, home_directory.characters()); + pid_t child_pid; const char* argv[] = { "/bin/Run", nullptr }; - if ((errno = posix_spawn(&child_pid, "/bin/Run", nullptr, nullptr, const_cast(argv), environ))) { + if ((errno = posix_spawn(&child_pid, "/bin/Run", &spawn_actions, nullptr, const_cast(argv), environ))) { perror("posix_spawn"); } else { if (disown(child_pid) < 0) perror("disown"); } + + posix_spawn_file_actions_destroy(&spawn_actions); })); system_menu->add_separator(); system_menu->add_action(GUI::Action::create("Exit...", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/power.png"), [](auto&) {