Skip to content

Commit

Permalink
feat: custom_color config option
Browse files Browse the repository at this point in the history
  • Loading branch information
DriesOlbrechts committed Oct 28, 2024
1 parent 9e7f3b2 commit d98975c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ paint_mode=brush
early_exit=false
fill_shape=false
auto_save=false
custom_color=rgba(193,125,17,1)
```

- `save_dir` is where swappshots will be saved, can contain env variables, when it does not exist, swappy attempts to create it first, but does not abort if directory creation fails
Expand All @@ -64,6 +65,9 @@ auto_save=false
- `early_exit` is used to make the application exit after saving the picture or copying it to the clipboard
- `fill_shape` is used to toggle shape filling (for the rectangle and ellipsis tools) on or off upon startup
- `auto_save` is used to toggle auto saving of final buffer to `save_dir` upon exit
- `early_exit` is used to make the application exit after saving the picture or copying it to the clipboard
- `custom_color` is used to set a default value for the custom color


## Keyboard Shortcuts

Expand Down
1 change: 1 addition & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define CONFIG_EARLY_EXIT_DEFAULT false
#define CONFIG_FILL_SHAPE_DEFAULT false
#define CONFIG_AUTO_SAVE_DEFAULT false
#define CONFIG_CUSTOM_COLOR_DEFAULT "rgba(193,125,17,1)"

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 @@ -153,6 +153,7 @@ struct swappy_config {
char *text_font;
gboolean early_exit;
gboolean auto_save;
char *custom_color;
};

struct swappy_state {
Expand Down
5 changes: 5 additions & 0 deletions src/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,8 @@ static bool load_css(struct swappy_state *state) {

static bool load_layout(struct swappy_state *state) {
GError *error = NULL;
// init color
GdkRGBA color;

/* Construct a GtkBuilder instance and load our UI description */
GtkBuilder *builder = gtk_builder_new();
Expand Down Expand Up @@ -785,6 +787,9 @@ static bool load_layout(struct swappy_state *state) {
state->ui->fill_shape = GTK_TOGGLE_BUTTON(
gtk_builder_get_object(builder, "fill-shape-toggle-button"));

gdk_rgba_parse(&color, state->config->custom_color);
gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(state->ui->color), &color);

state->ui->brush = brush;
state->ui->text = text;
state->ui->rectangle = rectangle;
Expand Down
12 changes: 12 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static void print_config(struct swappy_config *config) {
g_info("early_exit: %d", config->early_exit);
g_info("fill_shape: %d", config->fill_shape);
g_info("auto_save: %d", config->auto_save);
g_info("custom_color: %s", config->custom_color);
}

static char *get_default_save_dir() {
Expand Down Expand Up @@ -83,6 +84,7 @@ static void load_config_from_file(struct swappy_config *config,
gboolean early_exit;
gboolean fill_shape;
gboolean auto_save;
gchar *custom_color = NULL;
GError *error = NULL;

if (file == NULL) {
Expand Down Expand Up @@ -240,6 +242,14 @@ static void load_config_from_file(struct swappy_config *config,
config->auto_save = auto_save;
} else {
g_info("auto_save is missing in %s (%s)", file, error->message);
}

custom_color = g_key_file_get_string(gkf, group, "custom_color", &error);

if (error == NULL) {
config->custom_color = custom_color;
} else {
g_info("custom_color is missing in %s (%s)", file, error->message);
g_error_free(error);
error = NULL;
}
Expand All @@ -262,6 +272,7 @@ static void load_default_config(struct swappy_config *config) {
config->early_exit = CONFIG_EARLY_EXIT_DEFAULT;
config->fill_shape = CONFIG_FILL_SHAPE_DEFAULT;
config->auto_save = CONFIG_AUTO_SAVE_DEFAULT;
config->custom_color = CONFIG_CUSTOM_COLOR_DEFAULT;
}

void config_load(struct swappy_state *state) {
Expand All @@ -288,6 +299,7 @@ void config_free(struct swappy_state *state) {
g_free(state->config->save_dir);
g_free(state->config->save_filename_format);
g_free(state->config->text_font);
g_free(state->config->custom_color);
g_free(state->config);
state->config = NULL;
}
Expand Down
2 changes: 2 additions & 0 deletions swappy.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ The following lines can be used as swappy's default:
early_exit=false
fill_shape=false
auto_save=false
custom_color=rgba(192,125,17,1)
```

- *save_dir* is where swappshots will be saved, can contain env variables, when it does not exist, swappy attempts to create it first, but does not abort if directory creation fails
Expand All @@ -79,6 +80,7 @@ The following lines can be used as swappy's default:
- *early_exit* is used to make the application exit after saving the picture or copying it to the clipboard
- *fill_shape* is used to toggle shape filling (for the rectangle and ellipsis tools) on or off upon startup
- *auto_save* is used to toggle auto saving of final buffer to *save_dir* upon exit
- *custom_color* is used to set a default value for the custom color


# KEY BINDINGS
Expand Down

0 comments on commit d98975c

Please sign in to comment.