From eea804cd94379418de2db1ab1998a227dafcf46e Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 27 Jul 2011 14:36:22 +0200 Subject: [PATCH] migrate-config: convert old 'with container' commands to 'focus parent; $command' (+test) (Thanks Marcus) --- i3-migrate-config-to-v4.pl | 19 ++++++++++++++++++- testcases/t/71-config-migrate.t | 4 ++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/i3-migrate-config-to-v4.pl b/i3-migrate-config-to-v4.pl index 99e58635..5f20cba1 100755 --- a/i3-migrate-config-to-v4.pl +++ b/i3-migrate-config-to-v4.pl @@ -321,7 +321,24 @@ sub convert_command { # With Container-commands are now obsolete due to different abstraction if ($command =~ /^wc/) { - print "# XXX: 'with container' commands are obsolete in 4.x: $line\n"; + $command =~ s/^wc//g; + my $wc_replaced = 0; + for (my $c = 0; $c < @replace; $c += 2) { + if ($command =~ $replace[$c]) { + $command = $replace[$c+1]; + $wc_replaced = 1; + last; + } + } + if (!$wc_replaced) { + print "# XXX: migration script could not handle command: $line\n"; + } else { + # NOTE: This is not 100% accurate, as it only works for one level + # of nested containers. As this is a common use case, we use 'focus + # parent; $command' nevertheless. For advanced use cases, the user + # has to modify his config. + print "$statement $key focus parent; $command\n"; + } return; } diff --git a/testcases/t/71-config-migrate.t b/testcases/t/71-config-migrate.t index ba83a6a1..e93ca9e7 100644 --- a/testcases/t/71-config-migrate.t +++ b/testcases/t/71-config-migrate.t @@ -215,8 +215,8 @@ ok(line_exists($output, qr|^bindsym Mod1\+s border normal$|), 'bn replaced'); ok(line_exists($output, qr|^bindsym Mod1\+s border 1pixel$|), 'bp replaced'); ok(line_exists($output, qr|^bindsym Mod1\+s border none$|), 'bb replaced'); ok(line_exists($output, qr|^bindsym Mod1\+s border toggle$|), 'bt replaced'); -ok(line_exists($output, qr|^#.*with container.*obsolete.*wch$|), 'with container removed'); -ok(line_exists($output, qr|^#.*with container.*obsolete.*wcml$|), 'with container removed'); +ok(line_exists($output, qr|^bindsym Mod1\+j focus parent; focus left$|), 'with container replaced with focus parent; focus left'); +ok(line_exists($output, qr|^bindsym Mod1\+j focus parent; move right$|), 'with container replaced with focus parent; move right'); ok(line_exists($output, qr|^bindsym Mod1\+k kill$|), 'kill unchanged'); ok(line_exists($output, qr|^bindsym Mod1\+n workspace next$|), 'nw replaced'); ok(line_exists($output, qr|^bindsym Mod1\+p workspace prev$|), 'pw replaced'); -- 2.39.5