# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1592777091 0 # Node ID b33d020b04e748372a406165783bc3a4dd2d916f # Parent 37ce3e22ee1a79817a4da105c4e63ee3f86bf5a1 GTK3: Attempt at getting clicked callbacks on notifications working. Getting a GVariant warning in the callback handler but needed to commit. diff -r 37ce3e22ee1a -r b33d020b04e7 gtk3/dw.c --- a/gtk3/dw.c Wed Jun 17 16:50:24 2020 +0000 +++ b/gtk3/dw.c Sun Jun 21 22:04:51 2020 +0000 @@ -1955,6 +1955,26 @@ return NULL; } +#if GLIB_CHECK_VERSION(2,40,0) +/* Handle system notification click callbacks */ +static void _dw_notification_handler(GSimpleAction *action, GVariant *param, gpointer user_data) +{ + char textbuf[101] = {0}; + void (*func)(HWND, void *); + void *data; + + snprintf(textbuf, 100, "dw-notification-%llu-func", (unsigned long long)g_variant_get_uint64(param)); + func = g_object_get_data(G_OBJECT(_DWApp), textbuf); + g_object_set_data(G_OBJECT(_DWApp), textbuf, NULL); + snprintf(textbuf, 100, "dw-notification-%llu-data", (unsigned long long)g_variant_get_uint64(param)); + data = g_object_get_data(G_OBJECT(_DWApp), textbuf); + g_object_set_data(G_OBJECT(_DWApp), textbuf, NULL); + + if(func) + func((HWND)g_variant_get_uint64(param), data); +} +#endif + /* * Initializes the Dynamic Windows engine. * Parameters: @@ -2046,7 +2066,16 @@ */ _DWApp = g_application_new(_dw_app_id, G_APPLICATION_FLAGS_NONE); if(_DWApp && g_application_register(_DWApp, NULL, NULL)) + { +#if GLIB_CHECK_VERSION(2,40,0) + /* Creat our notification handler for any notifications */ + GSimpleAction *action = g_simple_action_new("notification", NULL); + + g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(_dw_notification_handler), NULL); + g_action_map_add_action(G_ACTION_MAP(_DWApp), G_ACTION(action)); +#endif g_application_activate(_DWApp); + } #endif return TRUE; } @@ -11050,6 +11079,8 @@ if(notification) { + GVariant *param = g_variant_new_uint64((guint64)notification); + if(description) { va_list args; @@ -11063,6 +11094,7 @@ } if(pixmap && pixmap->pixbuf) g_notification_set_icon(notification, G_ICON(pixmap->pixbuf)); + g_notification_set_default_action_and_target_value(notification, "app.notification", param); } return (HWND)notification; #else @@ -12018,6 +12050,19 @@ params[1] = discfunc; DW_MUTEX_LOCK; +#if GLIB_CHECK_VERSION(2,40,0) + /* Special case for handling notification signals, which aren't really signals */ + if (G_IS_NOTIFICATION(thiswindow) && strcmp(signame, DW_SIGNAL_CLICKED) == 0) + { + char textbuf[101] = {0}; + snprintf(textbuf, 100, "dw-notification-%llu-func", (unsigned long long)thiswindow); + g_object_set_data(G_OBJECT(_DWApp), textbuf, DW_POINTER(sigfunc)); + snprintf(textbuf, 100, "dw-notification-%llu-data", (unsigned long long)thiswindow); + g_object_set_data(G_OBJECT(_DWApp), textbuf, DW_POINTER(data)); + DW_MUTEX_UNLOCK; + return; + } +#endif /* * If the window we are setting the signal on is a scrolled window we need to get * the "real" widget type. thiswindow is the "real" widget type