# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1614858789 0 # Node ID e3d2058ea96a4208f4591bbe0c5cb79b931559f4 # Parent e5d4c86a0c93830237a60430f3420630b36b3d54 GTK3: Port new dw_exec() from GTK4 with additional GLib version checks. diff -r e5d4c86a0c93 -r e3d2058ea96a gtk3/dw.c --- a/gtk3/dw.c Thu Mar 04 11:19:44 2021 +0000 +++ b/gtk3/dw.c Thu Mar 04 11:53:09 2021 +0000 @@ -1213,12 +1213,12 @@ #if USE_WEBKIT2 pthread_t saved_thread = _dw_thread; WebKitJavascriptResult *js_result; - #if WEBKIT_CHECK_VERSION(2, 22, 0) +#if WEBKIT_CHECK_VERSION(2, 22, 0) JSCValue *value; - #else +#else JSValueRef value; JSGlobalContextRef context; - #endif +#endif GError *error = NULL; int (*htmlresultfunc)(HWND, int, char *, void *, void *) = NULL; gint handlerdata = GPOINTER_TO_INT(g_object_get_data(object, "_dw_html_result_id")); @@ -11505,6 +11505,12 @@ return filename; } +#if GLIB_CHECK_VERSION(2,36,0) +static void _dw_exec_launched(GAppLaunchContext *context, GAppInfo *info, GVariant *platform_data, gpointer data) +{ + g_variant_lookup(platform_data, "pid", "i", data); +} +#endif /* * Execute and external program in a seperate session. @@ -11513,58 +11519,54 @@ * type: Either DW_EXEC_CON or DW_EXEC_GUI. * params: An array of pointers to string arguements. * Returns: - * -1 on error. - */ -int dw_exec(const char *program, int type, char **params) -{ - int ret = -1; - - if((ret = fork()) == 0) - { - int i; - - for (i = 3; i < 256; i++) - close(i); - setsid(); - if(type == DW_EXEC_GUI) - { - execvp(program, params); - } - else if(type == DW_EXEC_CON) - { - char **tmpargs; - - if(!params) - { - tmpargs = malloc(sizeof(char *)); - tmpargs[0] = NULL; - } - else - { - int z = 0; - - while(params[z]) - { - z++; - } - tmpargs = malloc(sizeof(char *)*(z+3)); - z=0; - tmpargs[0] = "xterm"; - tmpargs[1] = "-e"; - while(params[z]) - { - tmpargs[z+2] = params[z]; - z++; - } - tmpargs[z+2] = NULL; - } - execvp("xterm", tmpargs); - free(tmpargs); - } - /* If we got here exec failed */ - _exit(-1); - } - return ret; + * DW_ERROR_UNKNOWN on error. + */ +int API dw_exec(const char *program, int type, char **params) +{ + GAppInfo *appinfo = NULL; + char *commandline; + int retval = DW_ERROR_UNKNOWN; + + /* Generate a command line from the parameters */ + if(params && *params) + { + int z = 0, len = 0; + + while(params[z]) + { + len+=strlen(params[z]) + 1; + z++; + } + z=1; + commandline = calloc(1, len); + strcpy(commandline, params[0]); + while(params[z]) + { + strcat(commandline, " "); + strcat(commandline, params[z]); + z++; + } + } + else + commandline = strdup(program); + + /* Attempt to use app preferences to launch the application, using the selected Terminal if necessary */ + if((appinfo = g_app_info_create_from_commandline(commandline, NULL, + type == DW_EXEC_CON ? G_APP_INFO_CREATE_NEEDS_TERMINAL : G_APP_INFO_CREATE_NONE, NULL))) + { + GAppLaunchContext *context = g_app_launch_context_new(); + +#if GLIB_CHECK_VERSION(2,36,0) + g_signal_connect(G_OBJECT(context), "launched", G_CALLBACK(_dw_exec_launched), (gpointer)&retval); +#endif + + g_app_info_launch(appinfo, NULL, context, NULL); + + g_object_unref(appinfo); + g_object_unref(context); + } + free(commandline); + return retval; } /*