Skip to content

Commit

Permalink
Merge pull request #1447 from bynect/fix-dbus
Browse files Browse the repository at this point in the history
Fix dbus reload signal and gradient
  • Loading branch information
bynect authored Feb 25, 2025
2 parents a0dbc00 + dbf43f0 commit 80cc23d
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 29 deletions.
2 changes: 1 addition & 1 deletion completions/_dunstctl.zshcomp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ case $state in
'history:Display notification history (in JSON)'
'history-clear:Delete all notifications from history'
'history-pop:Pop the latest notification from history or optionally the notification with given ID'
'history-remove:Remove the notification from'
'history-rm:Remove the notification with given ID from history'
'is-paused:Check if pause level is greater than 0'
'set-paused:Set the pause status'
'get-pause-level:Get the current pause level'
Expand Down
12 changes: 7 additions & 5 deletions src/dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ static void dbus_cb_dunst_NotificationListHistory(GDBusConnection *connection,
icon_path = (n->icon_path == NULL) ? "" : n->icon_path;
urgency = notification_urgency_to_string(n->urgency);
urls = (n->urls == NULL) ? "" : n->urls;
stack_tag = (n->stack_tag == NULL) ? "" : n->stack_tag;
stack_tag = (n->stack_tag == NULL) ? "" : n->stack_tag;

g_variant_builder_add(&n_builder, "{sv}", "body", g_variant_new_string(body));
g_variant_builder_add(&n_builder, "{sv}", "message", g_variant_new_string(msg));
Expand Down Expand Up @@ -437,9 +437,10 @@ static void dbus_cb_dunst_NotificationRemoveFromHistory(GDBusConnection *connect
guint32 id;
g_variant_get(parameters, "(u)", &id);

queues_history_remove_by_id(id);
signal_history_removed(id);
wake_up();
if (queues_history_remove_by_id(id)) {
signal_history_removed(id);
wake_up();
}

g_dbus_method_invocation_return_value(invocation, NULL);
g_dbus_connection_flush(connection, NULL, NULL, NULL);
Expand Down Expand Up @@ -1489,7 +1490,8 @@ void signal_config_reloaded(char **const configs)
LOG_E("Unable to send signal: No DBus connection.");
}

GVariant *body = g_variant_new("(as)", configs);
guint length = g_strv_length(configs);
GVariant *body = g_variant_new("(^as)", length != 0 ? configs : config_paths);
GError *err = NULL;

g_dbus_connection_emit_signal(dbus_conn,
Expand Down
5 changes: 3 additions & 2 deletions src/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,8 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, int
frame_y = h_without_progress_bar,
progress_width_without_frame = progress_width - 2 * frame_width,
progress_width_1 = progress_width_without_frame * progress / 100,
progress_width_2 = progress_width_without_frame - 1;
progress_width_2 = progress_width_without_frame - 1,
progress_width_scaled = (progress_width + 1) * scale;

switch (cl->n->progress_bar_alignment) {
case PANGO_ALIGN_LEFT:
Expand Down Expand Up @@ -902,7 +903,7 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, int

// top layer (fill)
cairo_matrix_t matrix;
cairo_matrix_init_scale(&matrix, 1.0 / width, 1.0);
cairo_matrix_init_scale(&matrix, 1.0 / progress_width_scaled, 1.0);
cairo_pattern_set_matrix(COLOR(cl, highlight->pattern), &matrix);
cairo_set_source(c, COLOR(cl, highlight->pattern));

Expand Down
4 changes: 2 additions & 2 deletions src/dunst.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ GMainLoop *mainloop = NULL;

static struct dunst_status status;
static bool setup_done = false;
static char **config_paths = NULL;
char **config_paths = NULL;

/* see dunst.h */
void dunst_status(const enum dunst_status_field field,
Expand Down Expand Up @@ -232,7 +232,7 @@ void reload(char **const configs)
rules = NULL;

settings_free(&settings);
load_settings(configs);
load_settings(length != 0 ? configs : config_paths);

draw_setup();
setup_done = true;
Expand Down
2 changes: 2 additions & 0 deletions src/dunst.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ enum dunst_status_field {
S_PAUSE_LEVEL,
};

extern char **config_paths;

/**
* Modify the current status of dunst
* @param field The field to change in the global status structure
Expand Down
2 changes: 1 addition & 1 deletion src/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

// unified fopen() result messages
#define MSG_FOPEN_SUCCESS(path, fp) "Opened '%s' (fd: '%d')", path, fileno(fp)
#define MSG_FOPEN_FAILURE(path) "Cannot open '%s': '%s'", path, strerror(errno)
#define MSG_FOPEN_FAILURE(path) "Cannot open '%s': %s", path, strerror(errno)

/**
* Set the current loglevel to `level`
Expand Down
7 changes: 4 additions & 3 deletions src/queues.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,11 @@ void queues_history_push_all(void)
}

/* see queues.h */
void queues_history_remove_by_id(gint id) {
bool queues_history_remove_by_id(gint id) {
struct notification *n = NULL;

if (g_queue_is_empty(history))
return;
return false;

for (GList *iter = g_queue_peek_head_link(history); iter;
iter = iter->next) {
Expand All @@ -448,10 +448,11 @@ void queues_history_remove_by_id(gint id) {
}

if (n == NULL)
return;
return false;

g_queue_remove(history, n);
notification_unref(n);
return true;
}

/* see queues.h */
Expand Down
2 changes: 1 addition & 1 deletion src/queues.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void queues_history_push_all(void);
/**
* Removes an notification identified by the given id from the history
*/
void queues_history_remove_by_id(gint id);
bool queues_history_remove_by_id(gint id);

/**
* Move inserted notifications from waiting queue to displayed queue
Expand Down
8 changes: 4 additions & 4 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,19 +262,19 @@ static void process_conf_file(const gpointer conf_fname, gpointer n_success) {
++(*(int *) n_success);
}

void load_settings(char **const config_paths)
void load_settings(char **const paths)
{
LOG_D("Setting defaults");
set_defaults();

guint length = g_strv_length(config_paths);
guint length = g_strv_length(paths);

GPtrArray *conf_files;

if (length != 0) {
conf_files = g_ptr_array_new_full(length, g_free);
for (int i = 0; config_paths[i]; i++)
g_ptr_array_add(conf_files, g_strdup(config_paths[i]));
for (int i = 0; paths[i]; i++)
g_ptr_array_add(conf_files, g_strdup(paths[i]));
} else {
// Use default locations (and search drop-ins)
conf_files = get_conf_files();
Expand Down
20 changes: 10 additions & 10 deletions test/setting.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ extern const char *base;
// In this suite a few dunstrc's are tested to see if the settings code works
// This file is called setting.c, since the name settings.c caused issues.

char *config_paths[2] = {0};
char *test_paths[2] = {0};

TEST test_dunstrc_markup(void) {
settings_free(&settings);

config_paths[0] = g_strconcat(base, "/data/dunstrc.markup", NULL);
load_settings(config_paths);
test_paths[0] = g_strconcat(base, "/data/dunstrc.markup", NULL);
load_settings(test_paths);

ASSERT_STR_EQ(settings.font, "Monospace 8");

Expand All @@ -26,15 +26,15 @@ TEST test_dunstrc_markup(void) {
ASSERT_STR_EQ(e_format, got_format);
ASSERT(settings.indicate_hidden);

g_clear_pointer(&config_paths[0], g_free);
g_clear_pointer(&test_paths[0], g_free);
PASS();
}

TEST test_dunstrc_nomarkup(void) {
settings_free(&settings);

config_paths[0] = g_strconcat(base, "/data/dunstrc.nomarkup", NULL);
load_settings(config_paths);
test_paths[0] = g_strconcat(base, "/data/dunstrc.nomarkup", NULL);
load_settings(test_paths);

ASSERT_STR_EQ(settings.font, "Monospace 8");

Expand All @@ -45,7 +45,7 @@ TEST test_dunstrc_nomarkup(void) {
ASSERT_STR_EQ(e_format, got_format);
ASSERT(settings.indicate_hidden);

g_clear_pointer(&config_paths[0], g_free);
g_clear_pointer(&test_paths[0], g_free);
PASS();
}

Expand All @@ -55,11 +55,11 @@ TEST test_dunstrc_defaults(void) {
struct settings s_default;
struct settings s_dunstrc;

config_paths[0] = g_strconcat(base, "/data/dunstrc.default", NULL);
test_paths[0] = g_strconcat(base, "/data/dunstrc.default", NULL);
set_defaults();
s_default = settings;

load_settings(config_paths);
load_settings(test_paths);
s_dunstrc = settings;

ASSERT_EQ(s_default.corner_radius, s_dunstrc.corner_radius);
Expand Down Expand Up @@ -116,7 +116,7 @@ TEST test_dunstrc_defaults(void) {
settings_free(&s_old);
settings_free(&s_default);

g_clear_pointer(&config_paths[0], g_free);
g_clear_pointer(&test_paths[0], g_free);
PASS();
}

Expand Down

0 comments on commit 80cc23d

Please sign in to comment.