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"
21 static gpointer
setup_func(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
);
22 static void free_func(gpointer options
);
23 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
25 static gboolean i_input_func(guint initial_state,
29 static void i_cancel_func(gpointer options);
32 void action_execute_startup(void)
34 actions_register("Execute",
41 static gpointer
setup_func(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
)
46 o
= g_new0(Options
, 1);
48 if ((n
= parse_find_node("command", node
)) ||
49 (n
= parse_find_node("execute", node
)))
51 gchar
*s
= parse_string(doc
, n
);
52 o
->cmd
= parse_expand_tilde(s
);
56 if ((n
= parse_find_node("prompt", node
)))
57 o
->prompt
= parse_string(doc
, n
);
59 if ((n
= parse_find_node("startupnotify", node
))) {
61 if ((m
= parse_find_node("enabled", n
->xmlChildrenNode
)))
62 o
->sn
= parse_bool(doc
, m
);
63 if ((m
= parse_find_node("name", n
->xmlChildrenNode
)))
64 o
->sn_name
= parse_string(doc
, m
);
65 if ((m
= parse_find_node("icon", n
->xmlChildrenNode
)))
66 o
->sn_icon
= parse_string(doc
, m
);
67 if ((m
= parse_find_node("wmclass", n
->xmlChildrenNode
)))
68 o
->sn_wmclass
= parse_string(doc
, m
);
73 static void free_func(gpointer options
)
81 g_free(o
->sn_wmclass
);
86 static Options
* dup_options(Options
*in
)
88 Options
*o
= g_new(Options
, 1);
89 o
->cmd
= g_strdup(in
->cmd
);
91 o
->sn_name
= g_strdup(in
->sn_name
);
92 o
->sn_icon
= g_strdup(in
->sn_icon
);
93 o
->sn_wmclass
= g_strdup(in
->sn_wmclass
);
98 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
100 static void prompt_cb(ObPrompt
*p
, gint result
, gpointer data
)
102 Options
*options
= data
;
105 run_func(NULL
, options
);
109 g_free(options
->cmd
);
110 g_free(options
->sn_name
);
111 g_free(options
->sn_icon
);
112 g_free(options
->sn_wmclass
);
116 /* Always return FALSE because its not interactive */
117 static gboolean
run_func(ObActionsData
*data
, gpointer options
)
122 Options
*o
= options
;
124 if (!o
->cmd
) return FALSE
;
129 ObPromptAnswer answers
[] = {
134 ocp
= dup_options(options
);
135 p
= prompt_new(o
->prompt
, answers
, 2, 0, 0, prompt_cb
, ocp
);
136 prompt_show(p
, NULL
, FALSE
);
141 cmd
= g_filename_from_utf8(o
->cmd
, -1, NULL
, NULL
, NULL
);
143 g_message(_("Failed to convert the path \"%s\" from utf8"), o
->cmd
);
147 /* If there is a keyboard grab going on then we need to cancel
148 it so the application can grab things */
149 event_cancel_all_key_grabs();
151 if (!g_shell_parse_argv(cmd
, NULL
, &argv
, &e
)) {
152 g_message(_("Failed to execute \"%s\": %s"), o
->cmd
, e
->message
);
156 gchar
*program
= NULL
;
159 program
= g_path_get_basename(argv
[0]);
160 /* sets up the environment */
161 sn_setup_spawn_environment(program
, o
->sn_name
, o
->sn_icon
,
163 /* launch it on the current desktop */
167 if (!g_spawn_async(NULL
, argv
, NULL
,
168 G_SPAWN_SEARCH_PATH
| G_SPAWN_DO_NOT_REAP_CHILD
,
169 NULL
, NULL
, NULL
, &e
))
171 g_message(_("Failed to execute \"%s\": %s"), o
->cmd
, e
->message
);
178 unsetenv("DESKTOP_STARTUP_ID");