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
);
84 static Options
* dup_options(Options
*in
)
86 Options
*o
= g_new(Options
, 1);
87 o
->cmd
= g_strdup(in
->cmd
);
89 o
->sn_name
= g_strdup(in
->sn_name
);
90 o
->sn_icon
= g_strdup(in
->sn_icon
);
91 o
->sn_wmclass
= g_strdup(in
->sn_wmclass
);
96 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
98 static void prompt_cb(ObPrompt
*p
, gint result
, gpointer options
)
101 run_func(NULL
, options
);
107 /* Always return FALSE because its not interactive */
108 static gboolean
run_func(ObActionsData
*data
, gpointer options
)
113 Options
*o
= options
;
115 if (!o
->cmd
) return FALSE
;
120 ObPromptAnswer answers
[] = {
125 ocp
= dup_options(options
);
126 p
= prompt_new(o
->prompt
, answers
, 2, 0, 0, prompt_cb
, ocp
);
127 prompt_show(p
, NULL
, FALSE
);
132 cmd
= g_filename_from_utf8(o
->cmd
, -1, NULL
, NULL
, NULL
);
134 g_message(_("Failed to convert the path \"%s\" from utf8"), o
->cmd
);
138 /* If there is a keyboard grab going on then we need to cancel
139 it so the application can grab things */
140 event_cancel_all_key_grabs();
142 if (!g_shell_parse_argv(cmd
, NULL
, &argv
, &e
)) {
143 g_message(_("Failed to execute \"%s\": %s"), o
->cmd
, e
->message
);
147 gchar
*program
= NULL
;
150 program
= g_path_get_basename(argv
[0]);
151 /* sets up the environment */
152 sn_setup_spawn_environment(program
, o
->sn_name
, o
->sn_icon
,
154 /* launch it on the current desktop */
158 if (!g_spawn_async(NULL
, argv
, NULL
,
159 G_SPAWN_SEARCH_PATH
| G_SPAWN_DO_NOT_REAP_CHILD
,
160 NULL
, NULL
, NULL
, &e
))
162 g_message(_("Failed to execute \"%s\": %s"), o
->cmd
, e
->message
);
169 unsetenv("DESKTOP_STARTUP_ID");