clean up search_match_client(); no behaviour change

This commit is contained in:
okan 2016-10-22 19:16:43 +00:00
parent 0bb1be86c6
commit b1af1bedd0

View File

@ -52,25 +52,17 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search)
(void)memset(tierp, 0, sizeof(tierp)); (void)memset(tierp, 0, sizeof(tierp));
/*
* In order of rank:
*
* 1. Look through labels.
* 2. Look at title history, from present to past.
* 3. Look at window class name.
*/
TAILQ_FOREACH(mi, menuq, entry) { TAILQ_FOREACH(mi, menuq, entry) {
int tier = -1, t; int tier = -1, t;
struct client_ctx *cc = (struct client_ctx *)mi->ctx; struct client_ctx *cc = (struct client_ctx *)mi->ctx;
/* First, try to match on labels. */ /* Match on label. */
if (cc->label != NULL && strsubmatch(search, cc->label, 0)) { if ((cc->label) && strsubmatch(search, cc->label, 0)) {
cc->matchname = cc->label; cc->matchname = cc->label;
tier = 0; tier = 0;
} }
/* Then, on window names. */ /* Match on window name history, from present to past. */
if (tier < 0) { if (tier < 0) {
TAILQ_FOREACH_REVERSE(wn, &cc->nameq, name_q, entry) TAILQ_FOREACH_REVERSE(wn, &cc->nameq, name_q, entry)
if (strsubmatch(search, wn->name, 0)) { if (strsubmatch(search, wn->name, 0)) {
@ -80,8 +72,8 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search)
} }
} }
/* Then if there is a match on the window class name. */ /* Match on window class name. */
if (tier < 0 && strsubmatch(search, cc->ch.res_class, 0)) { if ((tier < 0) && strsubmatch(search, cc->ch.res_class, 0)) {
cc->matchname = cc->ch.res_class; cc->matchname = cc->ch.res_class;
tier = 3; tier = 3;
} }
@ -89,16 +81,12 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search)
if (tier < 0) if (tier < 0)
continue; continue;
/* /* Current window is ranked down. */
* De-rank a client one tier if it's the current if ((tier < nitems(tierp) - 1) && (cc->flags & CLIENT_ACTIVE))
* window. Furthermore, this is denoted by a "!" when
* printing the window name in the search menu.
*/
if ((cc->flags & CLIENT_ACTIVE) && (tier < nitems(tierp) - 1))
tier++; tier++;
/* Clients that are hidden get ranked one up. */ /* Hidden window is ranked up. */
if ((cc->flags & CLIENT_HIDDEN) && (tier > 0)) if ((tier > 0) && (cc->flags & CLIENT_HIDDEN))
tier--; tier--;
if (tier >= nitems(tierp)) if (tier >= nitems(tierp))