Skip to content

Commit 80cc23d

Browse files
authored
Merge pull request #1447 from bynect/fix-dbus
Fix dbus reload signal and gradient
2 parents a0dbc00 + dbf43f0 commit 80cc23d

File tree

10 files changed

+35
-29
lines changed

10 files changed

+35
-29
lines changed

completions/_dunstctl.zshcomp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ case $state in
2424
'history:Display notification history (in JSON)'
2525
'history-clear:Delete all notifications from history'
2626
'history-pop:Pop the latest notification from history or optionally the notification with given ID'
27-
'history-remove:Remove the notification from'
27+
'history-rm:Remove the notification with given ID from history'
2828
'is-paused:Check if pause level is greater than 0'
2929
'set-paused:Set the pause status'
3030
'get-pause-level:Get the current pause level'

src/dbus.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ static void dbus_cb_dunst_NotificationListHistory(GDBusConnection *connection,
385385
icon_path = (n->icon_path == NULL) ? "" : n->icon_path;
386386
urgency = notification_urgency_to_string(n->urgency);
387387
urls = (n->urls == NULL) ? "" : n->urls;
388-
stack_tag = (n->stack_tag == NULL) ? "" : n->stack_tag;
388+
stack_tag = (n->stack_tag == NULL) ? "" : n->stack_tag;
389389

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

440-
queues_history_remove_by_id(id);
441-
signal_history_removed(id);
442-
wake_up();
440+
if (queues_history_remove_by_id(id)) {
441+
signal_history_removed(id);
442+
wake_up();
443+
}
443444

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

1492-
GVariant *body = g_variant_new("(as)", configs);
1493+
guint length = g_strv_length(configs);
1494+
GVariant *body = g_variant_new("(^as)", length != 0 ? configs : config_paths);
14931495
GError *err = NULL;
14941496

14951497
g_dbus_connection_emit_signal(dbus_conn,

src/draw.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,8 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, int
870870
frame_y = h_without_progress_bar,
871871
progress_width_without_frame = progress_width - 2 * frame_width,
872872
progress_width_1 = progress_width_without_frame * progress / 100,
873-
progress_width_2 = progress_width_without_frame - 1;
873+
progress_width_2 = progress_width_without_frame - 1,
874+
progress_width_scaled = (progress_width + 1) * scale;
874875

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

903904
// top layer (fill)
904905
cairo_matrix_t matrix;
905-
cairo_matrix_init_scale(&matrix, 1.0 / width, 1.0);
906+
cairo_matrix_init_scale(&matrix, 1.0 / progress_width_scaled, 1.0);
906907
cairo_pattern_set_matrix(COLOR(cl, highlight->pattern), &matrix);
907908
cairo_set_source(c, COLOR(cl, highlight->pattern));
908909

src/dunst.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ GMainLoop *mainloop = NULL;
2626

2727
static struct dunst_status status;
2828
static bool setup_done = false;
29-
static char **config_paths = NULL;
29+
char **config_paths = NULL;
3030

3131
/* see dunst.h */
3232
void dunst_status(const enum dunst_status_field field,
@@ -232,7 +232,7 @@ void reload(char **const configs)
232232
rules = NULL;
233233

234234
settings_free(&settings);
235-
load_settings(configs);
235+
load_settings(length != 0 ? configs : config_paths);
236236

237237
draw_setup();
238238
setup_done = true;

src/dunst.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ enum dunst_status_field {
2525
S_PAUSE_LEVEL,
2626
};
2727

28+
extern char **config_paths;
29+
2830
/**
2931
* Modify the current status of dunst
3032
* @param field The field to change in the global status structure

src/log.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

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

4949
/**
5050
* Set the current loglevel to `level`

src/queues.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,11 @@ void queues_history_push_all(void)
432432
}
433433

434434
/* see queues.h */
435-
void queues_history_remove_by_id(gint id) {
435+
bool queues_history_remove_by_id(gint id) {
436436
struct notification *n = NULL;
437437

438438
if (g_queue_is_empty(history))
439-
return;
439+
return false;
440440

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

450450
if (n == NULL)
451-
return;
451+
return false;
452452

453453
g_queue_remove(history, n);
454454
notification_unref(n);
455+
return true;
455456
}
456457

457458
/* see queues.h */

src/queues.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void queues_history_push_all(void);
141141
/**
142142
* Removes an notification identified by the given id from the history
143143
*/
144-
void queues_history_remove_by_id(gint id);
144+
bool queues_history_remove_by_id(gint id);
145145

146146
/**
147147
* Move inserted notifications from waiting queue to displayed queue

src/settings.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,19 +262,19 @@ static void process_conf_file(const gpointer conf_fname, gpointer n_success) {
262262
++(*(int *) n_success);
263263
}
264264

265-
void load_settings(char **const config_paths)
265+
void load_settings(char **const paths)
266266
{
267267
LOG_D("Setting defaults");
268268
set_defaults();
269269

270-
guint length = g_strv_length(config_paths);
270+
guint length = g_strv_length(paths);
271271

272272
GPtrArray *conf_files;
273273

274274
if (length != 0) {
275275
conf_files = g_ptr_array_new_full(length, g_free);
276-
for (int i = 0; config_paths[i]; i++)
277-
g_ptr_array_add(conf_files, g_strdup(config_paths[i]));
276+
for (int i = 0; paths[i]; i++)
277+
g_ptr_array_add(conf_files, g_strdup(paths[i]));
278278
} else {
279279
// Use default locations (and search drop-ins)
280280
conf_files = get_conf_files();

test/setting.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ extern const char *base;
99
// In this suite a few dunstrc's are tested to see if the settings code works
1010
// This file is called setting.c, since the name settings.c caused issues.
1111

12-
char *config_paths[2] = {0};
12+
char *test_paths[2] = {0};
1313

1414
TEST test_dunstrc_markup(void) {
1515
settings_free(&settings);
1616

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

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

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

29-
g_clear_pointer(&config_paths[0], g_free);
29+
g_clear_pointer(&test_paths[0], g_free);
3030
PASS();
3131
}
3232

3333
TEST test_dunstrc_nomarkup(void) {
3434
settings_free(&settings);
3535

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

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

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

48-
g_clear_pointer(&config_paths[0], g_free);
48+
g_clear_pointer(&test_paths[0], g_free);
4949
PASS();
5050
}
5151

@@ -55,11 +55,11 @@ TEST test_dunstrc_defaults(void) {
5555
struct settings s_default;
5656
struct settings s_dunstrc;
5757

58-
config_paths[0] = g_strconcat(base, "/data/dunstrc.default", NULL);
58+
test_paths[0] = g_strconcat(base, "/data/dunstrc.default", NULL);
5959
set_defaults();
6060
s_default = settings;
6161

62-
load_settings(config_paths);
62+
load_settings(test_paths);
6363
s_dunstrc = settings;
6464

6565
ASSERT_EQ(s_default.corner_radius, s_dunstrc.corner_radius);
@@ -116,7 +116,7 @@ TEST test_dunstrc_defaults(void) {
116116
settings_free(&s_old);
117117
settings_free(&s_default);
118118

119-
g_clear_pointer(&config_paths[0], g_free);
119+
g_clear_pointer(&test_paths[0], g_free);
120120
PASS();
121121
}
122122

0 commit comments

Comments
 (0)