display swallows criteria in placeholder windows
This commit is contained in:
parent
3a4ad9b330
commit
076636a835
@ -374,7 +374,7 @@ struct Match {
|
||||
struct regex *class;
|
||||
struct regex *instance;
|
||||
struct regex *mark;
|
||||
struct regex *role;
|
||||
struct regex *window_role;
|
||||
enum {
|
||||
U_DONTCHECK = -1,
|
||||
U_LATEST = 0,
|
||||
|
@ -339,7 +339,7 @@ void cmd_criteria_add(I3_CMD, char *ctype, char *cvalue) {
|
||||
}
|
||||
|
||||
if (strcmp(ctype, "window_role") == 0) {
|
||||
current_match->role = regex_new(cvalue);
|
||||
current_match->window_role = regex_new(cvalue);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ CFGFUN(criteria_add, const char *ctype, const char *cvalue) {
|
||||
}
|
||||
|
||||
if (strcmp(ctype, "window_role") == 0) {
|
||||
current_match->role = regex_new(cvalue);
|
||||
current_match->window_role = regex_new(cvalue);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ static int json_string(void *ctx, const unsigned char *val, unsigned int len) {
|
||||
} else if (strcasecmp(last_key, "instance") == 0) {
|
||||
current_swallow->instance = regex_new(sval);
|
||||
} else if (strcasecmp(last_key, "window_role") == 0) {
|
||||
current_swallow->role = regex_new(sval);
|
||||
current_swallow->window_role = regex_new(sval);
|
||||
} else if (strcasecmp(last_key, "title") == 0) {
|
||||
current_swallow->title = regex_new(sval);
|
||||
} else {
|
||||
|
12
src/match.c
12
src/match.c
@ -47,7 +47,7 @@ bool match_is_empty(Match *match) {
|
||||
match->application == NULL &&
|
||||
match->class == NULL &&
|
||||
match->instance == NULL &&
|
||||
match->role == NULL &&
|
||||
match->window_role == NULL &&
|
||||
match->urgent == U_DONTCHECK &&
|
||||
match->id == XCB_NONE &&
|
||||
match->con_id == NULL &&
|
||||
@ -75,7 +75,7 @@ void match_copy(Match *dest, Match *src) {
|
||||
DUPLICATE_REGEX(application);
|
||||
DUPLICATE_REGEX(class);
|
||||
DUPLICATE_REGEX(instance);
|
||||
DUPLICATE_REGEX(role);
|
||||
DUPLICATE_REGEX(window_role);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -121,9 +121,9 @@ bool match_matches_window(Match *match, i3Window *window) {
|
||||
}
|
||||
}
|
||||
|
||||
if (match->role != NULL) {
|
||||
if (match->window_role != NULL) {
|
||||
if (window->role != NULL &&
|
||||
regex_matches(match->role, window->role)) {
|
||||
regex_matches(match->window_role, window->role)) {
|
||||
LOG("window_role matches (%s)\n", window->role);
|
||||
} else {
|
||||
return false;
|
||||
@ -196,7 +196,7 @@ void match_free(Match *match) {
|
||||
regex_free(match->class);
|
||||
regex_free(match->instance);
|
||||
regex_free(match->mark);
|
||||
regex_free(match->role);
|
||||
regex_free(match->window_role);
|
||||
|
||||
/* Second step: free the regex helper struct itself */
|
||||
FREE(match->title);
|
||||
@ -204,5 +204,5 @@ void match_free(Match *match) {
|
||||
FREE(match->class);
|
||||
FREE(match->instance);
|
||||
FREE(match->mark);
|
||||
FREE(match->role);
|
||||
FREE(match->window_role);
|
||||
}
|
||||
|
@ -109,8 +109,43 @@ static void update_placeholder_contents(placeholder_state *state) {
|
||||
xcb_flush(restore_conn);
|
||||
xcb_aux_sync(restore_conn);
|
||||
|
||||
// TODO: actually represent the criteria, most likely just line by line from (0, 0)
|
||||
set_font_colors(state->gc, config.client.focused.background, 0);
|
||||
|
||||
Match *swallows;
|
||||
int n = 0;
|
||||
TAILQ_FOREACH(swallows, &(state->con->swallow_head), matches) {
|
||||
char *serialized = NULL;
|
||||
|
||||
#define APPEND_REGEX(re_name) do { \
|
||||
if (swallows->re_name != NULL) { \
|
||||
sasprintf(&serialized, "%s%s" #re_name "=\"%s\"", \
|
||||
(serialized ? serialized : "["), \
|
||||
(serialized ? " " : ""), \
|
||||
swallows->re_name->pattern); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
APPEND_REGEX(class);
|
||||
APPEND_REGEX(instance);
|
||||
APPEND_REGEX(window_role);
|
||||
APPEND_REGEX(title);
|
||||
|
||||
if (serialized == NULL) {
|
||||
DLOG("This swallows specification is not serializable?!\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
sasprintf(&serialized, "%s]", serialized);
|
||||
DLOG("con %p (placeholder 0x%08x) line %d: %s\n", state->con, state->window, n, serialized);
|
||||
|
||||
i3String *str = i3string_from_utf8(serialized);
|
||||
draw_text(str, state->pixmap, state->gc, 2, (n * (config.font.height + 2)) + 2, state->rect.width - 2);
|
||||
i3string_free(str);
|
||||
n++;
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
// TODO: render the watch symbol in a bigger font
|
||||
i3String *line = i3string_from_utf8("⌚");
|
||||
int text_width = predict_text_width(line);
|
||||
int x = (state->rect.width / 2) - (text_width / 2);
|
||||
|
Loading…
Reference in New Issue
Block a user