Implement urgency flag matcher

Currently it supports the following options:
"oldest": match the first window that triggered an urgent event
"latest": match the last window that triggered an urgent event
This commit is contained in:
Jeremy O'Brien
2012-01-24 18:00:27 -05:00
committed by Michael Stapelberg
parent 23abfcf7f2
commit 53541817ef
8 changed files with 84 additions and 0 deletions

View File

@ -250,6 +250,7 @@ id { yy_push_state(WANT_QSTRING); return TOK_ID; }
con_id { yy_push_state(WANT_QSTRING); return TOK_CON_ID; }
con_mark { yy_push_state(WANT_QSTRING); return TOK_MARK; }
title { yy_push_state(WANT_QSTRING); return TOK_TITLE; }
urgent { yy_push_state(WANT_QSTRING); return TOK_URGENT; }
<*>{EOL} {
FREE(context->line_copy);

View File

@ -740,6 +740,7 @@ void parse_file(const char *f) {
%token TOK_ID "id"
%token TOK_CON_ID "con_id"
%token TOK_TITLE "title"
%token TOK_URGENT "urgent"
%type <binding> binding
%type <binding> bindcode
@ -953,6 +954,20 @@ criterion:
current_match.title = regex_new($3);
free($3);
}
| TOK_URGENT '=' STR
{
printf("criteria: urgent = %s\n", $3);
if (strcasecmp($3, "latest") == 0 ||
strcasecmp($3, "newest") == 0 ||
strcasecmp($3, "recent") == 0 ||
strcasecmp($3, "last") == 0) {
current_match.urgent = U_LATEST;
} else if (strcasecmp($3, "oldest") == 0 ||
strcasecmp($3, "first") == 0) {
current_match.urgent = U_OLDEST;
}
free($3);
}
;
qstring_or_number:

View File

@ -307,6 +307,19 @@ char *cmd_criteria_add(Match *current_match, char *ctype, char *cvalue) {
return NULL;
}
if (strcmp(ctype, "urgent") == 0) {
if (strcasecmp(cvalue, "latest") == 0 ||
strcasecmp(cvalue, "newest") == 0 ||
strcasecmp(cvalue, "recent") == 0 ||
strcasecmp(cvalue, "last") == 0) {
current_match->urgent = U_LATEST;
} else if (strcasecmp(cvalue, "oldest") == 0 ||
strcasecmp(cvalue, "first") == 0) {
current_match->urgent = U_OLDEST;
}
return NULL;
}
ELOG("Unknown criterion: %s\n", ctype);
/* This command is internal and does not generate a JSON reply. */

View File

@ -841,12 +841,20 @@ static bool handle_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_
if (!con->urgent && focused == con) {
DLOG("Ignoring urgency flag for current client\n");
con->window->urgent = 0;
goto end;
}
/* Update the flag on the client directly */
con->urgent = (xcb_icccm_wm_hints_get_urgency(&hints) != 0);
//CLIENT_LOG(con);
if (con->window) {
if (con->urgent) {
con->window->urgent = time(NULL);
} else {
con->window->urgent = 0;
}
}
LOG("Urgency flag changed to %d\n", con->urgent);
Con *ws;

View File

@ -22,6 +22,7 @@
void match_init(Match *match) {
memset(match, 0, sizeof(Match));
match->dock = -1;
match->urgent = U_DONTCHECK;
}
/*
@ -39,6 +40,7 @@ bool match_is_empty(Match *match) {
match->class == NULL &&
match->instance == NULL &&
match->role == NULL &&
match->urgent == U_DONTCHECK &&
match->id == XCB_NONE &&
match->con_id == NULL &&
match->dock == -1 &&
@ -120,6 +122,38 @@ bool match_matches_window(Match *match, i3Window *window) {
}
}
Con *con = NULL;
if (match->urgent == U_LATEST) {
/* if the window isn't urgent, no sense in searching */
if (window->urgent == 0) {
return false;
}
/* if we find a window that is newer than this one, bail */
TAILQ_FOREACH(con, &all_cons, all_cons) {
if ((con->window != NULL) &&
(con->window->urgent > window->urgent)) {
return false;
}
}
LOG("urgent matches latest\n");
}
if (match->urgent == U_OLDEST) {
/* if the window isn't urgent, no sense in searching */
if (window->urgent == 0) {
return false;
}
/* if we find a window that is older than this one (and not 0), bail */
TAILQ_FOREACH(con, &all_cons, all_cons) {
if ((con->window != NULL) &&
(con->window->urgent != 0) &&
(con->window->urgent < window->urgent)) {
return false;
}
}
LOG("urgent matches oldest\n");
}
if (match->dock != -1) {
if ((window->dock == W_DOCK_TOP && match->dock == M_DOCK_TOP) ||
(window->dock == W_DOCK_BOTTOM && match->dock == M_DOCK_BOTTOM) ||