Mercurial > dwindows
comparison gtk/dw.c @ 2066:2c2530f8cbef
Initial design for system notification support on GTK.
Windows, Mac and possibly OS/2 Support will follow.
GTK support requires Glib 2.40 or higher.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 14 May 2020 01:52:27 +0000 |
parents | f7c462f27829 |
children | c2f13c5eefac |
comparison
equal
deleted
inserted
replaced
2065:2dacac5e4023 | 2066:2c2530f8cbef |
---|---|
117 | 117 |
118 GtkWidget *last_window = NULL, *popup = NULL; | 118 GtkWidget *last_window = NULL, *popup = NULL; |
119 GdkPixmap *_dw_tmppixmap = NULL; | 119 GdkPixmap *_dw_tmppixmap = NULL; |
120 GdkBitmap *_dw_tmpbitmap = NULL; | 120 GdkBitmap *_dw_tmpbitmap = NULL; |
121 | 121 |
122 #if GLIB_CHECK_VERSION(2,28,0) | |
123 GApplication *_DWApp = NULL; | |
124 #endif | |
122 char *_DWDefaultFont = NULL; | 125 char *_DWDefaultFont = NULL; |
123 static char _dw_share_path[PATH_MAX+1] = { 0 }; | 126 static char _dw_share_path[PATH_MAX+1] = { 0 }; |
124 | 127 |
125 #if GTK_MAJOR_VERSION < 2 | 128 #if GTK_MAJOR_VERSION < 2 |
126 static int _dw_file_active = 0; | 129 static int _dw_file_active = 0; |
1974 { | 1977 { |
1975 g_static_rec_mutex_unlock(&_dw_gdk_lock); | 1978 g_static_rec_mutex_unlock(&_dw_gdk_lock); |
1976 } | 1979 } |
1977 #endif | 1980 #endif |
1978 | 1981 |
1982 #define DW_APP_DOMAIN_DEFAULT "org.dbsoft.dwindows" | |
1983 | |
1979 /* | 1984 /* |
1980 * Initializes the Dynamic Windows engine. | 1985 * Initializes the Dynamic Windows engine. |
1981 * Parameters: | 1986 * Parameters: |
1982 * newthread: True if this is the only thread. | 1987 * newthread: True if this is the only thread. |
1983 * False if there is already a message loop running. | 1988 * False if there is already a message loop running. |
1988 char *fname; | 1993 char *fname; |
1989 static char * test_xpm[] = { | 1994 static char * test_xpm[] = { |
1990 "1 1 1 1", | 1995 "1 1 1 1", |
1991 " c None", | 1996 " c None", |
1992 " "}; | 1997 " "}; |
1998 #if GLIB_CHECK_VERSION(2,28,0) | |
1999 char appid[101] = {0}; | |
2000 | |
2001 /* Generate an Application ID based on the PID initially. */ | |
2002 snprintf(appid, 100, "%s.pid.%d", DW_APP_DOMAIN_DEFAULT, getpid()); | |
2003 #endif | |
1993 | 2004 |
1994 if(res) | 2005 if(res) |
1995 { | 2006 { |
1996 _resources.resource_max = res->resource_max; | 2007 _resources.resource_max = res->resource_max; |
1997 _resources.resource_id = res->resource_id; | 2008 _resources.resource_id = res->resource_id; |
2022 strncpy(_dw_share_path, pathcopy, (size_t)(binpos - pathcopy)); | 2033 strncpy(_dw_share_path, pathcopy, (size_t)(binpos - pathcopy)); |
2023 else | 2034 else |
2024 strcpy(_dw_share_path, "/usr/local"); | 2035 strcpy(_dw_share_path, "/usr/local"); |
2025 strcat(_dw_share_path, "/share/"); | 2036 strcat(_dw_share_path, "/share/"); |
2026 strcat(_dw_share_path, binname); | 2037 strcat(_dw_share_path, binname); |
2038 #if GLIB_CHECK_VERSION(2,28,0) | |
2039 /* If we have a binary name, use that for the Application ID instead. */ | |
2040 snprintf(appid, 100, "%s.%s", DW_APP_DOMAIN_DEFAULT, binname); | |
2041 #endif | |
2027 } | 2042 } |
2028 if(pathcopy) | 2043 if(pathcopy) |
2029 free(pathcopy); | 2044 free(pathcopy); |
2030 } | 2045 } |
2031 /* If that failed... just get the current directory */ | 2046 /* If that failed... just get the current directory */ |
2092 if ( (fname = getenv( "DWINDOWS_DEBUGFILE" ) ) != NULL ) | 2107 if ( (fname = getenv( "DWINDOWS_DEBUGFILE" ) ) != NULL ) |
2093 { | 2108 { |
2094 dbgfp = fopen( fname, "w" ); | 2109 dbgfp = fopen( fname, "w" ); |
2095 } | 2110 } |
2096 | 2111 |
2112 #if GLIB_CHECK_VERSION(2,28,0) | |
2113 /* Initialize the application subsystem on supported versions... | |
2114 * we generate an application ID based on the binary name or PID | |
2115 * instead of passing NULL to enable full application support. | |
2116 */ | |
2117 _DWApp = g_application_new(appid, G_APPLICATION_FLAGS_NONE); | |
2118 if(g_application_register(_DWApp, NULL, NULL)) | |
2119 g_application_activate(_DWApp); | |
2120 #endif | |
2097 return TRUE; | 2121 return TRUE; |
2098 } | 2122 } |
2099 | 2123 |
2100 /* | 2124 /* |
2101 * Runs a message loop for Dynamic Windows. | 2125 * Runs a message loop for Dynamic Windows. |
12297 gtk_signal_connect(GTK_OBJECT(window), "key_press_event", GTK_SIGNAL_FUNC(_default_key_press_event), next); | 12321 gtk_signal_connect(GTK_OBJECT(window), "key_press_event", GTK_SIGNAL_FUNC(_default_key_press_event), next); |
12298 DW_MUTEX_UNLOCK; | 12322 DW_MUTEX_UNLOCK; |
12299 } | 12323 } |
12300 | 12324 |
12301 /* | 12325 /* |
12326 * Creates a new system notification if possible. | |
12327 * Parameters: | |
12328 * title: The short title of the notification. | |
12329 * pixmap: Handle to an image to display or NULL if none. | |
12330 * description: A longer description of the notification, | |
12331 * or NULL if none is necessary. | |
12332 * Returns: | |
12333 * A handle to the notification which can be used to attach a "clicked" event if desired, | |
12334 * or NULL if it fails or notifications are not supported by the system. | |
12335 * Remarks: | |
12336 * This will create a system notification that will show in the notifaction panel | |
12337 * on supported systems, which may be clicked to perform another task. | |
12338 */ | |
12339 HWND dw_notification_new(const char *title, HPIXMAP pixmap, const char *description, ...) | |
12340 { | |
12341 #if GLIB_CHECK_VERSION(2,40,0) | |
12342 GNotification *notification = g_notification_new(title); | |
12343 | |
12344 if(notification) | |
12345 { | |
12346 if(description) | |
12347 { | |
12348 va_list args; | |
12349 char outbuf[1025] = {0}; | |
12350 | |
12351 va_start(args, description); | |
12352 vsnprintf(outbuf, 1024, description, args); | |
12353 va_end(args); | |
12354 | |
12355 g_notification_set_body(notification, outbuf); | |
12356 } | |
12357 #if GTK_MAJOR_VERSION > 1 | |
12358 /* GTK 1.x is not implemented as pixbuf, so only allow icons on 2.x */ | |
12359 if(pixmap && pixmap->pixbuf) | |
12360 g_notification_set_icon(notification, G_ICON(pixmap->pixbuf)); | |
12361 #endif | |
12362 } | |
12363 return (HWND)notification; | |
12364 #else | |
12365 return NULL; | |
12366 #endif | |
12367 } | |
12368 | |
12369 /* | |
12370 * Sends a notification created by dw_notification_new() after attaching signal handler. | |
12371 * Parameters: | |
12372 * notification: The handle to the notification returned by dw_notification_new(). | |
12373 * Returns: | |
12374 * DW_ERROR_NONE on success, DW_ERROR_UNKNOWN on error or not supported. | |
12375 */ | |
12376 int dw_notification_send(HWND notification) | |
12377 { | |
12378 #if GLIB_CHECK_VERSION(2,40,0) | |
12379 if(notification) | |
12380 { | |
12381 char id[101] = {0}; | |
12382 | |
12383 /* Generate a unique ID based on the notification handle, | |
12384 * so we can use it to remove the notification in dw_window_destroy(). | |
12385 */ | |
12386 snprintf(id, 100, "dw-notification-%llu", (unsigned long long)notification); | |
12387 g_application_send_notification(_DWApp, id, (GNotification *)notification); | |
12388 return DW_ERROR_NONE; | |
12389 } | |
12390 #endif | |
12391 return DW_ERROR_UNKNOWN; | |
12392 } | |
12393 | |
12394 /* | |
12302 * Returns some information about the current operating environment. | 12395 * Returns some information about the current operating environment. |
12303 * Parameters: | 12396 * Parameters: |
12304 * env: Pointer to a DWEnv struct. | 12397 * env: Pointer to a DWEnv struct. |
12305 */ | 12398 */ |
12306 void dw_environment_query(DWEnv *env) | 12399 void dw_environment_query(DWEnv *env) |