Skip to content
This repository

Progress hints #71

Merged
merged 9 commits into from over 1 year ago

2 participants

Sascha Kruse

Enables display of progress hints and includes some necessary bugfixes for clean progress updates.

Sascha Kruse
Owner

What's the advantage of doing this within the daemon instead of letting the client add the progress information to the summary or body?

And the new format placeholder should be documented in the manpage (README.pod) and the default dunstrc.

Apart from this and the inline comments this looks fine.

You are right, this should be done in the summary. I didn't think of that since xfce4-notifyd did not display the text at all.

If you still want to add it I'll clean up the comments later.

Sascha Kruse
Owner

Since it seems to be already used by other notification-daemons and clients this should be useful to increase compatibility.
So yes, I still want to merge this ;)

Thank you!

P.s: Please leave a short comment when you're done, since (at least I think) github doesn't send notifications when the pullrequest gets upated

I think it is ready.

Sascha Kruse knopwob merged commit 75cb6da into from October 08, 2012
Sascha Kruse knopwob closed this October 08, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
5  README.pod
Source Rendered
@@ -119,6 +119,8 @@ fmt is a string containing placeholders. The placeholders will be replaced with
119 119
 
120 120
 =item B<%I>  iconname (without its path)
121 121
 
  122
+=item B<%p>  progress value ([  0%] to [100%])
  123
+
122 124
 =back
123 125
 
124 126
 =head1 COLORS
@@ -131,6 +133,7 @@ X color names.
131 133
 
132 134
 dunst is able to get different colors for a message via notify-send.
133 135
 In order to do that you have to add a hint via the -h option.
  136
+The progress value can be set with a hint, too.
134 137
 
135 138
 =over 4
136 139
 
@@ -138,6 +141,8 @@ In order to do that you have to add a hint via the -h option.
138 141
 
139 142
 =item notify-send -h string:bgcolor:#4444ff -h string:fgcolor:#ff4444
140 143
 
  144
+=item notify-send -h int:value:42 "Working ..."
  145
+
141 146
 =back
142 147
 
143 148
 =head1 CONFIGURATION
14  dunst.c
@@ -907,6 +907,13 @@ int init_notification(notification * n, int id)
907 907
         n->msg = string_replace("%i", n->icon, n->msg);
908 908
         n->msg = string_replace("%I", basename(n->icon), n->msg);
909 909
         n->msg = string_replace("%b", n->body, n->msg);
  910
+        if (n->progress) {
  911
+                char pg[10];
  912
+                sprintf(pg, "[%3d%%]", n->progress-1);
  913
+                n->msg = string_replace("%p", pg, n->msg);
  914
+        } else {
  915
+                n->msg = string_replace("%p", "", n->msg);
  916
+        }
910 917
 
911 918
         n->msg = fix_markup(n->msg);
912 919
 
@@ -917,7 +924,7 @@ int init_notification(notification * n, int id)
917 924
         /* check if n is a duplicate */
918 925
         for (l_node * iter = notification_queue->head; iter; iter = iter->next) {
919 926
                 notification *orig = (notification *) iter->data;
920  
-                if (strcmp(orig->msg, n->msg) == 0) {
  927
+                if (strcmp(orig->appname, n->appname) == 0 && strcmp(orig->msg, n->msg) == 0) {
921 928
                         orig->dup_count++;
922 929
                         free_notification(n);
923 930
                         return orig->id;
@@ -927,7 +934,7 @@ int init_notification(notification * n, int id)
927 934
         for (l_node * iter = displayed_notifications->head; iter;
928 935
              iter = iter->next) {
929 936
                 notification *orig = (notification *) iter->data;
930  
-                if (strcmp(orig->msg, n->msg) == 0) {
  937
+                if (strcmp(orig->appname, n->appname) == 0 && strcmp(orig->msg, n->msg) == 0) {
931 938
                         orig->dup_count++;
932 939
                         orig->start = now;
933 940
                         free_notification(n);
@@ -963,6 +970,7 @@ int init_notification(notification * n, int id)
963 970
                 n->id = ++next_notification_id;
964 971
         } else {
965 972
                 close_notification_by_id(id, -1);
  973
+                n->id = id;
966 974
         }
967 975
 
968 976
         if(strlen(n->msg) == 0) {
@@ -1296,7 +1304,7 @@ void setup(void)
1296 1304
                                                         DefaultScreen(dc->dpy)),
1297 1305
                           CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
1298 1306
         transparency = transparency > 100 ? 100 : transparency;
1299  
-	setopacity(dc, win, (unsigned long)((100 - transparency) * (0xffffffff/100)));
  1307
+        setopacity(dc, win, (unsigned long)((100 - transparency) * (0xffffffff/100)));
1300 1308
         grab_key(&history_ks);
1301 1309
 }
1302 1310
 
1  dunst.h
@@ -54,6 +54,7 @@ typedef struct _notification {
54 54
         int dup_count;
55 55
         ColorSet *colors;
56 56
         char *color_strings[2];
  57
+        int progress;           /* percentage + 1, 0 to hide */
57 58
 } notification;
58 59
 
59 60
 typedef struct _notification_buffer {
14  dunst_dbus.c
@@ -20,7 +20,7 @@ static void _extract_basic(int type, DBusMessageIter * iter, void *target)
20 20
 }
21 21
 
22 22
 static void
23  
-_extract_hint(const char *name, const char *hint_name,
  23
+_extract_hint(int type, const char *name, const char *hint_name,
24 24
               DBusMessageIter * hint, void *target)
25 25
 {
26 26
 
@@ -30,7 +30,7 @@ _extract_hint(const char *name, const char *hint_name,
30 30
                 dbus_message_iter_next(hint);
31 31
                 dbus_message_iter_recurse(hint, &hint_value);
32 32
                 do {
33  
-                        dbus_message_iter_get_basic(&hint_value, target);
  33
+                        _extract_basic(type, &hint_value, target);
34 34
                 } while (dbus_message_iter_next(hint));
35 35
         }
36 36
 }
@@ -296,6 +296,7 @@ void notify(DBusMessage * dmsg)
296 296
         const char *fgcolor = NULL;
297 297
         const char *bgcolor = NULL;
298 298
         int urgency = 1;
  299
+        int progress = -1;
299 300
         notification *n = malloc(sizeof(notification));
300 301
         dbus_uint32_t replaces_id = 0;
301 302
         dbus_int32_t expires = -1;
@@ -335,9 +336,11 @@ void notify(DBusMessage * dmsg)
335 336
                                 continue;
336 337
                         }
337 338
                         dbus_message_iter_get_basic(&hint, &hint_name);
338  
-                        _extract_hint("urgency", hint_name, &hint, &urgency);
339  
-                        _extract_hint("fgcolor", hint_name, &hint, &fgcolor);
340  
-                        _extract_hint("bgcolor", hint_name, &hint, &bgcolor);
  339
+                        _extract_hint(DBUS_TYPE_BYTE, "urgency", hint_name, &hint, &urgency);
  340
+                        _extract_hint(DBUS_TYPE_STRING, "fgcolor", hint_name, &hint, &fgcolor);
  341
+                        _extract_hint(DBUS_TYPE_STRING, "bgcolor", hint_name, &hint, &bgcolor);
  342
+                        _extract_hint(DBUS_TYPE_INT32, "value", hint_name, &hint, &progress);
  343
+                        if (!progress) _extract_hint(DBUS_TYPE_UINT32, "value", hint_name, &hint, &progress);
341 344
                         dbus_message_iter_next(&hint);
342 345
                 }
343 346
                 dbus_message_iter_next(&hints);
@@ -355,6 +358,7 @@ void notify(DBusMessage * dmsg)
355 358
         n->body = body != NULL ? strdup(body) : "";
356 359
         n->icon = icon != NULL ? strdup(icon) : "";
357 360
         n->timeout = expires;
  361
+        n->progress = (progress < 0 || progress > 100) ? 0 : progress+1;
358 362
         n->urgency = urgency;
359 363
         n->dbus_client = strdup(dbus_message_get_sender(dmsg));
360 364
         for (i = 0; i < ColLast; i++) {
1  dunstrc
@@ -7,6 +7,7 @@
7 7
     #   %b  body
8 8
     #   %i  iconname (including its path)
9 9
     #   %I  iconname (without its path)
  10
+    #   %p  progress value if set ([  0%] to [100%]) or nothing
10 11
     format = "%s %b"
11 12
 
12 13
     # Sort messages by urgency
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.