From 314c0566371d83305d723c883884555a24cc0ad8 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Thu, 21 Jun 2007 23:57:35 +0000 Subject: [PATCH] make mouse use the new action stuff --- openbox/actions.c | 61 +++++++++++++++++++++++++++++++++++++++++++--- openbox/actions.h | 28 +++++++++++++++++---- openbox/keyboard.c | 6 ++--- openbox/keyboard.h | 6 ++--- openbox/mouse.c | 30 ++++++++++++++--------- openbox/mouse.h | 5 ++-- 6 files changed, 108 insertions(+), 28 deletions(-) diff --git a/openbox/actions.c b/openbox/actions.c index 8d523dc8..dff78f50 100644 --- a/openbox/actions.c +++ b/openbox/actions.c @@ -26,7 +26,7 @@ struct _ObActionsDefinition { guint ref; gchar *name; - gboolean allow_interactive; + ObActionsType type; ObActionsDataSetupFunc setup; ObActionsDataFreeFunc free; @@ -37,7 +37,6 @@ struct _ObActionsAct { guint ref; ObActionsDefinition *def; - gpointer options; }; @@ -63,7 +62,7 @@ void actions_shutdown(gboolean reconfig) } gboolean actions_register(const gchar *name, - gboolean allow_interactive, + ObActionsType type, ObActionsDataSetupFunc setup, ObActionsDataFreeFunc free, ObActionsRunFunc run) @@ -80,7 +79,7 @@ gboolean actions_register(const gchar *name, 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; @@ -161,3 +160,57 @@ void actions_act_unref(ObActionsAct *act) g_free(act); } } + +static void actions_setup_data(ObActionsData *data, + ObUserAction uact, + Time time, + guint state, + guint button, + gint x, + gint y) +{ + data->any.uact = uact; + data->any.time = time; + data->any.state = state; + data->any.button = button; + data->any.x = x; + data->any.y = y; +} + +void actions_run_acts(GSList *acts, + ObUserAction uact, + Time time, + guint state, + guint button, + gint x, + gint y, + ObFrameContext con, + struct _ObClient *client, + ObActionsInteractiveState interactive) +{ + 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, button, 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; + case OB_ACTION_TYPE_SELECTOR: + data.selector.interactive = interactive; + break; + default: + g_assert_not_reached(); + } + + /* fire the action's run function with this data */ + act->def->run(&data, act->options); + } +} diff --git a/openbox/actions.h b/openbox/actions.h index 548b40b5..2cafa306 100644 --- a/openbox/actions.h +++ b/openbox/actions.h @@ -20,6 +20,7 @@ #include "frame.h" #include "parser/parse.h" #include +#include typedef struct _ObActionsDefinition ObActionsDefinition; typedef struct _ObActionsAct ObActionsAct; @@ -56,21 +57,24 @@ typedef enum { OB_ACTION_TYPE_SELECTOR } ObActionsType; +/* These structures are all castable as eachother */ + struct _ObActionsAnyData { ObUserAction uact; + Time time; + guint state; + guint button; gint x; gint y; - gint button; - Time time; - - ObActionsInteractiveState interactive; }; struct _ObActionsGlobalData { + ObActionsType type; ObActionsAnyData any; }; struct _ObActionsClientData { + ObActionsType type; ObActionsAnyData any; struct _ObClient *c; @@ -78,8 +82,10 @@ struct _ObActionsClientData { }; struct _ObActionsSelectorData { + ObActionsType type; ObActionsAnyData any; + ObActionsInteractiveState interactive; GSList *actions; }; @@ -98,7 +104,7 @@ void actions_startup(gboolean reconfigure); void actions_shutdown(gboolean reconfigure); gboolean actions_register(const gchar *name, - gboolean allow_interactive, + ObActionsType type, ObActionsDataSetupFunc setup, ObActionsDataFreeFunc free, ObActionsRunFunc run); @@ -110,3 +116,15 @@ ObActionsAct* actions_parse_string(const gchar *name); void actions_act_ref(ObActionsAct *act); void actions_act_unref(ObActionsAct *act); + +/*! Pass in a GSList of ObActionsAct's to be run */ +void actions_run_acts(GSList *acts, + ObUserAction uact, + Time time, + guint state, + guint button, + gint x, + gint y, + ObFrameContext con, + struct _ObClient *client, + ObActionsInteractiveState interactive); diff --git a/openbox/keyboard.c b/openbox/keyboard.c index 7fdd1870..d9ec4f88 100644 --- a/openbox/keyboard.c +++ b/openbox/keyboard.c @@ -25,7 +25,7 @@ #include "event.h" #include "grab.h" #include "client.h" -#include "action.h" +#include "actions.h" #include "prop.h" #include "menuframe.h" #include "config.h" @@ -42,7 +42,7 @@ typedef struct { gboolean active; guint state; ObClient *client; - ObAction *action; + ObActionsAct *action; } ObInteractiveState; KeyBindingTree *keyboard_firstnode = NULL; @@ -142,7 +142,7 @@ void keyboard_chroot(GList *keylist) } } -gboolean keyboard_bind(GList *keylist, ObAction *action) +gboolean keyboard_bind(GList *keylist, ObActionsAct *action) { KeyBindingTree *tree, *t; gboolean conflict; diff --git a/openbox/keyboard.h b/openbox/keyboard.h index 95d8be32..1dfff654 100644 --- a/openbox/keyboard.h +++ b/openbox/keyboard.h @@ -27,7 +27,7 @@ #include struct _ObClient; -struct _ObActionAct; +struct _ObActionsAct; extern KeyBindingTree *keyboard_firstnode; @@ -35,7 +35,7 @@ void keyboard_startup(gboolean reconfig); void keyboard_shutdown(gboolean reconfig); void keyboard_chroot(GList *keylist); -gboolean keyboard_bind(GList *keylist, struct _ObActionAct *action); +gboolean keyboard_bind(GList *keylist, struct _ObActionsAct *action); void keyboard_unbind_all(); void keyboard_event(struct _ObClient *client, const XEvent *e); @@ -44,7 +44,7 @@ void keyboard_event(struct _ObClient *client, const XEvent *e); void keyboard_reset_chains(gint break_chroots); gboolean keyboard_interactive_grab(guint state, struct _ObClient *client, - struct _ObActionAct *action); + struct _ObActionsAct *action); gboolean keyboard_process_interactive_grab(const XEvent *e, struct _ObClient **client); gboolean keyboard_interactively_grabbed(); diff --git a/openbox/mouse.c b/openbox/mouse.c index f74063ed..f0403b97 100644 --- a/openbox/mouse.c +++ b/openbox/mouse.c @@ -20,7 +20,7 @@ #include "openbox.h" #include "config.h" #include "xerror.h" -#include "action.h" +#include "actions.h" #include "event.h" #include "client.h" #include "prop.h" @@ -156,7 +156,7 @@ void mouse_unbind_all() GSList *it; for (it = b->actions[j]; it; it = g_slist_next(it)) - action_unref(it->data); + actions_act_unref(it->data); g_slist_free(b->actions[j]); } g_free(b); @@ -166,6 +166,20 @@ void mouse_unbind_all() } } +static ObUserAction mouse_action_to_user_action(ObMouseAction a) +{ + switch (a) { + case OB_MOUSE_ACTION_PRESS: return OB_USER_ACTION_MOUSE_PRESS; + case OB_MOUSE_ACTION_RELEASE: return OB_USER_ACTION_MOUSE_RELEASE; + case OB_MOUSE_ACTION_CLICK: return OB_USER_ACTION_MOUSE_CLICK; + case OB_MOUSE_ACTION_DOUBLE_CLICK: + return OB_USER_ACTION_MOUSE_DOUBLE_CLICK; + case OB_MOUSE_ACTION_MOTION: return OB_USER_ACTION_MOUSE_MOTION; + default: + g_assert_not_reached(); + } +} + static gboolean fire_binding(ObMouseAction a, ObFrameContext context, ObClient *c, guint state, guint button, gint x, gint y, Time time) @@ -181,7 +195,8 @@ static gboolean fire_binding(ObMouseAction a, ObFrameContext context, /* if not bound, then nothing to do! */ if (it == NULL) return FALSE; - action_run_mouse(b->actions[a], c, context, state, button, x, y, time); + actions_run_acts(b->actions[a], mouse_action_to_user_action(a), + time, state, button, x, y, context, c, OB_ACTION_DONE); return TRUE; } @@ -327,7 +342,7 @@ void mouse_event(ObClient *client, XEvent *e) } gboolean mouse_bind(const gchar *buttonstr, const gchar *contextstr, - ObMouseAction mact, ObAction *action) + ObMouseAction mact, ObActionsAct *action) { guint state, button; ObFrameContext context; @@ -353,13 +368,6 @@ gboolean mouse_bind(const gchar *buttonstr, const gchar *contextstr, } } - /* when there are no modifiers in the binding, then the action cannot - be interactive */ - if (!state && action->data.any.interactive) { - action->data.any.interactive = FALSE; - action->data.inter.final = TRUE; - } - /* add the binding */ b = g_new0(ObMouseBinding, 1); b->state = state; diff --git a/openbox/mouse.h b/openbox/mouse.h index befe1296..44d563a3 100644 --- a/openbox/mouse.h +++ b/openbox/mouse.h @@ -19,17 +19,18 @@ #ifndef ob__mouse_h #define ob__mouse_h -#include "action.h" #include "frame.h" #include "misc.h" #include +struct _ObActionsAct; + void mouse_startup(gboolean reconfig); void mouse_shutdown(gboolean reconfig); gboolean mouse_bind(const gchar *buttonstr, const gchar *contextstr, - ObMouseAction mact, ObAction *action); + ObMouseAction mact, struct _ObActionsAct *action); void mouse_unbind_all(); void mouse_event(struct _ObClient *client, XEvent *e); -- 2.45.2