mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:47:36 +00:00
most apps now begin in the correct directory
This commit is contained in:
parent
e3f81bce49
commit
50154a23cb
7 changed files with 34 additions and 14 deletions
|
@ -14,6 +14,7 @@
|
||||||
#include <LibGUI/GTreeView.h>
|
#include <LibGUI/GTreeView.h>
|
||||||
#include <LibGUI/GFileSystemModel.h>
|
#include <LibGUI/GFileSystemModel.h>
|
||||||
#include <LibGUI/GSplitter.h>
|
#include <LibGUI/GSplitter.h>
|
||||||
|
#include <LibCore/CUserInfo.h>
|
||||||
#include <AK/FileSystemPath.h>
|
#include <AK/FileSystemPath.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <LibCore/CUserInfo.h>
|
||||||
|
|
||||||
static GWindow* make_launcher_window();
|
static GWindow* make_launcher_window();
|
||||||
|
|
||||||
|
@ -23,6 +24,7 @@ void handle_sigchld(int)
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
chdir(get_current_user_home_path());
|
||||||
GApplication app(argc, argv);
|
GApplication app(argc, argv);
|
||||||
|
|
||||||
signal(SIGCHLD, handle_sigchld);
|
signal(SIGCHLD, handle_sigchld);
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
|
#include <pwd.h>
|
||||||
#include "Terminal.h"
|
#include "Terminal.h"
|
||||||
#include <Kernel/KeyCode.h>
|
#include <Kernel/KeyCode.h>
|
||||||
#include <LibGUI/GApplication.h>
|
#include <LibGUI/GApplication.h>
|
||||||
|
@ -16,6 +17,7 @@
|
||||||
#include <LibGUI/GAction.h>
|
#include <LibGUI/GAction.h>
|
||||||
#include <LibGUI/GFontDatabase.h>
|
#include <LibGUI/GFontDatabase.h>
|
||||||
#include <LibGUI/GSlider.h>
|
#include <LibGUI/GSlider.h>
|
||||||
|
#include <LibCore/CUserInfo.h>
|
||||||
|
|
||||||
static void make_shell(int ptm_fd)
|
static void make_shell(int ptm_fd)
|
||||||
{
|
{
|
||||||
|
@ -80,6 +82,8 @@ int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
GApplication app(argc, argv);
|
GApplication app(argc, argv);
|
||||||
|
|
||||||
|
chdir(get_current_user_home_path());
|
||||||
|
|
||||||
int ptm_fd = open("/dev/ptmx", O_RDWR);
|
int ptm_fd = open("/dev/ptmx", O_RDWR);
|
||||||
if (ptm_fd < 0) {
|
if (ptm_fd < 0) {
|
||||||
perror("open(ptmx)");
|
perror("open(ptmx)");
|
||||||
|
@ -112,7 +116,7 @@ int main(int argc, char** argv)
|
||||||
slider->set_fill_with_background_color(true);
|
slider->set_fill_with_background_color(true);
|
||||||
slider->set_background_color(Color::LightGray);
|
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;
|
float opacity = value / 100.0;
|
||||||
terminal.set_opacity(opacity);
|
terminal.set_opacity(opacity);
|
||||||
};
|
};
|
||||||
|
@ -138,11 +142,11 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
auto font_menu = make<GMenu>("Font");
|
auto font_menu = make<GMenu>("Font");
|
||||||
GFontDatabase::the().for_each_fixed_width_font([&] (const String& font_name) {
|
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()));
|
terminal.set_font(GFontDatabase::the().get_by_name(action.text()));
|
||||||
auto metadata = GFontDatabase::the().get_metadata_by_name(action.text());
|
auto metadata = GFontDatabase::the().get_metadata_by_name(action.text());
|
||||||
terminal.config()->write_entry("Text", "Font", metadata.path);
|
config->write_entry("Text", "Font", metadata.path);
|
||||||
terminal.config()->sync();
|
config->sync();
|
||||||
terminal.force_repaint();
|
terminal.force_repaint();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <LibCore/CConfigFile.h>
|
#include <LibCore/CConfigFile.h>
|
||||||
#include <LibCore/CFile.h>
|
#include <LibCore/CFile.h>
|
||||||
|
#include <LibCore/CUserInfo.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
@ -7,15 +8,8 @@
|
||||||
|
|
||||||
Retained<CConfigFile> CConfigFile::get_for_app(const String& app_name)
|
Retained<CConfigFile> CConfigFile::get_for_app(const String& app_name)
|
||||||
{
|
{
|
||||||
String home_path;
|
String home_path = get_current_user_home_path();
|
||||||
if (auto* home_env = getenv("HOME")) {
|
if (home_path == "/")
|
||||||
home_path = home_env;
|
|
||||||
} else {
|
|
||||||
uid_t uid = getuid();
|
|
||||||
if (auto* pwd = getpwuid(uid))
|
|
||||||
home_path = pwd->pw_dir;
|
|
||||||
}
|
|
||||||
if (home_path.is_empty())
|
|
||||||
home_path = String::format("/tmp");
|
home_path = String::format("/tmp");
|
||||||
auto path = String::format("%s/%s.ini", home_path.characters(), app_name.characters());
|
auto path = String::format("%s/%s.ini", home_path.characters(), app_name.characters());
|
||||||
return adopt(*new CConfigFile(path));
|
return adopt(*new CConfigFile(path));
|
||||||
|
|
17
LibCore/CUserInfo.cpp
Normal file
17
LibCore/CUserInfo.cpp
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#include "CUserInfo.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
1
LibCore/CUserInfo.h
Normal file
1
LibCore/CUserInfo.h
Normal file
|
@ -0,0 +1 @@
|
||||||
|
const char *get_current_user_home_path();
|
|
@ -19,7 +19,8 @@ OBJS = \
|
||||||
CConfigFile.o \
|
CConfigFile.o \
|
||||||
CEvent.o \
|
CEvent.o \
|
||||||
CProcessStatisticsReader.o \
|
CProcessStatisticsReader.o \
|
||||||
CDirIterator.o
|
CDirIterator.o \
|
||||||
|
CUserInfo.o
|
||||||
|
|
||||||
LIBRARY = libcore.a
|
LIBRARY = libcore.a
|
||||||
DEFINES += -DUSERLAND
|
DEFINES += -DUSERLAND
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue