1 #include "openbox/actions.h"
2 #include "openbox/event.h"
3 #include "openbox/startupnotify.h"
4 #include "openbox/screen.h"
20 static gpointer setup_func(xmlNodePtr node);
21 static void free_func(gpointer options);
22 static gboolean run_func(ObActionsData *data, gpointer options);
24 static gboolean i_input_func(guint initial_state,
28 static void i_cancel_func(gpointer options);
31 void action_execute_startup(void)
33 actions_register("Execute", setup_func, free_func, run_func, NULL, NULL);
36 static gpointer setup_func(xmlNodePtr node)
41 o = g_new0(Options, 1);
43 if ((n = obt_parse_find_node(node, "command")) ||
44 (n = obt_parse_find_node(node, "execute")))
46 gchar *s = obt_parse_node_string(n);
47 o->cmd = obt_paths_expand_tilde(s);
51 if ((n = obt_parse_find_node(node, "startupnotify"))) {
53 if ((m = obt_parse_find_node(n->children, "enabled")))
54 o->sn = obt_parse_node_bool(m);
55 if ((m = obt_parse_find_node(n->children, "name")))
56 o->sn_name = obt_parse_node_string(m);
57 if ((m = obt_parse_find_node(n->children, "icon")))
58 o->sn_icon = obt_parse_node_string(m);
59 if ((m = obt_parse_find_node(n->children, "wmclass")))
60 o->sn_wmclass = obt_parse_node_string(m);
65 static void free_func(gpointer options)
73 g_free(o->sn_wmclass);
78 /* Always return FALSE because its not interactive */
79 static gboolean run_func(ObActionsData *data, gpointer options)
86 if (!o->cmd) return FALSE;
87 cmd = g_filename_from_utf8(o->cmd, -1, NULL, NULL, NULL);
89 g_message(_("Failed to convert the path '%s' from utf8"), o->cmd);
93 /* If there is a keyboard grab going on then we need to cancel
94 it so the application can grab things */
95 event_cancel_all_key_grabs();
97 if (!g_shell_parse_argv(cmd, NULL, &argv, &e)) {
98 g_message(_("Failed to execute '%s': %s"), o->cmd, e->message);
102 gchar *program = NULL;
105 program = g_path_get_basename(argv[0]);
106 /* sets up the environment */
107 sn_setup_spawn_environment(program, o->sn_name, o->sn_icon,
109 /* launch it on the current desktop */
113 if (!g_spawn_async(NULL, argv, NULL,
114 G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
115 NULL, NULL, NULL, &e))
117 g_message(_("Failed to execute '%s': %s"), o->cmd, e->message);
124 unsetenv("DESKTOP_STARTUP_ID");