Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default action to execute in ForEach when none of the clien matches the query. Fixes #12 #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions openbox/actions/if.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ typedef struct {
GArray *queries;
GSList *thenacts;
GSList *elseacts;
GSList *noneacts;
} Options;

static gpointer setup_func(xmlNodePtr node);
static void free_func(gpointer options);
static gboolean run_func_if(ObActionsData *data, gpointer options);
static gboolean do_run_func_if(ObActionsData *data, gpointer options);
static gboolean run_func_stop(ObActionsData *data, gpointer options);
static gboolean run_func_foreach(ObActionsData *data, gpointer options);

Expand Down Expand Up @@ -253,6 +255,16 @@ static gpointer setup_func(xmlNodePtr node)
m = obt_xml_find_node(m->next, "action");
}
}
if ((n = obt_xml_find_node(node, "none"))) {
xmlNodePtr m;

m = obt_xml_find_node(n->children, "action");
while (m) {
ObActionsAct *action = actions_parse(m);
if (action) o->noneacts = g_slist_append(o->noneacts, action);
m = obt_xml_find_node(m->next, "action");
}
}

xmlNodePtr query_node = obt_xml_find_node(node, "query");
if (!query_node) {
Expand Down Expand Up @@ -306,13 +318,26 @@ static void free_func(gpointer options)
g_slice_free(Options, o);
}

/* Always return FALSE because its not interactive */
/*{{{ If
* Always return FALSE because its not interactive */
static gboolean run_func_if(ObActionsData *data, gpointer options)
{
do_run_func_if(data, options);

return FALSE;
}//}}}

/*{{{ Run If
* Actually performs the action and returns the result
* true - if executed "then" branch
* false - if execute "else" branch */
static gboolean do_run_func_if(ObActionsData *data, gpointer options)
{
Options *o = options;
ObClient *action_target = data->client;
gboolean is_true = TRUE;

//{{{ Run Queries
guint i;
for (i = 0; is_true && i < o->queries->len; ++i) {
Query *q = g_array_index(o->queries, Query*, i);
Expand Down Expand Up @@ -413,8 +438,9 @@ static gboolean run_func_if(ObActionsData *data, gpointer options)
if (q->client_monitor)
is_true &= client_monitor(query_target) == q->client_monitor - 1;

}
} //}}}

//{{{ Run Actions
GSList *acts;
if (is_true)
acts = o->thenacts;
Expand All @@ -424,25 +450,36 @@ static gboolean run_func_if(ObActionsData *data, gpointer options)
actions_run_acts(acts, data->uact, data->state,
data->x, data->y, data->button,
data->context, action_target);
//}}}

return FALSE;
return is_true;
}

/*}}}*/

static gboolean run_func_foreach(ObActionsData *data, gpointer options)
{
Options *o = options;
GList *it;

gboolean found = FALSE;
foreach_stop = FALSE;

for (it = client_list; it; it = g_list_next(it)) {
data->client = it->data;
run_func_if(data, options);
found = do_run_func_if(data, options);
if (foreach_stop) {
foreach_stop = FALSE;
break;
}
}

if (!found) {
actions_run_acts(o->noneacts, data->uact, data->state,
data->x, data->y, data->button,
data->context, data->client);
}

return FALSE;
}

Expand All @@ -456,3 +493,6 @@ static gboolean run_func_stop(ObActionsData *data, gpointer options)
client */
return TRUE;
}

// vim: tabstop=4 shiftwidth=4 expandtab foldmethod=marker