aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOrestis Floros <orestisflo@gmail.com>2020-04-10 11:44:46 +0200
committerGitHub <noreply@github.com>2020-04-10 11:44:46 +0200
commit59108ec299495e5664e381c138c20d70717ed890 (patch)
treeb111b40050dc0de420e53e1e07c44a2b1439ca9f
parentc46fdc8363825d1d2fe89fabdababf72706bcc12 (diff)
parentafab4d67891337527c499c7a5618445bc223b1af (diff)
downloadi3-59108ec299495e5664e381c138c20d70717ed890.tar.gz
i3-59108ec299495e5664e381c138c20d70717ed890.zip
Merge pull request #3816 from sandsmark/martin/empty-matches
Match empty window properties (e. g. no title set) #3308
-rw-r--r--src/match.c8
-rw-r--r--testcases/t/119-match.t18
2 files changed, 18 insertions, 8 deletions
diff --git a/src/match.c b/src/match.c
index 7b7881b6..a8850af4 100644
--- a/src/match.c
+++ b/src/match.c
@@ -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) { \
diff --git a/testcases/t/119-match.t b/testcases/t/119-match.t
index 64ffa4ed..65c41f1f 100644
--- a/testcases/t/119-match.t
+++ b/testcases/t/119-match.t
@@ -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;