static void onCloseNotification(GDBusConnection * connection, const gchar * sender, GVariant * parameters, GDBusMethodInvocation * invocation) { guint32 id; g_variant_get(parameters, "(u)", &id); notification_close_by_id(id, 3); g_dbus_method_invocation_return_value(invocation, NULL); g_dbus_connection_flush(connection, NULL, NULL, NULL); }
static void onGetServerInformation(GDBusConnection * connection, const gchar * sender, const GVariant * parameters, GDBusMethodInvocation * invocation) { GVariant *value; value = g_variant_new("(ssss)", "dunst", "knopwob", VERSION, "1.2"); g_dbus_method_invocation_return_value(invocation, value); g_dbus_connection_flush(connection, NULL, NULL, NULL); }
static void onGetCapabilities(GDBusConnection * connection, const gchar * sender, const GVariant * parameters, GDBusMethodInvocation * invocation) { GVariantBuilder *builder; GVariant *value; builder = g_variant_builder_new(G_VARIANT_TYPE("as")); g_variant_builder_add(builder, "s", "actions"); g_variant_builder_add(builder, "s", "body"); g_variant_builder_add(builder, "s", "body-markup"); value = g_variant_new("(as)", builder); g_variant_builder_unref(builder); g_dbus_method_invocation_return_value(invocation, value); g_dbus_connection_flush(connection, NULL, NULL, NULL); g_variant_unref(value); }
static void onNotify(GDBusConnection * connection, const gchar * sender, GVariant * parameters, GDBusMethodInvocation * invocation) { gchar *appname = NULL; guint replaces_id = 0; gchar *icon = NULL; gchar *summary = NULL; gchar *body = NULL; Actions *actions = malloc(sizeof(Actions)); gint timeout = -1; /* hints */ gint urgency = 1; gint progress = -1; gchar *fgcolor = NULL; gchar *bgcolor = NULL; gchar *category = NULL; actions->actions = NULL; actions->count = 0; { GVariantIter *iter = g_variant_iter_new(parameters); GVariant *content; GVariant *dict_value; int idx = 0; while ((content = g_variant_iter_next_value(iter))) { switch (idx) { case 0: if (g_variant_is_of_type (content, G_VARIANT_TYPE_STRING)) appname = g_variant_dup_string(content, NULL); break; case 1: if (g_variant_is_of_type (content, G_VARIANT_TYPE_UINT32)) replaces_id = g_variant_get_uint32(content); break; case 2: if (g_variant_is_of_type (content, G_VARIANT_TYPE_STRING)) icon = g_variant_dup_string(content, NULL); break; case 3: if (g_variant_is_of_type (content, G_VARIANT_TYPE_STRING)) summary = g_variant_dup_string(content, NULL); break; case 4: if (g_variant_is_of_type (content, G_VARIANT_TYPE_STRING)) body = g_variant_dup_string(content, NULL); break; case 5: if (g_variant_is_of_type (content, G_VARIANT_TYPE_STRING_ARRAY)) actions->actions = g_variant_dup_strv(content, &(actions-> count)); break; case 6: if (g_variant_is_of_type (content, G_VARIANT_TYPE_DICTIONARY)) { dict_value = g_variant_lookup_value(content, "urgency", G_VARIANT_TYPE_BYTE); if (dict_value) urgency = g_variant_get_byte (dict_value); dict_value = g_variant_lookup_value(content, "fgcolor", G_VARIANT_TYPE_STRING); if (dict_value) fgcolor = g_variant_dup_string (dict_value, NULL); dict_value = g_variant_lookup_value(content, "bgcolor", G_VARIANT_TYPE_STRING); if (dict_value) bgcolor = g_variant_dup_string (dict_value, NULL); dict_value = g_variant_lookup_value(content, "category", G_VARIANT_TYPE_STRING); if (dict_value) { category = g_variant_dup_string( dict_value, NULL); } dict_value = g_variant_lookup_value(content, "value", G_VARIANT_TYPE_INT32); if (dict_value) { progress = g_variant_get_int32(dict_value); } else { dict_value = g_variant_lookup_value(content, "value", G_VARIANT_TYPE_UINT32); if (dict_value) progress = g_variant_get_uint32(dict_value); } } break; case 7: if (g_variant_is_of_type (content, G_VARIANT_TYPE_INT32)) timeout = g_variant_get_int32(content); break; } idx++; } g_variant_iter_free(iter); } fflush(stdout); if (timeout > 0) { /* do some rounding */ timeout = (timeout + 500) / 1000; if (timeout < 1) { timeout = 1; } } notification *n = malloc(sizeof(notification)); n->appname = appname; n->summary = summary; n->body = body; n->icon = icon; n->timeout = timeout; n->progress = (progress < 0 || progress > 100) ? 0 : progress + 1; n->urgency = urgency; n->category = category; n->dbus_client = strdup(sender); if (actions->count > 0) { n->actions = actions; } else { n->actions = NULL; free(actions); } for (int i = 0; i < ColLast; i++) { n->color_strings[i] = NULL; } n->color_strings[ColFG] = fgcolor; n->color_strings[ColBG] = bgcolor; int id = notification_init(n, replaces_id); wake_up(); GVariant *reply = g_variant_new("(u)", id); g_dbus_method_invocation_return_value(invocation, reply); g_dbus_connection_flush(connection, NULL, NULL, NULL); run(NULL); }
static void onNotify(GDBusConnection *connection, const gchar *sender, GVariant *parameters, GDBusMethodInvocation *invocation) { gchar *app_name = NULL; guint replaces_id = 0; gchar *app_icon = NULL; gchar *summary = NULL; gchar *body = NULL; gint expire_timeout = -1; { GVariantIter *iter = g_variant_iter_new(parameters); GVariant *content; int i = 0; while ((content = g_variant_iter_next_value(iter))) { switch(i) { case 0: if (g_variant_is_of_type(content, G_VARIANT_TYPE_STRING)) app_name = g_variant_dup_string(content, NULL); break; case 1: if (g_variant_is_of_type(content, G_VARIANT_TYPE_UINT32)) replaces_id = g_variant_get_uint32(content); break; case 2: if (g_variant_is_of_type(content, G_VARIANT_TYPE_STRING)) app_icon = g_variant_dup_string(content, NULL); break; case 3: if (g_variant_is_of_type(content, G_VARIANT_TYPE_STRING)) summary = g_variant_dup_string(content, NULL); break; case 4: if (g_variant_is_of_type(content, G_VARIANT_TYPE_STRING)) body = g_variant_dup_string(content, NULL); break; case 5: break; case 6: break; case 7: if (g_variant_is_of_type(content, G_VARIANT_TYPE_INT32)) expire_timeout = g_variant_get_int32(content); break; } g_variant_unref(content); i++; } g_variant_iter_free(iter); } Notification *n = notification_create (app_name, replaces_id, app_icon, summary, body, expire_timeout); n->app_name = app_name; n->replaces_id = replaces_id; n->app_icon = app_icon; n->summary = summary; n->body = body; n->expire_timeout = expire_timeout; int id = 1; GVariant *reply = g_variant_new("(u)", id); g_dbus_method_invocation_return_value(invocation, reply); g_dbus_connection_flush(connection, NULL, NULL, NULL); g_print("About to print the summary from yarn.c\n"); prepare(n); }