Continue merging kb and mouse functions: fold

mousefunc_menu_{client,cmd,group} into the respective
kbfunc_menu_{client,cmd,group} functions; simply pass a flag down from
config denoting mouse action behaviour.
This commit is contained in:
okan 2016-09-22 14:36:03 +00:00
parent 3947f1268a
commit 57b2a6cf79
4 changed files with 28 additions and 91 deletions

View File

@ -508,10 +508,6 @@ void mousefunc_client_move(struct client_ctx *,
union arg *);
void mousefunc_client_resize(struct client_ctx *,
union arg *);
void mousefunc_menu_client(struct client_ctx *,
union arg *);
void mousefunc_menu_cmd(struct client_ctx *, union arg *);
void mousefunc_menu_group(struct client_ctx *, union arg *);
struct menu *menu_filter(struct screen_ctx *, struct menu_q *,
const char *, const char *, int,

9
conf.c
View File

@ -485,9 +485,12 @@ static const struct {
{ "window_resize", mousefunc_client_resize, CWM_CONTEXT_CLIENT, {0} },
{ "window_grouptoggle", kbfunc_client_grouptoggle, CWM_CONTEXT_CLIENT,
{.i = CWM_MOUSE} },
{ "menu_group", mousefunc_menu_group, CWM_CONTEXT_SCREEN, {0} },
{ "menu_unhide", mousefunc_menu_client, CWM_CONTEXT_SCREEN, {0} },
{ "menu_cmd", mousefunc_menu_cmd, CWM_CONTEXT_SCREEN, {0} },
{ "menu_group", kbfunc_menu_group, CWM_CONTEXT_SCREEN,
{.i = CWM_MOUSE} },
{ "menu_unhide", kbfunc_menu_client, CWM_CONTEXT_SCREEN,
{.i = CWM_MOUSE} },
{ "menu_cmd", kbfunc_menu_cmd, CWM_CONTEXT_SCREEN,
{.i = CWM_MOUSE} },
};
static const struct {

View File

@ -167,14 +167,22 @@ kbfunc_menu_client(struct client_ctx *cc, union arg *arg)
struct client_ctx *old_cc;
struct menu *mi;
struct menu_q menuq;
int m = (arg->i == CWM_MOUSE);
old_cc = client_current();
TAILQ_INIT(&menuq);
TAILQ_FOREACH(cc, &sc->clientq, entry)
menuq_add(&menuq, cc, NULL);
TAILQ_FOREACH(cc, &sc->clientq, entry) {
if (m) {
if (cc->flags & CLIENT_HIDDEN)
menuq_add(&menuq, cc, NULL);
} else
menuq_add(&menuq, cc, NULL);
}
if ((mi = menu_filter(sc, &menuq, "window", NULL, 0,
if ((mi = menu_filter(sc, &menuq,
(m) ? NULL : "window", NULL,
(m) ? CWM_MENU_LIST : 0,
search_match_client, search_print_client)) != NULL) {
cc = (struct client_ctx *)mi->ctx;
if (cc->flags & CLIENT_HIDDEN)
@ -194,6 +202,7 @@ kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg)
struct cmd *cmd;
struct menu *mi;
struct menu_q menuq;
int m = (arg->i == CWM_MOUSE);
TAILQ_INIT(&menuq);
TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
@ -204,9 +213,13 @@ kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg)
menuq_add(&menuq, cmd, "%s", cmd->name);
}
if ((mi = menu_filter(sc, &menuq, "application", NULL, 0,
search_match_text, search_print_cmd)) != NULL)
u_spawn(((struct cmd *)mi->ctx)->path);
if ((mi = menu_filter(sc, &menuq,
(m) ? NULL : "application", NULL,
(m) ? CWM_MENU_LIST : 0,
search_match_text, search_print_cmd)) != NULL) {
cmd = (struct cmd *)mi->ctx;
u_spawn(cmd->path);
}
menuq_clear(&menuq);
}
@ -218,6 +231,7 @@ kbfunc_menu_group(struct client_ctx *cc, union arg *arg)
struct group_ctx *gc;
struct menu *mi;
struct menu_q menuq;
int m = (arg->i == CWM_MOUSE);
TAILQ_INIT(&menuq);
TAILQ_FOREACH(gc, &sc->groupq, entry) {
@ -226,7 +240,8 @@ kbfunc_menu_group(struct client_ctx *cc, union arg *arg)
menuq_add(&menuq, gc, "%d %s", gc->num, gc->name);
}
if ((mi = menu_filter(sc, &menuq, "group", NULL, CWM_MENU_LIST,
if ((mi = menu_filter(sc, &menuq,
(m) ? NULL : "group", NULL, CWM_MENU_LIST,
search_match_text, search_print_group)) != NULL) {
gc = (struct group_ctx *)mi->ctx;
(group_holds_only_hidden(gc)) ?

View File

@ -155,80 +155,3 @@ mousefunc_client_move(struct client_ctx *cc, union arg *arg)
}
/* NOTREACHED */
}
void
mousefunc_menu_group(struct client_ctx *cc, union arg *arg)
{
struct screen_ctx *sc = cc->sc;
struct group_ctx *gc;
struct menu *mi;
struct menu_q menuq;
TAILQ_INIT(&menuq);
TAILQ_FOREACH(gc, &sc->groupq, entry) {
if (group_holds_only_sticky(gc))
continue;
menuq_add(&menuq, gc, "%d %s", gc->num, gc->name);
}
if ((mi = menu_filter(sc, &menuq, NULL, NULL, CWM_MENU_LIST,
NULL, search_print_group)) != NULL) {
gc = (struct group_ctx *)mi->ctx;
(group_holds_only_hidden(gc)) ?
group_show(gc) : group_hide(gc);
}
menuq_clear(&menuq);
}
void
mousefunc_menu_client(struct client_ctx *cc, union arg *arg)
{
struct screen_ctx *sc = cc->sc;
struct client_ctx *old_cc;
struct menu *mi;
struct menu_q menuq;
old_cc = client_current();
TAILQ_INIT(&menuq);
TAILQ_FOREACH(cc, &sc->clientq, entry) {
if (cc->flags & CLIENT_HIDDEN) {
menuq_add(&menuq, cc, NULL);
}
}
if ((mi = menu_filter(sc, &menuq, NULL, NULL, CWM_MENU_LIST,
NULL, search_print_client)) != NULL) {
cc = (struct client_ctx *)mi->ctx;
client_unhide(cc);
if (old_cc != NULL)
client_ptrsave(old_cc);
client_ptrwarp(cc);
}
menuq_clear(&menuq);
}
void
mousefunc_menu_cmd(struct client_ctx *cc, union arg *arg)
{
struct screen_ctx *sc = cc->sc;
struct cmd *cmd;
struct menu *mi;
struct menu_q menuq;
TAILQ_INIT(&menuq);
TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
if ((strcmp(cmd->name, "lock") == 0) ||
(strcmp(cmd->name, "term") == 0))
continue;
menuq_add(&menuq, cmd, NULL);
}
if ((mi = menu_filter(sc, &menuq, NULL, NULL, CWM_MENU_LIST,
NULL, search_print_cmd)) != NULL)
u_spawn(((struct cmd *)mi->ctx)->path);
menuq_clear(&menuq);
}