1 #include "openbox/actions.h"
2 #include "openbox/event.h"
3 #include "openbox/startupnotify.h"
4 #include "openbox/screen.h"
16 static gpointer
setup_func(xmlNodePtr node
);
17 static void free_func(gpointer options
);
18 static gboolean
run_func(ObActionsData
*data
, gpointer options
);
20 static gboolean i_input_func(guint initial_state,
24 static void i_cancel_func(gpointer options);
27 void action_execute_startup(void)
29 actions_register("Execute", setup_func
, free_func
, run_func
, NULL
, NULL
);
32 static gpointer
setup_func(xmlNodePtr node
)
37 o
= g_new0(Options
, 1);
39 if ((n
= obt_parse_find_node(node
, "command")) ||
40 (n
= obt_parse_find_node(node
, "execute")))
42 gchar
*s
= obt_parse_node_string(n
);
43 o
->cmd
= obt_paths_expand_tilde(s
);
47 if ((n
= obt_parse_find_node(node
, "startupnotify"))) {
49 if ((m
= obt_parse_find_node(n
->children
, "enabled")))
50 o
->sn
= obt_parse_node_bool(m
);
51 if ((m
= obt_parse_find_node(n
->children
, "name")))
52 o
->sn_name
= obt_parse_node_string(m
);
53 if ((m
= obt_parse_find_node(n
->children
, "icon")))
54 o
->sn_icon
= obt_parse_node_string(m
);
55 if ((m
= obt_parse_find_node(n
->children
, "wmclass")))
56 o
->sn_wmclass
= obt_parse_node_string(m
);
61 static void free_func(gpointer options
)
69 g_free(o
->sn_wmclass
);
74 /* Always return FALSE because its not interactive */
75 static gboolean
run_func(ObActionsData
*data
, gpointer options
)
82 if (!o
->cmd
) return FALSE
;
83 cmd
= g_filename_from_utf8(o
->cmd
, -1, NULL
, NULL
, NULL
);
85 g_message(_("Failed to convert the path '%s' from utf8"), o
->cmd
);
89 /* If there is a keyboard grab going on then we need to cancel
90 it so the application can grab things */
91 event_cancel_all_key_grabs();
93 if (!g_shell_parse_argv(cmd
, NULL
, &argv
, &e
)) {
94 g_message(_("Failed to execute '%s': %s"), o
->cmd
, e
->message
);
98 gchar
*program
= NULL
;
101 program
= g_path_get_basename(argv
[0]);
102 /* sets up the environment */
103 sn_setup_spawn_environment(program
, o
->sn_name
, o
->sn_icon
,
104 /* launch it on the current desktop */
108 if (!g_spawn_async(NULL
, argv
, NULL
,
109 G_SPAWN_SEARCH_PATH
| G_SPAWN_DO_NOT_REAP_CHILD
,
110 NULL
, NULL
, NULL
, &e
))
112 g_message(_("Failed to execute '%s': %s"), o
->cmd
, e
->message
);
119 unsetenv("DESKTOP_STARTUP_ID");