diff 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
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.