From: Dana Jansens Date: Fri, 22 Jun 2007 03:40:01 +0000 (+0000) Subject: the execute action works again. X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=b76ec18d1c8857cf32598c822364298fc535c84e;p=chaz%2Fopenbox the execute action works again. default hardcoded bindings are temporarily offline --- diff --git a/Makefile.am b/Makefile.am index 0ebc9aad..222eefd3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -154,6 +154,9 @@ openbox_openbox_LDADD = \ openbox_openbox_LDFLAGS = -export-dynamic openbox_openbox_SOURCES = \ gettext.h \ + openbox/actions/all.c \ + openbox/actions/all.h \ + openbox/actions/execute.c \ openbox/actions.c \ openbox/actions.h \ openbox/client.c \ diff --git a/openbox/action.c b/openbox/action.c index 4268987f..df3037da 100644 --- a/openbox/action.c +++ b/openbox/action.c @@ -1248,59 +1248,6 @@ void action_debug(union ActionData *data) void action_execute(union ActionData *data) { - GError *e = NULL; - gchar *cmd, **argv = 0; - if (data->execute.path) { - cmd = g_filename_from_utf8(data->execute.path, -1, NULL, NULL, NULL); - if (cmd) { - /* If there is a keyboard grab going on then we need to cancel - it so the application can grab things */ - event_cancel_all_key_grabs(); - - if (!g_shell_parse_argv (cmd, NULL, &argv, &e)) { - g_message(_("Failed to execute '%s': %s"), - cmd, e->message); - g_error_free(e); - } else if (data->execute.startupnotify) { - gchar *program; - - program = g_path_get_basename(argv[0]); - /* sets up the environment */ - sn_setup_spawn_environment(program, - data->execute.name, - data->execute.icon_name, - /* launch it on the current - desktop */ - screen_desktop, - data->execute.any.time); - if (!g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH | - G_SPAWN_DO_NOT_REAP_CHILD, - NULL, NULL, NULL, &e)) { - g_message(_("Failed to execute '%s': %s"), - cmd, e->message); - g_error_free(e); - sn_spawn_cancel(); - } - unsetenv("DESKTOP_STARTUP_ID"); - g_free(program); - g_strfreev(argv); - } else { - if (!g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH | - G_SPAWN_DO_NOT_REAP_CHILD, - NULL, NULL, NULL, &e)) - { - g_message(_("Failed to execute '%s': %s"), - cmd, e->message); - g_error_free(e); - } - g_strfreev(argv); - } - g_free(cmd); - } else { - g_message(_("Failed to convert the path '%s' from utf8"), - data->execute.path); - } - } } void action_activate(union ActionData *data) diff --git a/openbox/actions.c b/openbox/actions.c index 00563a70..44a39cb5 100644 --- a/openbox/actions.c +++ b/openbox/actions.c @@ -21,6 +21,8 @@ #include "grab.h" #include "screen.h" +#include "actions/all.h" + static void actions_definition_ref(ObActionsDefinition *def); static void actions_definition_unref(ObActionsDefinition *def); static gboolean actions_interactive_begin_act(ObActionsAct *act, guint state); @@ -33,7 +35,6 @@ struct _ObActionsDefinition { guint ref; gchar *name; - ObActionsType type; ObActionsDataSetupFunc setup; ObActionsDataFreeFunc free; @@ -55,6 +56,8 @@ static GSList *registered = NULL; void actions_startup(gboolean reconfig) { if (reconfig) return; + + action_all_startup(); } void actions_shutdown(gboolean reconfig) @@ -71,7 +74,6 @@ void actions_shutdown(gboolean reconfig) } gboolean actions_register(const gchar *name, - ObActionsType type, ObActionsDataSetupFunc setup, ObActionsDataFreeFunc free, ObActionsRunFunc run, @@ -92,12 +94,14 @@ gboolean actions_register(const gchar *name, def = g_new(ObActionsDefinition, 1); def->ref = 1; def->name = g_strdup(name); - def->type = type; def->setup = setup; def->free = free; def->run = run; def->i_input = i_input; def->i_cancel = i_cancel; + + registered = g_slist_prepend(registered, def); + return TRUE; } @@ -117,7 +121,7 @@ static void actions_definition_unref(ObActionsDefinition *def) ObActionsAct* actions_parse_string(const gchar *name) { GSList *it; - ObActionsDefinition *def; + ObActionsDefinition *def = NULL; ObActionsAct *act = NULL; /* find the requested action */ @@ -152,7 +156,7 @@ ObActionsAct* actions_parse(ObParseInst *i, if (parse_attr_string("name", node, &name)) { if ((act = actions_parse_string(name))) /* there is more stuff to parse here */ - act->options = act->def->setup(i, doc, node->children); + act->options = act->def->setup(i, doc, node->xmlChildrenNode); g_free(name); } @@ -186,13 +190,17 @@ static void actions_setup_data(ObActionsData *data, Time time, guint state, gint x, - gint y) + gint y, + ObFrameContext con, + struct _ObClient *client) { - data->any.uact = uact; - data->any.time = time; - data->any.state = state; - data->any.x = x; - data->any.y = y; + 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, @@ -219,18 +227,7 @@ void actions_run_acts(GSList *acts, ObActionsAct *act = it->data; gboolean ok = TRUE; - 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(); - } + actions_setup_data(&data, uact, time, state, x, y, con, client); if (actions_act_is_interactive(act) && (!interactive_act || interactive_act->def != act->def)) @@ -242,8 +239,13 @@ void actions_run_acts(GSList *acts, if (ok) { if (!act->def->run(&data, act->options)) actions_interactive_end_act(); - else - break; /* no actions are run after the interactive one */ + 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; + } } } } diff --git a/openbox/actions.h b/openbox/actions.h index df304130..3db6d792 100644 --- a/openbox/actions.h +++ b/openbox/actions.h @@ -41,51 +41,23 @@ typedef gboolean (*ObActionsInteractiveInputFunc)(guint initial_state, gboolean *used); typedef void (*ObActionsInteractiveCancelFunc)(gpointer options); -typedef enum { - OB_ACTION_TYPE_GLOBAL, - OB_ACTION_TYPE_CLIENT -} ObActionsType; - -/* These structures are all castable as eachother */ - -struct _ObActionsAnyData { +struct _ObActionsData { ObUserAction uact; Time time; guint state; gint x; gint y; -}; - -struct _ObActionsGlobalData { - ObActionsType type; - ObActionsAnyData any; -}; -struct _ObActionsClientData { - ObActionsType type; - ObActionsAnyData any; - - struct _ObClient *c; + struct _ObClient *client; ObFrameContext context; }; -struct _ObActionsData { - ObActionsType type; - - union { - ObActionsAnyData any; - ObActionsGlobalData global; - ObActionsClientData client; - }; -}; - void actions_startup(gboolean reconfigure); void actions_shutdown(gboolean reconfigure); /*! If the action is interactive, then i_input and i_cancel are not NULL. Otherwise, they should both be NULL. */ gboolean actions_register(const gchar *name, - ObActionsType type, ObActionsDataSetupFunc setup, ObActionsDataFreeFunc free, ObActionsRunFunc run, diff --git a/openbox/actions/Makefile b/openbox/actions/Makefile new file mode 100644 index 00000000..b90edacf --- /dev/null +++ b/openbox/actions/Makefile @@ -0,0 +1,4 @@ +all clean install: + $(MAKE) -C .. -$(MAKEFLAGS) $@ + +.PHONY: all clean install diff --git a/openbox/actions/all.c b/openbox/actions/all.c new file mode 100644 index 00000000..7c0b253e --- /dev/null +++ b/openbox/actions/all.c @@ -0,0 +1,6 @@ +#include "all.h" + +void action_all_startup() +{ + action_execute_startup(); +} diff --git a/openbox/actions/all.h b/openbox/actions/all.h new file mode 100644 index 00000000..599c29fc --- /dev/null +++ b/openbox/actions/all.h @@ -0,0 +1,8 @@ +#ifndef __actions_all_h +#define __actions_all_h + +void action_all_startup(); + +void action_execute_startup(); + +#endif diff --git a/openbox/actions/execute.c b/openbox/actions/execute.c new file mode 100644 index 00000000..606bb153 --- /dev/null +++ b/openbox/actions/execute.c @@ -0,0 +1,130 @@ +#include "openbox/actions.h" +#include "openbox/event.h" +#include "openbox/startupnotify.h" +#include "openbox/screen.h" +#include "gettext.h" + +typedef struct { + gchar *cmd; + gboolean sn; + gchar *sn_name; + gchar *sn_icon; + gchar *sn_wmclass; +} Options; + +static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node); +static void free_func(gpointer options); +static gboolean run_func(ObActionsData *data, gpointer options); +/* +static gboolean i_input_func(guint initial_state, + XEvent *e, + gpointer options, + gboolean *used); +static void i_cancel_func(gpointer options); +*/ + +void action_execute_startup() +{ + actions_register("Execute", + setup_func, + free_func, + run_func, + NULL, NULL); +} + +static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node) +{ + xmlNodePtr n; + Options *o; + + o = g_new0(Options, 1); + + if ((n = parse_find_node("execute", node))) { + gchar *s = parse_string(doc, n); + o->cmd = parse_expand_tilde(s); + g_free(s); + } + + if ((n = parse_find_node("startupnotify", node))) { + xmlNodePtr m; + if ((m = parse_find_node("enabled", n->xmlChildrenNode))) + o->sn = parse_bool(doc, m); + if ((m = parse_find_node("name", n->xmlChildrenNode))) + o->sn_name = parse_string(doc, m); + if ((m = parse_find_node("icon", n->xmlChildrenNode))) + o->sn_icon = parse_string(doc, m); + if ((m = parse_find_node("wmclass", n->xmlChildrenNode))) + o->sn_wmclass = parse_string(doc, m); + } + return o; +} + +static void free_func(gpointer options) +{ + Options *o = options; + + if (o) { + g_free(o->cmd); + g_free(o->sn_name); + g_free(o->sn_icon); + g_free(o->sn_wmclass); + g_free(o); + } +} + +/* Always return FALSE because its not interactive */ +static gboolean run_func(ObActionsData *data, gpointer options) +{ + GError *e = NULL; + gchar **argv = NULL; + gchar *cmd; + Options *o = options; + + if (!o->cmd) return FALSE; + cmd = g_filename_from_utf8(o->cmd, -1, NULL, NULL, NULL); + if (!cmd) { + g_message(_("Failed to convert the path '%s' from utf8"), o->cmd); + return FALSE; + } + + /* If there is a keyboard grab going on then we need to cancel + it so the application can grab things */ + event_cancel_all_key_grabs(); + + if (!g_shell_parse_argv(cmd, NULL, &argv, &e)) { + g_message(_("Failed to execute '%s': %s"), o->cmd, e->message); + g_error_free(e); + } + else { + gchar *program = NULL; + + if (o->sn) { + program = g_path_get_basename(argv[0]); + /* sets up the environment */ + sn_setup_spawn_environment(program, o->sn_name, o->sn_icon, + /* launch it on the current desktop */ + screen_desktop, + data->time); + } + + if (!g_spawn_async(NULL, argv, NULL, + G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, + NULL, NULL, NULL, &e)) + { + g_message(_("Failed to execute '%s': %s"), o->cmd, e->message); + g_error_free(e); + + if (o->sn) + sn_spawn_cancel(); + } + if (o->sn) + unsetenv("DESKTOP_STARTUP_ID"); + + g_free(program); + g_strfreev(argv); + } + + g_free(cmd); + + return FALSE; +} diff --git a/openbox/config.c b/openbox/config.c index 48df2e79..7f51e7c8 100644 --- a/openbox/config.c +++ b/openbox/config.c @@ -764,6 +764,7 @@ static void bind_default_keyboard() { ObDefKeyBind *it; ObDefKeyBind binds[] = { + { NULL, NULL }, { "A-Tab", "NextWindow" }, { "S-A-Tab", "PreviousWindow" }, { "A-F4", "Close" }, @@ -789,6 +790,7 @@ static void bind_default_mouse() { ObDefMouseBind *it; ObDefMouseBind binds[] = { + { NULL, NULL, 0, NULL }, { "Left", "Client", OB_MOUSE_ACTION_PRESS, "Focus" }, { "Middle", "Client", OB_MOUSE_ACTION_PRESS, "Focus" }, { "Right", "Client", OB_MOUSE_ACTION_PRESS, "Focus" }, diff --git a/openbox/openbox.c b/openbox/openbox.c index db14afb0..250ca6d0 100644 --- a/openbox/openbox.c +++ b/openbox/openbox.c @@ -240,10 +240,10 @@ gint main(gint argc, gchar **argv) of the rc */ i = parse_startup(); - /* start up config which sets up with the parser */ - config_startup(i); /* register all the available actions */ actions_startup(reconfigure); + /* start up config which sets up with the parser */ + config_startup(i); /* parse/load user options */ if (parse_load_rc(NULL, &doc, &node)) { @@ -376,8 +376,8 @@ gint main(gint argc, gchar **argv) sn_shutdown(reconfigure); window_shutdown(reconfigure); event_shutdown(reconfigure); - actions_shutdown(reconfigure); config_shutdown(); + actions_shutdown(reconfigure); modkeys_shutdown(reconfigure); } while (reconfigure); } diff --git a/po/POTFILES.in b/po/POTFILES.in index 46c13af9..8146eda9 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,5 +1,5 @@ # List of source files containing translatable strings. -openbox/action.c +openbox/actions/execute.c openbox/client_list_combined_menu.c openbox/client_list_menu.c openbox/client_menu.c