Skip to content

Commit

Permalink
feat(config): add show_panel config
Browse files Browse the repository at this point in the history
Allows to toggle paint panel on/off upon startup.

Closes #12
  • Loading branch information
jtheoof committed Jun 18, 2020
1 parent 8a82e79 commit 307f579
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ The following lines can be used as swappy's default:
```
[Default]
save_dir=$HOME/Desktop
show_panel=false
line_size=5
text_size=20
text_font=sans-serif
```

- `save_dir` is where swappshots will be saved, can contain env variables and must exist in your filesystem
- `show_panel` is used to toggle the paint panel on or off upon startup
- `line_size` is the default line size (must be between 1 and 50)
- `text_size` is the default text size (must be between 10 and 50)
- `text_font` is the font used to render text, its format is pango friendly
Expand Down
1 change: 1 addition & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define CONFIG_LINE_SIZE_DEFAULT 5
#define CONFIG_TEXT_FONT_DEFAULT "sans-serif"
#define CONFIG_TEXT_SIZE_DEFAULT 20
#define CONFIG_SHOW_PANEL_DEFAULT false

void config_load(struct swappy_state *state);
void config_free(struct swappy_state *state);
1 change: 1 addition & 0 deletions include/swappy.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ struct swappy_wayland {
struct swappy_config {
char *config_file;
char *save_dir;
gboolean show_panel;
guint32 line_size;
guint32 text_size;
char *text_font;
Expand Down
2 changes: 1 addition & 1 deletion src/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,9 @@ static bool load_layout(struct swappy_state *state) {
state->ui->window = window;

compute_window_size(state);

gtk_widget_set_size_request(area, state->window->width,
state->window->height);
action_toggle_painting_panel(state, &state->config->show_panel);

g_object_unref(G_OBJECT(builder));

Expand Down
13 changes: 13 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ static void print_config(struct swappy_config *config) {
g_info("printing config:");
g_info("config_dir: %s", config->config_file);
g_info("save_dir: %s", config->save_dir);
g_info("show_panel: %d", config->show_panel);
g_info("line_size: %d", config->line_size);
g_info("text_font: %s", config->text_font);
g_info("text_size: %d", config->text_size);
Expand Down Expand Up @@ -67,6 +68,7 @@ static void load_config_from_file(struct swappy_config *config,
GKeyFile *gkf;
const gchar *group = "Default";
gchar *save_dir = NULL;
gboolean show_panel;
gchar *save_dir_expanded = NULL;
guint64 line_size, text_size;
gchar *text_font = NULL;
Expand Down Expand Up @@ -150,6 +152,16 @@ static void load_config_from_file(struct swappy_config *config,
error = NULL;
}

show_panel = g_key_file_get_boolean(gkf, group, "show_panel", &error);

if (error == NULL) {
config->show_panel = show_panel;
} else {
g_info("show_panel is missing in %s (%s)", file, error->message);
g_error_free(error);
error = NULL;
}

g_key_file_free(gkf);
}

Expand All @@ -162,6 +174,7 @@ static void load_default_config(struct swappy_config *config) {
config->line_size = CONFIG_LINE_SIZE_DEFAULT;
config->text_font = g_strdup(CONFIG_TEXT_FONT_DEFAULT);
config->text_size = CONFIG_TEXT_SIZE_DEFAULT;
config->show_panel = CONFIG_SHOW_PANEL_DEFAULT;
}

void config_load(struct swappy_state *state) {
Expand Down
2 changes: 2 additions & 0 deletions swappy.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ The following lines can be used as swappy's default:
```
[Default]
save_dir=$HOME/Desktop
show_panel=false
blur_level=80
line_size=5
text_size=20
text_font=sans-serif
```

- *save_dir* is where swappshots will be saved, can contain env variables and must exist in your filesystem
- *show_panel* is used to toggle the paint panel on or off upon startup
- *blur_level* is the default blur level (must be between 1 and 500)
- *line_size* is the default line size (must be between 1 and 50)
- *text_size* is the default text size (must be between 10 and 50)
Expand Down

0 comments on commit 307f579

Please sign in to comment.