Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gboolean/bool mixup #1423

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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",
Expand All @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions src/rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
};
Expand Down
3 changes: 3 additions & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions test/dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading