Skip to content

Commit

Permalink
Implement time and geometry setting types
Browse files Browse the repository at this point in the history
  • Loading branch information
fwsmit committed Jan 29, 2021
1 parent cf63770 commit 6153c02
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 30 deletions.
16 changes: 11 additions & 5 deletions src/option_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,9 @@ int get_setting_id(const char *key, const char *section) {
}

if (error_code == -2) {
LOG_W("Setting %s is in the wrong section (%s, should be %s)",
key, section,
allowed_settings[partial_match_id].section);
/* LOG_W("Setting %s is in the wrong section (%s, should be %s)", */ // TODO fix this warning
/* key, section, */
/* allowed_settings[partial_match_id].section); */
// found, but in wrong section
return -2;
}
Expand All @@ -441,7 +441,7 @@ int get_setting_id(const char *key, const char *section) {
}

bool set_setting(struct setting setting, char* value) {
LOG_D("Setting %s to %s", setting.name, value);
LOG_D("Trying to set %s to %s", setting.name, value);
switch (setting.type) {
case TYPE_INT:
*(int*) setting.value = atoi(value);
Expand All @@ -450,7 +450,7 @@ bool set_setting(struct setting setting, char* value) {
*(bool*) setting.value = str_to_bool(value);
return true;
case TYPE_STRING:
*(char**)setting.value = value;
*(char**) setting.value = value;
return true;
case TYPE_ENUM:
if (setting.parser == NULL) {
Expand All @@ -473,6 +473,12 @@ bool set_setting(struct setting setting, char* value) {
}
*(char**) setting.value = path;
return true;
case TYPE_TIME: ;
*(gint64*) setting.value = string_to_time(value);
return true;
case TYPE_GEOMETRY:
*(struct geometry*) setting.value = x_parse_geometry(value);
return true;
default:
LOG_W("Setting type of '%s' is not known (type %i)", setting.name, setting.type);
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ void load_settings(char *cmdline_config_path)
}

load_ini_file(config_file);
printf("\n");
LOG_I("### Before setting defaults");
test_print_settings();
set_defaults();
printf("\n");
LOG_I("### After setting defaults");
test_print_settings();
save_settings();
LOG_I("\n");
LOG_I("### After setting from config");
test_print_settings();
/* return; */
#else
LOG_M("dunstrc parsing disabled. "
Expand Down
5 changes: 3 additions & 2 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ enum zwlr_layer_shell_v1_layer {
ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY = 3,
};
#endif /* ZWLR_LAYER_SHELL_V1_LAYER_ENUM */
enum setting_type { TYPE_INT, TYPE_ENUM, TYPE_STRING, TYPE_BOOLEAN,
TYPE_DEPRECATED, TYPE_TIME, TYPE_PATH, TYPE_GEOMETRY }; // to be implemented
enum setting_type { TYPE_INT, TYPE_ENUM, TYPE_STRING, TYPE_BOOLEAN, TYPE_PATH,
TYPE_TIME, TYPE_GEOMETRY,
TYPE_DEPRECATED, TYPE_LIST }; // to be implemented

struct separator_color_data {
enum separator_color type;
Expand Down
40 changes: 20 additions & 20 deletions src/settings_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,16 +418,16 @@ struct setting allowed_settings[] = {
.parser = NULL,
.parser_data = NULL,
},
// { // TODO rebase for this setting
// .name = "text_icon_padding",
// .section = "global",
// .description = "Padding between text and icon",
// .type = TYPE_INT,
// .default_value = "0",
// .value = &settings.text_icon_padding,
// .parser = NULL,
// .parser_data = NULL,
// },
{
.name = "text_icon_padding",
.section = "global",
.description = "Padding between text and icon",
.type = TYPE_INT,
.default_value = "0",
.value = &settings.text_icon_padding,
.parser = NULL,
.parser_data = NULL,
},
{
.name = "transparency",
.section = "global",
Expand Down Expand Up @@ -870,16 +870,16 @@ struct setting allowed_settings[] = {
.parser = string_parse_enum,
.parser_data = vertical_alignment_enum_data,
},
// { // TODO rebase
// .name = "layer",
// .section = "global",
// .description = "Select the layer where notifications should be placed",
// .type = TYPE_ENUM,
// .default_value = "overlay",
// .value = &settings.layer,
// .parser = string_parse_enum,
// .parser_data = layer_enum_data,
// },
{
.name = "layer",
.section = "global",
.description = "Select the layer where notifications should be placed",
.type = TYPE_ENUM,
.default_value = "overlay",
.value = &settings.layer,
.parser = string_parse_enum,
.parser_data = layer_enum_data,
},
// TODO maybe implement deprecated icon_folders
};
#endif

0 comments on commit 6153c02

Please sign in to comment.