cleanup notification_* function names

This commit is contained in:
Sascha Kruse 2013-02-20 10:26:12 +01:00
parent 39b4dfb726
commit f2e42aabfd
3 changed files with 49 additions and 45 deletions

4
dbus.c
View File

@ -230,7 +230,7 @@ static void onNotify(GDBusConnection *connection,
n->color_strings[ColFG] = fgcolor; n->color_strings[ColFG] = fgcolor;
n->color_strings[ColBG] = bgcolor; n->color_strings[ColBG] = bgcolor;
int id = init_notification(n, replaces_id); int id = notification_init(n, replaces_id);
wake_up(); wake_up();
GVariant *reply = g_variant_new ("(u)", id); GVariant *reply = g_variant_new ("(u)", id);
@ -247,7 +247,7 @@ static void onCloseNotification(GDBusConnection *connection,
{ {
guint32 id; guint32 id;
g_variant_get(parameters, "(u)", &id); g_variant_get(parameters, "(u)", &id);
close_notification_by_id(id, 3); notification_close_by_id(id, 3);
g_dbus_method_invocation_return_value(invocation, NULL); g_dbus_method_invocation_return_value(invocation, NULL);
g_dbus_connection_flush(connection, NULL, NULL, NULL); g_dbus_connection_flush(connection, NULL, NULL, NULL);
} }

84
dunst.c
View File

@ -102,9 +102,13 @@ void rule_apply_all(notification *n);
bool rule_matches_notification(rule_t *r, notification *n); bool rule_matches_notification(rule_t *r, notification *n);
void rule_init(rule_t *r); void rule_init(rule_t *r);
/* notifications */
int notification_cmp(const void *a, const void *b);
int notification_cmp_data(const void *a, const void *b, void *data);
void notification_run_script(notification *n);
int notification_close(notification * n, int reason);
/* misc funtions */ /* misc funtions */
int cmp_notification(const void *a, const void *b);
int cmp_notification_data(const void *va, const void *vb, void *data);
void check_timeouts(void); void check_timeouts(void);
char *fix_markup(char *str); char *fix_markup(char *str);
void handle_mouse_click(XEvent ev); void handle_mouse_click(XEvent ev);
@ -119,7 +123,6 @@ void move_all_to_history(void);
void print_version(void); void print_version(void);
char *extract_urls(const char *str); char *extract_urls(const char *str);
void context_menu(void); void context_menu(void);
void run_script(notification *n);
void wake_up(void); void wake_up(void);
void init_shortcut(keyboard_shortcut * shortcut); void init_shortcut(keyboard_shortcut * shortcut);
@ -169,7 +172,7 @@ x11_fd_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
&& XLookupKeysym(&ev.xkey, 0) == close_ks.sym && XLookupKeysym(&ev.xkey, 0) == close_ks.sym
&& close_ks.mask == ev.xkey.state) { && close_ks.mask == ev.xkey.state) {
if (displayed) { if (displayed) {
close_notification(g_queue_peek_head_link(displayed)->data, 2); notification_close(g_queue_peek_head_link(displayed)->data, 2);
} }
} }
if (history_ks.str if (history_ks.str
@ -193,26 +196,6 @@ x11_fd_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
return true; return true;
} }
int cmp_notification(const void *va, const void *vb)
{
notification *a = (notification*) va;
notification *b = (notification*) vb;
if (!sort)
return 1;
if (a->urgency != b->urgency) {
return b->urgency - a->urgency;
} else {
return a->timestamp - b->timestamp;
}
}
int cmp_notification_data(const void *va, const void *vb, void *data)
{
return cmp_notification(va, vb);
}
char *extract_urls( const char * to_match) char *extract_urls( const char * to_match)
{ {
@ -619,7 +602,7 @@ void check_timeouts(void)
if (difftime(time(NULL), n->start) > n->timeout) { if (difftime(time(NULL), n->start) > n->timeout) {
force_redraw = true; force_redraw = true;
/* close_notification may conflict with iter, so restart */ /* close_notification may conflict with iter, so restart */
close_notification(n, 1); notification_close(n, 1);
check_timeouts(); check_timeouts();
return; return;
} }
@ -634,7 +617,7 @@ void update_lists()
if (pause_display) { if (pause_display) {
while (displayed->length > 0) { while (displayed->length > 0) {
g_queue_insert_sorted(queue, g_queue_pop_head(queue), cmp_notification_data, NULL); g_queue_insert_sorted(queue, g_queue_pop_head(queue), notification_cmp_data, NULL);
} }
return; return;
} }
@ -669,7 +652,7 @@ void update_lists()
run_script(n); run_script(n);
} }
g_queue_insert_sorted(displayed, n, cmp_notification_data, NULL); g_queue_insert_sorted(displayed, n, notification_cmp_data, NULL);
} }
} }
@ -1122,7 +1105,7 @@ void handle_mouse_click(XEvent ev)
y += height + separator_height; y += height + separator_height;
} }
if (n) if (n)
close_notification(n, 2); notification_close(n, 2);
} }
} }
@ -1130,7 +1113,7 @@ void handle_mouse_click(XEvent ev)
void move_all_to_history() void move_all_to_history()
{ {
while (displayed->length > 0) { while (displayed->length > 0) {
close_notification(g_queue_peek_head_link(displayed)->data, 2); notification_close(g_queue_peek_head_link(displayed)->data, 2);
} }
notification *n = g_queue_pop_head(queue); notification *n = g_queue_pop_head(queue);
@ -1157,7 +1140,28 @@ void history_pop(void)
} }
} }
void free_notification(notification * n) int notification_cmp(const void *va, const void *vb)
{
notification *a = (notification*) va;
notification *b = (notification*) vb;
if (!sort)
return 1;
if (a->urgency != b->urgency) {
return b->urgency - a->urgency;
} else {
return a->timestamp - b->timestamp;
}
}
int notification_cmp_data(const void *va, const void *vb, void *data)
{
return notification_cmp(va, vb);
}
void notification_free(notification * n)
{ {
if (n == NULL) if (n == NULL)
return; return;
@ -1170,7 +1174,7 @@ void free_notification(notification * n)
free(n); free(n);
} }
int init_notification(notification * n, int id) int notification_init(notification * n, int id)
{ {
const char *fg = NULL; const char *fg = NULL;
const char *bg = NULL; const char *bg = NULL;
@ -1229,7 +1233,7 @@ int init_notification(notification * n, int id)
if (strcmp(orig->appname, n->appname) == 0 if (strcmp(orig->appname, n->appname) == 0
&& strcmp(orig->msg, n->msg) == 0) { && strcmp(orig->msg, n->msg) == 0) {
orig->dup_count++; orig->dup_count++;
free_notification(n); notification_free(n);
wake_up(); wake_up();
return orig->id; return orig->id;
} }
@ -1241,7 +1245,7 @@ int init_notification(notification * n, int id)
&& strcmp(orig->msg, n->msg) == 0) { && strcmp(orig->msg, n->msg) == 0) {
orig->dup_count++; orig->dup_count++;
orig->start = time(NULL); orig->start = time(NULL);
free_notification(n); notification_free(n);
wake_up(); wake_up();
return orig->id; return orig->id;
} }
@ -1274,15 +1278,15 @@ int init_notification(notification * n, int id)
if (id == 0) { if (id == 0) {
n->id = ++next_notification_id; n->id = ++next_notification_id;
} else { } else {
close_notification_by_id(id, -1); notification_close_by_id(id, -1);
n->id = id; n->id = id;
} }
if (strlen(n->msg) == 0) { if (strlen(n->msg) == 0) {
close_notification(n, 2); notification_close(n, 2);
printf("skipping notification: %s %s\n", n->body, n->summary); printf("skipping notification: %s %s\n", n->body, n->summary);
} else { } else {
g_queue_insert_sorted(queue, n, cmp_notification_data, NULL); g_queue_insert_sorted(queue, n, notification_cmp_data, NULL);
} }
char *tmp = g_strconcat(n->summary, " ", n->body, NULL); char *tmp = g_strconcat(n->summary, " ", n->body, NULL);
@ -1322,7 +1326,7 @@ int init_notification(notification * n, int id)
* 2 -> the notification was dismissed by the user_data * 2 -> the notification was dismissed by the user_data
* 3 -> The notification was closed by a call to CloseNotification * 3 -> The notification was closed by a call to CloseNotification
*/ */
int close_notification_by_id(int id, int reason) int notification_close_by_id(int id, int reason)
{ {
notification *target = NULL; notification *target = NULL;
@ -1354,11 +1358,11 @@ int close_notification_by_id(int id, int reason)
return reason; return reason;
} }
int close_notification(notification * n, int reason) int notification_close(notification * n, int reason)
{ {
if (n == NULL) if (n == NULL)
return -1; return -1;
return close_notification_by_id(n->id, reason); return notification_close_by_id(n->id, reason);
} }
KeySym string_to_mask(char *str) KeySym string_to_mask(char *str)
@ -2050,7 +2054,7 @@ int main(int argc, char *argv[])
n->color_strings[1] = NULL; n->color_strings[1] = NULL;
n->actions = NULL; n->actions = NULL;
n->urls = NULL; n->urls = NULL;
init_notification(n, 0); notification_init(n, 0);
} }
mainloop = g_main_loop_new(NULL, FALSE); mainloop = g_main_loop_new(NULL, FALSE);

View File

@ -100,9 +100,9 @@ typedef struct _render_text {
extern int verbosity; extern int verbosity;
/* return id of notification */ /* return id of notification */
int init_notification(notification * n, int id); int notification_init(notification * n, int id);
int close_notification(notification * n, int reason); int notification_close(notification * n, int reason);
int close_notification_by_id(int id, int reason); int notification_close_by_id(int id, int reason);
void map_win(void); void map_win(void);
gboolean run(void *data); gboolean run(void *data);
void wake_up(void); void wake_up(void);