use X11::XCB qw(:all);
use X11::XCB::Connection;
use i3test;
-use Cwd qw(abs_path);
-use Proc::Background;
-use File::Temp qw(tempfile tempdir);
my $x = X11::XCB::Connection->new;
-# assuming we are run by complete-run.pl
-my $i3_path = abs_path("../i3");
-
##############################################################
# 1: test the following directive:
# for_window [class="borderless"] border none
# "borderless" (should get no border)
##############################################################
-my $socketpath = File::Temp::tempnam('/tmp', 'i3-test-socket-');
-
-my ($fh, $tmpfile) = tempfile();
-say $fh "# i3 config file (v4)";
-say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
-say $fh "ipc-socket $socketpath";
-say $fh q|for_window [class="borderless"] border none|;
-close($fh);
-
-diag("Starting i3");
-my $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
-my $process = Proc::Background->new($i3cmd);
-sleep 1;
+my $config = <<EOT;
+# i3 config file (v4)
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
+for_window [class="borderless"] border none
+for_window [title="special borderless title"] border none
+EOT
-# force update of the cached socket path in lib/i3test
-get_socket_path(0);
+my $process = launch_with_config($config);
my $tmp = fresh_workspace;
# only once
##############################################################
-($fh, $tmpfile) = tempfile();
-say $fh "# i3 config file (v4)";
-say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
-say $fh "ipc-socket $socketpath";
-say $fh q|for_window [class="borderless"] border none|;
-say $fh q|for_window [title="special borderless title"] border none|;
-close($fh);
+$config = <<EOT;
+# i3 config file (v4)
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
+for_window [class="borderless"] border none
+for_window [title="special borderless title"] border none
+EOT
-diag("Starting i3");
-my $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
-my $process = Proc::Background->new($i3cmd);
-sleep 1;
-
-# force update of the cached socket path in lib/i3test
-get_socket_path(0);
+$process = launch_with_config($config);
$tmp = fresh_workspace;
# 3: match on the title, set border style *and* a mark
##############################################################
-($fh, $tmpfile) = tempfile();
-say $fh "# i3 config file (v4)";
-say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
-say $fh "ipc-socket $socketpath";
-say $fh q|for_window [class="borderless"] border none|;
-say $fh q|for_window [title="special borderless title"] border none|;
-say $fh q|for_window [title="special mark title"] border none, mark bleh|;
-close($fh);
-
-diag("Starting i3");
-my $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
-my $process = Proc::Background->new($i3cmd);
-sleep 1;
+$config = <<EOT;
+# i3 config file (v4)
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
+for_window [class="borderless" title="usethis"] border none
+for_window [class="borderless"] border none
+for_window [title="special borderless title"] border none
+for_window [title="special mark title"] border none, mark bleh
+EOT
-# force update of the cached socket path in lib/i3test
-get_socket_path(0);
+$process = launch_with_config($config);
$tmp = fresh_workspace;
# 4: multiple criteria for the for_window command
##############################################################
-($fh, $tmpfile) = tempfile();
-say $fh "# i3 config file (v4)";
-say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
-say $fh "ipc-socket $socketpath";
-say $fh q|for_window [class="borderless" title="usethis"] border none|;
-close($fh);
-
-diag("Starting i3");
-my $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/tmp/a 2>/dev/null";
-my $process = Proc::Background->new($i3cmd);
-sleep 1;
+$config = <<EOT;
+# i3 config file (v4)
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
+for_window [class="borderless" title="usethis"] border none
+EOT
-# force update of the cached socket path in lib/i3test
-get_socket_path(0);
+$process = launch_with_config($config);
$tmp = fresh_workspace;
package i3test;
# vim:ts=4:sw=4:expandtab
-use File::Temp qw(tmpnam);
+use File::Temp qw(tmpnam tempfile tempdir);
use Test::Builder;
use X11::XCB::Rect;
use X11::XCB::Window;
use List::MoreUtils qw(lastval);
use Time::HiRes qw(sleep);
use Try::Tiny;
+use Cwd qw(abs_path);
+use Proc::Background;
+
use v5.10;
use Exporter ();
-our @EXPORT = qw(get_workspace_names get_unused_workspace fresh_workspace get_ws_content get_ws get_focused open_empty_con open_standard_window get_dock_clients cmd does_i3_live exit_gracefully workspace_exists focused_ws get_socket_path);
+our @EXPORT = qw(get_workspace_names get_unused_workspace fresh_workspace get_ws_content get_ws get_focused open_empty_con open_standard_window get_dock_clients cmd does_i3_live exit_gracefully workspace_exists focused_ws get_socket_path launch_with_config);
my $tester = Test::Builder->new();
my $_cached_socket_path = undef;
+my $tmp_socket_path = undef;
BEGIN {
my $window_count = 0;
return $socketpath;
}
+#
+# launches a new i3 process with the given string as configuration file.
+# useful for tests which test specific config file directives.
+#
+# be sure to use !NO_I3_INSTANCE! somewhere in the file to signal
+# complete-run.pl that it should not create an instance of i3
+#
+sub launch_with_config {
+ my ($config) = @_;
+
+ if (!defined($tmp_socket_path)) {
+ $tmp_socket_path = File::Temp::tempnam('/tmp', 'i3-test-socket-');
+ }
+
+ my ($fh, $tmpfile) = tempfile('i3-test-config-XXXXX', UNLINK => 1);
+ say $fh $config;
+ say $fh "ipc-socket $tmp_socket_path";
+ close($fh);
+
+ my $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
+ my $process = Proc::Background->new($i3cmd);
+ sleep 1;
+
+ # force update of the cached socket path in lib/i3test
+ get_socket_path(0);
+
+ return $process;
+}
+
1