Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Progress hints #71

Merged
merged 9 commits into from

2 participants

progandy Sascha Kruse
progandy

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.

progandy

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

progandy

I think it is ready.

Sascha Kruse knopwob merged commit 75cb6da into from
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.
Showing with 27 additions and 8 deletions.
  1. +5 −0 README.pod
  2. +11 −3 dunst.c
  3. +1 −0  dunst.h
  4. +9 −5 dunst_dbus.c
  5. +1 −0  dunstrc
5 README.pod
View
@@ -119,6 +119,8 @@ fmt is a string containing placeholders. The placeholders will be replaced with
=item B<%I> iconname (without its path)
+=item B<%p> progress value ([ 0%] to [100%])
+
=back
=head1 COLORS
@@ -131,6 +133,7 @@ X color names.
dunst is able to get different colors for a message via notify-send.
In order to do that you have to add a hint via the -h option.
+The progress value can be set with a hint, too.
=over 4
@@ -138,6 +141,8 @@ In order to do that you have to add a hint via the -h option.
=item notify-send -h string:bgcolor:#4444ff -h string:fgcolor:#ff4444
+=item notify-send -h int:value:42 "Working ..."
+
=back
=head1 CONFIGURATION
14 dunst.c
View
@@ -907,6 +907,13 @@ int init_notification(notification * n, int id)
n->msg = string_replace("%i", n->icon, n->msg);
n->msg = string_replace("%I", basename(n->icon), n->msg);
n->msg = string_replace("%b", n->body, n->msg);
+ if (n->progress) {
+ char pg[10];
+ sprintf(pg, "[%3d%%]", n->progress-1);
+ n->msg = string_replace("%p", pg, n->msg);
+ } else {
+ n->msg = string_replace("%p", "", n->msg);
+ }
n->msg = fix_markup(n->msg);
@@ -917,7 +924,7 @@ int init_notification(notification * n, int id)
/* check if n is a duplicate */
for (l_node * iter = notification_queue->head; iter; iter = iter->next) {
notification *orig = (notification *) iter->data;
- if (strcmp(orig->msg, n->msg) == 0) {
+ if (strcmp(orig->appname, n->appname) == 0 && strcmp(orig->msg, n->msg) == 0) {
orig->dup_count++;
free_notification(n);
return orig->id;
@@ -927,7 +934,7 @@ int init_notification(notification * n, int id)
for (l_node * iter = displayed_notifications->head; iter;
iter = iter->next) {
notification *orig = (notification *) iter->data;
- if (strcmp(orig->msg, n->msg) == 0) {
+ if (strcmp(orig->appname, n->appname) == 0 && strcmp(orig->msg, n->msg) == 0) {
orig->dup_count++;
orig->start = now;
free_notification(n);
@@ -963,6 +970,7 @@ int init_notification(notification * n, int id)
n->id = ++next_notification_id;
} else {
close_notification_by_id(id, -1);
+ n->id = id;
}
if(strlen(n->msg) == 0) {
@@ -1296,7 +1304,7 @@ void setup(void)
DefaultScreen(dc->dpy)),
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
transparency = transparency > 100 ? 100 : transparency;
- setopacity(dc, win, (unsigned long)((100 - transparency) * (0xffffffff/100)));
+ setopacity(dc, win, (unsigned long)((100 - transparency) * (0xffffffff/100)));
grab_key(&history_ks);
}
1  dunst.h
View
@@ -54,6 +54,7 @@ typedef struct _notification {
int dup_count;
ColorSet *colors;
char *color_strings[2];
+ int progress; /* percentage + 1, 0 to hide */
} notification;
typedef struct _notification_buffer {
14 dunst_dbus.c
View
@@ -20,7 +20,7 @@ static void _extract_basic(int type, DBusMessageIter * iter, void *target)
}
static void
-_extract_hint(const char *name, const char *hint_name,
+_extract_hint(int type, const char *name, const char *hint_name,
DBusMessageIter * hint, void *target)
{
@@ -30,7 +30,7 @@ _extract_hint(const char *name, const char *hint_name,
dbus_message_iter_next(hint);
dbus_message_iter_recurse(hint, &hint_value);
do {
- dbus_message_iter_get_basic(&hint_value, target);
+ _extract_basic(type, &hint_value, target);
} while (dbus_message_iter_next(hint));
}
}
@@ -296,6 +296,7 @@ void notify(DBusMessage * dmsg)
const char *fgcolor = NULL;
const char *bgcolor = NULL;
int urgency = 1;
+ int progress = -1;
notification *n = malloc(sizeof(notification));
dbus_uint32_t replaces_id = 0;
dbus_int32_t expires = -1;
@@ -335,9 +336,11 @@ void notify(DBusMessage * dmsg)
continue;
}
dbus_message_iter_get_basic(&hint, &hint_name);
- _extract_hint("urgency", hint_name, &hint, &urgency);
- _extract_hint("fgcolor", hint_name, &hint, &fgcolor);
- _extract_hint("bgcolor", hint_name, &hint, &bgcolor);
+ _extract_hint(DBUS_TYPE_BYTE, "urgency", hint_name, &hint, &urgency);
+ _extract_hint(DBUS_TYPE_STRING, "fgcolor", hint_name, &hint, &fgcolor);
+ _extract_hint(DBUS_TYPE_STRING, "bgcolor", hint_name, &hint, &bgcolor);
+ _extract_hint(DBUS_TYPE_INT32, "value", hint_name, &hint, &progress);
+ if (!progress) _extract_hint(DBUS_TYPE_UINT32, "value", hint_name, &hint, &progress);
dbus_message_iter_next(&hint);
}
dbus_message_iter_next(&hints);
@@ -355,6 +358,7 @@ void notify(DBusMessage * dmsg)
n->body = body != NULL ? strdup(body) : "";
n->icon = icon != NULL ? strdup(icon) : "";
n->timeout = expires;
+ n->progress = (progress < 0 || progress > 100) ? 0 : progress+1;
n->urgency = urgency;
n->dbus_client = strdup(dbus_message_get_sender(dmsg));
for (i = 0; i < ColLast; i++) {
1  dunstrc
View
@@ -7,6 +7,7 @@
# %b body
# %i iconname (including its path)
# %I iconname (without its path)
+ # %p progress value if set ([ 0%] to [100%]) or nothing
format = "%s %b"
# Sort messages by urgency
Something went wrong with that request. Please try again.