Skip to content

Commit

Permalink
Add an option to set the screenshot directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arignir committed Oct 26, 2024
1 parent fb5c1dd commit b4fdbd4
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
10 changes: 10 additions & 0 deletions include/app/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ struct settings {
// Hide the cursor after a few seconds of inactivity
bool hide_cursor_when_mouse_inactive;

// If set, use the system screenshot directory.
// Otherwise, use the one specified by `screenshot_dir`.
// TODO: Move this elsewhere
bool use_system_screenshot_dir_path;

// Screenshot directory
// Only relevant if `use_system_screenshot_dir` is set.
// TODO: Move this elsewhere
char *screenshot_dir_path;

/*
** Debug
*/
Expand Down
18 changes: 16 additions & 2 deletions source/app/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ app_config_load(

// Video
{
char str[4096];
int b;
double d;

Expand Down Expand Up @@ -180,9 +181,18 @@ app_config_load(
if (mjson_get_bool(data, data_len, "$.video.hide_cursor_when_mouse_inactive", &b)) {
app->settings.video.hide_cursor_when_mouse_inactive = b;
}

if (mjson_get_bool(data, data_len, "$.video.use_system_screenshot_dir_path", &b)) {
app->settings.video.use_system_screenshot_dir_path = b;
}

if (mjson_get_string(data, data_len, "$.video.screenshot_dir_path", str, sizeof(str)) > 0) {
free(app->settings.video.screenshot_dir_path);
app->settings.video.screenshot_dir_path = strdup(str);
}
}

// Video
// Audio
{
int b;
double d;
Expand Down Expand Up @@ -344,7 +354,9 @@ app_config_save(
"texture_filter": %d,
"pixel_color_filter": %d,
"pixel_scaling_filter": %d,
"hide_cursor_when_mouse_inactive": %B
"hide_cursor_when_mouse_inactive": %B,
"use_system_screenshot_dir_path": %B,
"screenshot_dir_path": %Q
},

// Audio
Expand Down Expand Up @@ -387,6 +399,8 @@ app_config_save(
(int)app->settings.video.pixel_color_filter,
(int)app->settings.video.pixel_scaling_filter,
(int)app->settings.video.hide_cursor_when_mouse_inactive,
(int)app->settings.video.use_system_screenshot_dir_path,
app->settings.video.screenshot_dir_path,
(int)app->settings.audio.mute,
app->settings.audio.level
);
Expand Down
2 changes: 2 additions & 0 deletions source/app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ app_settings_default(
settings->video.pixel_color_filter = PIXEL_COLOR_FILTER_COLOR_CORRECTION;
settings->video.pixel_scaling_filter = PIXEL_SCALING_FILTER_LCD_GRID;
settings->video.hide_cursor_when_mouse_inactive = true;
settings->video.use_system_screenshot_dir_path = true;
settings->video.screenshot_dir_path = strdup("./screenshots/");
settings->audio.mute = false;
settings->audio.level = 1.0f;
}
Expand Down
5 changes: 4 additions & 1 deletion source/app/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,8 @@ char const *
app_path_screenshots(
struct app *app
) {
return (app->file.sys_pictures_dir_path ?: "screeenshots");
if (!app->settings.video.use_system_screenshot_dir_path && app->settings.video.screenshot_dir_path) {
return (app->settings.video.screenshot_dir_path);
}
return app->file.sys_pictures_dir_path ?: "screeenshots";
}
38 changes: 38 additions & 0 deletions source/app/windows/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,44 @@ app_win_settings_video(
igTableSetupColumn("##VideoSettingsMiscLabel", ImGuiTableColumnFlags_WidthFixed, vp->WorkSize.x / 5.f, 0);
igTableSetupColumn("##VideoSettingsMiscValue", ImGuiTableColumnFlags_WidthStretch, 0.f, 0);

// Use System Directory For Screenshots
igTableNextRow(ImGuiTableRowFlags_None, 0.f);
igTableNextColumn();
igTextWrapped("Use System Directory For Screenshots");

igTableNextColumn();
igCheckbox("##UseSystemDirectoryForScreenshots", &app->settings.video.use_system_screenshot_dir_path);

// Screenshot Directory
igTableNextRow(ImGuiTableRowFlags_None, 0.f);
igTableNextColumn();
igTextWrapped("Screenshot Directory");

igBeginDisabled(app->settings.video.use_system_screenshot_dir_path);

igTableNextColumn();
igBeginDisabled(true);
igInputText("##ScreenshotDirectory", app->settings.video.screenshot_dir_path, strlen(app->settings.video.screenshot_dir_path), ImGuiInputTextFlags_ReadOnly, NULL, NULL);
igEndDisabled();
igSameLine(0.0f, -1.0f);
if (igButton("Choose", (ImVec2){ 50.f, 0.f})) {
nfdresult_t result;
nfdchar_t *path;

result = NFD_PickFolder(
&path,
app->settings.video.screenshot_dir_path
);

if (result == NFD_OKAY) {
free(app->settings.video.screenshot_dir_path);
app->settings.video.screenshot_dir_path = strdup(path);
NFD_FreePath(path);
}
}

igEndDisabled();

// Hide the cursor when the mouse is inactive
igTableNextRow(ImGuiTableRowFlags_None, 0.f);
igTableNextColumn();
Expand Down

0 comments on commit b4fdbd4

Please sign in to comment.