]> Dogcows Code - chaz/openbox/blobdiff - openbox/actions.c
add interactive action functions. some other changes to stuff that wasnt going to...
[chaz/openbox] / openbox / actions.c
index 8d523dc8b2f83d01bb5d8269746e5c39a587d1bd..c516969e11cde635119e9c691ac349838b7d6835 100644 (file)
@@ -26,18 +26,19 @@ struct _ObActionsDefinition {
     guint ref;
 
     gchar *name;
-    gboolean allow_interactive;
+    ObActionsType type;
 
     ObActionsDataSetupFunc setup;
     ObActionsDataFreeFunc free;
     ObActionsRunFunc run;
+    ObActionsInteractiveInputFunc i_input;
+    ObActionsInteractiveCancelFunc i_cancel;
 };
 
 struct _ObActionsAct {
     guint ref;
 
     ObActionsDefinition *def;
-
     gpointer options;
 };
 
@@ -63,10 +64,12 @@ void actions_shutdown(gboolean reconfig)
 }
 
 gboolean actions_register(const gchar *name,
-                          gboolean allow_interactive,
+                          ObActionsType type,
                           ObActionsDataSetupFunc setup,
                           ObActionsDataFreeFunc free,
-                          ObActionsRunFunc run)
+                          ObActionsRunFunc run,
+                          ObActionsInteractiveInputFunc i_input,
+                          ObActionsInteractiveCancelFunc i_cancel)
 {
     GSList *it;
     ObActionsDefinition *def;
@@ -77,13 +80,17 @@ gboolean actions_register(const gchar *name,
             return FALSE;
     }
 
+    g_assert((i_input == NULL) == (i_cancel == NULL));
+
     def = g_new(ObActionsDefinition, 1);
     def->ref = 1;
     def->name = g_strdup(name);
-    def->allow_interactive = allow_interactive;
+    def->type = type;
     def->setup = setup;
     def->free = free;
     def->run = run;
+    def->i_input = i_input;
+    def->i_cancel = i_cancel;
     return TRUE;
 }
 
@@ -146,6 +153,11 @@ ObActionsAct* actions_parse(ObParseInst *i,
     return act;
 }
 
+gboolean actions_act_is_interactive(ObActionsAct *act)
+{
+    return act->def->i_cancel != NULL;
+}
+
 void actions_act_ref(ObActionsAct *act)
 {
     ++act->ref;
@@ -161,3 +173,50 @@ void actions_act_unref(ObActionsAct *act)
         g_free(act);
     }
 }
+
+static void actions_setup_data(ObActionsData *data,
+                               ObUserAction uact,
+                               Time time,
+                               guint state,
+                               gint x,
+                               gint y)
+{
+    data->any.uact = uact;
+    data->any.time = time;
+    data->any.state = state;
+    data->any.x = x;
+    data->any.y = y;
+}
+
+void actions_run_acts(GSList *acts,
+                      ObUserAction uact,
+                      Time time,
+                      guint state,
+                      gint x,
+                      gint y,
+                      ObFrameContext con,
+                      struct _ObClient *client)
+{
+    GSList *it;
+
+    for (it = acts; it; it = g_slist_next(it)) {
+        ObActionsData data;
+        ObActionsAct *act = it->data;
+
+        data.type = act->def->type;
+        actions_setup_data(&data, uact, time, state, x, y);
+        switch (data.type) {
+        case OB_ACTION_TYPE_GLOBAL:
+            break;
+        case OB_ACTION_TYPE_CLIENT:
+            data.client.context = con;
+            data.client.c = client;
+            break;
+        default:
+            g_assert_not_reached();
+        }
+
+        /* fire the action's run function with this data */
+        act->def->run(&data, act->options);
+    }
+}
This page took 0.026937 seconds and 4 git commands to generate.