Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a custom_color config option #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ text_size=20
text_font=sans-serif
paint_mode=brush
early_exit=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 @@ -60,6 +61,8 @@ early_exit=false
- `text_font` is the font used to render text, its format is pango friendly
- `paint_mode` is the mode activated at application start (must be one of: brush|text|rectangle|ellipse|arrow|blur, matching is case-insensitive)
- `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 @@ -7,6 +7,7 @@
#define CONFIG_SAVE_FILENAME_FORMAT_DEFAULT "swappy-%Y%m%d_%H%M%S.png"
#define CONFIG_PAINT_MODE_DEFAULT SWAPPY_PAINT_MODE_BRUSH
#define CONFIG_EARLY_EXIT_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 @@ -149,6 +149,7 @@ struct swappy_config {
guint32 text_size;
char *text_font;
gboolean early_exit;
char *custom_color;
};

struct swappy_state {
Expand Down
4 changes: 4 additions & 0 deletions src/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,10 @@ static bool load_layout(struct swappy_state *state) {
state->ui->text_size =
GTK_BUTTON(gtk_builder_get_object(builder, "text-size-button"));

GdkRGBA color;
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
13 changes: 13 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static void print_config(struct swappy_config *config) {
g_info("text_size: %d", config->text_size);
g_info("paint_mode: %d", config->paint_mode);
g_info("early_exit: %d", config->early_exit);
g_info("custom_color: %s", config->custom_color);
}

static char *get_default_save_dir() {
Expand Down Expand Up @@ -79,6 +80,7 @@ static void load_config_from_file(struct swappy_config *config,
gchar *text_font = NULL;
gchar *paint_mode = NULL;
gboolean early_exit;
gchar *custom_color = NULL;
GError *error = NULL;

if (file == NULL) {
Expand Down Expand Up @@ -220,6 +222,15 @@ static void load_config_from_file(struct swappy_config *config,
error = NULL;
}

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;
}

g_key_file_free(gkf);
}

Expand All @@ -236,6 +247,7 @@ static void load_default_config(struct swappy_config *config) {
config->show_panel = CONFIG_SHOW_PANEL_DEFAULT;
config->paint_mode = CONFIG_PAINT_MODE_DEFAULT;
config->early_exit = CONFIG_EARLY_EXIT_DEFAULT;
config->custom_color = CONFIG_CUSTOM_COLOR_DEFAULT;
}

void config_load(struct swappy_state *state) {
Expand All @@ -262,6 +274,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 @@ -65,6 +65,7 @@ The following lines can be used as swappy's default:
text_font=sans-serif
paint_mode=brush
early_exit=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 @@ -75,6 +76,7 @@ The following lines can be used as swappy's default:
- *text_font* is the font used to render text, its format is pango friendly
- *paint_mode* is the mode activated at application start (must be one of: brush|text|rectangle|ellipse|arrow|blur, matching is case-insensitive)
- *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


# KEY BINDINGS
Expand Down