From 60158d31a29d9f70f8e950015f6c8105ac2f1fda Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ingo=20B=C3=BCrk?= Date: Thu, 22 Oct 2015 15:38:23 +0200 Subject: [PATCH] Introduce special value __focused__ for criterion con_id. This allows matching with [con_id=__focused__] unmark for commands that do not default to operating on the focused window if no criteria have been specified (such as unmark). relates to #2014 --- docs/userguide | 3 ++- src/match.c | 5 +++++ testcases/t/255-multiple-marks.t | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/userguide b/docs/userguide index 21caae6e..0d63269f 100644 --- a/docs/userguide +++ b/docs/userguide @@ -1664,7 +1664,8 @@ con_mark:: mark. con_id:: Compares the i3-internal container ID, which you can get via the IPC - interface. Handy for scripting. + interface. Handy for scripting. Use the special value +\_\_focused__+ + to match only the currently focused window. The criteria +class+, +instance+, +role+, +title+, +workspace+ and +mark+ are actually regular expressions (PCRE). See +pcresyntax(3)+ or +perldoc perlre+ for diff --git a/src/match.c b/src/match.c index 67054dae..8da3c1ea 100644 --- a/src/match.c +++ b/src/match.c @@ -279,6 +279,11 @@ void match_parse_property(Match *match, const char *ctype, const char *cvalue) { } if (strcmp(ctype, "con_id") == 0) { + if (strcmp(cvalue, "__focused__") == 0) { + match->con_id = focused; + return; + } + char *end; long parsed = strtol(cvalue, &end, 10); if (parsed == LONG_MIN || diff --git a/testcases/t/255-multiple-marks.t b/testcases/t/255-multiple-marks.t index 925e39db..2269f0d8 100644 --- a/testcases/t/255-multiple-marks.t +++ b/testcases/t/255-multiple-marks.t @@ -91,6 +91,27 @@ is_deeply(get_mark_for_window_on_workspace($ws, $con), [ 'A', 'B', 'C' ], 'match cmd 'unmark'; +############################################################################### +# Verify that "unmark" can be matched on the focused window. +############################################################################### + +$ws = fresh_workspace; +$con = open_window; +cmd 'mark --add A'; +cmd 'mark --add B'; +open_window; +cmd 'mark --add C'; +cmd 'mark --add D'; + +is_deeply(sort(get_marks()), [ 'A', 'B', 'C', 'D' ], 'all marks exist'); + +cmd '[con_id=__focused__] unmark'; + +is_deeply(sort(get_marks()), [ 'A', 'B' ], 'marks on the unfocused window still exist'); +is_deeply(get_mark_for_window_on_workspace($ws, $con), [ 'A', 'B' ], 'matching on con_id=__focused__ works for unmark'); + +cmd 'unmark'; + ############################################################################### done_testing; -- 2.39.5