diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index e187e4af51f..7c6fe3bc734 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include diff --git a/Applications/Launcher/main.cpp b/Applications/Launcher/main.cpp index 2004da1a1b2..9f4db8cbdd3 100644 --- a/Applications/Launcher/main.cpp +++ b/Applications/Launcher/main.cpp @@ -10,6 +10,7 @@ #include #include #include +#include static GWindow* make_launcher_window(); @@ -23,6 +24,7 @@ void handle_sigchld(int) int main(int argc, char** argv) { + chdir(get_current_user_home_path()); GApplication app(argc, argv); signal(SIGCHLD, handle_sigchld); diff --git a/Applications/Terminal/main.cpp b/Applications/Terminal/main.cpp index ba0d95f7c5a..ad36b72ea9d 100644 --- a/Applications/Terminal/main.cpp +++ b/Applications/Terminal/main.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "Terminal.h" #include #include @@ -16,6 +17,7 @@ #include #include #include +#include static void make_shell(int ptm_fd) { @@ -80,6 +82,8 @@ int main(int argc, char** argv) { GApplication app(argc, argv); + chdir(get_current_user_home_path()); + int ptm_fd = open("/dev/ptmx", O_RDWR); if (ptm_fd < 0) { perror("open(ptmx)"); @@ -112,7 +116,7 @@ int main(int argc, char** argv) slider->set_fill_with_background_color(true); slider->set_background_color(Color::LightGray); - slider->on_value_changed = [&terminal] (int value) { + slider->on_value_changed = [&terminal, &config] (int value) { float opacity = value / 100.0; terminal.set_opacity(opacity); }; @@ -138,11 +142,11 @@ int main(int argc, char** argv) auto font_menu = make("Font"); GFontDatabase::the().for_each_fixed_width_font([&] (const String& font_name) { - font_menu->add_action(GAction::create(font_name, [&terminal] (const GAction& action) { + font_menu->add_action(GAction::create(font_name, [&terminal, &config] (const GAction& action) { terminal.set_font(GFontDatabase::the().get_by_name(action.text())); auto metadata = GFontDatabase::the().get_metadata_by_name(action.text()); - terminal.config()->write_entry("Text", "Font", metadata.path); - terminal.config()->sync(); + config->write_entry("Text", "Font", metadata.path); + config->sync(); terminal.force_repaint(); })); }); diff --git a/LibCore/CConfigFile.cpp b/LibCore/CConfigFile.cpp index 1c4b108c71b..e21014783cc 100644 --- a/LibCore/CConfigFile.cpp +++ b/LibCore/CConfigFile.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -7,15 +8,8 @@ Retained CConfigFile::get_for_app(const String& app_name) { - String home_path; - if (auto* home_env = getenv("HOME")) { - home_path = home_env; - } else { - uid_t uid = getuid(); - if (auto* pwd = getpwuid(uid)) - home_path = pwd->pw_dir; - } - if (home_path.is_empty()) + String home_path = get_current_user_home_path(); + if (home_path == "/") home_path = String::format("/tmp"); auto path = String::format("%s/%s.ini", home_path.characters(), app_name.characters()); return adopt(*new CConfigFile(path)); diff --git a/LibCore/CUserInfo.cpp b/LibCore/CUserInfo.cpp new file mode 100644 index 00000000000..e297468fee0 --- /dev/null +++ b/LibCore/CUserInfo.cpp @@ -0,0 +1,17 @@ +#include "CUserInfo.h" +#include +#include +#include + +const char *get_current_user_home_path() { + if (auto* home_env = getenv("HOME")) { + return home_env; + } else { + auto d = "/"; + uid_t uid = getuid(); + if (auto* pwd = getpwuid(uid)) + return pwd->pw_dir; + else + return d; + } +} diff --git a/LibCore/CUserInfo.h b/LibCore/CUserInfo.h new file mode 100644 index 00000000000..22ef0a8fb49 --- /dev/null +++ b/LibCore/CUserInfo.h @@ -0,0 +1 @@ +const char *get_current_user_home_path(); diff --git a/LibCore/Makefile b/LibCore/Makefile index e6068b44ff0..da0a92e3ca9 100644 --- a/LibCore/Makefile +++ b/LibCore/Makefile @@ -19,7 +19,8 @@ OBJS = \ CConfigFile.o \ CEvent.o \ CProcessStatisticsReader.o \ - CDirIterator.o + CDirIterator.o \ + CUserInfo.o LIBRARY = libcore.a DEFINES += -DUSERLAND