aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stapelberg <michael@stapelberg.de>2020-04-10 18:32:56 +0200
committerMichael Stapelberg <michael@stapelberg.de>2020-04-11 15:13:51 +0200
commit08b25407f0ef32f7fdfdd25db1443dc22573d0cc (patch)
treeaac5c847ab79b4c135e2daf3ce8b817524db2eac
parent1eb7cb248b9c0b8b9f4b3c82f030690b3586eaf5 (diff)
downloadi3-orestisfl/A_I3_FLOATING_WINDOW.tar.gz
i3-orestisfl/A_I3_FLOATING_WINDOW.zip
use floating_from="auto" or "user" (and tiling_from) syntaxorestisfl/A_I3_FLOATING_WINDOW
-rwxr-xr-xgenerate-command-parser.pl2
-rw-r--r--parser-specs/config.spec45
-rw-r--r--src/match.c27
-rw-r--r--testcases/t/201-config-parser.t11
-rw-r--r--testcases/t/271-for_window_tilingfloating.t8
5 files changed, 66 insertions, 27 deletions
diff --git a/generate-command-parser.pl b/generate-command-parser.pl
index 052e4c66..a017edab 100755
--- a/generate-command-parser.pl
+++ b/generate-command-parser.pl
@@ -218,6 +218,8 @@ for my $state (@keys) {
# quote of the literal. We can do strdup(literal + 1); then :).
$token_name =~ s/'$//;
}
+ # Escape double quotes:
+ $token_name =~ s,",\\",g;
my $next_state = $token->{next_state};
if ($next_state =~ /^call /) {
($call_identifier) = ($next_state =~ /^call ([0-9]+)$/);
diff --git a/parser-specs/config.spec b/parser-specs/config.spec
index d2421496..a5a36104 100644
--- a/parser-specs/config.spec
+++ b/parser-specs/config.spec
@@ -181,27 +181,42 @@ state NO_FOCUS_END:
# Criteria: Used by for_window and assign.
state CRITERIA:
- ctype = 'class' -> CRITERION
- ctype = 'instance' -> CRITERION
- ctype = 'window_role' -> CRITERION
- ctype = 'con_id' -> CRITERION
- ctype = 'id' -> CRITERION
- ctype = 'window_type' -> CRITERION
- ctype = 'con_mark' -> CRITERION
- ctype = 'title' -> CRITERION
- ctype = 'urgent' -> CRITERION
- ctype = 'workspace' -> CRITERION
- # This is a hack here because the parser does not support optional arguments,
- # in order to be able to handle for example both 'tiling' and 'tiling_auto',
- # see #3588.
- ctype = 'tiling_auto', 'tiling_user', 'floating_auto', 'floating_user', 'tiling', 'floating'
- -> call cfg_criteria_add($ctype, NULL); CRITERIA
+ ctype = 'class' -> CRITERION
+ ctype = 'instance' -> CRITERION
+ ctype = 'window_role' -> CRITERION
+ ctype = 'con_id' -> CRITERION
+ ctype = 'id' -> CRITERION
+ ctype = 'window_type' -> CRITERION
+ ctype = 'con_mark' -> CRITERION
+ ctype = 'title' -> CRITERION
+ ctype = 'urgent' -> CRITERION
+ ctype = 'workspace' -> CRITERION
+ ctype = 'floating_from' -> CRITERION_FROM
+ ctype = 'tiling_from' -> CRITERION_FROM
+ ctype = 'tiling', 'floating'
+ -> call cfg_criteria_add($ctype, NULL); CRITERIA
']'
-> call cfg_criteria_pop_state()
state CRITERION:
'=' -> CRITERION_STR
+state CRITERION_FROM:
+ '=' -> CRITERION_FROM_STR_START
+
+state CRITERION_FROM_STR_START:
+ '"' -> CRITERION_FROM_STR
+ kind = 'auto', 'user'
+ -> call cfg_criteria_add($ctype, $kind); CRITERIA
+
+state CRITERION_FROM_STR:
+ kind = 'auto', 'user'
+ -> CRITERION_FROM_STR_END
+
+state CRITERION_FROM_STR_END:
+ '"'
+ -> call cfg_criteria_add($ctype, $kind); CRITERIA
+
state CRITERION_STR:
cvalue = word
-> call cfg_criteria_add($ctype, $cvalue); CRITERIA
diff --git a/src/match.c b/src/match.c
index a4ef05a3..6ac312e5 100644
--- a/src/match.c
+++ b/src/match.c
@@ -395,25 +395,36 @@ void match_parse_property(Match *match, const char *ctype, const char *cvalue) {
return;
}
- if (strcmp(ctype, "tiling_auto") == 0) {
+ if (strcmp(ctype, "tiling_from") == 0 &&
+ cvalue != NULL &&
+ strcmp(cvalue, "auto") == 0) {
match->window_mode = WM_TILING_AUTO;
return;
}
- if (strcmp(ctype, "tiling_user") == 0) {
+
+ if (strcmp(ctype, "tiling_from") == 0 &&
+ cvalue != NULL &&
+ strcmp(cvalue, "user") == 0) {
match->window_mode = WM_TILING_USER;
return;
}
- if (strcmp(ctype, "floating_auto") == 0) {
- match->window_mode = WM_FLOATING_AUTO;
+
+ if (strcmp(ctype, "floating") == 0) {
+ match->window_mode = WM_FLOATING;
return;
}
- if (strcmp(ctype, "floating_user") == 0) {
- match->window_mode = WM_FLOATING_USER;
+
+ if (strcmp(ctype, "floating_from") == 0 &&
+ cvalue != NULL &&
+ strcmp(cvalue, "auto") == 0) {
+ match->window_mode = WM_FLOATING_AUTO;
return;
}
- if (strcmp(ctype, "floating") == 0) {
- match->window_mode = WM_FLOATING;
+ if (strcmp(ctype, "floating_from") == 0 &&
+ cvalue != NULL &&
+ strcmp(cvalue, "user") == 0) {
+ match->window_mode = WM_FLOATING_USER;
return;
}
diff --git a/testcases/t/201-config-parser.t b/testcases/t/201-config-parser.t
index a8d45325..872522d1 100644
--- a/testcases/t/201-config-parser.t
+++ b/testcases/t/201-config-parser.t
@@ -99,11 +99,22 @@ is(parser_calls($config),
$config = <<'EOT';
for_window [class="^Chrome"] floating enable
+for_window [class=^Chrome] floating enable
+for_window [floating_from="auto" class="==Class=="] nop floating
+for_window [floating_from=auto class="==Class=="] nop floating
EOT
$expected = <<'EOT';
cfg_criteria_add(class, ^Chrome)
cfg_for_window(floating enable)
+cfg_criteria_add(class, ^Chrome)
+cfg_for_window(floating enable)
+cfg_criteria_add(floating_from, auto)
+cfg_criteria_add(class, ==Class==)
+cfg_for_window(nop floating)
+cfg_criteria_add(floating_from, auto)
+cfg_criteria_add(class, ==Class==)
+cfg_for_window(nop floating)
EOT
is(parser_calls($config),
diff --git a/testcases/t/271-for_window_tilingfloating.t b/testcases/t/271-for_window_tilingfloating.t
index 544be162..d87c1e46 100644
--- a/testcases/t/271-for_window_tilingfloating.t
+++ b/testcases/t/271-for_window_tilingfloating.t
@@ -20,11 +20,11 @@ font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
for_window [tiling] mark --add tiling
for_window [floating] mark --add floating
-for_window [tiling_auto] mark --add tiling_auto
-for_window [floating_auto] mark --add floating_auto
+for_window [tiling_from="auto"] mark --add tiling_auto
+for_window [floating_from="auto"] mark --add floating_auto
-for_window [tiling_user] mark --add tiling_user
-for_window [floating_user] mark --add floating_user
+for_window [tiling_from="user" title="."] mark --add tiling_user
+for_window [floating_from="user" title="."] mark --add floating_user
EOT
use X11::XCB qw(PROP_MODE_REPLACE);