diff --git a/config.c b/config.c
index 50affec..eedab76 100644
--- a/config.c
+++ b/config.c
@@ -17,47 +17,9 @@ static int32_t max(int32_t a, int32_t b) {
return (a > b) ? a : b;
}
-void init_default_config(struct mako_config *config) {
+static void init_config(struct mako_config *config) {
+ memset(config, 0, sizeof(struct mako_config));
wl_list_init(&config->criteria);
- struct mako_criteria *new_criteria = create_criteria(config);
- init_default_style(&new_criteria->style);
- new_criteria->raw_string = strdup("(root)");
-
- // Hide grouped notifications by default, and put the group count in
- // their format...
- new_criteria = create_criteria(config);
- init_empty_style(&new_criteria->style);
- new_criteria->grouped = true;
- new_criteria->spec.grouped = true;
- new_criteria->style.invisible = true;
- new_criteria->style.spec.invisible = true;
- new_criteria->style.format = strdup("(%g) %s\n%b");
- new_criteria->style.spec.format = true;
- new_criteria->raw_string = strdup("(default grouped)");
-
- // ...but make the first one in the group visible.
- new_criteria = create_criteria(config);
- init_empty_style(&new_criteria->style);
- new_criteria->group_index = 0;
- new_criteria->spec.group_index = true;
- new_criteria->style.invisible = false;
- new_criteria->style.spec.invisible = true;
- new_criteria->raw_string = strdup("(default group-index=0)");
-
- // Define the default format for the hidden placeholder notification.
- new_criteria = create_criteria(config);
- init_empty_style(&new_criteria->style);
- new_criteria->hidden = true;
- new_criteria->spec.hidden = true;
- new_criteria->style.format = strdup("(%h more)");
- new_criteria->style.spec.format = true;
- new_criteria->raw_string = strdup("(default hidden)");
-
- init_empty_style(&config->superstyle);
-
- config->max_history = 5;
- config->sort_criteria = MAKO_SORT_CRITERIA_TIME;
- config->sort_asc = 0;
}
void finish_config(struct mako_config *config) {
@@ -69,72 +31,6 @@ void finish_config(struct mako_config *config) {
finish_style(&config->superstyle);
}
-void init_default_style(struct mako_style *style) {
- style->width = 300;
- style->height = 100;
-
- style->outer_margin.top = 0;
- style->outer_margin.right = 0;
- style->outer_margin.bottom = 0;
- style->outer_margin.left = 0;
-
- style->margin.top = 10;
- style->margin.right = 10;
- style->margin.bottom = 10;
- style->margin.left = 10;
-
- style->padding.top = 5;
- style->padding.right = 5;
- style->padding.bottom = 5;
- style->padding.left = 5;
-
- style->border_size = 2;
- style->border_radius = 0;
-
-#ifdef HAVE_ICONS
- style->icons = true;
-#else
- style->icons = false;
-#endif
- style->max_icon_size = 64;
- style->icon_path = strdup(""); // hicolor and pixmaps are implicit.
-
- style->font = strdup("monospace 10");
- style->markup = true;
- style->format = strdup("%s\n%b");
- style->text_alignment = PANGO_ALIGN_LEFT;
-
- style->actions = true;
- style->default_timeout = 0;
- style->ignore_timeout = false;
-
- style->colors.background = 0x285577FF;
- style->colors.text = 0xFFFFFFFF;
- style->colors.border = 0x4C7899FF;
- style->colors.progress.value = 0x5588AAFF;
- style->colors.progress.operator = CAIRO_OPERATOR_OVER;
-
- style->group_criteria_spec.none = true;
- style->invisible = false;
- style->history = true;
- style->icon_location = MAKO_ICON_LOCATION_LEFT;
-
- style->output = strdup("");
- style->layer = ZWLR_LAYER_SHELL_V1_LAYER_TOP;
- style->max_visible = 5;
-
- style->anchor =
- ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
-
- style->button_bindings.left.action = MAKO_BINDING_INVOKE_DEFAULT_ACTION;
- style->button_bindings.right.action = MAKO_BINDING_DISMISS;
- style->button_bindings.middle.action = MAKO_BINDING_NONE;
- style->touch_binding.action = MAKO_BINDING_DISMISS;
-
- // Everything in the default config is explicitly specified.
- memset(&style->spec, true, sizeof(struct mako_style_spec));
-}
-
void init_empty_style(struct mako_style *style) {
memset(style, 0, sizeof(struct mako_style));
}
@@ -722,21 +618,10 @@ static char *get_config_path(void) {
return NULL;
}
-int load_config_file(struct mako_config *config, char *config_arg) {
- char *path = NULL;
- if (config_arg == NULL) {
- path = get_config_path();
- if (!path) {
- return 0;
- }
- } else {
- path = config_arg;
- }
-
+static int load_config_file(struct mako_config *config, char *path) {
FILE *f = fopen(path, "r");
if (!f) {
fprintf(stderr, "Unable to open %s for reading\n", path);
- free(path);
return -1;
}
const char *base = basename(path);
@@ -800,7 +685,6 @@ int load_config_file(struct mako_config *config, char *config_arg) {
valid_option = apply_config_option(config, line, eq + 1);
}
-
if (!valid_option) {
fprintf(stderr, "[%s:%d] Failed to parse option '%s'\n",
base, lineno, line);
@@ -820,7 +704,6 @@ int load_config_file(struct mako_config *config, char *config_arg) {
free(section);
free(line);
fclose(f);
- free(path);
return ret;
}
@@ -865,7 +748,7 @@ int parse_config_arguments(struct mako_config *config, int argc, char **argv) {
};
optind = 1;
- char *config_arg = NULL;
+ const char *config_arg = NULL;
int opt_status = 0;
while (1) {
int option_index = -1;
@@ -876,8 +759,7 @@ int parse_config_arguments(struct mako_config *config, int argc, char **argv) {
opt_status = 1;
break;
} else if (c == 'c') {
- free(config_arg);
- config_arg = strdup(optarg);
+ config_arg = optarg;
} else if (c != 0) {
opt_status = -1;
break;
@@ -885,14 +767,24 @@ int parse_config_arguments(struct mako_config *config, int argc, char **argv) {
}
if (opt_status != 0) {
- free(config_arg);
return opt_status;
}
- int config_status = load_config_file(config, config_arg);
+ char *config_path = NULL;
+ if (config_arg == NULL) {
+ config_path = get_config_path();
+ } else {
+ config_path = strdup(config_arg);
+ }
+ if (!config_path) {
+ return -1;
+ }
+
+ int config_status = load_config_file(config, config_path);
if (config_status < 0) {
return -1;
}
+ free(config_path);
optind = 1;
while (1) {
@@ -920,7 +812,13 @@ int parse_config_arguments(struct mako_config *config, int argc, char **argv) {
// immediately due to something the user asked for (like help).
int reload_config(struct mako_config *config, int argc, char **argv) {
struct mako_config new_config = {0};
- init_default_config(&new_config);
+ init_config(&new_config);
+
+ int ret = load_config_file(&new_config, SYSCONFDIR "/mako/config");
+ if (ret != 0) {
+ fprintf(stderr, "Failed to parse default config\n");
+ return ret;
+ }
int args_status = parse_config_arguments(&new_config, argc, argv);
diff --git a/config.in b/config.in
new file mode 100644
index 0000000..9c101cf
--- /dev/null
+++ b/config.in
@@ -0,0 +1,37 @@
+width=300
+height=100
+margin=10
+padding=5
+border-size=2
+icons=@icons@
+max-icon-size=64
+font=monospace 10
+markup=1
+actions=1
+history=1
+format=%s\n%b
+text-alignment=left
+layer=top
+max-visible=5
+anchor=top-right
+
+on-button-left=invoke-default-action
+on-button-right=dismiss
+on-touch=dismiss
+
+max-history=5
+sort=-time
+
+# Hide grouped notifications by default, and put the group count in
+# their format...
+[grouped]
+invisible=1
+format=(%g) %s\n%b
+
+# ...but make the first one in the group visible.
+[group_index=0]
+invisible=0
+
+# Define the default format for the hidden placeholder notification.
+[hidden]
+format=(%h more)
diff --git a/include/config.h b/include/config.h
index 70b4acd..76264b8 100644
--- a/include/config.h
+++ b/include/config.h
@@ -109,10 +109,8 @@ struct mako_config {
struct mako_style superstyle;
};
-void init_default_config(struct mako_config *config);
void finish_config(struct mako_config *config);
-void init_default_style(struct mako_style *style);
void init_empty_style(struct mako_style *style);
void finish_style(struct mako_style *style);
bool apply_style(struct mako_style *target, const struct mako_style *style);
@@ -120,7 +118,6 @@ bool apply_superset_style(
struct mako_style *target, struct mako_config *config);
int parse_config_arguments(struct mako_config *config, int argc, char **argv);
-int load_config_file(struct mako_config *config, char *config_arg);
int reload_config(struct mako_config *config, int argc, char **argv);
bool apply_global_option(struct mako_config *config, const char *name,
const char *value);
diff --git a/main.c b/main.c
index e7bfc9a..05d1091 100644
--- a/main.c
+++ b/main.c
@@ -107,14 +107,10 @@ int main(int argc, char *argv[]) {
wl_list_init(&state.surfaces);
// This is a bit wasteful, but easier than special-casing the reload.
- init_default_config(&state.config);
int ret = reload_config(&state.config, argc, argv);
-
if (ret < 0) {
- finish_config(&state.config);
return EXIT_FAILURE;
} else if (ret > 0) {
- finish_config(&state.config);
printf("%s", usage);
return EXIT_SUCCESS;
}
diff --git a/meson.build b/meson.build
index 83c17a2..b8c00e8 100644
--- a/meson.build
+++ b/meson.build
@@ -38,6 +38,8 @@ if (not cc.has_function('timerfd_create', prefix: '#include ') or
epoll = dependency('epoll-shim')
endif
+add_project_arguments('-DSYSCONFDIR="@0@"'.format(get_option('sysconfdir')), language: 'c')
+
if get_option('sd-bus-provider') == 'auto'
assert(get_option('auto_features').auto(), 'sd-bus-provider must not be set to auto since auto_features != auto')
sdbus = dependency('libsystemd', 'libelogind', 'basu')
@@ -105,6 +107,7 @@ install_data(
conf_data = configuration_data()
conf_data.set('bindir', get_option('prefix') / get_option('bindir'))
+conf_data.set('icons', gdk_pixbuf.found().to_int())
configure_file(
configuration: conf_data,
@@ -113,6 +116,13 @@ configure_file(
install_dir: get_option('datadir') + '/dbus-1/services',
)
+configure_file(
+ configuration: conf_data,
+ input: 'config.in',
+ output: '@BASENAME@',
+ install_dir: get_option('sysconfdir') + '/mako/config',
+)
+
scdoc = dependency('scdoc', required: get_option('man-pages'), version: '>= 1.9.7', native: true)
if scdoc.found()
man_pages = ['mako.1.scd', 'mako.5.scd', 'makoctl.1.scd']