1 #include "openbox/actions.h"
2 #include "openbox/event.h"
3 #include "openbox/startupnotify.h"
4 #include "openbox/prompt.h"
5 #include "openbox/screen.h"
22 static gpointer setup_func(xmlNodePtr node);
23 static void free_func(gpointer options);
24 static gboolean run_func(ObActionsData *data, gpointer options);
26 static gboolean i_input_func(guint initial_state,
30 static void i_cancel_func(gpointer options);
33 void action_execute_startup(void)
35 actions_register("Execute", setup_func, free_func, run_func, NULL, NULL);
38 static gpointer setup_func(xmlNodePtr node)
43 o = g_new0(Options, 1);
45 if ((n = obt_parse_find_node(node, "command")) ||
46 (n = obt_parse_find_node(node, "execute")))
48 gchar *s = obt_parse_node_string(n);
49 o->cmd = obt_paths_expand_tilde(s);
53 if ((n = obt_parse_find_node(node, "prompt")))
54 o->prompt = obt_parse_node_string(n);
56 if ((n = obt_parse_find_node(node, "startupnotify"))) {
58 if ((m = obt_parse_find_node(n->children, "enabled")))
59 o->sn = obt_parse_node_bool(m);
60 if ((m = obt_parse_find_node(n->children, "name")))
61 o->sn_name = obt_parse_node_string(m);
62 if ((m = obt_parse_find_node(n->children, "icon")))
63 o->sn_icon = obt_parse_node_string(m);
64 if ((m = obt_parse_find_node(n->children, "wmclass")))
65 o->sn_wmclass = obt_parse_node_string(m);
70 static void free_func(gpointer options)
78 g_free(o->sn_wmclass);
83 static Options* dup_options(Options *in)
85 Options *o = g_new(Options, 1);
86 o->cmd = g_strdup(in->cmd);
88 o->sn_name = g_strdup(in->sn_name);
89 o->sn_icon = g_strdup(in->sn_icon);
90 o->sn_wmclass = g_strdup(in->sn_wmclass);
95 static gboolean run_func(ObActionsData *data, gpointer options);
97 static void prompt_cb(ObPrompt *p, gint result, gpointer data)
99 Options *options = data;
102 run_func(NULL, options);
106 g_free(options->cmd);
107 g_free(options->sn_name);
108 g_free(options->sn_icon);
109 g_free(options->sn_wmclass);
113 /* Always return FALSE because its not interactive */
114 static gboolean run_func(ObActionsData *data, gpointer options)
119 Options *o = options;
121 if (!o->cmd) return FALSE;
126 ObPromptAnswer answers[] = {
131 ocp = dup_options(options);
132 p = prompt_new(o->prompt, answers, 2, 0, 0, prompt_cb, ocp);
133 prompt_show(p, NULL, FALSE);
138 cmd = g_filename_from_utf8(o->cmd, -1, NULL, NULL, NULL);
140 g_message(_("Failed to convert the path \"%s\" from utf8"), o->cmd);
144 /* If there is a keyboard grab going on then we need to cancel
145 it so the application can grab things */
146 event_cancel_all_key_grabs();
148 if (!g_shell_parse_argv(cmd, NULL, &argv, &e)) {
149 g_message(_("Failed to execute \"%s\": %s"), o->cmd, e->message);
153 gchar *program = NULL;
156 program = g_path_get_basename(argv[0]);
157 /* sets up the environment */
158 sn_setup_spawn_environment(program, o->sn_name, o->sn_icon,
160 /* launch it on the current desktop */
164 if (!g_spawn_async(NULL, argv, NULL,
165 G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
166 NULL, NULL, NULL, &e))
168 g_message(_("Failed to execute \"%s\": %s"), o->cmd, e->message);
175 unsetenv("DESKTOP_STARTUP_ID");