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>
31 extern char **environ;
34 * gdk_make_spawn_environment_for_screen:
35 * @screen: A #GdkScreen
36 * @envp: program environment to copy, or %NULL to use current environment.
38 * Returns a modified copy of the program environment @envp (or the current
39 * environment if @envp is %NULL) with <envar>DISPLAY</envar> set such that
40 * a launched application (which calls gdk_display_open()) inheriting this
41 * environment would have @screen as its default screen..
43 * Returns: a newly-allocated %NULL-terminated array of strings.
44 * Use g_strfreev() to free it.
49 gdk_spawn_make_environment_for_screen (GdkScreen *screen,
52 gchar **retval = NULL;
54 gint display_index = -1;
57 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
62 for (env_len = 0; envp[env_len]; env_len++)
63 if (strncmp (envp[env_len], "DISPLAY", strlen ("DISPLAY")) == 0)
64 display_index = env_len;
66 retval = g_new (char *, env_len + 1);
67 retval[env_len] = NULL;
69 display_name = gdk_screen_make_display_name (screen);
71 for (i = 0; i < env_len; i++)
72 if (i == display_index)
73 retval[i] = g_strconcat ("DISPLAY=", display_name, NULL);
75 retval[i] = g_strdup (envp[i]);
77 g_assert (i == env_len);
79 g_free (display_name);
85 * gdk_spawn_on_screen:
86 * @screen: a #GdkScreen
87 * @working_directory: child's current working directory, or %NULL to
89 * @argv: child's argument vector
90 * @envp: child's environment, or %NULL to inherit parent's
91 * @flags: flags from #GSpawnFlags
92 * @child_setup: function to run in the child just before exec()
93 * @user_data: user data for @child_setup
94 * @child_pid: return location for child process ID, or %NULL
95 * @error: return location for error
97 * Like g_spawn_async(), except the child process is spawned in such
98 * an environment that on calling gdk_display_open() it would be
99 * returned a #GdkDisplay with @screen as the default screen.
101 * This is useful for applications which wish to launch an application
102 * on a specific screen.
104 * Return value: %TRUE on success, %FALSE if error is set
109 gdk_spawn_on_screen (GdkScreen *screen,
110 const gchar *working_directory,
114 GSpawnChildSetupFunc child_setup,
122 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
124 new_envp = gdk_spawn_make_environment_for_screen (screen, envp);
126 retval = g_spawn_async (working_directory,
135 g_strfreev (new_envp);
141 * gdk_spawn_on_screen_with_pipes:
142 * @screen: a #GdkScreen
143 * @working_directory: child's current working directory, or %NULL to
145 * @argv: child's argument vector
146 * @envp: child's environment, or %NULL to inherit parent's
147 * @flags: flags from #GSpawnFlags
148 * @child_setup: function to run in the child just before exec()
149 * @user_data: user data for @child_setup
150 * @child_pid: return location for child process ID, or %NULL
151 * @standard_input: return location for file descriptor to write to
152 * child's stdin, or %NULL
153 * @standard_output: return location for file descriptor to read child's
155 * @standard_error: return location for file descriptor to read child's
157 * @error: return location for error
159 * Like g_spawn_async_with_pipes(), except the child process is
160 * spawned in such an environment that on calling gdk_display_open()
161 * it would be returned a #GdkDisplay with @screen as the default
164 * This is useful for applications which wish to launch an application
165 * on a specific screen.
167 * Return value: %TRUE on success, %FALSE if an error was set
172 gdk_spawn_on_screen_with_pipes (GdkScreen *screen,
173 const gchar *working_directory,
177 GSpawnChildSetupFunc child_setup,
180 gint *standard_input,
181 gint *standard_output,
182 gint *standard_error,
188 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
190 new_envp = gdk_spawn_make_environment_for_screen (screen, envp);
192 retval = g_spawn_async_with_pipes (working_directory,
204 g_strfreev (new_envp);
210 * gdk_spawn_command_line_on_screen:
211 * @screen: a #GdkScreen
212 * @command_line: a command line
213 * @error: return location for errors
215 * Like g_spawn_command_line_async(), except the child process is
216 * spawned in such an environment that on calling gdk_display_open()
217 * it would be returned a #GdkDisplay with @screen as the default
220 * This is useful for applications which wish to launch an application
221 * on a specific screen.
223 * Return value: %TRUE on success, %FALSE if error is set.
228 gdk_spawn_command_line_on_screen (GdkScreen *screen,
229 const gchar *command_line,
235 g_return_val_if_fail (command_line != NULL, FALSE);
237 if (!g_shell_parse_argv (command_line,
242 retval = gdk_spawn_on_screen (screen,