2 * Copyright (C) 2003 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
19 * Authors: Mark McLoughlin <mark@skynet.ie>
25 #ifdef HAVE_CRT_EXTERNS_H
26 #include <crt_externs.h> /* for _NSGetEnviron */
35 #ifdef HAVE__NSGETENVIRON
36 #define environ (*_NSGetEnviron())
39 /* According to the Single Unix Specification, environ is not in
40 * any system header, although unistd.h often declares it.
42 extern char **environ;
46 * gdk_make_spawn_environment_for_screen:
47 * @screen: A #GdkScreen
48 * @envp: program environment to copy, or %NULL to use current environment.
50 * Returns a modified copy of the program environment @envp (or the current
51 * environment if @envp is %NULL) with <envar>DISPLAY</envar> set such that
52 * a launched application (which calls gdk_display_open()) inheriting this
53 * environment would have @screen as its default screen..
55 * Returns: a newly-allocated %NULL-terminated array of strings.
56 * Use g_strfreev() to free it.
61 gdk_spawn_make_environment_for_screen (GdkScreen *screen,
64 gchar **retval = NULL;
66 gint display_index = -1;
69 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
74 for (env_len = 0; envp[env_len]; env_len++)
75 if (strncmp (envp[env_len], "DISPLAY", strlen ("DISPLAY")) == 0)
76 display_index = env_len;
78 retval = g_new (char *, env_len + 1);
79 retval[env_len] = NULL;
81 display_name = gdk_screen_make_display_name (screen);
83 for (i = 0; i < env_len; i++)
84 if (i == display_index)
85 retval[i] = g_strconcat ("DISPLAY=", display_name, NULL);
87 retval[i] = g_strdup (envp[i]);
89 g_assert (i == env_len);
91 g_free (display_name);
97 * gdk_spawn_on_screen:
98 * @screen: a #GdkScreen
99 * @working_directory: child's current working directory, or %NULL to
101 * @argv: child's argument vector
102 * @envp: child's environment, or %NULL to inherit parent's
103 * @flags: flags from #GSpawnFlags
104 * @child_setup: function to run in the child just before exec()
105 * @user_data: user data for @child_setup
106 * @child_pid: return location for child process ID, or %NULL
107 * @error: return location for error
109 * Like g_spawn_async(), except the child process is spawned in such
110 * an environment that on calling gdk_display_open() it would be
111 * returned a #GdkDisplay with @screen as the default screen.
113 * This is useful for applications which wish to launch an application
114 * on a specific screen.
116 * Return value: %TRUE on success, %FALSE if error is set
121 gdk_spawn_on_screen (GdkScreen *screen,
122 const gchar *working_directory,
126 GSpawnChildSetupFunc child_setup,
134 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
136 new_envp = gdk_spawn_make_environment_for_screen (screen, envp);
138 retval = g_spawn_async (working_directory,
147 g_strfreev (new_envp);
153 * gdk_spawn_on_screen_with_pipes:
154 * @screen: a #GdkScreen
155 * @working_directory: child's current working directory, or %NULL to
157 * @argv: child's argument vector
158 * @envp: child's environment, or %NULL to inherit parent's
159 * @flags: flags from #GSpawnFlags
160 * @child_setup: function to run in the child just before exec()
161 * @user_data: user data for @child_setup
162 * @child_pid: return location for child process ID, or %NULL
163 * @standard_input: return location for file descriptor to write to
164 * child's stdin, or %NULL
165 * @standard_output: return location for file descriptor to read child's
167 * @standard_error: return location for file descriptor to read child's
169 * @error: return location for error
171 * Like g_spawn_async_with_pipes(), except the child process is
172 * spawned in such an environment that on calling gdk_display_open()
173 * it would be returned a #GdkDisplay with @screen as the default
176 * This is useful for applications which wish to launch an application
177 * on a specific screen.
179 * Return value: %TRUE on success, %FALSE if an error was set
184 gdk_spawn_on_screen_with_pipes (GdkScreen *screen,
185 const gchar *working_directory,
189 GSpawnChildSetupFunc child_setup,
192 gint *standard_input,
193 gint *standard_output,
194 gint *standard_error,
200 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
202 new_envp = gdk_spawn_make_environment_for_screen (screen, envp);
204 retval = g_spawn_async_with_pipes (working_directory,
216 g_strfreev (new_envp);
222 * gdk_spawn_command_line_on_screen:
223 * @screen: a #GdkScreen
224 * @command_line: a command line
225 * @error: return location for errors
227 * Like g_spawn_command_line_async(), except the child process is
228 * spawned in such an environment that on calling gdk_display_open()
229 * it would be returned a #GdkDisplay with @screen as the default
232 * This is useful for applications which wish to launch an application
233 * on a specific screen.
235 * Return value: %TRUE on success, %FALSE if error is set.
240 gdk_spawn_command_line_on_screen (GdkScreen *screen,
241 const gchar *command_line,
247 g_return_val_if_fail (command_line != NULL, FALSE);
249 if (!g_shell_parse_argv (command_line,
254 retval = gdk_spawn_on_screen (screen,
264 #define __GDK_SPAWN_X11_C__
265 #include "gdkaliasdef.c"