+
+static void actions_setup_data(ObActionsData *data,
+ ObUserAction uact,
+ Time time,
+ guint state,
+ gint x,
+ gint y,
+ ObFrameContext con,
+ struct _ObClient *client)
+{
+ data->uact = uact;
+ data->time = time;
+ data->state = state;
+ data->x = x;
+ data->y = y;
+ data->context = con;
+ data->client = client;
+}
+
+void actions_run_acts(GSList *acts,
+ ObUserAction uact,
+ Time time,
+ guint state,
+ gint x,
+ gint y,
+ ObFrameContext con,
+ struct _ObClient *client)
+{
+ GSList *it;
+
+ /* Don't allow saving the initial state when running things from the
+ menu */
+ if (uact == OB_USER_ACTION_MENU_SELECTION)
+ state = 0;
+ /* If x and y are < 0 then use the current pointer position */
+ if (x < 0 && y < 0)
+ screen_pointer_pos(&x, &y);
+
+ for (it = acts; it; it = g_slist_next(it)) {
+ ObActionsData data;
+ ObActionsAct *act = it->data;
+ gboolean ok = TRUE;
+
+ actions_setup_data(&data, uact, time, state, x, y, con, client);
+
+ if (actions_act_is_interactive(act) &&
+ (!interactive_act || interactive_act->def != act->def))
+ {
+ ok = actions_interactive_begin_act(act, state);
+ }
+
+ /* fire the action's run function with this data */
+ if (ok) {
+ if (!act->def->run(&data, act->options))
+ actions_interactive_end_act();
+ else {
+ /* make sure its interactive if it returned TRUE */
+ g_assert(act->def->i_cancel && act->def->i_input);
+
+ /* no actions are run after the interactive one */
+ break;
+ }
+ }
+ }
+}
+
+gboolean actions_interactive_act_running()
+{
+ return interactive_act != NULL;
+}
+
+void actions_interactive_cancel_act()
+{
+ if (interactive_act) {
+ interactive_act->def->i_cancel(interactive_act->options);
+ actions_interactive_end_act();
+ }
+}
+
+static gboolean actions_interactive_begin_act(ObActionsAct *act, guint state)
+{
+ /* cancel the old one */
+ if (interactive_act)
+ actions_interactive_cancel_act();
+
+ if (grab_keyboard()) {
+ interactive_act = act;
+ actions_act_ref(interactive_act);
+
+ interactive_initial_state = state;
+ return TRUE;
+ }
+ else
+ return FALSE;
+}
+
+static void actions_interactive_end_act()
+{
+ if (interactive_act) {
+ ungrab_keyboard();
+
+ actions_act_unref(interactive_act);
+ interactive_act = NULL;
+ }
+}
+
+gboolean actions_interactive_input_event(XEvent *e)
+{
+ gboolean used = FALSE;
+ if (interactive_act) {
+ if (!interactive_act->def->i_input(interactive_initial_state, e,
+ interactive_act->options, &used))
+ {
+ used = TRUE; /* if it cancelled the action then it has to of
+ been used */
+ actions_interactive_end_act();
+ }
+ }
+ return used;
+}