1 #include "openbox/actions.h"
2 #include "openbox/event.h"
3 #include "openbox/startupnotify.h"
4 #include "openbox/client.h"
5 #include "openbox/prompt.h"
6 #include "openbox/screen.h"
23 static gpointer
setup_func(xmlNodePtr node
);
24 static void free_func(gpointer options
);
25 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
27 static gboolean i_input_func(guint initial_state,
31 static void i_cancel_func(gpointer options);
34 void action_execute_startup(void)
36 actions_register("Execute", setup_func
, free_func
, run_func
, NULL
, NULL
);
39 static gpointer
setup_func(xmlNodePtr node
)
44 o
= g_new0(Options
, 1);
46 if ((n
= obt_parse_find_node(node
, "command")) ||
47 (n
= obt_parse_find_node(node
, "execute")))
49 gchar
*s
= obt_parse_node_string(n
);
50 o
->cmd
= obt_paths_expand_tilde(s
);
54 if ((n
= obt_parse_find_node(node
, "prompt")))
55 o
->prompt
= obt_parse_node_string(n
);
57 if ((n
= obt_parse_find_node(node
, "startupnotify"))) {
59 if ((m
= obt_parse_find_node(n
->children
, "enabled")))
60 o
->sn
= obt_parse_node_bool(m
);
61 if ((m
= obt_parse_find_node(n
->children
, "name")))
62 o
->sn_name
= obt_parse_node_string(m
);
63 if ((m
= obt_parse_find_node(n
->children
, "icon")))
64 o
->sn_icon
= obt_parse_node_string(m
);
65 if ((m
= obt_parse_find_node(n
->children
, "wmclass")))
66 o
->sn_wmclass
= obt_parse_node_string(m
);
71 static void free_func(gpointer options
)
79 g_free(o
->sn_wmclass
);
85 static Options
* dup_options(Options
*in
)
87 Options
*o
= g_new(Options
, 1);
88 o
->cmd
= g_strdup(in
->cmd
);
90 o
->sn_name
= g_strdup(in
->sn_name
);
91 o
->sn_icon
= g_strdup(in
->sn_icon
);
92 o
->sn_wmclass
= g_strdup(in
->sn_wmclass
);
97 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
99 static void prompt_cb(ObPrompt
*p
, gint result
, gpointer options
)
102 run_func(NULL
, options
);
108 /* Always return FALSE because its not interactive */
109 static gboolean
run_func(ObActionsData
*data
, gpointer options
)
114 Options
*o
= options
;
116 if (!o
->cmd
) return FALSE
;
121 ObPromptAnswer answers
[] = {
126 ocp
= dup_options(options
);
127 p
= prompt_new(o
->prompt
, answers
, 2, 0, 0, prompt_cb
, ocp
);
128 prompt_show(p
, NULL
, FALSE
);
133 cmd
= g_filename_from_utf8(o
->cmd
, -1, NULL
, NULL
, NULL
);
135 g_message(_("Failed to convert the path \"%s\" from utf8"), o
->cmd
);
139 /* If there is a keyboard grab going on then we need to cancel
140 it so the application can grab things */
141 event_cancel_all_key_grabs();
143 if (!g_shell_parse_argv(cmd
, NULL
, &argv
, &e
)) {
144 g_message(_("Failed to execute \"%s\": %s"), o
->cmd
, e
->message
);
148 gchar
*program
= NULL
;
151 program
= g_path_get_basename(argv
[0]);
152 /* sets up the environment */
153 sn_setup_spawn_environment(program
, o
->sn_name
, o
->sn_icon
,
155 /* launch it on the current desktop */
159 if (data
->client
&& data
->client
->pid
) {
162 pid
= g_strdup_printf("%u", data
->client
->pid
);
163 setenv("PID", pid
, TRUE
);
172 wid
= g_strdup_printf("%u", data
->client
->window
);
173 setenv("WINDOW_ID", wid
, TRUE
);
177 unsetenv("WINDOW_ID");
179 if (!g_spawn_async(NULL
, argv
, NULL
,
180 G_SPAWN_SEARCH_PATH
| G_SPAWN_DO_NOT_REAP_CHILD
,
181 NULL
, NULL
, NULL
, &e
))
183 g_message(_("Failed to execute \"%s\": %s"), o
->cmd
, e
->message
);
190 unsetenv("DESKTOP_STARTUP_ID");
193 unsetenv("WINDOW_ID");