diff options
| author | 2024-10-19 13:54:49 -0400 | |
|---|---|---|
| committer | 2024-10-19 13:54:49 -0400 | |
| commit | 27ebc9f4dea4d4456060cff8f3737a24351ef3a8 (patch) | |
| tree | 58390a98c091ea0d527c6f7d076a85d1fa970a0f | |
| parent | 33af4c0bf80acb0b6087d53bbde344daf285def3 (diff) | |
| download | mauri-27ebc9f4dea4d4456060cff8f3737a24351ef3a8.tar.gz mauri-27ebc9f4dea4d4456060cff8f3737a24351ef3a8.tar.bz2 mauri-27ebc9f4dea4d4456060cff8f3737a24351ef3a8.zip | |
Add config for assets path
Signed-off-by: Andrew Opalach <andrew@akon.city>
| -rw-r--r-- | src/mauri.cc | 10 | ||||
| -rw-r--r-- | taro/config.h | 49 | ||||
| -rw-r--r-- | taro/daemon.c | 6 | ||||
| -rw-r--r-- | taro/ui.c | 6 |
4 files changed, 52 insertions, 19 deletions
diff --git a/src/mauri.cc b/src/mauri.cc index 74e2fb1..ed41cde 100644 --- a/src/mauri.cc +++ b/src/mauri.cc @@ -15,9 +15,10 @@ using namespace Mauri; #define HELP_TEXT "\ Usage: mauri (-p, --package [path_to_scene.pkg]|-d, --directory [path_to_wallpaper]) [OPTIONS]\n\ + -a, --assets search path for common assets\n\ -w, --width window width (default: 640)\n\ -h, --height window height (default: 480)\n\ - -o, --offset offset of scene camera (default: 0,0)\n\ + -o, --offset offset of the scene camera (default: 0,0)\n\ -m, --monitor set as the background of this monitor (by name)\n\ -t, --target dump scene into this directory and exit\ " @@ -34,6 +35,7 @@ auto wmain(s32 argc, wchar_t **argv) -> s32 args.newString("package p", ""); args.newString("directory d", ""); + args.newString("assets a", ""); args.newInt("width w", 0); args.newInt("height h", 0); args.newString("offset o", "0,0"); @@ -78,13 +80,15 @@ auto wmain(s32 argc, wchar_t **argv) -> s32 } } - asset_manager()->add_search_directory("./assets"); - if (args.found("directory")) { asset_manager()->add_search_directory(args.getString("directory")); } + if (args.found("assets")) { + asset_manager()->add_search_directory(args.getString("assets")); + } + Scene *scene = Scene::parse("scene.json"); if (!scene) return EXIT_FAILURE; diff --git a/taro/config.h b/taro/config.h index 1a1f10d..5b9a257 100644 --- a/taro/config.h +++ b/taro/config.h @@ -9,6 +9,7 @@ struct config { str config_dir; + str asset_dir; str wallpaper_dir; }; @@ -17,29 +18,52 @@ AL_UNUSED_FUNCTION_PUSH static void close_config(struct config *conf) { al_str_free(&conf->config_dir); + al_str_free(&conf->asset_dir); al_str_free(&conf->wallpaper_dir); } +static void maybe_replace_home_in_path(str *dest, const char *envhome, const char *path) +{ + if (path[0] == '~') { + al_str_from(dest, envhome); + path++; + al_str_cat(dest, al_str_cr(path)); + } else if (al_str_cmp(al_str_cr(path), al_str_c("$HOME"), 0, 5) == 0) { + al_str_from(dest, envhome); + path += 5; + al_str_cat(dest, al_str_cr(path)); + } else { + al_str_from(dest, path); + } +} + static bool parse_config_json(struct config *conf, char *envhome, json_t *root) { bool valid = true; - json_t *wallpaper_dir = json_object_get(root, "wallpaper_directory"); - if (!wallpaper_dir || !json_is_string(wallpaper_dir) || al_strlen(json_string_value(wallpaper_dir)) == 0) { - al_log_error("taro", "'wallpaper_directory' not set or invalid"); + json_t *directories = json_object_get(root, "directories"); + if (!directories) { valid = false; goto out; } - const char *dir_str = json_string_value(wallpaper_dir); - if (dir_str[0] == '~') { - al_str_from(&conf->wallpaper_dir, envhome); - dir_str++; - al_str_cat(&conf->wallpaper_dir, al_str_cr(dir_str)); - } else { - al_str_from(&conf->wallpaper_dir, dir_str); + json_t *assets = json_object_get(directories, "assets"); + if (!assets || !json_is_string(assets) || al_strlen(json_string_value(assets)) == 0) { + al_log_error("taro", "asset directory not set or invalid"); + valid = false; + goto out; + } + + json_t *wallpapers = json_object_get(directories, "wallpapers"); + if (!wallpapers || !json_is_string(wallpapers) || al_strlen(json_string_value(wallpapers)) == 0) { + al_log_error("taro", "wallpaper directory not set or invalid"); + valid = false; + goto out; } + maybe_replace_home_in_path(&conf->asset_dir, envhome, json_string_value(assets)); + maybe_replace_home_in_path(&conf->wallpaper_dir, envhome, json_string_value(wallpapers)); + out: json_decref(root); @@ -67,7 +91,10 @@ static bool open_config(struct config *conf, bool create) if (!aki_file_exists(&config_path)) { if (aki_file_create(&config_path)) { json_t *blank = json_object(); - json_object_set_new(blank, "wallpaper_directory", json_string_nocheck("")); + json_t *directories = json_object(); + json_object_set_new(directories, "assets", json_string_nocheck("")); + json_object_set_new(directories, "wallpapers", json_string_nocheck("")); + json_object_set_new(blank, "directories", directories); aki_dump_json_and_decref(&config_path, blank); } } diff --git a/taro/daemon.c b/taro/daemon.c index 984f339..682a8d3 100644 --- a/taro/daemon.c +++ b/taro/daemon.c @@ -172,14 +172,16 @@ static bool run_wallpaper(struct daemon *dmon, struct monitor *monitor) char *c_str0 = al_str_to_c_str(&wallpaper_path); al_str_free(&wallpaper_path); + char *c_str1 = al_str_to_c_str(&dmon->conf.asset_dir); if (is_package) { monitor->pid = exec_or_exit((char *[]){ - "mauri", "-p", c_str0, "-m", monitor->os->name, "-w", width, "-h", height, NULL}); + "mauri", "-p", c_str0, "-a", c_str1, "-m", monitor->os->name, "-w", width, "-h", height, NULL}); } else { monitor->pid = exec_or_exit((char *[]){ - "mauri", "-d", c_str0, "-m", monitor->os->name, "-w", width, "-h", height, NULL}); + "mauri", "-d", c_str0, "-a", c_str1, "-m", monitor->os->name, "-w", width, "-h", height, NULL}); } al_free(c_str0); + al_free(c_str1); if (monitor->covered && signal_monitor(monitor, SIGSTOP)) { monitor->paused = true; @@ -1173,13 +1173,13 @@ s32 main(void) { if (!aki_common_init()) return EXIT_FAILURE; - s32 ret = EXIT_FAILURE; - if (!open_config(&u.conf, false)) { al_log_error("taro", "failed to open config, run `tarod` at least once to generate needed config"); - goto out; + return EXIT_FAILURE; } + s32 ret = EXIT_FAILURE; + if (!db_load_entries(&u.db, &u.conf.wallpaper_dir)) { goto out; } |