the execute action works again.

default hardcoded bindings are temporarily offline
This commit is contained in:
Dana Jansens 2007-06-22 03:40:01 +00:00
parent 780d1b0961
commit b76ec18d1c
11 changed files with 186 additions and 112 deletions

View file

@ -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 \

View file

@ -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)

View file

@ -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;
}
}
}
}

View file

@ -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,

4
openbox/actions/Makefile Normal file
View file

@ -0,0 +1,4 @@
all clean install:
$(MAKE) -C .. -$(MAKEFLAGS) $@
.PHONY: all clean install

6
openbox/actions/all.c Normal file
View file

@ -0,0 +1,6 @@
#include "all.h"
void action_all_startup()
{
action_execute_startup();
}

8
openbox/actions/all.h Normal file
View file

@ -0,0 +1,8 @@
#ifndef __actions_all_h
#define __actions_all_h
void action_all_startup();
void action_execute_startup();
#endif

130
openbox/actions/execute.c Normal file
View file

@ -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;
}

View file

@ -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" },

View file

@ -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);
}

View file

@ -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