Mercurial > dwindows
comparison gtk/dw.c @ 2071:c2f13c5eefac
GTK: Add dw_app_id_set() and reconfigure based on the new code path.
Mac: Fix a typo that causes incorrect behavior generating an app ID.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 15 May 2020 02:13:57 +0000 |
parents | 2c2530f8cbef |
children | 24875681eec5 |
comparison
equal
deleted
inserted
replaced
2070:370baf78abdc | 2071:c2f13c5eefac |
---|---|
1 /* | 1 /* |
2 * Dynamic Windows: | 2 * Dynamic Windows: |
3 * A GTK like cross-platform GUI | 3 * A GTK like cross-platform GUI |
4 * GTK forwarder module for portabilty. | 4 * GTK forwarder module for portabilty. |
5 * | 5 * |
6 * (C) 2000-2019 Brian Smith <brian@dbsoft.org> | 6 * (C) 2000-2020 Brian Smith <brian@dbsoft.org> |
7 * (C) 2003-2011 Mark Hessling <mark@rexx.org> | 7 * (C) 2003-2011 Mark Hessling <mark@rexx.org> |
8 * (C) 2002 Nickolay V. Shmyrev <shmyrev@yandex.ru> | 8 * (C) 2002 Nickolay V. Shmyrev <shmyrev@yandex.ru> |
9 */ | 9 */ |
10 #include "config.h" | 10 #include "config.h" |
11 #include "dw.h" | 11 #include "dw.h" |
122 #if GLIB_CHECK_VERSION(2,28,0) | 122 #if GLIB_CHECK_VERSION(2,28,0) |
123 GApplication *_DWApp = NULL; | 123 GApplication *_DWApp = NULL; |
124 #endif | 124 #endif |
125 char *_DWDefaultFont = NULL; | 125 char *_DWDefaultFont = NULL; |
126 static char _dw_share_path[PATH_MAX+1] = { 0 }; | 126 static char _dw_share_path[PATH_MAX+1] = { 0 }; |
127 static char _dw_app_id[101] = { 0 }; | |
127 | 128 |
128 #if GTK_MAJOR_VERSION < 2 | 129 #if GTK_MAJOR_VERSION < 2 |
129 static int _dw_file_active = 0; | 130 static int _dw_file_active = 0; |
130 #endif | 131 #endif |
131 static int _dw_ignore_click = 0, _dw_ignore_expand = 0, _dw_color_active = 0; | 132 static int _dw_ignore_click = 0, _dw_ignore_expand = 0, _dw_color_active = 0; |
1977 { | 1978 { |
1978 g_static_rec_mutex_unlock(&_dw_gdk_lock); | 1979 g_static_rec_mutex_unlock(&_dw_gdk_lock); |
1979 } | 1980 } |
1980 #endif | 1981 #endif |
1981 | 1982 |
1982 #define DW_APP_DOMAIN_DEFAULT "org.dbsoft.dwindows" | |
1983 | |
1984 /* | 1983 /* |
1985 * Initializes the Dynamic Windows engine. | 1984 * Initializes the Dynamic Windows engine. |
1986 * Parameters: | 1985 * Parameters: |
1987 * newthread: True if this is the only thread. | 1986 * newthread: True if this is the only thread. |
1988 * False if there is already a message loop running. | 1987 * False if there is already a message loop running. |
1993 char *fname; | 1992 char *fname; |
1994 static char * test_xpm[] = { | 1993 static char * test_xpm[] = { |
1995 "1 1 1 1", | 1994 "1 1 1 1", |
1996 " c None", | 1995 " c None", |
1997 " "}; | 1996 " "}; |
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 | |
2004 | 1997 |
2005 if(res) | 1998 if(res) |
2006 { | 1999 { |
2007 _resources.resource_max = res->resource_max; | 2000 _resources.resource_max = res->resource_max; |
2008 _resources.resource_id = res->resource_id; | 2001 _resources.resource_id = res->resource_id; |
2034 else | 2027 else |
2035 strcpy(_dw_share_path, "/usr/local"); | 2028 strcpy(_dw_share_path, "/usr/local"); |
2036 strcat(_dw_share_path, "/share/"); | 2029 strcat(_dw_share_path, "/share/"); |
2037 strcat(_dw_share_path, binname); | 2030 strcat(_dw_share_path, binname); |
2038 #if GLIB_CHECK_VERSION(2,28,0) | 2031 #if GLIB_CHECK_VERSION(2,28,0) |
2039 /* If we have a binary name, use that for the Application ID instead. */ | 2032 if(!_dw_app_id[0]) |
2040 snprintf(appid, 100, "%s.%s", DW_APP_DOMAIN_DEFAULT, binname); | 2033 { |
2034 /* If we have a binary name, use that for the Application ID instead. */ | |
2035 snprintf(_dw_app_id, 100, "%s.%s", DW_APP_DOMAIN_DEFAULT, binname); | |
2036 } | |
2041 #endif | 2037 #endif |
2042 } | 2038 } |
2043 if(pathcopy) | 2039 if(pathcopy) |
2044 free(pathcopy); | 2040 free(pathcopy); |
2045 } | 2041 } |
2108 { | 2104 { |
2109 dbgfp = fopen( fname, "w" ); | 2105 dbgfp = fopen( fname, "w" ); |
2110 } | 2106 } |
2111 | 2107 |
2112 #if GLIB_CHECK_VERSION(2,28,0) | 2108 #if GLIB_CHECK_VERSION(2,28,0) |
2109 if(!_dw_app_id[0]) | |
2110 { | |
2111 /* Generate an Application ID based on the PID if all else fails. */ | |
2112 snprintf(_dw_app_id, 100, "%s.pid.%d", DW_APP_DOMAIN_DEFAULT, getpid()); | |
2113 } | |
2114 | |
2113 /* Initialize the application subsystem on supported versions... | 2115 /* Initialize the application subsystem on supported versions... |
2114 * we generate an application ID based on the binary name or PID | 2116 * we generate an application ID based on the binary name or PID |
2115 * instead of passing NULL to enable full application support. | 2117 * instead of passing NULL to enable full application support. |
2116 */ | 2118 */ |
2117 _DWApp = g_application_new(appid, G_APPLICATION_FLAGS_NONE); | 2119 _DWApp = g_application_new(_dw_app_id, G_APPLICATION_FLAGS_NONE); |
2118 if(g_application_register(_DWApp, NULL, NULL)) | 2120 if(g_application_register(_DWApp, NULL, NULL)) |
2119 g_application_activate(_DWApp); | 2121 g_application_activate(_DWApp); |
2120 #endif | 2122 #endif |
2121 return TRUE; | 2123 return TRUE; |
2122 } | 2124 } |
13269 { | 13271 { |
13270 return _dw_share_path; | 13272 return _dw_share_path; |
13271 } | 13273 } |
13272 | 13274 |
13273 /* | 13275 /* |
13276 * Sets the application ID used by this Dynamic Windows application instance. | |
13277 * Parameters: | |
13278 * appid: A string typically in the form: com.company.division.application | |
13279 * appguid: A globally unique identifier required on Windows or NULL. | |
13280 * Returns: | |
13281 * DW_ERROR_NONE after successfully setting the application ID. | |
13282 * DW_ERROR_UNKNOWN if unsupported on this system. | |
13283 * DW_ERROR_GENERAL if the application ID is not allowed. | |
13284 * Remarks: | |
13285 * This must be called before dw_init(). If dw_init() is called first | |
13286 * it will create a unique ID in the form: org.dbsoft.dwindows.application | |
13287 * or if the application name cannot be detected: org.dbsoft.dwindows.pid.# | |
13288 * The GUID is only required on Windows, NULL can be passed on other platforms. | |
13289 */ | |
13290 int dw_app_id_set(const char *appid, const char *appguid) | |
13291 { | |
13292 #if GLIB_CHECK_VERSION(2,28,0) | |
13293 if(g_application_id_is_valid(appid)) | |
13294 { | |
13295 strncpy(_dw_app_id, appid, 100); | |
13296 return DW_ERROR_NONE; | |
13297 } | |
13298 return DW_ERROR_GENERAL; | |
13299 #else | |
13300 return DW_ERROR_UNKNOWN; | |
13301 #endif | |
13302 } | |
13303 | |
13304 /* | |
13274 * Call a function from the window (widget)'s context. | 13305 * Call a function from the window (widget)'s context. |
13275 * Parameters: | 13306 * Parameters: |
13276 * handle: Window handle of the widget. | 13307 * handle: Window handle of the widget. |
13277 * function: Function pointer to be called. | 13308 * function: Function pointer to be called. |
13278 * data: Pointer to the data to be passed to the function. | 13309 * data: Pointer to the data to be passed to the function. |