comparison gtk3/dw.c @ 2112:b33d020b04e7

GTK3: Attempt at getting clicked callbacks on notifications working. Getting a GVariant warning in the callback handler but needed to commit.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 21 Jun 2020 22:04:51 +0000
parents 68f1924fdd13
children aaea278c2356
comparison
equal deleted inserted replaced
2111:37ce3e22ee1a 2112:b33d020b04e7
1953 return icon_pixbuf; 1953 return icon_pixbuf;
1954 } 1954 }
1955 return NULL; 1955 return NULL;
1956 } 1956 }
1957 1957
1958 #if GLIB_CHECK_VERSION(2,40,0)
1959 /* Handle system notification click callbacks */
1960 static void _dw_notification_handler(GSimpleAction *action, GVariant *param, gpointer user_data)
1961 {
1962 char textbuf[101] = {0};
1963 void (*func)(HWND, void *);
1964 void *data;
1965
1966 snprintf(textbuf, 100, "dw-notification-%llu-func", (unsigned long long)g_variant_get_uint64(param));
1967 func = g_object_get_data(G_OBJECT(_DWApp), textbuf);
1968 g_object_set_data(G_OBJECT(_DWApp), textbuf, NULL);
1969 snprintf(textbuf, 100, "dw-notification-%llu-data", (unsigned long long)g_variant_get_uint64(param));
1970 data = g_object_get_data(G_OBJECT(_DWApp), textbuf);
1971 g_object_set_data(G_OBJECT(_DWApp), textbuf, NULL);
1972
1973 if(func)
1974 func((HWND)g_variant_get_uint64(param), data);
1975 }
1976 #endif
1977
1958 /* 1978 /*
1959 * Initializes the Dynamic Windows engine. 1979 * Initializes the Dynamic Windows engine.
1960 * Parameters: 1980 * Parameters:
1961 * newthread: True if this is the only thread. 1981 * newthread: True if this is the only thread.
1962 * False if there is already a message loop running. 1982 * False if there is already a message loop running.
2044 * we generate an application ID based on the binary name or PID 2064 * we generate an application ID based on the binary name or PID
2045 * instead of passing NULL to enable full application support. 2065 * instead of passing NULL to enable full application support.
2046 */ 2066 */
2047 _DWApp = g_application_new(_dw_app_id, G_APPLICATION_FLAGS_NONE); 2067 _DWApp = g_application_new(_dw_app_id, G_APPLICATION_FLAGS_NONE);
2048 if(_DWApp && g_application_register(_DWApp, NULL, NULL)) 2068 if(_DWApp && g_application_register(_DWApp, NULL, NULL))
2069 {
2070 #if GLIB_CHECK_VERSION(2,40,0)
2071 /* Creat our notification handler for any notifications */
2072 GSimpleAction *action = g_simple_action_new("notification", NULL);
2073
2074 g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(_dw_notification_handler), NULL);
2075 g_action_map_add_action(G_ACTION_MAP(_DWApp), G_ACTION(action));
2076 #endif
2049 g_application_activate(_DWApp); 2077 g_application_activate(_DWApp);
2078 }
2050 #endif 2079 #endif
2051 return TRUE; 2080 return TRUE;
2052 } 2081 }
2053 2082
2054 /* 2083 /*
11048 #if GLIB_CHECK_VERSION(2,40,0) 11077 #if GLIB_CHECK_VERSION(2,40,0)
11049 GNotification *notification = g_notification_new(title); 11078 GNotification *notification = g_notification_new(title);
11050 11079
11051 if(notification) 11080 if(notification)
11052 { 11081 {
11082 GVariant *param = g_variant_new_uint64((guint64)notification);
11083
11053 if(description) 11084 if(description)
11054 { 11085 {
11055 va_list args; 11086 va_list args;
11056 char outbuf[1025] = {0}; 11087 char outbuf[1025] = {0};
11057 11088
11061 11092
11062 g_notification_set_body(notification, outbuf); 11093 g_notification_set_body(notification, outbuf);
11063 } 11094 }
11064 if(pixmap && pixmap->pixbuf) 11095 if(pixmap && pixmap->pixbuf)
11065 g_notification_set_icon(notification, G_ICON(pixmap->pixbuf)); 11096 g_notification_set_icon(notification, G_ICON(pixmap->pixbuf));
11097 g_notification_set_default_action_and_target_value(notification, "app.notification", param);
11066 } 11098 }
11067 return (HWND)notification; 11099 return (HWND)notification;
11068 #else 11100 #else
11069 return NULL; 11101 return NULL;
11070 #endif 11102 #endif
12016 12048
12017 /* Save the disconnect function pointer */ 12049 /* Save the disconnect function pointer */
12018 params[1] = discfunc; 12050 params[1] = discfunc;
12019 12051
12020 DW_MUTEX_LOCK; 12052 DW_MUTEX_LOCK;
12053 #if GLIB_CHECK_VERSION(2,40,0)
12054 /* Special case for handling notification signals, which aren't really signals */
12055 if (G_IS_NOTIFICATION(thiswindow) && strcmp(signame, DW_SIGNAL_CLICKED) == 0)
12056 {
12057 char textbuf[101] = {0};
12058 snprintf(textbuf, 100, "dw-notification-%llu-func", (unsigned long long)thiswindow);
12059 g_object_set_data(G_OBJECT(_DWApp), textbuf, DW_POINTER(sigfunc));
12060 snprintf(textbuf, 100, "dw-notification-%llu-data", (unsigned long long)thiswindow);
12061 g_object_set_data(G_OBJECT(_DWApp), textbuf, DW_POINTER(data));
12062 DW_MUTEX_UNLOCK;
12063 return;
12064 }
12065 #endif
12021 /* 12066 /*
12022 * If the window we are setting the signal on is a scrolled window we need to get 12067 * If the window we are setting the signal on is a scrolled window we need to get
12023 * the "real" widget type. thiswindow is the "real" widget type 12068 * the "real" widget type. thiswindow is the "real" widget type
12024 */ 12069 */
12025 if (GTK_IS_SCROLLED_WINDOW(thiswindow) 12070 if (GTK_IS_SCROLLED_WINDOW(thiswindow)