Skip to content

Commit

Permalink
cvsimport
Browse files Browse the repository at this point in the history
  • Loading branch information
okan committed Jul 12, 2015
2 parents 6716719 + 0d13b7c commit c0f2d0c
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 59 deletions.
2 changes: 2 additions & 0 deletions calmwm.h
Expand Up @@ -471,6 +471,7 @@ void search_match_text(struct menu_q *, struct menu_q *,
char *);
void search_print_client(struct menu *, int);
void search_print_cmd(struct menu *, int);
void search_print_group(struct menu *, int);

struct geom screen_apply_gap(struct screen_ctx *, struct geom);
struct screen_ctx *screen_find(Window);
Expand Down Expand Up @@ -517,6 +518,7 @@ void kbfunc_cwm_status(struct client_ctx *, union arg *);
void kbfunc_exec(struct client_ctx *, union arg *);
void kbfunc_lock(struct client_ctx *, union arg *);
void kbfunc_menu_cmd(struct client_ctx *, union arg *);
void kbfunc_menu_group(struct client_ctx *, union arg *);
void kbfunc_ssh(struct client_ctx *, union arg *);
void kbfunc_term(struct client_ctx *, union arg *);
void kbfunc_tile(struct client_ctx *, union arg *);
Expand Down
8 changes: 4 additions & 4 deletions client.c
Expand Up @@ -655,15 +655,15 @@ client_cycle(struct screen_ctx *sc, int flags)

oldcc = client_current();
if (oldcc == NULL)
oldcc = (flags & CWM_RCYCLE ?
oldcc = ((flags & CWM_RCYCLE) ?
TAILQ_LAST(&sc->clientq, client_ctx_q) :
TAILQ_FIRST(&sc->clientq));

newcc = oldcc;
while (again) {
again = 0;

newcc = (flags & CWM_RCYCLE ? client_prev(newcc) :
newcc = ((flags & CWM_RCYCLE) ? client_prev(newcc) :
client_next(newcc));

/* Only cycle visible and non-ignored windows. */
Expand Down Expand Up @@ -707,7 +707,7 @@ client_next(struct client_ctx *cc)
struct screen_ctx *sc = cc->sc;
struct client_ctx *ccc;

return((ccc = TAILQ_NEXT(cc, entry)) != NULL ?
return(((ccc = TAILQ_NEXT(cc, entry)) != NULL) ?
ccc : TAILQ_FIRST(&sc->clientq));
}

Expand All @@ -717,7 +717,7 @@ client_prev(struct client_ctx *cc)
struct screen_ctx *sc = cc->sc;
struct client_ctx *ccc;

return((ccc = TAILQ_PREV(cc, client_ctx_q, entry)) != NULL ?
return(((ccc = TAILQ_PREV(cc, client_ctx_q, entry)) != NULL) ?
ccc : TAILQ_LAST(&sc->clientq, client_ctx_q));
}

Expand Down
5 changes: 3 additions & 2 deletions conf.c
Expand Up @@ -346,8 +346,8 @@ conf_client(struct client_ctx *cc)
}
}

cc->bwidth = ignore ? 0 : Conf.bwidth;
cc->flags |= ignore ? CLIENT_IGNORE : 0;
cc->bwidth = (ignore) ? 0 : Conf.bwidth;
cc->flags |= (ignore) ? CLIENT_IGNORE : 0;
}

static const struct {
Expand All @@ -360,6 +360,7 @@ static const struct {
{ "raise", kbfunc_client_raise, CWM_WIN, {0} },
{ "search", kbfunc_client_search, 0, {0} },
{ "menusearch", kbfunc_menu_cmd, 0, {0} },
{ "groupsearch", kbfunc_menu_group, 0, {0} },
{ "hide", kbfunc_client_hide, CWM_WIN, {0} },
{ "cycle", kbfunc_client_cycle, 0, {.i = CWM_CYCLE} },
{ "rcycle", kbfunc_client_cycle, 0, {.i = CWM_RCYCLE} },
Expand Down
2 changes: 2 additions & 0 deletions cwmrc.5
Expand Up @@ -251,6 +251,8 @@ Lock the screen.
Launch window search menu.
.It menusearch
Launch application search menu.
.It groupsearch
Launch group search menu.
.It exec
Launch
.Dq exec program
Expand Down
27 changes: 26 additions & 1 deletion kbfunc.c
Expand Up @@ -178,7 +178,7 @@ kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg)

TAILQ_INIT(&menuq);
TAILQ_FOREACH(cmd, &Conf.cmdq, entry)
menuq_add(&menuq, cmd, NULL);
menuq_add(&menuq, cmd, "%s", cmd->name);

if ((mi = menu_filter(sc, &menuq, "application", NULL, 0,
search_match_text, search_print_cmd)) != NULL)
Expand All @@ -187,6 +187,31 @@ kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg)
menuq_clear(&menuq);
}

void
kbfunc_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, "group", NULL, CWM_MENU_LIST,
search_match_text, 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
kbfunc_client_cycle(struct client_ctx *cc, union arg *arg)
{
Expand Down
28 changes: 10 additions & 18 deletions menu.c
Expand Up @@ -359,18 +359,14 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq)
}

TAILQ_FOREACH(mi, resultq, resultentry) {
char *text;

if (mc->print != NULL) {
if (mc->print != NULL)
(*mc->print)(mi, mc->listing);
text = mi->print;
} else {
mi->print[0] = '\0';
text = mi->text;
}
else
(void)snprintf(mi->print, sizeof(mi->print),
"%s", mi->text);

mc->geom.w = MAX(mc->geom.w, xu_xft_width(sc->xftfont, text,
MIN(strlen(text), MENU_MAXENTRY)));
mc->geom.w = MAX(mc->geom.w, xu_xft_width(sc->xftfont,
mi->print, MIN(strlen(mi->print), MENU_MAXENTRY)));
mc->geom.h += sc->xftfont->height + 1;
mc->num++;
}
Expand Down Expand Up @@ -411,15 +407,13 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq)
n = 0;

TAILQ_FOREACH(mi, resultq, resultentry) {
char *text = mi->print[0] != '\0' ?
mi->print : mi->text;
int y = n * (sc->xftfont->height + 1) + sc->xftfont->ascent + 1;

/* Stop drawing when menu doesn't fit inside the screen. */
if (mc->geom.y + y > area.h)
break;

xu_xft_draw(sc, text, CWM_COLOR_MENU_FONT, 0, y);
xu_xft_draw(sc, mi->print, CWM_COLOR_MENU_FONT, 0, y);
n++;
}
if (mc->hasprompt && n > 1)
Expand All @@ -432,7 +426,6 @@ menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq,
{
struct screen_ctx *sc = mc->sc;
struct menu *mi;
char *text;
int color, i = 0;

if (mc->hasprompt)
Expand All @@ -444,13 +437,12 @@ menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq,
if (mi == NULL)
return;

color = active ? CWM_COLOR_MENU_FG : CWM_COLOR_MENU_BG;
text = mi->print[0] != '\0' ? mi->print : mi->text;
color = (active) ? CWM_COLOR_MENU_FG : CWM_COLOR_MENU_BG;
XftDrawRect(sc->xftdraw, &sc->xftcolor[color], 0,
(sc->xftfont->height + 1) * entry, mc->geom.w,
(sc->xftfont->height + 1) + sc->xftfont->descent);
color = active ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT;
xu_xft_draw(sc, text, color,
color = (active) ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT;
xu_xft_draw(sc, mi->print, color,
0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1);
}

Expand Down
10 changes: 4 additions & 6 deletions mousefunc.c
Expand Up @@ -43,8 +43,8 @@ mousefunc_sweep_calc(struct client_ctx *cc, int x, int y, int mx, int my)

client_applysizehints(cc);

cc->geom.x = x <= mx ? x : x - cc->geom.w;
cc->geom.y = y <= my ? y : y - cc->geom.h;
cc->geom.x = (x <= mx) ? x : x - cc->geom.w;
cc->geom.y = (y <= my) ? y : y - cc->geom.h;
}

static void
Expand Down Expand Up @@ -182,13 +182,11 @@ mousefunc_menu_group(struct client_ctx *cc, union arg *arg)
TAILQ_FOREACH(gc, &sc->groupq, entry) {
if (group_holds_only_sticky(gc))
continue;
menuq_add(&menuq, gc,
group_holds_only_hidden(gc) ? "%d: [%s]" : "%d: %s",
gc->num, gc->name);
menuq_add(&menuq, gc, "%d %s", gc->num, gc->name);
}

if ((mi = menu_filter(sc, &menuq, NULL, NULL, CWM_MENU_LIST,
NULL, NULL)) != NULL) {
NULL, search_print_group)) != NULL) {
gc = (struct group_ctx *)mi->ctx;
(group_holds_only_hidden(gc)) ?
group_show(gc) : group_hide(gc);
Expand Down
41 changes: 14 additions & 27 deletions search.c
Expand Up @@ -134,7 +134,17 @@ search_print_cmd(struct menu *mi, int i)
special = 1;

(void)snprintf(mi->print, sizeof(mi->print),
(special) ? "[%s]" : "%s", cmd->name);
(special) ? "[%s]" : "%s", cmd->name);
}

void
search_print_group(struct menu *mi, int i)
{
struct group_ctx *gc = (struct group_ctx *)mi->ctx;

(void)snprintf(mi->print, sizeof(mi->print),
(group_holds_only_hidden(gc)) ? "%d: [%s]" : "%d: %s",
gc->num, gc->name);
}

void
Expand All @@ -148,35 +158,12 @@ search_print_client(struct menu *mi, int list)
else if (cc->flags & CLIENT_HIDDEN)
flag = '&';

if (list)
if ((list) || (cc->matchname == cc->label))
cc->matchname = cc->name;

(void)snprintf(mi->print, sizeof(mi->print), "(%d) %c[%s] %s",
cc->group ? cc->group->num : 0, flag,
cc->label ? cc->label : "", cc->matchname);

if (!list && cc->matchname != cc->name &&
strlen(mi->print) < sizeof(mi->print) - 1) {
const char *marker = "";
char buf[MENU_MAXENTRY + 1];
int diff;

diff = sizeof(mi->print) - 1 - strlen(mi->print);

/* One for the ':' */
diff -= 1;

if (strlen(cc->name) > diff) {
marker = "..";
diff -= 2;
} else {
diff = strlen(cc->name);
}

(void)strlcpy(buf, mi->print, sizeof(buf));
(void)snprintf(mi->print, sizeof(mi->print),
"%s:%.*s%s", buf, diff, cc->name, marker);
}
(cc->group) ? cc->group->num : 0, flag,
(cc->label) ? cc->label : "", cc->matchname);
}

static void
Expand Down
2 changes: 1 addition & 1 deletion xevents.c
Expand Up @@ -279,7 +279,7 @@ xev_handle_keypress(XEvent *ee)
if ((kb->modmask | modshift) != e->state)
continue;

if (kb->press.keysym == (modshift == 0 ? keysym : skeysym))
if (kb->press.keysym == ((modshift == 0) ? keysym : skeysym))
break;
}

Expand Down

0 comments on commit c0f2d0c

Please sign in to comment.