1 #include "openbox/actions.h"
2 #include "openbox/event.h"
3 #include "openbox/startupnotify.h"
4 #include "openbox/screen.h"
15 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
16 static void free_func(gpointer options);
17 static gboolean run_func(ObActionsData *data, gpointer options);
19 static gboolean i_input_func(guint initial_state,
23 static void i_cancel_func(gpointer options);
26 void action_execute_startup()
28 actions_register("Execute",
35 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
40 o = g_new0(Options, 1);
42 if ((n = parse_find_node("execute", node))) {
43 gchar *s = parse_string(doc, n);
44 o->cmd = parse_expand_tilde(s);
48 if ((n = parse_find_node("startupnotify", node))) {
50 if ((m = parse_find_node("enabled", n->xmlChildrenNode)))
51 o->sn = parse_bool(doc, m);
52 if ((m = parse_find_node("name", n->xmlChildrenNode)))
53 o->sn_name = parse_string(doc, m);
54 if ((m = parse_find_node("icon", n->xmlChildrenNode)))
55 o->sn_icon = parse_string(doc, m);
56 if ((m = parse_find_node("wmclass", n->xmlChildrenNode)))
57 o->sn_wmclass = parse_string(doc, m);
62 static void free_func(gpointer options)
70 g_free(o->sn_wmclass);
75 /* Always return FALSE because its not interactive */
76 static gboolean run_func(ObActionsData *data, gpointer options)
83 if (!o->cmd) return FALSE;
84 cmd = g_filename_from_utf8(o->cmd, -1, NULL, NULL, NULL);
86 g_message(_("Failed to convert the path '%s' from utf8"), o->cmd);
90 /* If there is a keyboard grab going on then we need to cancel
91 it so the application can grab things */
92 event_cancel_all_key_grabs();
94 if (!g_shell_parse_argv(cmd, NULL, &argv, &e)) {
95 g_message(_("Failed to execute '%s': %s"), o->cmd, e->message);
99 gchar *program = NULL;
102 program = g_path_get_basename(argv[0]);
103 /* sets up the environment */
104 sn_setup_spawn_environment(program, o->sn_name, o->sn_icon,
105 /* launch it on the current desktop */
109 if (!g_spawn_async(NULL, argv, NULL,
110 G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
111 NULL, NULL, NULL, &e))
113 g_message(_("Failed to execute '%s': %s"), o->cmd, e->message);
120 unsetenv("DESKTOP_STARTUP_ID");