X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Faction.c;h=daa18ad18cf9ff590023994544d9ca087809414b;hb=eb51015bc39dead34d041ab48fec51a56ba99e7a;hp=bef8768039d80488527029dfc92fcd833a0f008e;hpb=11615ac2c4576d6c3e0db20e8b62375184d374db;p=chaz%2Fopenbox diff --git a/openbox/action.c b/openbox/action.c index bef87680..daa18ad1 100644 --- a/openbox/action.c +++ b/openbox/action.c @@ -30,6 +30,7 @@ #include "keyboard.h" #include "event.h" #include "config.h" +#include "mainloop.h" #include @@ -65,19 +66,26 @@ typedef struct void (*setup)(ObAction **, ObUserAction uact); } ActionString; -static ObAction *action_new(void (*func)(union ActionData *data), - ObUserAction uact) +static ObAction *action_new(void (*func)(union ActionData *data)) { ObAction *a = g_new0(ObAction, 1); + a->ref = 1; a->func = func; return a; } -void action_free(ObAction *a) +void action_ref(ObAction *a) +{ + ++a->ref; +} + +void action_unref(ObAction *a) { if (a == NULL) return; + if (--a->ref > 0) return; + /* deal with pointers */ if (a->func == action_execute || a->func == action_restart) g_free(a->data.execute.path); @@ -87,6 +95,21 @@ void action_free(ObAction *a) g_free(a); } +ObAction* action_copy(const ObAction *src) +{ + ObAction *a = action_new(src->func); + + a->data = src->data; + + /* deal with pointers */ + if (a->func == action_execute || a->func == action_restart) + a->data.execute.path = g_strdup(a->data.execute.path); + else if (a->func == action_showmenu) + a->data.showmenu.name = g_strdup(a->data.showmenu.name); + + return a; +} + void setup_action_directional_focus_north(ObAction **a, ObUserAction uact) { (*a)->data.interdiraction.inter.any.interactive = TRUE; @@ -339,7 +362,8 @@ void setup_action_move(ObAction **a, ObUserAction uact) (*a)->data.moveresize.any.client_action = OB_CLIENT_ACTION_ALWAYS; (*a)->data.moveresize.move = TRUE; (*a)->data.moveresize.keyboard = - (uact == OB_USER_ACTION_KEYBOARD_KEY || + (uact == OB_USER_ACTION_NONE || + uact == OB_USER_ACTION_KEYBOARD_KEY || uact == OB_USER_ACTION_MENU_SELECTION); } @@ -348,7 +372,8 @@ void setup_action_resize(ObAction **a, ObUserAction uact) (*a)->data.moveresize.any.client_action = OB_CLIENT_ACTION_ALWAYS; (*a)->data.moveresize.move = FALSE; (*a)->data.moveresize.keyboard = - (uact == OB_USER_ACTION_KEYBOARD_KEY || + (uact == OB_USER_ACTION_NONE || + uact == OB_USER_ACTION_KEYBOARD_KEY || uact == OB_USER_ACTION_MENU_SELECTION); } @@ -359,7 +384,7 @@ void setup_action_showmenu(ObAction **a, ObUserAction uact) assumptions that there is only one menu (and submenus) open at a time! */ if (uact == OB_USER_ACTION_MENU_SELECTION) { - action_free(*a); + action_unref(*a); a = NULL; } } @@ -772,7 +797,7 @@ ObAction *action_from_string(const gchar *name, ObUserAction uact) for (i = 0; actionstrings[i].name; i++) if (!g_ascii_strcasecmp(name, actionstrings[i].name)) { exist = TRUE; - a = action_new(actionstrings[i].func, uact); + a = action_new(actionstrings[i].func); if (actionstrings[i].setup) actionstrings[i].setup(&a, uact); /* only key bindings can be interactive. thus saith the xor. @@ -896,11 +921,24 @@ void action_run_list(GSList *acts, ObClient *c, ObFrameContext context, keyboard_interactive_grab(state, a->data.any.c, a); } - a->func(&a->data); + ob_main_loop_queue_action(ob_main_loop, a); } } } +void action_run_string(const gchar *name, struct _ObClient *c) +{ + ObAction *a; + GSList *l; + + a = action_from_string(name, OB_USER_ACTION_NONE); + g_assert(a); + + l = g_slist_append(NULL, a); + + action_run(l, c, 0); +} + void action_execute(union ActionData *data) { GError *e = NULL;