Mercurial > dwindows
comparison gtk/dw.c @ 2113:aaea278c2356
GTK: Fix variant warning, needed to specify parameter type on action.
Implemented notification clicked callback on GTK2.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 22 Jun 2020 04:44:47 +0000 |
parents | 68f1924fdd13 |
children | 251d050d306b |
comparison
equal
deleted
inserted
replaced
2112:b33d020b04e7 | 2113:aaea278c2356 |
---|---|
1978 { | 1978 { |
1979 g_static_rec_mutex_unlock(&_dw_gdk_lock); | 1979 g_static_rec_mutex_unlock(&_dw_gdk_lock); |
1980 } | 1980 } |
1981 #endif | 1981 #endif |
1982 | 1982 |
1983 #if GLIB_CHECK_VERSION(2,40,0) | |
1984 /* Handle system notification click callbacks */ | |
1985 static void _dw_notification_handler(GSimpleAction *action, GVariant *param, gpointer user_data) | |
1986 { | |
1987 char textbuf[101] = {0}; | |
1988 int (*func)(HWND, void *); | |
1989 void *data; | |
1990 | |
1991 snprintf(textbuf, 100, "dw-notification-%llu-func", (unsigned long long)g_variant_get_uint64(param)); | |
1992 func = g_object_get_data(G_OBJECT(_DWApp), textbuf); | |
1993 g_object_set_data(G_OBJECT(_DWApp), textbuf, NULL); | |
1994 snprintf(textbuf, 100, "dw-notification-%llu-data", (unsigned long long)g_variant_get_uint64(param)); | |
1995 data = g_object_get_data(G_OBJECT(_DWApp), textbuf); | |
1996 g_object_set_data(G_OBJECT(_DWApp), textbuf, NULL); | |
1997 | |
1998 if(func) | |
1999 func((HWND)g_variant_get_uint64(param), data); | |
2000 } | |
2001 #endif | |
2002 | |
1983 /* | 2003 /* |
1984 * Initializes the Dynamic Windows engine. | 2004 * Initializes the Dynamic Windows engine. |
1985 * Parameters: | 2005 * Parameters: |
1986 * newthread: True if this is the only thread. | 2006 * newthread: True if this is the only thread. |
1987 * False if there is already a message loop running. | 2007 * False if there is already a message loop running. |
2116 * we generate an application ID based on the binary name or PID | 2136 * we generate an application ID based on the binary name or PID |
2117 * instead of passing NULL to enable full application support. | 2137 * instead of passing NULL to enable full application support. |
2118 */ | 2138 */ |
2119 _DWApp = g_application_new(_dw_app_id, G_APPLICATION_FLAGS_NONE); | 2139 _DWApp = g_application_new(_dw_app_id, G_APPLICATION_FLAGS_NONE); |
2120 if(g_application_register(_DWApp, NULL, NULL)) | 2140 if(g_application_register(_DWApp, NULL, NULL)) |
2141 { | |
2142 #if GLIB_CHECK_VERSION(2,40,0) | |
2143 /* Creat our notification handler for any notifications */ | |
2144 GSimpleAction *action = g_simple_action_new("notification", "t"); | |
2145 | |
2146 g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(_dw_notification_handler), NULL); | |
2147 g_action_map_add_action(G_ACTION_MAP(_DWApp), G_ACTION(action)); | |
2148 #endif | |
2121 g_application_activate(_DWApp); | 2149 g_application_activate(_DWApp); |
2150 } | |
2122 #endif | 2151 #endif |
2123 return TRUE; | 2152 return TRUE; |
2124 } | 2153 } |
2125 | 2154 |
2126 /* | 2155 /* |
12359 #if GTK_MAJOR_VERSION > 1 | 12388 #if GTK_MAJOR_VERSION > 1 |
12360 /* GTK 1.x is not implemented as pixbuf, so only allow icons on 2.x */ | 12389 /* GTK 1.x is not implemented as pixbuf, so only allow icons on 2.x */ |
12361 if(pixmap && pixmap->pixbuf) | 12390 if(pixmap && pixmap->pixbuf) |
12362 g_notification_set_icon(notification, G_ICON(pixmap->pixbuf)); | 12391 g_notification_set_icon(notification, G_ICON(pixmap->pixbuf)); |
12363 #endif | 12392 #endif |
12393 g_notification_set_default_action_and_target(notification, "app.notification", "t", (guint64)notification); | |
12364 } | 12394 } |
12365 return (HWND)notification; | 12395 return (HWND)notification; |
12366 #else | 12396 #else |
12367 return NULL; | 12397 return NULL; |
12368 #endif | 12398 #endif |
13492 | 13522 |
13493 /* Save the disconnect function pointer */ | 13523 /* Save the disconnect function pointer */ |
13494 params[1] = discfunc; | 13524 params[1] = discfunc; |
13495 | 13525 |
13496 DW_MUTEX_LOCK; | 13526 DW_MUTEX_LOCK; |
13527 #if GLIB_CHECK_VERSION(2,40,0) | |
13528 /* Special case for handling notification signals, which aren't really signals */ | |
13529 if (G_IS_NOTIFICATION(thiswindow) && strcmp(signame, DW_SIGNAL_CLICKED) == 0) | |
13530 { | |
13531 char textbuf[101] = {0}; | |
13532 snprintf(textbuf, 100, "dw-notification-%llu-func", (unsigned long long)thiswindow); | |
13533 g_object_set_data(G_OBJECT(_DWApp), textbuf, DW_POINTER(sigfunc)); | |
13534 snprintf(textbuf, 100, "dw-notification-%llu-data", (unsigned long long)thiswindow); | |
13535 g_object_set_data(G_OBJECT(_DWApp), textbuf, DW_POINTER(data)); | |
13536 DW_MUTEX_UNLOCK; | |
13537 return; | |
13538 } | |
13539 #endif | |
13497 /* | 13540 /* |
13498 * If the window we are setting the signal on is a scrolled window we need to get | 13541 * If the window we are setting the signal on is a scrolled window we need to get |
13499 * the "real" widget type. thiswindow is the "real" widget type | 13542 * the "real" widget type. thiswindow is the "real" widget type |
13500 */ | 13543 */ |
13501 if (GTK_IS_SCROLLED_WINDOW(thiswindow)) | 13544 if (GTK_IS_SCROLLED_WINDOW(thiswindow)) |