From 13bff8a79065356735ccd2ab3452b3a6bc07aa76 Mon Sep 17 00:00:00 2001 From: bynect <68197565+bynect@users.noreply.github.com> Date: Thu, 26 Dec 2024 01:28:55 +0100 Subject: [PATCH] Fix gboolean/bool mixup --- src/dbus.c | 14 +++++++------- src/rules.h | 14 +++++++------- src/utils.h | 3 +++ test/dbus.c | 7 +++++++ 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/dbus.c b/src/dbus.c index 6dfa2ee75..dbb2806c4 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -483,7 +483,7 @@ static void dbus_cb_dunst_RuleList(GDBusConnection *connection, g_variant_dict_insert(&dict, "name", "s", r->name); // filters - order according to rule_matches_notification - g_variant_dict_insert(&dict, "enabled", "b", r->enabled); + g_variant_dict_insert(&dict, "enabled", "b", BOOL2G(r->enabled)); // undocumented filter? if (r->match_dbus_timeout > -1) g_variant_dict_insert(&dict, "match_dbus_timeout", "i", r->match_dbus_timeout); @@ -493,7 +493,7 @@ static void dbus_cb_dunst_RuleList(GDBusConnection *connection, "s", enum_to_string(urgency_enum_data, r->msg_urgency)); if (r->match_transient > -1) - g_variant_dict_insert(&dict, "match_transient", "b", r->match_transient); + g_variant_dict_insert(&dict, "match_transient", "b", BOOL2G(r->match_transient)); if (r->appname) g_variant_dict_insert(&dict, "appname", "s", r->appname); if (r->desktop_entry) @@ -520,13 +520,13 @@ static void dbus_cb_dunst_RuleList(GDBusConnection *connection, "s", enum_to_string(fullscreen_enum_data, r->fullscreen)); if (r->history_ignore != -1) - g_variant_dict_insert(&dict, "history_ignore", "b", r->history_ignore); + g_variant_dict_insert(&dict, "history_ignore", "b", BOOL2G(r->history_ignore)); if (r->set_transient != -1) - g_variant_dict_insert(&dict, "set_transient", "b", r->set_transient); + g_variant_dict_insert(&dict, "set_transient", "b", BOOL2G(r->set_transient)); if (r->skip_display != -1) - g_variant_dict_insert(&dict, "skip_display", "b", r->skip_display); + g_variant_dict_insert(&dict, "skip_display", "b", BOOL2G(r->skip_display)); if (r->word_wrap != -1) - g_variant_dict_insert(&dict, "word_wrap", "b", r->word_wrap); + g_variant_dict_insert(&dict, "word_wrap", "b", BOOL2G(r->word_wrap)); if (r->ellipsize != -1) g_variant_dict_insert(&dict, "ellipsize", @@ -538,7 +538,7 @@ static void dbus_cb_dunst_RuleList(GDBusConnection *connection, "s", enum_to_string(horizontal_alignment_enum_data, r->alignment)); if (r->hide_text != -1) - g_variant_dict_insert(&dict, "hide_text", "b", r->hide_text); + g_variant_dict_insert(&dict, "hide_text", "b", BOOL2G(r->hide_text)); if (r->progress_bar_alignment != -1) g_variant_dict_insert(&dict, "progress_bar_alignment", diff --git a/src/rules.h b/src/rules.h index 9f99c01de..463078ebc 100644 --- a/src/rules.h +++ b/src/rules.h @@ -34,14 +34,14 @@ struct rule { enum urgency urgency; char *action_name; enum markup_mode markup; - int history_ignore; - int match_transient; - int set_transient; - int skip_display; - int word_wrap; + gint history_ignore; + gint match_transient; + gint set_transient; + gint skip_display; + gint word_wrap; int ellipsize; int alignment; - int hide_text; + gint hide_text; int icon_position; int min_icon_size; int max_icon_size; @@ -56,7 +56,7 @@ struct rule { char *format; char *script; enum behavior_fullscreen fullscreen; - gboolean enabled; + bool enabled; int progress_bar_alignment; char *set_stack_tag; // this has to be the last modifying rule }; diff --git a/src/utils.h b/src/utils.h index ea712cd9b..8a160104b 100644 --- a/src/utils.h +++ b/src/utils.h @@ -24,6 +24,9 @@ #define STR_TO(...) _STR_TO(__VA_ARGS__) #define _STR_TO(...) "" # __VA_ARGS__ +//! Make a gboolean from a boolean value +// See https://github.com/dunst-project/dunst/issues/1421 +#define BOOL2G(x) ((x) ? TRUE : FALSE) //! Assert that expr evaluates to true, if not return with val #define ASSERT_OR_RET(expr, val) if (!(expr)) return val; diff --git a/test/dbus.c b/test/dbus.c index 66e9e9fdc..98b8fe03b 100644 --- a/test/dbus.c +++ b/test/dbus.c @@ -621,6 +621,7 @@ TEST test_dbus_cb_dunst_RuleList(void) struct rule *rule = rule_new("testing RuleList"); rule->appname = "dunstify"; rule->urgency = URG_CRIT; + rule->match_transient = true; rule->fg = (struct color){.r = 0.1, .g = 0.1, .b = 0.1, .a = 1.0}; GVariant *result = dbus_invoke_ifac("RuleList", NULL, DUNST_IFAC); @@ -648,6 +649,12 @@ TEST test_dbus_cb_dunst_RuleList(void) ASSERT(g_variant_dict_lookup(&d, "enabled", "b", &boolean)); ASSERT(boolean); + ASSERT(!g_variant_dict_lookup(&d, "hide_text", "b", &boolean)); + ASSERT(!g_variant_dict_lookup(&d, "history_ignore", "b", &boolean)); + + ASSERT(g_variant_dict_lookup(&d, "match_transient", "b", &boolean)); + ASSERT(boolean); + ASSERT(g_variant_dict_lookup(&d, "appname", "s", &str)); ASSERT_STR_EQ("dunstify", str); g_free(str);