changeset 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 370baf78abdc
children b7514ecd6305
files gtk/dw.c gtk3/dw.c mac/dw.m
diffstat 3 files changed, 87 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/gtk/dw.c	Fri May 15 01:19:55 2020 +0000
+++ b/gtk/dw.c	Fri May 15 02:13:57 2020 +0000
@@ -3,7 +3,7 @@
  *          A GTK like cross-platform GUI
  *          GTK forwarder module for portabilty.
  *
- * (C) 2000-2019 Brian Smith <brian@dbsoft.org>
+ * (C) 2000-2020 Brian Smith <brian@dbsoft.org>
  * (C) 2003-2011 Mark Hessling <mark@rexx.org>
  * (C) 2002 Nickolay V. Shmyrev <shmyrev@yandex.ru>
  */
@@ -124,6 +124,7 @@
 #endif
 char *_DWDefaultFont = NULL;
 static char _dw_share_path[PATH_MAX+1] = { 0 };
+static char _dw_app_id[101] = { 0 };
 
 #if GTK_MAJOR_VERSION < 2
 static int _dw_file_active = 0;
@@ -1979,8 +1980,6 @@
 }
 #endif
 
-#define DW_APP_DOMAIN_DEFAULT "org.dbsoft.dwindows"
-
 /*
  * Initializes the Dynamic Windows engine.
  * Parameters:
@@ -1995,12 +1994,6 @@
       "1 1 1 1",
       " 	c None",
       " "};
-#if GLIB_CHECK_VERSION(2,28,0)
-   char appid[101] = {0};
-   
-   /* Generate an Application ID based on the PID initially. */
-   snprintf(appid, 100, "%s.pid.%d", DW_APP_DOMAIN_DEFAULT, getpid());
-#endif
 
    if(res)
    {
@@ -2036,8 +2029,11 @@
          strcat(_dw_share_path, "/share/");
          strcat(_dw_share_path, binname);
 #if GLIB_CHECK_VERSION(2,28,0)
-         /* If we have a binary name, use that for the Application ID instead. */
-         snprintf(appid, 100, "%s.%s", DW_APP_DOMAIN_DEFAULT, binname);
+         if(!_dw_app_id[0])
+         {
+            /* If we have a binary name, use that for the Application ID instead. */
+            snprintf(_dw_app_id, 100, "%s.%s", DW_APP_DOMAIN_DEFAULT, binname);
+         }
 #endif
       }
       if(pathcopy)
@@ -2110,11 +2106,17 @@
    }
 
 #if GLIB_CHECK_VERSION(2,28,0)
+   if(!_dw_app_id[0])
+   {
+      /* Generate an Application ID based on the PID if all else fails. */
+      snprintf(_dw_app_id, 100, "%s.pid.%d", DW_APP_DOMAIN_DEFAULT, getpid());
+   }
+   
    /* Initialize the application subsystem on supported versions...
     * we generate an application ID based on the binary name or PID
     * instead of passing NULL to enable full application support.
     */
-   _DWApp = g_application_new(appid, G_APPLICATION_FLAGS_NONE);
+   _DWApp = g_application_new(_dw_app_id, G_APPLICATION_FLAGS_NONE);
    if(g_application_register(_DWApp, NULL, NULL))
       g_application_activate(_DWApp);
 #endif
@@ -13271,6 +13273,35 @@
 }
 
 /*
+ * Sets the application ID used by this Dynamic Windows application instance.
+ * Parameters:
+ *         appid: A string typically in the form: com.company.division.application
+ *         appguid: A globally unique identifier required on Windows or NULL.
+ * Returns:
+ *         DW_ERROR_NONE after successfully setting the application ID.
+ *         DW_ERROR_UNKNOWN if unsupported on this system.
+ *         DW_ERROR_GENERAL if the application ID is not allowed.
+ * Remarks:
+ *          This must be called before dw_init().  If dw_init() is called first
+ *          it will create a unique ID in the form: org.dbsoft.dwindows.application
+ *          or if the application name cannot be detected: org.dbsoft.dwindows.pid.#
+ *          The GUID is only required on Windows, NULL can be passed on other platforms.
+ */
+int dw_app_id_set(const char *appid, const char *appguid)
+{
+#if GLIB_CHECK_VERSION(2,28,0)
+   if(g_application_id_is_valid(appid))
+   {
+      strncpy(_dw_app_id, appid, 100);
+      return DW_ERROR_NONE;
+   }
+   return DW_ERROR_GENERAL;
+#else
+   return DW_ERROR_UNKNOWN;
+#endif
+}
+
+/*
  * Call a function from the window (widget)'s context.
  * Parameters:
  *       handle: Window handle of the widget.
--- a/gtk3/dw.c	Fri May 15 01:19:55 2020 +0000
+++ b/gtk3/dw.c	Fri May 15 02:13:57 2020 +0000
@@ -174,6 +174,7 @@
 #endif
 char *_DWDefaultFont = NULL;
 static char _dw_share_path[PATH_MAX+1] = { 0 };
+static char _dw_app_id[101] = { 0 };
 
 typedef struct
 {
@@ -1954,8 +1955,6 @@
    return NULL;
 }
 
-#define DW_APP_DOMAIN_DEFAULT "org.dbsoft.dwindows"
-
 /*
  * Initializes the Dynamic Windows engine.
  * Parameters:
@@ -1964,12 +1963,6 @@
  */
 int dw_int_init(DWResources *res, int newthread, int *argc, char **argv[])
 {
-#if GLIB_CHECK_VERSION(2,28,0)
-   char appid[101] = {0};
-   
-   /* Generate an Application ID based on the PID initially. */
-   snprintf(appid, 100, "%s.pid.%d", DW_APP_DOMAIN_DEFAULT, getpid());
-#endif
    if(res)
    {
       _resources.resource_max = res->resource_max;
@@ -2004,8 +1997,11 @@
          strcat(_dw_share_path, "/share/");
          strcat(_dw_share_path, binname);
 #if GLIB_CHECK_VERSION(2,28,0)
-         /* If we have a binary name, use that for the Application ID instead. */
-         snprintf(appid, 100, "%s.%s", DW_APP_DOMAIN_DEFAULT, binname);
+         if(!_dw_app_id[0])
+         {
+            /* If we have a binary name, use that for the Application ID instead. */
+            snprintf(_dw_app_id, 100, "%s.%s", DW_APP_DOMAIN_DEFAULT, binname);
+         }
 #endif
       }
       if(pathcopy)
@@ -2038,12 +2034,18 @@
    _DWObject = g_object_new(G_TYPE_OBJECT, NULL);
    
 #if GLIB_CHECK_VERSION(2,28,0)
+   if(!_dw_app_id[0])
+   {
+      /* Generate an Application ID based on the PID if all else fails. */
+      snprintf(_dw_app_id, 100, "%s.pid.%d", DW_APP_DOMAIN_DEFAULT, getpid());
+   }
+   
    /* Initialize the application subsystem on supported versions...
     * we generate an application ID based on the binary name or PID
     * instead of passing NULL to enable full application support.
     */
-   _DWApp = g_application_new(appid, G_APPLICATION_FLAGS_NONE);
-   if(g_application_register(_DWApp, NULL, NULL))
+   _DWApp = g_application_new(_dw_app_id, G_APPLICATION_FLAGS_NONE);
+   if(_DWApp && g_application_register(_DWApp, NULL, NULL))
       g_application_activate(_DWApp);
 #endif
    return TRUE;
@@ -11764,6 +11766,35 @@
 }
 
 /*
+ * Sets the application ID used by this Dynamic Windows application instance.
+ * Parameters:
+ *         appid: A string typically in the form: com.company.division.application
+ *         appguid: A globally unique identifier required on Windows or NULL.
+ * Returns:
+ *         DW_ERROR_NONE after successfully setting the application ID.
+ *         DW_ERROR_UNKNOWN if unsupported on this system.
+ *         DW_ERROR_GENERAL if the application ID is not allowed.
+ * Remarks:
+ *          This must be called before dw_init().  If dw_init() is called first
+ *          it will create a unique ID in the form: org.dbsoft.dwindows.application
+ *          or if the application name cannot be detected: org.dbsoft.dwindows.pid.#
+ *          The GUID is only required on Windows, NULL can be passed on other platforms.
+ */
+int dw_app_id_set(const char *appid, const char *appguid)
+{
+#if GLIB_CHECK_VERSION(2,28,0)
+   if(g_application_id_is_valid(appid))
+   {
+      strncpy(_dw_app_id, appid, 100);
+      return DW_ERROR_NONE;
+   }
+   return DW_ERROR_GENERAL;
+#else
+   return DW_ERROR_UNKNOWN;
+#endif
+}
+
+/*
  * Call a function from the window (widget)'s context.
  * Parameters:
  *       handle: Window handle of the widget.
--- a/mac/dw.m	Fri May 15 01:19:55 2020 +0000
+++ b/mac/dw.m	Fri May 15 02:13:57 2020 +0000
@@ -12018,7 +12018,7 @@
         char *app = strstr(pathcopy, ".app/");
         char *binname = strrchr(pathcopy, '/');
         
-        if(binname && (binname++) && _dw_app_id[0])
+        if(binname && (binname++) && !_dw_app_id[0])
         {
             /* If we have a binary name, use that for the Application ID instead. */
             snprintf(_dw_app_id, 100, "%s.%s", DW_APP_DOMAIN_DEFAULT, binname);