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(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(void)
28 actions_register("Execute", setup_func, free_func, run_func, NULL, NULL);
31 static gpointer setup_func(xmlNodePtr node)
36 o = g_new0(Options, 1);
38 if ((n = obt_parse_find_node(node, "command")) ||
39 (n = obt_parse_find_node(node, "execute")))
41 gchar *s = obt_parse_node_string(n);
42 o->cmd = parse_expand_tilde(s);
46 if ((n = obt_parse_find_node(node, "startupnotify"))) {
48 if ((m = obt_parse_find_node(n->children, "enabled")))
49 o->sn = obt_parse_node_bool(m);
50 if ((m = obt_parse_find_node(n->children, "name")))
51 o->sn_name = obt_parse_node_string(m);
52 if ((m = obt_parse_find_node(n->children, "icon")))
53 o->sn_icon = obt_parse_node_string(m);
54 if ((m = obt_parse_find_node(n->children, "wmclass")))
55 o->sn_wmclass = obt_parse_node_string(m);
60 static void free_func(gpointer options)
68 g_free(o->sn_wmclass);
73 /* Always return FALSE because its not interactive */
74 static gboolean run_func(ObActionsData *data, gpointer options)
81 if (!o->cmd) return FALSE;
82 cmd = g_filename_from_utf8(o->cmd, -1, NULL, NULL, NULL);
84 g_message(_("Failed to convert the path '%s' from utf8"), o->cmd);
88 /* If there is a keyboard grab going on then we need to cancel
89 it so the application can grab things */
90 event_cancel_all_key_grabs();
92 if (!g_shell_parse_argv(cmd, NULL, &argv, &e)) {
93 g_message(_("Failed to execute '%s': %s"), o->cmd, e->message);
97 gchar *program = NULL;
100 program = g_path_get_basename(argv[0]);
101 /* sets up the environment */
102 sn_setup_spawn_environment(program, o->sn_name, o->sn_icon,
103 /* launch it on the current desktop */
107 if (!g_spawn_async(NULL, argv, NULL,
108 G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
109 NULL, NULL, NULL, &e))
111 g_message(_("Failed to execute '%s': %s"), o->cmd, e->message);
118 unsetenv("DESKTOP_STARTUP_ID");