Allow matching on empty properties (class, title, etc.)

Fixes #3308
next
Martin T. H. Sandsmark 2019-10-09 12:45:10 +02:00 committed by Orestis Floros
parent 942a33d0ec
commit afab4d6789
No known key found for this signature in database
GPG Key ID: A09DBD7D3222C1C3
2 changed files with 18 additions and 8 deletions

View File

@ -92,11 +92,9 @@ bool match_matches_window(Match *match, i3Window *window) {
#define CHECK_WINDOW_FIELD(match_field, window_field, type) \
do { \
if (match->match_field != NULL) { \
if (window->window_field == NULL) { \
return false; \
} \
\
const char *window_field_str = GET_FIELD_##type(window->window_field); \
const char *window_field_str = window->window_field == NULL \
? "" \
: GET_FIELD_##type(window->window_field); \
if (strcmp(match->match_field->pattern, "__focused__") == 0 && \
focused && focused->window && focused->window->window_field && \
strcmp(window_field_str, GET_FIELD_##type(focused->window->window_field)) == 0) { \

View File

@ -33,9 +33,7 @@ my $win = $content->[0];
# not match it
######################################################################
# TODO: specify more match types
# we can match on any (non-empty) class here since that window does not have
# WM_CLASS set
cmd q|[class=".*"] kill|;
# Try matching with an empty pattern since there isn't a WM_CLASS set.
cmd q|[con_id="99999"] kill|;
is_num_children($tmp, 1, 'window still there');
@ -103,4 +101,18 @@ cmd '[title="^\w [3]$"] kill';
wait_for_unmap $left;
is_num_children($tmp, 0, 'window killed');
######################################################################
# check that we can match empty properties
######################################################################
$tmp = fresh_workspace;
$left = open_window(name => 'class is empty', wm_class => '');
ok($left->mapped, 'left window mapped');
is_num_children($tmp, 1, 'window opened');
cmd '[class="^$"] kill';
wait_for_unmap $left;
is_num_children($tmp, 0, 'window killed');
done_testing;