Merge pull request #371 from bebehei/configh

Improve usage of config.h
This commit is contained in:
Nikos Tsipinakis 2017-10-21 20:25:36 +03:00 committed by GitHub
commit 3691b7e47c
6 changed files with 205 additions and 169 deletions

1
.gitignore vendored
View File

@ -2,7 +2,6 @@ dunst
*.o
core
vgcore.*
config.h
dunst.1
org.knopwob.dunst.service
dunst.systemd.service

View File

@ -14,12 +14,7 @@ all: doc dunst service
.c.o:
${CC} -o $@ -c $< ${CFLAGS}
${OBJ}: config.h config.mk
config.h: config.def.h
@if test -s $@; then echo $< is newer than $@, merge and save $@. If you haven\'t edited $@ you can just delete it && exit 1; fi
@echo creating $@ from $<
@cp $< $@
${OBJ}: config.mk
dunst: ${OBJ} main.o
${CC} ${CFLAGS} -o $@ ${OBJ} main.o ${LDFLAGS}
@ -38,11 +33,6 @@ clean-doc:
clean: clean-dunst clean-dunstify clean-doc test-clean
distclean: clean clean-config
clean-config:
rm -f config.h
doc: docs/dunst.1
docs/dunst.1: docs/dunst.pod
pod2man --name=dunst -c "Dunst Reference" --section=1 --release=${VERSION} $< > $@

View File

@ -1,107 +0,0 @@
/* see example dunstrc for additional explanations about these options */
char *font = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*";
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 */
char *icons[] = { "dialog-information", "dialog-information", "dialog-warning" }; /* low, normal, critical */
unsigned int transparency = 0; /* transparency */
char *geom = "0x0"; /* geometry */
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 */
int padding = 0;
int h_padding = 0; /* horizontal padding */
enum separator_color sep_color = AUTO; /* AUTO, FOREGROUND, FRAME, CUSTOM */
char *sep_custom_color_str = NULL; /* custom color if sep_color is set to CUSTOM */
int frame_width = 0;
char *frame_color = "#888888";
/* show a notification on startup
* This is mainly for crash detection since dbus restarts dunst
* automatically after a crash, so crashes might get unnotices otherwise
* */
int startup_notification = false;
/* monitor to display notifications on */
int monitor = 0;
/* path to dmenu */
char *dmenu = "/usr/bin/dmenu";
char *browser = "/usr/bin/firefox";
int max_icon_size = 0;
/* paths to default icons */
char *icon_path = "/usr/share/icons/gnome/16x16/status/:/usr/share/icons/gnome/16x16/devices/";
/* follow focus to different monitor and display notifications there?
* possible values:
* FOLLOW_NONE
* FOLLOW_MOUSE
* FOLLOW_KEYBOARD
*
* everything else than FOLLOW_NONE overrides 'monitor'
*/
enum follow_mode f_mode = FOLLOW_NONE;
/* keyboard shortcuts
* use for example "ctrl+shift+space"
* use "none" to disable
*/
keyboard_shortcut close_ks = {.str = "none",
.code = 0,.sym = NoSymbol,.is_valid = false
}; /* ignore this */
keyboard_shortcut close_all_ks = {.str = "none",
.code = 0,.sym = NoSymbol,.is_valid = false
}; /* ignore this */
keyboard_shortcut history_ks = {.str = "none",
.code = 0,.sym = NoSymbol,.is_valid = false
}; /* ignore this */
keyboard_shortcut context_ks = {.str = "none",
.code = 0,.sym = NoSymbol,.is_valid = false
}; /* ignore this */
rule_t default_rules[] = {
/* name can be any unique string. It is used to identify the rule in dunstrc to override it there */
/* name, appname, summary, body, icon, category, msg_urgency, timeout, urgency, markup, history_ignore, match_transient, set_transient, new_icon, fg, bg, format, script */
{ "empty", NULL, NULL, NULL, NULL, NULL, -1, -1, -1, MARKUP_NULL, -1, -1, -1, NULL, NULL, NULL, NULL, NULL},
/* ignore transient hints in history by default */
{ "ignore_transient_in_history",
NULL, NULL, NULL, NULL, NULL, -1, -1, -1, MARKUP_NULL, 1, 1, -1, NULL, NULL, NULL, NULL, NULL},
/* { "rule1", "notify-send", NULL, NULL, NULL, NULL, -1, -1, -1, MARKUP_NULL, -1, -1, -1, NULL, NULL, NULL, "%s %b", NULL}, */
/* { "rule2", "Pidgin", "*says*, NULL, NULL, NULL, -1, -1, CRITICAL, MARKUP_NULL, -1, -1, -1, NULL, NULL, NULL, NULL, NULL}, */
/* { "rule3", "Pidgin", "*signed on*", NULL, NULL, NULL, -1, -1, LOW, MARKUP_NULL, -1, -1, -1, NULL, NULL, NULL, NULL, NULL}, */
/* { "rule4", "Pidgin", "*signed off*", NULL, NULL, NULL, -1, -1, LOW, MARKUP_NULL, -1, -1, -1, NULL, NULL, NULL, NULL, NULL}, */
/* { "rule5", NULL, "*foobar*", NULL, NULL, NULL, -1, -1, -1, MARKUP_NULL, -1, -1, -1, NULL, NULL, "#00FF00", NULL, NULL}, */
};
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */

148
config.h Normal file
View File

@ -0,0 +1,148 @@
/* see example dunstrc for additional explanations about these options */
settings_t defaults = {
.font = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*",
.markup = MARKUP_NO,
.normbgcolor = "#1793D1",
.normfgcolor = "#DDDDDD",
.critbgcolor = "#ffaaaa",
.critfgcolor = "#000000",
.lowbgcolor = "#aaaaff",
.lowfgcolor = "#000000",
.format = "%s %b", /* default format */
.timeouts = { 10*G_USEC_PER_SEC, 10*G_USEC_PER_SEC, 0 }, /* low, normal, critical */
.icons = { "dialog-information", "dialog-information", "dialog-warning" }, /* low, normal, critical */
.transparency = 0, /* transparency */
.geom = "0x0", /* geometry */
.title = "Dunst", /* the title of dunst notification windows */
.class = "Dunst", /* the class of dunst notification windows */
.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",
/* show a notification on startup
* This is mainly for crash detection since dbus restarts dunst
* automatically after a crash, so crashes might get unnotices otherwise
* */
.startup_notification = false,
/* monitor to display notifications on */
.monitor = 0,
/* path to dmenu */
.dmenu = "/usr/bin/dmenu",
.browser = "/usr/bin/firefox",
.max_icon_size = 0,
/* paths to default icons */
.icon_path = "/usr/share/icons/gnome/16x16/status/:/usr/share/icons/gnome/16x16/devices/",
/* follow focus to different monitor and display notifications there?
* possible values:
* FOLLOW_NONE
* FOLLOW_MOUSE
* FOLLOW_KEYBOARD
*
* everything else than FOLLOW_NONE overrides 'monitor'
*/
.f_mode = FOLLOW_NONE,
/* keyboard shortcuts
* use for example "ctrl+shift+space"
* use "none" to disable
*/
.close_ks = {.str = "none",
.code = 0,.sym = NoSymbol,.is_valid = false
}, /* ignore this */
.close_all_ks = {.str = "none",
.code = 0,.sym = NoSymbol,.is_valid = false
}, /* ignore this */
.history_ks = {.str = "none",
.code = 0,.sym = NoSymbol,.is_valid = false
}, /* ignore this */
.context_ks = {.str = "none",
.code = 0,.sym = NoSymbol,.is_valid = false
}, /* ignore this */
};
rule_t default_rules[] = {
/* name can be any unique string. It is used to identify
* the rule in dunstrc to override it there
*/
/* an empty rule with no effect */
{
.name = "empty",
.appname = NULL,
.summary = NULL,
.body = NULL,
.icon = NULL,
.category = NULL,
.msg_urgency = -1,
.timeout = -1,
.urgency = -1,
.markup = MARKUP_NULL,
.history_ignore = 1,
.match_transient = 1,
.set_transient = -1,
.new_icon = NULL,
.fg = NULL,
.bg = NULL,
.format = NULL,
.script = NULL,
},
/* ignore transient hints in history by default */
{
.name = "ignore_transient_in_history",
.appname = NULL,
.summary = NULL,
.body = NULL,
.icon = NULL,
.category = NULL,
.msg_urgency = -1,
.timeout = -1,
.urgency = -1,
.markup = MARKUP_NULL,
.history_ignore = 1,
.match_transient = 1,
.set_transient = -1,
.new_icon = NULL,
.fg = NULL,
.bg = NULL,
.format = NULL,
.script = NULL,
},
};
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */

View File

@ -7,6 +7,7 @@ ifneq ($(wildcard ./.git/.),)
VERSION := $(shell git describe --tags)
endif
# Warning: This is deprecated behavior
# uncomment to disable parsing of dunstrc
# or use "CFLAGS=-DSTATIC_CONFIG make" to build
#STATIC= -DSTATIC_CONFIG
@ -27,6 +28,8 @@ pkg_config_packs := dbus-1 x11 xscrnsaver \
# check if we need libxdg-basedir
ifeq (,$(findstring STATIC_CONFIG,$(CFLAGS)))
pkg_config_packs += libxdg-basedir
else
$(warning STATIC_CONFIG is deprecated behavior. It will get removed in future releases)
endif
# includes and libs

View File

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