From 4b5cc2c9bc0c21bc19b41d38cc9332c5cbb15731 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 16 Sep 2018 00:39:06 +0200 Subject: [PATCH 01/13] Remove superfluous fflush call The blame reveals commit 820cfe73, which introduced printing of notifications similar to notification_print(). The fflush call is still left over since porting the printfs into their dedicated method. As notification_print() is called after this fflush() call, it's not necessary anymore. --- src/dbus.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/dbus.c b/src/dbus.c index fb75b75..b36c702 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -258,8 +258,6 @@ static struct notification *dbus_message_to_notification(const gchar *sender, GV g_variant_iter_free(iter); } - fflush(stdout); - if (n->actions->count < 1) g_clear_pointer(&n->actions, actions_free); From 0231fabbd3921b320fece58131491dec37bc9bb1 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 23 Sep 2018 23:03:48 +0200 Subject: [PATCH 02/13] Make parse_follow_mode a real parser function --- src/settings.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/settings.c b/src/settings.c index 110b98b..21b2e8c 100644 --- a/src/settings.c +++ b/src/settings.c @@ -21,17 +21,20 @@ struct settings settings; -static void parse_follow_mode(const char *mode) +static enum follow_mode parse_follow_mode(const char *mode) { + if (!mode) + return FOLLOW_NONE; + if (strcmp(mode, "mouse") == 0) - settings.f_mode = FOLLOW_MOUSE; + return FOLLOW_MOUSE; else if (strcmp(mode, "keyboard") == 0) - settings.f_mode = FOLLOW_KEYBOARD; + return FOLLOW_KEYBOARD; else if (strcmp(mode, "none") == 0) - settings.f_mode = FOLLOW_NONE; + return FOLLOW_NONE; else { LOG_W("Unknown follow mode: '%s'", mode); - settings.f_mode = FOLLOW_NONE; + return FOLLOW_NONE; } } @@ -252,14 +255,12 @@ void load_settings(char *cmdline_config_path) { char *c = option_get_string( "global", - "follow", "-follow", "", + "follow", "-follow", NULL, "Follow mouse, keyboard or none?" ); - if (strlen(c) > 0) { - parse_follow_mode(c); - g_free(c); - } + settings.f_mode = parse_follow_mode(c); + g_free(c); } settings.title = option_get_string( From 3b3ed0328efadf332531849641f3e184732de5e8 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 23 Sep 2018 23:14:08 +0200 Subject: [PATCH 03/13] Free layouts inline --- src/draw.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/draw.c b/src/draw.c index 96c4a94..6f56573 100644 --- a/src/draw.c +++ b/src/draw.c @@ -376,10 +376,6 @@ static GSList *create_layouts(cairo_t *c) return layouts; } -static void free_layouts(GSList *layouts) -{ - g_slist_free_full(layouts, free_colored_layout); -} static int layout_get_height(struct colored_layout *cl) { @@ -637,7 +633,7 @@ void draw(void) x_display_surface(image_surface, win, &dim); cairo_surface_destroy(image_surface); - free_layouts(layouts); + g_slist_free_full(layouts, free_colored_layout); } void draw_deinit(void) From 0306446efb3328c2b096a1b466816de4ba815d1f Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 23 Sep 2018 23:14:22 +0200 Subject: [PATCH 04/13] Scale PixBuf easier --- src/icon.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/icon.c b/src/icon.c index 8755585..6527973 100644 --- a/src/icon.c +++ b/src/icon.c @@ -161,18 +161,18 @@ cairo_surface_t *icon_get_for_notification(const struct notification *n) int h = gdk_pixbuf_get_height(pixbuf); int larger = w > h ? w : h; if (settings.max_icon_size && larger > settings.max_icon_size) { - GdkPixbuf *scaled; - if (w >= h) { - scaled = gdk_pixbuf_scale_simple(pixbuf, - settings.max_icon_size, - (settings.max_icon_size * h) / w, - GDK_INTERP_BILINEAR); - } else { - scaled = gdk_pixbuf_scale_simple(pixbuf, - (settings.max_icon_size * w) / h, - settings.max_icon_size, - GDK_INTERP_BILINEAR); - } + int scaled_w = settings.max_icon_size; + int scaled_h = settings.max_icon_size; + if (w >= h) + scaled_h = (settings.max_icon_size * h) / w; + else + scaled_w = (settings.max_icon_size * w) / h; + + GdkPixbuf *scaled = gdk_pixbuf_scale_simple( + pixbuf, + scaled_w, + scaled_h, + GDK_INTERP_BILINEAR); g_object_unref(pixbuf); pixbuf = scaled; } From 403e4cc176cde79f1ccabc30c878e5201e696d1b Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Mon, 1 Oct 2018 19:56:00 +0200 Subject: [PATCH 05/13] Remove libxdg-basedir dependency GLib's g_get_user_config_dir function does exactly the same thing and we don't need libxdg-basedir for something else. --- .travis.yml | 1 - .valgrind.suppressions | 11 ---------- CHANGELOG.md | 1 + README.md | 1 - config.mk | 5 +---- src/settings.c | 47 ++++++++++++++++++++++++++++-------------- 6 files changed, 34 insertions(+), 32 deletions(-) diff --git a/.travis.yml b/.travis.yml index 101fd93..726ae4c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,6 @@ addons: - libxrandr-dev - libxinerama-dev - libxss-dev - - libxdg-basedir-dev - libglib2.0-dev - libpango1.0-dev - libcairo2-dev diff --git a/.valgrind.suppressions b/.valgrind.suppressions index 2b694ff..2d0e661 100644 --- a/.valgrind.suppressions +++ b/.valgrind.suppressions @@ -1,14 +1,3 @@ -{ - xdgBaseDir_leak - # see https://github.com/devnev/libxdg-basedir/pull/6 - Memcheck:Leak - fun:malloc - ... - fun:xdgInitHandle - ... - fun:main -} - # librsvg leaks some memory, when an invalid svg file is read # TODO: find the memory leak and fix it upstream { diff --git a/CHANGELOG.md b/CHANGELOG.md index 14b684b..15e555e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Added +- Remove libxdg-basedir dependency (GLib's function is used instead) - `fullscreen` rule to hide notifications when a fullscreen window is active - When new notifications arrive, but display is full, important notifications don't have to wait for a timeout in a displayed notification (#541) diff --git a/README.md b/README.md index eb8b84c..ea7fe6f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,6 @@ Dunst has a number of build dependencies that must be present before attempting - libxinerama - libxrandr - libxss -- libxdg-basedir - glib - pango/cairo - libgtk-3-dev diff --git a/config.mk b/config.mk index 3d57c92..3507f09 100644 --- a/config.mk +++ b/config.mk @@ -32,10 +32,7 @@ pkg_config_packs := dbus-1 \ "xrandr >= 1.5" \ xscrnsaver -# check if we need libxdg-basedir -ifeq (,$(findstring STATIC_CONFIG,$(CFLAGS))) - pkg_config_packs += libxdg-basedir -else +ifneq (,$(findstring STATIC_CONFIG,$(CFLAGS))) $(warning STATIC_CONFIG is deprecated behavior. It will get removed in future releases) endif diff --git a/src/settings.c b/src/settings.c index 21b2e8c..2a686d5 100644 --- a/src/settings.c +++ b/src/settings.c @@ -5,10 +5,6 @@ #include #include #include -#ifndef STATIC_CONFIG -#include -#include -#endif #include "rules.h" // put before config.h to fix missing include #include "config.h" @@ -88,15 +84,35 @@ static enum urgency ini_get_urgency(const char *section, const char *key, const return ret; } +static FILE *xdg_config(const char *filename) +{ + const gchar * const * systemdirs = g_get_system_config_dirs(); + const gchar * userdir = g_get_user_config_dir(); + + FILE *f; + char *path; + + path = g_strconcat(userdir, filename, NULL); + f = fopen(path, "r"); + g_free(path); + + for (const gchar * const *d = systemdirs; + !f && *d; + d++) { + path = g_strconcat(*d, filename, NULL); + f = fopen(path, "r"); + g_free(path); + } + + return f; +} + void load_settings(char *cmdline_config_path) { #ifndef STATIC_CONFIG - xdgHandle xdg; FILE *config_file = NULL; - xdgInitHandle(&xdg); - if (cmdline_config_path) { if (0 == strcmp(cmdline_config_path, "-")) { config_file = stdin; @@ -104,21 +120,23 @@ void load_settings(char *cmdline_config_path) config_file = fopen(cmdline_config_path, "r"); } - if(!config_file) { + if (!config_file) { DIE("Cannot find config file: '%s'", cmdline_config_path); } } + if (!config_file) { - config_file = xdgConfigOpen("dunst/dunstrc", "r", &xdg); + config_file = xdg_config("/dunst/dunstrc"); } + if (!config_file) { /* Fall back to just "dunstrc", which was used before 2013-06-23 * (before v0.2). */ - config_file = xdgConfigOpen("dunstrc", "r", &xdg); - if (!config_file) { - LOG_W("No dunstrc found."); - xdgWipeHandle(&xdg); - } + config_file = xdg_config("/dunstrc"); + } + + if (!config_file) { + LOG_W("No dunstrc found."); } load_ini_file(config_file); @@ -788,7 +806,6 @@ void load_settings(char *cmdline_config_path) if (config_file) { fclose(config_file); free_ini(); - xdgWipeHandle(&xdg); } #endif } From 2ef74c0d642b96398184b0433ec2d5e231d5e27b Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Wed, 3 Oct 2018 13:47:32 +0200 Subject: [PATCH 06/13] Respect follow mode from defaults struct --- src/settings.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/settings.c b/src/settings.c index 2a686d5..2bca7bd 100644 --- a/src/settings.c +++ b/src/settings.c @@ -17,6 +17,16 @@ struct settings settings; +static const char *follow_mode_to_string(enum follow_mode f_mode) +{ + switch(f_mode) { + case FOLLOW_NONE: return "none"; + case FOLLOW_MOUSE: return "mouse"; + case FOLLOW_KEYBOARD: return "keyboard"; + default: return ""; + } +} + static enum follow_mode parse_follow_mode(const char *mode) { if (!mode) @@ -273,7 +283,7 @@ void load_settings(char *cmdline_config_path) { char *c = option_get_string( "global", - "follow", "-follow", NULL, + "follow", "-follow", follow_mode_to_string(defaults.f_mode), "Follow mouse, keyboard or none?" ); From da846d8442df6446b5ae29edd8d5b7d9707e7590 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Wed, 3 Oct 2018 15:18:08 +0200 Subject: [PATCH 07/13] Do not count longer than necessary And also use g_strndup. This makes allocation easier and also ensures a null-byte at the end of the string. --- src/notification.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/notification.c b/src/notification.c index b36a817..eb57507 100644 --- a/src/notification.c +++ b/src/notification.c @@ -421,11 +421,8 @@ static void notification_format_message(struct notification *n) n->msg = g_strchomp(n->msg); /* truncate overlong messages */ - if (strlen(n->msg) > DUNST_NOTIF_MAX_CHARS) { - char *buffer = g_malloc(DUNST_NOTIF_MAX_CHARS); - strncpy(buffer, n->msg, DUNST_NOTIF_MAX_CHARS); - buffer[DUNST_NOTIF_MAX_CHARS-1] = '\0'; - + if (strnlen(n->msg, DUNST_NOTIF_MAX_CHARS + 1) > DUNST_NOTIF_MAX_CHARS) { + char * buffer = g_strndup(n->msg, DUNST_NOTIF_MAX_CHARS); g_free(n->msg); n->msg = buffer; } From 1f4cd4bd1509b4fe3b3c62738fbc59b4f5162f9b Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Wed, 3 Oct 2018 15:28:08 +0200 Subject: [PATCH 08/13] Use STR_(EMPTY|FULL) for string emptyness checks --- src/icon.c | 4 ++-- src/notification.c | 4 ++-- src/option_parser.c | 4 ++-- src/queues.c | 2 +- src/settings.c | 11 +++++------ src/utils.c | 4 ++-- src/utils.h | 3 +++ 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/icon.c b/src/icon.c index 6527973..ab43e19 100644 --- a/src/icon.c +++ b/src/icon.c @@ -76,7 +76,7 @@ GdkPixbuf *get_pixbuf_from_file(const char *filename) GdkPixbuf *get_pixbuf_from_icon(const char *iconname) { - if (!iconname || iconname[0] == '\0') + if (STR_EMPTY(iconname)) return NULL; const char *suffixes[] = { ".svg", ".png", ".xpm", NULL }; @@ -117,7 +117,7 @@ GdkPixbuf *get_pixbuf_from_icon(const char *iconname) break; start = end + 1; - } while (*(end) != '\0'); + } while (STR_FULL(end)); if (!pixbuf) LOG_W("No icon found in path: '%s'", iconname); } diff --git a/src/notification.c b/src/notification.c index eb57507..26ea205 100644 --- a/src/notification.c +++ b/src/notification.c @@ -89,7 +89,7 @@ void notification_print(const struct notification *n) /* see notification.h */ void notification_run_script(struct notification *n) { - if (!n->script || strlen(n->script) < 1) + if (STR_EMPTY(n->script)) return; if (n->script_run && !settings.always_run_script) @@ -300,7 +300,7 @@ void notification_init(struct notification *n) n->timeout = settings.timeouts[n->urgency]; /* Icon handling */ - if (n->icon && strlen(n->icon) <= 0) + if (STR_EMPTY(n->icon)) g_clear_pointer(&n->icon, g_free); if (!n->raw_icon && !n->icon) n->icon = g_strdup(settings.icons[n->urgency]); diff --git a/src/option_parser.c b/src/option_parser.c index 0cb8354..aeb9463 100644 --- a/src/option_parser.c +++ b/src/option_parser.c @@ -231,7 +231,7 @@ int load_ini_file(FILE *fp) char *start = g_strstrip(line); - if (*start == ';' || *start == '#' || strlen(start) == 0) + if (*start == ';' || *start == '#' || STR_EMPTY(start)) continue; if (*start == '[') { @@ -521,7 +521,7 @@ int option_get_bool(const char *ini_section, void cmdline_usage_append(const char *key, const char *type, const char *description) { char *key_type; - if (type && strlen(type) > 0) + if (STR_FULL(type)) key_type = g_strdup_printf("%s (%s)", key, type); else key_type = g_strdup(key); diff --git a/src/queues.c b/src/queues.c index f5d2077..6620eb8 100644 --- a/src/queues.c +++ b/src/queues.c @@ -125,7 +125,7 @@ int queues_notification_insert(struct notification *n) { /* do not display the message, if the message is empty */ - if (strlen(n->msg) == 0) { + if (STR_EMPTY(n->msg)) { if (settings.always_run_script) { notification_run_script(n); } diff --git a/src/settings.c b/src/settings.c index 2bca7bd..90c108b 100644 --- a/src/settings.c +++ b/src/settings.c @@ -80,7 +80,7 @@ static enum urgency ini_get_urgency(const char *section, const char *key, const int ret = def; char *urg = ini_get_string(section, key, ""); - if (strlen(urg) > 0) { + if (STR_FULL(urg)) { if (strcmp(urg, "low") == 0) ret = URG_LOW; else if (strcmp(urg, "normal") == 0) @@ -247,7 +247,7 @@ void load_settings(char *cmdline_config_path) "Ellipsize truncated lines on the start/middle/end" ); - if (strlen(c) == 0) { + if (STR_EMPTY(c)) { settings.ellipsize = defaults.ellipsize; } else if (strcmp(c, "start") == 0) { settings.ellipsize = ELLIPSE_START; @@ -346,8 +346,7 @@ void load_settings(char *cmdline_config_path) "alignment", "-align/-alignment", "", "Text alignment left/center/right" ); - - if (strlen(c) > 0) { + if (STR_FULL(c)) { if (strcmp(c, "left") == 0) settings.align = ALIGN_LEFT; else if (strcmp(c, "center") == 0) @@ -427,7 +426,7 @@ void load_settings(char *cmdline_config_path) "Color of the separator line (or 'auto')" ); - if (strlen(c) > 0) { + if (STR_FULL(c)) { if (strcmp(c, "auto") == 0) settings.sep_color = SEP_AUTO; else if (strcmp(c, "foreground") == 0) @@ -484,7 +483,7 @@ void load_settings(char *cmdline_config_path) "Align icons left/right/off" ); - if (strlen(c) > 0) { + if (STR_FULL(c)) { if (strcmp(c, "left") == 0) settings.icon_position = ICON_LEFT; else if (strcmp(c, "right") == 0) diff --git a/src/utils.c b/src/utils.c index 8f06141..fa5ae40 100644 --- a/src/utils.c +++ b/src/utils.c @@ -79,11 +79,11 @@ char *string_replace_all(const char *needle, const char *replacement, char *hays char *string_append(char *a, const char *b, const char *sep) { - if (!a || *a == '\0') { + if (STR_EMPTY(a)) { g_free(a); return g_strdup(b); } - if (!b || *b == '\0') + if (STR_EMPTY(b)) return a; char *new; diff --git a/src/utils.h b/src/utils.h index 48ee618..5cef754 100644 --- a/src/utils.h +++ b/src/utils.h @@ -4,6 +4,9 @@ #include +#define STR_EMPTY(s) (!s || (*s == '\0')) +#define STR_FULL(s) !(STR_EMPTY(s)) + /* replace all occurrences of the character needle with the character replacement in haystack */ char *string_replace_char(char needle, char replacement, char *haystack); From 516161e7657de8b46576fa3f02ee86b98b6530da Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Mon, 8 Oct 2018 17:36:53 +0200 Subject: [PATCH 09/13] Typo --- src/x11/x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/x11/x.c b/src/x11/x.c index aa8d7c9..45c3a1b 100644 --- a/src/x11/x.c +++ b/src/x11/x.c @@ -335,7 +335,7 @@ gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer case FocusIn: case FocusOut: case PropertyNotify: - LOG_D("XEvent: Checking for active sceen changes"); + LOG_D("XEvent: Checking for active screen changes"); fullscreen_now = have_fullscreen_window(); scr = get_active_screen(); From bb02897bc84cf01c9cb791375d280936931a2c98 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Tue, 9 Oct 2018 00:17:55 +0200 Subject: [PATCH 10/13] Introduce STR_EQ and STRN_EQ macros --- src/log.c | 2 ++ src/utils.c | 1 - src/utils.h | 9 +++++++++ src/x11/screen.c | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/log.c b/src/log.c index 3f41c0c..b822e85 100644 --- a/src/log.c +++ b/src/log.c @@ -8,6 +8,8 @@ #include +#include "utils.h" + static GLogLevelFlags log_level = G_LOG_LEVEL_WARNING; /* see log.h */ diff --git a/src/utils.c b/src/utils.c index fa5ae40..761dca9 100644 --- a/src/utils.c +++ b/src/utils.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include "log.h" diff --git a/src/utils.h b/src/utils.h index 5cef754..29c4812 100644 --- a/src/utils.h +++ b/src/utils.h @@ -3,9 +3,18 @@ #define DUNST_UTILS_H #include +#include +//! Test if a string is NULL or empty #define STR_EMPTY(s) (!s || (*s == '\0')) +//! Test if a string is non-NULL and not empty #define STR_FULL(s) !(STR_EMPTY(s)) +//! Test if string a and b contain the same chars +#define STR_EQ(a, b) (strcmp(a, b) == 0) +//! Test if string a and b are same up to n chars +#define STRN_EQ(a, b, n) (strncmp(a, b, n) == 0) +//! Test if string a and b are the same case-insensitively +#define STR_CASEQ(a, b) (strcasecmp(a, b) == 0) /* replace all occurrences of the character needle with the character replacement in haystack */ char *string_replace_char(char needle, char replacement, char *haystack); diff --git a/src/x11/screen.c b/src/x11/screen.c index edf9838..d7fbfbf 100644 --- a/src/x11/screen.c +++ b/src/x11/screen.c @@ -17,6 +17,7 @@ #include "src/log.h" #include "src/settings.h" +#include "src/utils.h" #include "x.h" struct screen_info *screens; From c0e2a2a7e387b5d93b656ad4f43641be484c4fe2 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Tue, 9 Oct 2018 09:58:46 +0200 Subject: [PATCH 11/13] Move all strcmp operations to STR*EQ macros --- src/dbus.c | 8 +++--- src/log.c | 18 ++++++------ src/notification.c | 10 +++---- src/option_parser.c | 18 ++++++------ src/queues.c | 6 ++-- src/settings.c | 68 ++++++++++++++++++++++----------------------- src/utils.c | 12 ++++---- src/x11/screen.c | 2 +- src/x11/x.c | 14 +++++----- 9 files changed, 78 insertions(+), 78 deletions(-) diff --git a/src/dbus.c b/src/dbus.c index b36c702..29c4304 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -92,13 +92,13 @@ void handle_method_call(GDBusConnection *connection, GDBusMethodInvocation *invocation, gpointer user_data) { - if (g_strcmp0(method_name, "GetCapabilities") == 0) { + if (STR_EQ(method_name, "GetCapabilities")) { on_get_capabilities(connection, sender, parameters, invocation); - } else if (g_strcmp0(method_name, "Notify") == 0) { + } else if (STR_EQ(method_name, "Notify")) { on_notify(connection, sender, parameters, invocation); - } else if (g_strcmp0(method_name, "CloseNotification") == 0) { + } else if (STR_EQ(method_name, "CloseNotification")) { on_close_notification(connection, sender, parameters, invocation); - } else if (g_strcmp0(method_name, "GetServerInformation") == 0) { + } else if (STR_EQ(method_name, "GetServerInformation")) { on_get_server_information(connection, sender, parameters, invocation); } else { LOG_M("Unknown method name: '%s' (sender: '%s').", diff --git a/src/log.c b/src/log.c index b822e85..3e51fb0 100644 --- a/src/log.c +++ b/src/log.c @@ -32,23 +32,23 @@ void log_set_level_from_string(const char *level) if (!level) return; - if (g_ascii_strcasecmp(level, "critical") == 0) + if (STR_CASEQ(level, "critical")) log_level = G_LOG_LEVEL_CRITICAL; - else if (g_ascii_strcasecmp(level, "crit") == 0) + else if (STR_CASEQ(level, "crit")) log_level = G_LOG_LEVEL_CRITICAL; - else if (g_ascii_strcasecmp(level, "warning") == 0) + else if (STR_CASEQ(level, "warning")) log_level = G_LOG_LEVEL_WARNING; - else if (g_ascii_strcasecmp(level, "warn") == 0) + else if (STR_CASEQ(level, "warn")) log_level = G_LOG_LEVEL_WARNING; - else if (g_ascii_strcasecmp(level, "message") == 0) + else if (STR_CASEQ(level, "message")) log_level = G_LOG_LEVEL_MESSAGE; - else if (g_ascii_strcasecmp(level, "mesg") == 0) + else if (STR_CASEQ(level, "mesg")) log_level = G_LOG_LEVEL_MESSAGE; - else if (g_ascii_strcasecmp(level, "info") == 0) + else if (STR_CASEQ(level, "info")) log_level = G_LOG_LEVEL_INFO; - else if (g_ascii_strcasecmp(level, "debug") == 0) + else if (STR_CASEQ(level, "debug")) log_level = G_LOG_LEVEL_DEBUG; - else if (g_ascii_strcasecmp(level, "deb") == 0) + else if (STR_CASEQ(level, "deb")) log_level = G_LOG_LEVEL_DEBUG; else LOG_W("Unknown log level: '%s'", level); diff --git a/src/notification.c b/src/notification.c index 26ea205..f4fa8f0 100644 --- a/src/notification.c +++ b/src/notification.c @@ -178,10 +178,10 @@ int notification_is_duplicate(const struct notification *a, const struct notific && (a->raw_icon || b->raw_icon)) return false; - return strcmp(a->appname, b->appname) == 0 - && strcmp(a->summary, b->summary) == 0 - && strcmp(a->body, b->body) == 0 - && (settings.icon_position != ICON_OFF ? strcmp(a->icon, b->icon) == 0 : 1) + return STR_EQ(a->appname, b->appname) + && STR_EQ(a->summary, b->summary) + && STR_EQ(a->body, b->body) + && (settings.icon_position != ICON_OFF ? STR_EQ(a->icon, b->icon) : 1) && a->urgency == b->urgency; } @@ -534,7 +534,7 @@ void notification_do_action(const struct notification *n) return; } for (int i = 0; i < n->actions->count; i += 2) { - if (strcmp(n->actions->actions[i], "default") == 0) { + if (STR_EQ(n->actions->actions[i], "default")) { signal_action_invoked(n, n->actions->actions[i]); return; } diff --git a/src/option_parser.c b/src/option_parser.c index aeb9463..0d68afc 100644 --- a/src/option_parser.c +++ b/src/option_parser.c @@ -43,7 +43,7 @@ static int cmdline_find_option(const char *key); struct section *new_section(const char *name) { for (int i = 0; i < section_count; i++) { - if (!strcmp(name, sections[i].name)) { + if (STR_EQ(name, sections[i].name)) { DIE("Duplicated section in dunstrc detected."); } } @@ -73,7 +73,7 @@ void free_ini(void) struct section *get_section(const char *name) { for (int i = 0; i < section_count; i++) { - if (strcmp(sections[i].name, name) == 0) + if (STR_EQ(sections[i].name, name)) return §ions[i]; } @@ -101,7 +101,7 @@ const char *get_value(const char *section, const char *key) } for (int i = 0; i < s->entry_count; i++) { - if (strcmp(s->entries[i].key, key) == 0) { + if (STR_EQ(s->entries[i].key, key)) { return s->entries[i].value; } } @@ -166,7 +166,7 @@ const char *next_section(const char *section) return sections[0].name; for (int i = 0; i < section_count; i++) { - if (strcmp(section, sections[i].name) == 0) { + if (STR_EQ(section, sections[i].name)) { if (i + 1 >= section_count) return NULL; else @@ -306,7 +306,7 @@ int cmdline_find_option(const char *key) /* look for first key */ for (int i = 0; i < cmdline_argc; i++) { - if (strcmp(key1, cmdline_argv[i]) == 0) { + if (STR_EQ(key1, cmdline_argv[i])) { g_free(key1); return i; } @@ -315,7 +315,7 @@ int cmdline_find_option(const char *key) /* look for second key if one was specified */ if (key2) { for (int i = 0; i < cmdline_argc; i++) { - if (strcmp(key2, cmdline_argv[i]) == 0) { + if (STR_EQ(key2, cmdline_argv[i])) { g_free(key1); return i; } @@ -554,11 +554,11 @@ enum behavior_fullscreen parse_enum_fullscreen(const char *string, enum behavior if (!string) return def; - if (strcmp(string, "show") == 0) + if (STR_EQ(string, "show")) return FS_SHOW; - else if (strcmp(string, "delay") == 0) + else if (STR_EQ(string, "delay")) return FS_DELAY; - else if (strcmp(string, "pushback") == 0) + else if (STR_EQ(string, "pushback")) return FS_PUSHBACK; else { LOG_W("Unknown fullscreen value: '%s'\n", string); diff --git a/src/queues.c b/src/queues.c index 6620eb8..c40d2c9 100644 --- a/src/queues.c +++ b/src/queues.c @@ -133,15 +133,15 @@ int queues_notification_insert(struct notification *n) return 0; } /* Do not insert the message if it's a command */ - if (strcmp("DUNST_COMMAND_PAUSE", n->summary) == 0) { + if (STR_EQ("DUNST_COMMAND_PAUSE", n->summary)) { pause_displayed = true; return 0; } - if (strcmp("DUNST_COMMAND_RESUME", n->summary) == 0) { + if (STR_EQ("DUNST_COMMAND_RESUME", n->summary)) { pause_displayed = false; return 0; } - if (strcmp("DUNST_COMMAND_TOGGLE", n->summary) == 0) { + if (STR_EQ("DUNST_COMMAND_TOGGLE", n->summary)) { pause_displayed = !pause_displayed; return 0; } diff --git a/src/settings.c b/src/settings.c index 90c108b..383a9a3 100644 --- a/src/settings.c +++ b/src/settings.c @@ -32,11 +32,11 @@ static enum follow_mode parse_follow_mode(const char *mode) if (!mode) return FOLLOW_NONE; - if (strcmp(mode, "mouse") == 0) + if (STR_EQ(mode, "mouse")) return FOLLOW_MOUSE; - else if (strcmp(mode, "keyboard") == 0) + else if (STR_EQ(mode, "keyboard")) return FOLLOW_KEYBOARD; - else if (strcmp(mode, "none") == 0) + else if (STR_EQ(mode, "none")) return FOLLOW_NONE; else { LOG_W("Unknown follow mode: '%s'", mode); @@ -46,11 +46,11 @@ static enum follow_mode parse_follow_mode(const char *mode) static enum markup_mode parse_markup_mode(const char *mode) { - if (strcmp(mode, "strip") == 0) { + if (STR_EQ(mode, "strip")) { return MARKUP_STRIP; - } else if (strcmp(mode, "no") == 0) { + } else if (STR_EQ(mode, "no")) { return MARKUP_NO; - } else if (strcmp(mode, "full") == 0 || strcmp(mode, "yes") == 0) { + } else if (STR_EQ(mode, "full") || STR_EQ(mode, "yes")) { return MARKUP_FULL; } else { LOG_W("Unknown markup mode: '%s'", mode); @@ -60,13 +60,13 @@ static enum markup_mode parse_markup_mode(const char *mode) static enum mouse_action parse_mouse_action(const char *action) { - if (strcmp(action, "none") == 0) + if (STR_EQ(action, "none")) return MOUSE_NONE; - else if (strcmp(action, "do_action") == 0) + else if (STR_EQ(action, "do_action")) return MOUSE_DO_ACTION; - else if (strcmp(action, "close_current") == 0) + else if (STR_EQ(action, "close_current")) return MOUSE_CLOSE_CURRENT; - else if (strcmp(action, "close_all") == 0) + else if (STR_EQ(action, "close_all")) return MOUSE_CLOSE_ALL; else { LOG_W("Unknown mouse action: '%s'", action); @@ -81,11 +81,11 @@ static enum urgency ini_get_urgency(const char *section, const char *key, const char *urg = ini_get_string(section, key, ""); if (STR_FULL(urg)) { - if (strcmp(urg, "low") == 0) + if (STR_EQ(urg, "low")) ret = URG_LOW; - else if (strcmp(urg, "normal") == 0) + else if (STR_EQ(urg, "normal")) ret = URG_NORM; - else if (strcmp(urg, "critical") == 0) + else if (STR_EQ(urg, "critical")) ret = URG_CRIT; else LOG_W("Unknown urgency: '%s'", urg); @@ -124,7 +124,7 @@ void load_settings(char *cmdline_config_path) FILE *config_file = NULL; if (cmdline_config_path) { - if (0 == strcmp(cmdline_config_path, "-")) { + if (STR_EQ(cmdline_config_path, "-")) { config_file = stdin; } else { config_file = fopen(cmdline_config_path, "r"); @@ -249,11 +249,11 @@ void load_settings(char *cmdline_config_path) if (STR_EMPTY(c)) { settings.ellipsize = defaults.ellipsize; - } else if (strcmp(c, "start") == 0) { + } else if (STR_EQ(c, "start")) { settings.ellipsize = ELLIPSE_START; - } else if (strcmp(c, "middle") == 0) { + } else if (STR_EQ(c, "middle")) { settings.ellipsize = ELLIPSE_MIDDLE; - } else if (strcmp(c, "end") == 0) { + } else if (STR_EQ(c, "end")) { settings.ellipsize = ELLIPSE_END; } else { LOG_W("Unknown ellipsize value: '%s'", c); @@ -347,11 +347,11 @@ void load_settings(char *cmdline_config_path) "Text alignment left/center/right" ); if (STR_FULL(c)) { - if (strcmp(c, "left") == 0) + if (STR_EQ(c, "left")) settings.align = ALIGN_LEFT; - else if (strcmp(c, "center") == 0) + else if (STR_EQ(c, "center")) settings.align = ALIGN_CENTER; - else if (strcmp(c, "right") == 0) + else if (STR_EQ(c, "right")) settings.align = ALIGN_RIGHT; else LOG_W("Unknown alignment value: '%s'", c); @@ -427,11 +427,11 @@ void load_settings(char *cmdline_config_path) ); if (STR_FULL(c)) { - if (strcmp(c, "auto") == 0) + if (STR_EQ(c, "auto")) settings.sep_color = SEP_AUTO; - else if (strcmp(c, "foreground") == 0) + else if (STR_EQ(c, "foreground")) settings.sep_color = SEP_FOREGROUND; - else if (strcmp(c, "frame") == 0) + else if (STR_EQ(c, "frame")) settings.sep_color = SEP_FRAME; else { settings.sep_color = SEP_CUSTOM; @@ -484,11 +484,11 @@ void load_settings(char *cmdline_config_path) ); if (STR_FULL(c)) { - if (strcmp(c, "left") == 0) + if (STR_EQ(c, "left")) settings.icon_position = ICON_LEFT; - else if (strcmp(c, "right") == 0) + else if (STR_EQ(c, "right")) settings.icon_position = ICON_RIGHT; - else if (strcmp(c, "off") == 0) + else if (STR_EQ(c, "off")) settings.icon_position = ICON_OFF; else LOG_W("Unknown icon position: '%s'", c); @@ -745,13 +745,13 @@ void load_settings(char *cmdline_config_path) cur_section = next_section(cur_section); if (!cur_section) break; - if (strcmp(cur_section, "global") == 0 - || strcmp(cur_section, "frame") == 0 - || strcmp(cur_section, "experimental") == 0 - || strcmp(cur_section, "shortcuts") == 0 - || strcmp(cur_section, "urgency_low") == 0 - || strcmp(cur_section, "urgency_normal") == 0 - || strcmp(cur_section, "urgency_critical") == 0) + if (STR_EQ(cur_section, "global") + || STR_EQ(cur_section, "frame") + || STR_EQ(cur_section, "experimental") + || STR_EQ(cur_section, "shortcuts") + || STR_EQ(cur_section, "urgency_low") + || STR_EQ(cur_section, "urgency_normal") + || STR_EQ(cur_section, "urgency_critical")) continue; /* check for existing rule with same name */ @@ -759,7 +759,7 @@ void load_settings(char *cmdline_config_path) for (GSList *iter = rules; iter; iter = iter->next) { struct rule *match = iter->data; if (match->name && - strcmp(match->name, cur_section) == 0) + STR_EQ(match->name, cur_section)) r = match; } diff --git a/src/utils.c b/src/utils.c index 761dca9..f076115 100644 --- a/src/utils.c +++ b/src/utils.c @@ -114,7 +114,7 @@ void string_strip_delimited(char *str, char a, char b) char *string_to_path(char *string) { - if (string && 0 == strncmp(string, "~/", 2)) { + if (string && STRN_EQ(string, "~/", 2)) { char *home = g_strconcat(getenv("HOME"), "/", NULL); string = string_replace("~/", home, string); @@ -151,15 +151,15 @@ gint64 string_to_time(const char *string) while (*endptr == ' ') endptr++; - if (0 == strncmp(endptr, "ms", 2)) + if (STRN_EQ(endptr, "ms", 2)) return val * 1000; - else if (0 == strncmp(endptr, "s", 1)) + else if (STRN_EQ(endptr, "s", 1)) return val * G_USEC_PER_SEC; - else if (0 == strncmp(endptr, "m", 1)) + else if (STRN_EQ(endptr, "m", 1)) return val * G_USEC_PER_SEC * 60; - else if (0 == strncmp(endptr, "h", 1)) + else if (STRN_EQ(endptr, "h", 1)) return val * G_USEC_PER_SEC * 60 * 60; - else if (0 == strncmp(endptr, "d", 1)) + else if (STRN_EQ(endptr, "d", 1)) return val * G_USEC_PER_SEC * 60 * 60 * 24; else return 0; diff --git a/src/x11/screen.c b/src/x11/screen.c index d7fbfbf..af47e85 100644 --- a/src/x11/screen.c +++ b/src/x11/screen.c @@ -260,7 +260,7 @@ bool window_is_fullscreen(Window window) char *atom = XGetAtomName(xctx.dpy, ((Atom*)prop_to_return)[i]); if (atom) { - if(0 == strcmp("_NET_WM_STATE_FULLSCREEN", atom)) + if(STR_EQ("_NET_WM_STATE_FULLSCREEN", atom)) fs = true; XFree(atom); if(fs) diff --git a/src/x11/x.c b/src/x11/x.c index 45c3a1b..b96174a 100644 --- a/src/x11/x.c +++ b/src/x11/x.c @@ -712,17 +712,17 @@ void x_win_hide(struct window_x11 *win) */ KeySym x_shortcut_string_to_mask(const char *str) { - if (!strcmp(str, "ctrl")) { + if (STR_EQ(str, "ctrl")) { return ControlMask; - } else if (!strcmp(str, "mod4")) { + } else if (STR_EQ(str, "mod4")) { return Mod4Mask; - } else if (!strcmp(str, "mod3")) { + } else if (STR_EQ(str, "mod3")) { return Mod3Mask; - } else if (!strcmp(str, "mod2")) { + } else if (STR_EQ(str, "mod2")) { return Mod2Mask; - } else if (!strcmp(str, "mod1")) { + } else if (STR_EQ(str, "mod1")) { return Mod1Mask; - } else if (!strcmp(str, "shift")) { + } else if (STR_EQ(str, "shift")) { return ShiftMask; } else { LOG_W("Unknown Modifier: '%s'", str); @@ -828,7 +828,7 @@ static void x_shortcut_init(struct keyboard_shortcut *ks) if (!ks|| !ks->str) return; - if (!strcmp(ks->str, "none") || (!strcmp(ks->str, ""))) { + if (STR_EQ(ks->str, "none") || (STR_EQ(ks->str, ""))) { ks->is_valid = false; return; } From 750e05f03bdac49b50065ec152e5e3a11a7cddfe Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Wed, 10 Oct 2018 11:52:35 +0200 Subject: [PATCH 12/13] Remove trailing spaces --- .github/ISSUE_TEMPLATE.md | 2 +- Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index ea22ec0..ba4066f 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -7,7 +7,7 @@ These program calls might help: While the notification gets sent: `dbus-monitor path=/org/freedesktop/Notifications` -If dunst segfaults (please install the debug symbols or install dunst manually again): +If dunst segfaults (please install the debug symbols or install dunst manually again): `gdb -ex run dunst -ex bt` * ISSUE DESCRIPTION GOES BELOW THIS LINE * --> diff --git a/Makefile b/Makefile index 3edd1e7..21d9306 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ endif ifeq (,${SYSTEMD}) # Check for systemctl to avoid discrepancies on systems, where -# systemd is installed, but systemd.pc is in another package +# systemd is installed, but systemd.pc is in another package systemctl := $(shell command -v systemctl >/dev/null && echo systemctl) ifeq (systemctl,${systemctl}) SYSTEMD := 1 From f0e4870d99801f84e4bc9a3b18f2f38b9830b982 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Wed, 10 Oct 2018 12:58:02 +0200 Subject: [PATCH 13/13] Reorder CC arguments similarily Output first, then all required objects and then the FLAGS --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 21d9306..5261b17 100644 --- a/Makefile +++ b/Makefile @@ -64,10 +64,10 @@ debug: all ${OBJ}: config.mk dunst: ${OBJ} main.o - ${CC} ${CFLAGS} -o $@ ${OBJ} main.o ${LDFLAGS} + ${CC} -o ${@} ${OBJ} main.o ${CFLAGS} ${LDFLAGS} dunstify: dunstify.o - ${CC} ${CFLAGS} -o $@ dunstify.o ${LDFLAGS} + ${CC} -o ${@} dunstify.o ${CFLAGS} ${LDFLAGS} .PHONY: test test-valgrind test: test/test @@ -85,7 +85,7 @@ test-valgrind: test/test ./test test/test: ${OBJ} ${TEST_OBJ} - ${CC} ${CFLAGS} -o $@ ${TEST_OBJ} ${OBJ} ${LDFLAGS} + ${CC} -o ${@} ${TEST_OBJ} ${OBJ} ${CFLAGS} ${LDFLAGS} .PHONY: doc doc-doxygen doc: docs/dunst.1