Move default values into separate settings struct

This commit is contained in:
Benedikt Heine 2017-10-07 18:16:45 +02:00
parent c711b59df2
commit 7965fd3e9f
2 changed files with 107 additions and 101 deletions

View File

@ -1,63 +1,67 @@
/* see example dunstrc for additional explanations about these options */ /* see example dunstrc for additional explanations about these options */
char *font = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*"; settings_t defaults = {
char *markup = "no";
char *normbgcolor = "#1793D1";
char *normfgcolor = "#DDDDDD";
char *critbgcolor = "#ffaaaa";
char *critfgcolor = "#000000";
char *lowbgcolor = "#aaaaff";
char *lowfgcolor = "#000000";
char *format = "%s %b"; /* default format */
gint64 timeouts[] = { 10*G_USEC_PER_SEC, 10*G_USEC_PER_SEC, 0 }; /* low, normal, critical */ .font = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*",
char *icons[] = { "dialog-information", "dialog-information", "dialog-warning" }; /* low, normal, critical */ .markup = MARKUP_NO,
.normbgcolor = "#1793D1",
.normfgcolor = "#DDDDDD",
.critbgcolor = "#ffaaaa",
.critfgcolor = "#000000",
.lowbgcolor = "#aaaaff",
.lowfgcolor = "#000000",
.format = "%s %b", /* default format */
unsigned int transparency = 0; /* transparency */ .timeouts = { 10*G_USEC_PER_SEC, 10*G_USEC_PER_SEC, 0 }, /* low, normal, critical */
char *geom = "0x0"; /* geometry */ .icons = { "dialog-information", "dialog-information", "dialog-warning" }, /* low, normal, critical */
char *title = "Dunst"; /* the title of dunst notification windows */
char *class = "Dunst"; /* the class of dunst notification windows */
int shrink = false; /* shrinking */
int sort = true; /* sort messages by urgency */
int indicate_hidden = true; /* show count of hidden messages */
gint64 idle_threshold = 0; /* don't timeout notifications when idle for x seconds */
gint64 show_age_threshold = -1; /* show age of notification, when notification is older than x seconds */
enum alignment align = left; /* text alignment [left/center/right] */
int sticky_history = true;
int history_length = 20; /* max amount of notifications kept in history */
int show_indicators = true;
int word_wrap = false;
enum ellipsize ellipsize = middle;
int ignore_newline = false;
int line_height = 0; /* if line height < font height, it will be raised to font height */
int notification_height = 0; /* if notification height < font height and padding, it will be raised */
int separator_height = 2; /* height of the separator line between two notifications */ .transparency = 0, /* transparency */
int padding = 0; .geom = "0x0", /* geometry */
int h_padding = 0; /* horizontal padding */ .title = "Dunst", /* the title of dunst notification windows */
enum separator_color sep_color = AUTO; /* AUTO, FOREGROUND, FRAME, CUSTOM */ .class = "Dunst", /* the class of dunst notification windows */
char *sep_custom_color_str = NULL; /* custom color if sep_color is set to CUSTOM */ .shrink = false, /* shrinking */
.sort = true, /* sort messages by urgency */
.indicate_hidden = true, /* show count of hidden messages */
.idle_threshold = 0, /* don't timeout notifications when idle for x seconds */
.show_age_threshold = -1, /* show age of notification, when notification is older than x seconds */
.align = left, /* text alignment [left/center/right] */
.sticky_history = true,
.history_length = 20, /* max amount of notifications kept in history */
.show_indicators = true,
.word_wrap = false,
.ellipsize = middle,
.ignore_newline = false,
.line_height = 0, /* if line height < font height, it will be raised to font height */
.notification_height = 0, /* if notification height < font height and padding, it will be raised */
.separator_height = 2, /* height of the separator line between two notifications */
.padding = 0,
.h_padding = 0, /* horizontal padding */
.sep_color = AUTO, /* AUTO, FOREGROUND, FRAME, CUSTOM */
.sep_custom_color_str = NULL,/* custom color if sep_color is set to CUSTOM */
.frame_width = 0,
.frame_color = "#888888",
int frame_width = 0;
char *frame_color = "#888888";
/* show a notification on startup /* show a notification on startup
* This is mainly for crash detection since dbus restarts dunst * This is mainly for crash detection since dbus restarts dunst
* automatically after a crash, so crashes might get unnotices otherwise * automatically after a crash, so crashes might get unnotices otherwise
* */ * */
int startup_notification = false; .startup_notification = false,
/* monitor to display notifications on */ /* monitor to display notifications on */
int monitor = 0; .monitor = 0,
/* path to dmenu */ /* path to dmenu */
char *dmenu = "/usr/bin/dmenu"; .dmenu = "/usr/bin/dmenu",
char *browser = "/usr/bin/firefox"; .browser = "/usr/bin/firefox",
int max_icon_size = 0; .max_icon_size = 0,
/* paths to default icons */ /* paths to default icons */
char *icon_path = "/usr/share/icons/gnome/16x16/status/:/usr/share/icons/gnome/16x16/devices/"; .icon_path = "/usr/share/icons/gnome/16x16/status/:/usr/share/icons/gnome/16x16/devices/",
/* follow focus to different monitor and display notifications there? /* follow focus to different monitor and display notifications there?
* possible values: * possible values:
@ -67,27 +71,29 @@ char *icon_path = "/usr/share/icons/gnome/16x16/status/:/usr/share/icons/gnome/1
* *
* everything else than FOLLOW_NONE overrides 'monitor' * everything else than FOLLOW_NONE overrides 'monitor'
*/ */
enum follow_mode f_mode = FOLLOW_NONE; .f_mode = FOLLOW_NONE,
/* keyboard shortcuts /* keyboard shortcuts
* use for example "ctrl+shift+space" * use for example "ctrl+shift+space"
* use "none" to disable * use "none" to disable
*/ */
keyboard_shortcut close_ks = {.str = "none", .close_ks = {.str = "none",
.code = 0,.sym = NoSymbol,.is_valid = false .code = 0,.sym = NoSymbol,.is_valid = false
}; /* ignore this */ }, /* ignore this */
keyboard_shortcut close_all_ks = {.str = "none", .close_all_ks = {.str = "none",
.code = 0,.sym = NoSymbol,.is_valid = false .code = 0,.sym = NoSymbol,.is_valid = false
}; /* ignore this */ }, /* ignore this */
keyboard_shortcut history_ks = {.str = "none", .history_ks = {.str = "none",
.code = 0,.sym = NoSymbol,.is_valid = false .code = 0,.sym = NoSymbol,.is_valid = false
}; /* ignore this */ }, /* ignore this */
keyboard_shortcut context_ks = {.str = "none", .context_ks = {.str = "none",
.code = 0,.sym = NoSymbol,.is_valid = false .code = 0,.sym = NoSymbol,.is_valid = false
}; /* ignore this */ }, /* ignore this */
};
rule_t default_rules[] = { rule_t default_rules[] = {
/* name can be any unique string. It is used to identify /* name can be any unique string. It is used to identify

View File

@ -111,7 +111,7 @@ void load_settings(char *cmdline_config_path)
settings.font = option_get_string( settings.font = option_get_string(
"global", "global",
"font", "-font/-fn", font, "font", "-font/-fn", defaults.font,
"The font dunst should use." "The font dunst should use."
); );
@ -140,32 +140,32 @@ void load_settings(char *cmdline_config_path)
if(c){ if(c){
settings.markup = parse_markup_mode(c); settings.markup = parse_markup_mode(c);
} else if (!settings.markup) { } else if (!settings.markup) {
settings.markup = parse_markup_mode(markup); settings.markup = defaults.markup;
} }
g_free(c); g_free(c);
} }
settings.format = option_get_string( settings.format = option_get_string(
"global", "global",
"format", "-format", format, "format", "-format", defaults.format,
"The format template for the notifications" "The format template for the notifications"
); );
settings.sort = option_get_bool( settings.sort = option_get_bool(
"global", "global",
"sort", "-sort", sort, "sort", "-sort", defaults.sort,
"Sort notifications by urgency and date?" "Sort notifications by urgency and date?"
); );
settings.indicate_hidden = option_get_bool( settings.indicate_hidden = option_get_bool(
"global", "global",
"indicate_hidden", "-indicate_hidden", indicate_hidden, "indicate_hidden", "-indicate_hidden", defaults.indicate_hidden,
"Show how many notificaitons are hidden?" "Show how many notificaitons are hidden?"
); );
settings.word_wrap = option_get_bool( settings.word_wrap = option_get_bool(
"global", "global",
"word_wrap", "-word_wrap", word_wrap, "word_wrap", "-word_wrap", defaults.word_wrap,
"Truncating long lines or do word wrap" "Truncating long lines or do word wrap"
); );
@ -177,7 +177,7 @@ void load_settings(char *cmdline_config_path)
); );
if (strlen(c) == 0) { if (strlen(c) == 0) {
settings.ellipsize = ellipsize; settings.ellipsize = defaults.ellipsize;
} else if (strcmp(c, "start") == 0) { } else if (strcmp(c, "start") == 0) {
settings.ellipsize = start; settings.ellipsize = start;
} else if (strcmp(c, "middle") == 0) { } else if (strcmp(c, "middle") == 0) {
@ -186,26 +186,26 @@ void load_settings(char *cmdline_config_path)
settings.ellipsize = end; settings.ellipsize = end;
} else { } else {
fprintf(stderr, "Warning: unknown ellipsize value: \"%s\"\n", c); fprintf(stderr, "Warning: unknown ellipsize value: \"%s\"\n", c);
settings.ellipsize = ellipsize; settings.ellipsize = defaults.ellipsize;
} }
g_free(c); g_free(c);
} }
settings.ignore_newline = option_get_bool( settings.ignore_newline = option_get_bool(
"global", "global",
"ignore_newline", "-ignore_newline", ignore_newline, "ignore_newline", "-ignore_newline", defaults.ignore_newline,
"Ignore newline characters in notifications" "Ignore newline characters in notifications"
); );
settings.idle_threshold = option_get_time( settings.idle_threshold = option_get_time(
"global", "global",
"idle_threshold", "-idle_threshold", idle_threshold, "idle_threshold", "-idle_threshold", defaults.idle_threshold,
"Don't timeout notifications if user is longer idle than threshold" "Don't timeout notifications if user is longer idle than threshold"
); );
settings.monitor = option_get_int( settings.monitor = option_get_int(
"global", "global",
"monitor", "-mon/-monitor", monitor, "monitor", "-mon/-monitor", defaults.monitor,
"On which monitor should the notifications be displayed" "On which monitor should the notifications be displayed"
); );
@ -224,37 +224,37 @@ void load_settings(char *cmdline_config_path)
settings.title = option_get_string( settings.title = option_get_string(
"global", "global",
"title", "-t/-title", title, "title", "-t/-title", defaults.title,
"Define the title of windows spawned by dunst." "Define the title of windows spawned by dunst."
); );
settings.class = option_get_string( settings.class = option_get_string(
"global", "global",
"class", "-c/-class", class, "class", "-c/-class", defaults.class,
"Define the class of windows spawned by dunst." "Define the class of windows spawned by dunst."
); );
settings.geom = option_get_string( settings.geom = option_get_string(
"global", "global",
"geometry", "-geom/-geometry", geom, "geometry", "-geom/-geometry", defaults.geom,
"Geometry for the window" "Geometry for the window"
); );
settings.shrink = option_get_bool( settings.shrink = option_get_bool(
"global", "global",
"shrink", "-shrink", shrink, "shrink", "-shrink", defaults.shrink,
"Shrink window if it's smaller than the width" "Shrink window if it's smaller than the width"
); );
settings.line_height = option_get_int( settings.line_height = option_get_int(
"global", "global",
"line_height", "-lh/-line_height", line_height, "line_height", "-lh/-line_height", defaults.line_height,
"Add spacing between lines of text" "Add spacing between lines of text"
); );
settings.notification_height = option_get_int( settings.notification_height = option_get_int(
"global", "global",
"notification_height", "-nh/-notification_height", notification_height, "notification_height", "-nh/-notification_height", defaults.notification_height,
"Define height of the window" "Define height of the window"
); );
@ -281,7 +281,7 @@ void load_settings(char *cmdline_config_path)
settings.show_age_threshold = option_get_time( settings.show_age_threshold = option_get_time(
"global", "global",
"show_age_threshold", "-show_age_threshold", show_age_threshold, "show_age_threshold", "-show_age_threshold", defaults.show_age_threshold,
"When should the age of the notification be displayed?" "When should the age of the notification be displayed?"
); );
@ -293,43 +293,43 @@ void load_settings(char *cmdline_config_path)
settings.sticky_history = option_get_bool( settings.sticky_history = option_get_bool(
"global", "global",
"sticky_history", "-sticky_history", sticky_history, "sticky_history", "-sticky_history", defaults.sticky_history,
"Don't timeout notifications popped up from history" "Don't timeout notifications popped up from history"
); );
settings.history_length = option_get_int( settings.history_length = option_get_int(
"global", "global",
"history_length", "-history_length", history_length, "history_length", "-history_length", defaults.history_length,
"Max amount of notifications kept in history" "Max amount of notifications kept in history"
); );
settings.show_indicators = option_get_bool( settings.show_indicators = option_get_bool(
"global", "global",
"show_indicators", "-show_indicators", show_indicators, "show_indicators", "-show_indicators", defaults.show_indicators,
"Show indicators for actions \"(A)\" and URLs \"(U)\"" "Show indicators for actions \"(A)\" and URLs \"(U)\""
); );
settings.separator_height = option_get_int( settings.separator_height = option_get_int(
"global", "global",
"separator_height", "-sep_height/-separator_height", separator_height, "separator_height", "-sep_height/-separator_height", defaults.separator_height,
"height of the separator line" "height of the separator line"
); );
settings.padding = option_get_int( settings.padding = option_get_int(
"global", "global",
"padding", "-padding", padding, "padding", "-padding", defaults.padding,
"Padding between text and separator" "Padding between text and separator"
); );
settings.h_padding = option_get_int( settings.h_padding = option_get_int(
"global", "global",
"horizontal_padding", "-horizontal_padding", h_padding, "horizontal_padding", "-horizontal_padding", defaults.h_padding,
"horizontal padding" "horizontal padding"
); );
settings.transparency = option_get_int( settings.transparency = option_get_int(
"global", "global",
"transparency", "-transparency", transparency, "transparency", "-transparency", defaults.transparency,
"Transparency. range 0-100" "Transparency. range 0-100"
); );
@ -369,7 +369,7 @@ void load_settings(char *cmdline_config_path)
settings.dmenu = option_get_path( settings.dmenu = option_get_path(
"global", "global",
"dmenu", "-dmenu", dmenu, "dmenu", "-dmenu", defaults.dmenu,
"path to dmenu" "path to dmenu"
); );
@ -386,7 +386,7 @@ void load_settings(char *cmdline_config_path)
settings.browser = option_get_path( settings.browser = option_get_path(
"global", "global",
"browser", "-browser", browser, "browser", "-browser", defaults.browser,
"path to browser" "path to browser"
); );
@ -413,7 +413,7 @@ void load_settings(char *cmdline_config_path)
settings.max_icon_size = option_get_int( settings.max_icon_size = option_get_int(
"global", "global",
"max_icon_size", "-max_icon_size", max_icon_size, "max_icon_size", "-max_icon_size", defaults.max_icon_size,
"Scale larger icons down to this size, set to 0 to disable" "Scale larger icons down to this size, set to 0 to disable"
); );
@ -422,7 +422,7 @@ void load_settings(char *cmdline_config_path)
if (ini_is_set("global", "icon_folders") || cmdline_is_set("-icon_folders")) { if (ini_is_set("global", "icon_folders") || cmdline_is_set("-icon_folders")) {
settings.icon_path = option_get_string( settings.icon_path = option_get_string(
"global", "global",
"icon_folders", "-icon_folders", icon_path, "icon_folders", "-icon_folders", defaults.icon_path,
"folders to default icons (deprecated, please use 'icon_path' instead)" "folders to default icons (deprecated, please use 'icon_path' instead)"
); );
fprintf(stderr, "Warning: 'icon_folders' is deprecated, please use 'icon_path' instead.\n"); fprintf(stderr, "Warning: 'icon_folders' is deprecated, please use 'icon_path' instead.\n");
@ -433,7 +433,7 @@ void load_settings(char *cmdline_config_path)
settings.icon_path = option_get_string( settings.icon_path = option_get_string(
"global", "global",
"icon_path", "-icon_path", "icon_path", "-icon_path",
settings.icon_path ? settings.icon_path : icon_path, settings.icon_path ? settings.icon_path : defaults.icon_path,
"paths to default icons" "paths to default icons"
); );
@ -442,7 +442,7 @@ void load_settings(char *cmdline_config_path)
if (ini_is_set("frame", "width")) { if (ini_is_set("frame", "width")) {
settings.frame_width = option_get_int( settings.frame_width = option_get_int(
"frame", "frame",
"width", NULL, frame_width, "width", NULL, defaults.frame_width,
"Width of frame around the window" "Width of frame around the window"
); );
fprintf(stderr, "Warning: The frame section is deprecated, width has been renamed to frame_width and moved to the global section.\n"); fprintf(stderr, "Warning: The frame section is deprecated, width has been renamed to frame_width and moved to the global section.\n");
@ -451,14 +451,14 @@ void load_settings(char *cmdline_config_path)
settings.frame_width = option_get_int( settings.frame_width = option_get_int(
"global", "global",
"frame_width", "-frame_width", "frame_width", "-frame_width",
settings.frame_width ? settings.frame_width : frame_width, settings.frame_width ? settings.frame_width : defaults.frame_width,
"Width of frame around the window" "Width of frame around the window"
); );
if (ini_is_set("frame", "color")) { if (ini_is_set("frame", "color")) {
settings.frame_color = option_get_string( settings.frame_color = option_get_string(
"frame", "frame",
"color", NULL, frame_color, "color", NULL, defaults.frame_color,
"Color of the frame around the window" "Color of the frame around the window"
); );
fprintf(stderr, "Warning: The frame section is deprecated, color has been renamed to frame_color and moved to the global section.\n"); fprintf(stderr, "Warning: The frame section is deprecated, color has been renamed to frame_color and moved to the global section.\n");
@ -467,20 +467,20 @@ void load_settings(char *cmdline_config_path)
settings.frame_color = option_get_string( settings.frame_color = option_get_string(
"global", "global",
"frame_color", "-frame_color", "frame_color", "-frame_color",
settings.frame_color ? settings.frame_color : frame_color, settings.frame_color ? settings.frame_color : defaults.frame_color,
"Color of the frame around the window" "Color of the frame around the window"
); );
} }
settings.lowbgcolor = option_get_string( settings.lowbgcolor = option_get_string(
"urgency_low", "urgency_low",
"background", "-lb", lowbgcolor, "background", "-lb", defaults.lowbgcolor,
"Background color for notifications with low urgency" "Background color for notifications with low urgency"
); );
settings.lowfgcolor = option_get_string( settings.lowfgcolor = option_get_string(
"urgency_low", "urgency_low",
"foreground", "-lf", lowfgcolor, "foreground", "-lf", defaults.lowfgcolor,
"Foreground color for notifications with low urgency" "Foreground color for notifications with low urgency"
); );
@ -492,25 +492,25 @@ void load_settings(char *cmdline_config_path)
settings.timeouts[LOW] = option_get_time( settings.timeouts[LOW] = option_get_time(
"urgency_low", "urgency_low",
"timeout", "-lto", timeouts[LOW], "timeout", "-lto", defaults.timeouts[LOW],
"Timeout for notifications with low urgency" "Timeout for notifications with low urgency"
); );
settings.icons[LOW] = option_get_string( settings.icons[LOW] = option_get_string(
"urgency_low", "urgency_low",
"icon", "-li", icons[LOW], "icon", "-li", defaults.icons[LOW],
"Icon for notifications with low urgency" "Icon for notifications with low urgency"
); );
settings.normbgcolor = option_get_string( settings.normbgcolor = option_get_string(
"urgency_normal", "urgency_normal",
"background", "-nb", normbgcolor, "background", "-nb", defaults.normbgcolor,
"Background color for notifications with normal urgency" "Background color for notifications with normal urgency"
); );
settings.normfgcolor = option_get_string( settings.normfgcolor = option_get_string(
"urgency_normal", "urgency_normal",
"foreground", "-nf", normfgcolor, "foreground", "-nf", defaults.normfgcolor,
"Foreground color for notifications with normal urgency" "Foreground color for notifications with normal urgency"
); );
@ -522,25 +522,25 @@ void load_settings(char *cmdline_config_path)
settings.timeouts[NORM] = option_get_time( settings.timeouts[NORM] = option_get_time(
"urgency_normal", "urgency_normal",
"timeout", "-nto", timeouts[NORM], "timeout", "-nto", defaults.timeouts[NORM],
"Timeout for notifications with normal urgency" "Timeout for notifications with normal urgency"
); );
settings.icons[NORM] = option_get_string( settings.icons[NORM] = option_get_string(
"urgency_normal", "urgency_normal",
"icon", "-ni", icons[NORM], "icon", "-ni", defaults.icons[NORM],
"Icon for notifications with normal urgency" "Icon for notifications with normal urgency"
); );
settings.critbgcolor = option_get_string( settings.critbgcolor = option_get_string(
"urgency_critical", "urgency_critical",
"background", "-cb", critbgcolor, "background", "-cb", defaults.critbgcolor,
"Background color for notifications with critical urgency" "Background color for notifications with critical urgency"
); );
settings.critfgcolor = option_get_string( settings.critfgcolor = option_get_string(
"urgency_critical", "urgency_critical",
"foreground", "-cf", critfgcolor, "foreground", "-cf", defaults.critfgcolor,
"Foreground color for notifications with ciritical urgency" "Foreground color for notifications with ciritical urgency"
); );
@ -552,37 +552,37 @@ void load_settings(char *cmdline_config_path)
settings.timeouts[CRIT] = option_get_time( settings.timeouts[CRIT] = option_get_time(
"urgency_critical", "urgency_critical",
"timeout", "-cto", timeouts[CRIT], "timeout", "-cto", defaults.timeouts[CRIT],
"Timeout for notifications with critical urgency" "Timeout for notifications with critical urgency"
); );
settings.icons[CRIT] = option_get_string( settings.icons[CRIT] = option_get_string(
"urgency_critical", "urgency_critical",
"icon", "-ci", icons[CRIT], "icon", "-ci", defaults.icons[CRIT],
"Icon for notifications with critical urgency" "Icon for notifications with critical urgency"
); );
settings.close_ks.str = option_get_string( settings.close_ks.str = option_get_string(
"shortcuts", "shortcuts",
"close", "-key", close_ks.str, "close", "-key", defaults.close_ks.str,
"Shortcut for closing one notification" "Shortcut for closing one notification"
); );
settings.close_all_ks.str = option_get_string( settings.close_all_ks.str = option_get_string(
"shortcuts", "shortcuts",
"close_all", "-all_key", close_all_ks.str, "close_all", "-all_key", defaults.close_all_ks.str,
"Shortcut for closing all notifications" "Shortcut for closing all notifications"
); );
settings.history_ks.str = option_get_string( settings.history_ks.str = option_get_string(
"shortcuts", "shortcuts",
"history", "-history_key", history_ks.str, "history", "-history_key", defaults.history_ks.str,
"Shortcut to pop the last notification from history" "Shortcut to pop the last notification from history"
); );
settings.context_ks.str = option_get_string( settings.context_ks.str = option_get_string(
"shortcuts", "shortcuts",
"context", "-context_key", context_ks.str, "context", "-context_key", defaults.context_ks.str,
"Shortcut for context menu" "Shortcut for context menu"
); );