Mercurial > dwindows
comparison gtk3/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 |
---|---|
172 #if GLIB_CHECK_VERSION(2,28,0) | 172 #if GLIB_CHECK_VERSION(2,28,0) |
173 GApplication *_DWApp = NULL; | 173 GApplication *_DWApp = NULL; |
174 #endif | 174 #endif |
175 char *_DWDefaultFont = NULL; | 175 char *_DWDefaultFont = NULL; |
176 static char _dw_share_path[PATH_MAX+1] = { 0 }; | 176 static char _dw_share_path[PATH_MAX+1] = { 0 }; |
177 static char _dw_app_id[101] = { 0 }; | |
177 | 178 |
178 typedef struct | 179 typedef struct |
179 { | 180 { |
180 void *func; | 181 void *func; |
181 char name[30]; | 182 char name[30]; |
1952 return icon_pixbuf; | 1953 return icon_pixbuf; |
1953 } | 1954 } |
1954 return NULL; | 1955 return NULL; |
1955 } | 1956 } |
1956 | 1957 |
1957 #define DW_APP_DOMAIN_DEFAULT "org.dbsoft.dwindows" | |
1958 | |
1959 /* | 1958 /* |
1960 * Initializes the Dynamic Windows engine. | 1959 * Initializes the Dynamic Windows engine. |
1961 * Parameters: | 1960 * Parameters: |
1962 * newthread: True if this is the only thread. | 1961 * newthread: True if this is the only thread. |
1963 * False if there is already a message loop running. | 1962 * False if there is already a message loop running. |
1964 */ | 1963 */ |
1965 int dw_int_init(DWResources *res, int newthread, int *argc, char **argv[]) | 1964 int dw_int_init(DWResources *res, int newthread, int *argc, char **argv[]) |
1966 { | 1965 { |
1967 #if GLIB_CHECK_VERSION(2,28,0) | |
1968 char appid[101] = {0}; | |
1969 | |
1970 /* Generate an Application ID based on the PID initially. */ | |
1971 snprintf(appid, 100, "%s.pid.%d", DW_APP_DOMAIN_DEFAULT, getpid()); | |
1972 #endif | |
1973 if(res) | 1966 if(res) |
1974 { | 1967 { |
1975 _resources.resource_max = res->resource_max; | 1968 _resources.resource_max = res->resource_max; |
1976 _resources.resource_id = res->resource_id; | 1969 _resources.resource_id = res->resource_id; |
1977 _resources.resource_data = res->resource_data; | 1970 _resources.resource_data = res->resource_data; |
2002 else | 1995 else |
2003 strcpy(_dw_share_path, "/usr/local"); | 1996 strcpy(_dw_share_path, "/usr/local"); |
2004 strcat(_dw_share_path, "/share/"); | 1997 strcat(_dw_share_path, "/share/"); |
2005 strcat(_dw_share_path, binname); | 1998 strcat(_dw_share_path, binname); |
2006 #if GLIB_CHECK_VERSION(2,28,0) | 1999 #if GLIB_CHECK_VERSION(2,28,0) |
2007 /* If we have a binary name, use that for the Application ID instead. */ | 2000 if(!_dw_app_id[0]) |
2008 snprintf(appid, 100, "%s.%s", DW_APP_DOMAIN_DEFAULT, binname); | 2001 { |
2002 /* If we have a binary name, use that for the Application ID instead. */ | |
2003 snprintf(_dw_app_id, 100, "%s.%s", DW_APP_DOMAIN_DEFAULT, binname); | |
2004 } | |
2009 #endif | 2005 #endif |
2010 } | 2006 } |
2011 if(pathcopy) | 2007 if(pathcopy) |
2012 free(pathcopy); | 2008 free(pathcopy); |
2013 } | 2009 } |
2036 | 2032 |
2037 /* Create a global object for glib activities */ | 2033 /* Create a global object for glib activities */ |
2038 _DWObject = g_object_new(G_TYPE_OBJECT, NULL); | 2034 _DWObject = g_object_new(G_TYPE_OBJECT, NULL); |
2039 | 2035 |
2040 #if GLIB_CHECK_VERSION(2,28,0) | 2036 #if GLIB_CHECK_VERSION(2,28,0) |
2037 if(!_dw_app_id[0]) | |
2038 { | |
2039 /* Generate an Application ID based on the PID if all else fails. */ | |
2040 snprintf(_dw_app_id, 100, "%s.pid.%d", DW_APP_DOMAIN_DEFAULT, getpid()); | |
2041 } | |
2042 | |
2041 /* Initialize the application subsystem on supported versions... | 2043 /* Initialize the application subsystem on supported versions... |
2042 * we generate an application ID based on the binary name or PID | 2044 * we generate an application ID based on the binary name or PID |
2043 * instead of passing NULL to enable full application support. | 2045 * instead of passing NULL to enable full application support. |
2044 */ | 2046 */ |
2045 _DWApp = g_application_new(appid, G_APPLICATION_FLAGS_NONE); | 2047 _DWApp = g_application_new(_dw_app_id, G_APPLICATION_FLAGS_NONE); |
2046 if(g_application_register(_DWApp, NULL, NULL)) | 2048 if(_DWApp && g_application_register(_DWApp, NULL, NULL)) |
2047 g_application_activate(_DWApp); | 2049 g_application_activate(_DWApp); |
2048 #endif | 2050 #endif |
2049 return TRUE; | 2051 return TRUE; |
2050 } | 2052 } |
2051 | 2053 |
11762 { | 11764 { |
11763 return _dw_share_path; | 11765 return _dw_share_path; |
11764 } | 11766 } |
11765 | 11767 |
11766 /* | 11768 /* |
11769 * Sets the application ID used by this Dynamic Windows application instance. | |
11770 * Parameters: | |
11771 * appid: A string typically in the form: com.company.division.application | |
11772 * appguid: A globally unique identifier required on Windows or NULL. | |
11773 * Returns: | |
11774 * DW_ERROR_NONE after successfully setting the application ID. | |
11775 * DW_ERROR_UNKNOWN if unsupported on this system. | |
11776 * DW_ERROR_GENERAL if the application ID is not allowed. | |
11777 * Remarks: | |
11778 * This must be called before dw_init(). If dw_init() is called first | |
11779 * it will create a unique ID in the form: org.dbsoft.dwindows.application | |
11780 * or if the application name cannot be detected: org.dbsoft.dwindows.pid.# | |
11781 * The GUID is only required on Windows, NULL can be passed on other platforms. | |
11782 */ | |
11783 int dw_app_id_set(const char *appid, const char *appguid) | |
11784 { | |
11785 #if GLIB_CHECK_VERSION(2,28,0) | |
11786 if(g_application_id_is_valid(appid)) | |
11787 { | |
11788 strncpy(_dw_app_id, appid, 100); | |
11789 return DW_ERROR_NONE; | |
11790 } | |
11791 return DW_ERROR_GENERAL; | |
11792 #else | |
11793 return DW_ERROR_UNKNOWN; | |
11794 #endif | |
11795 } | |
11796 | |
11797 /* | |
11767 * Call a function from the window (widget)'s context. | 11798 * Call a function from the window (widget)'s context. |
11768 * Parameters: | 11799 * Parameters: |
11769 * handle: Window handle of the widget. | 11800 * handle: Window handle of the widget. |
11770 * function: Function pointer to be called. | 11801 * function: Function pointer to be called. |
11771 * data: Pointer to the data to be passed to the function. | 11802 * data: Pointer to the data to be passed to the function. |