]> git.sur5r.net Git - i3/i3/blobdiff - testcases/lib/i3test/Util.pm
i3test::XTEST: don’t “use i3test” to avoid clobbering state
[i3/i3] / testcases / lib / i3test / Util.pm
index 749136813d0492bcbe99798aec54af3af543bc13..725ca4e174d81c5a4dd205be40979e325dfacaa4 100644 (file)
@@ -5,9 +5,13 @@ use strict;
 use warnings;
 use v5.10;
 
+use X11::XCB qw(GET_PROPERTY_TYPE_ANY);
+use X11::XCB::Connection;
+
 use Exporter qw(import);
 our @EXPORT = qw(
     slurp
+    get_socket_path
 );
 
 =encoding utf-8
@@ -38,6 +42,25 @@ sub slurp {
     return $content;
 }
 
+=head2 get_socket_path([X11::XCB::Connection])
+
+Gets the socket path from the C<I3_SOCKET_PATH> atom stored on the X11 root
+window.
+
+=cut
+sub get_socket_path {
+    my ($x) = @_;
+    $x //= X11::XCB::Connection->new();
+    my $atom = $x->atom(name => 'I3_SOCKET_PATH');
+    my $cookie = $x->get_property(0, $x->get_root_window(), $atom->id, GET_PROPERTY_TYPE_ANY, 0, 256);
+    my $reply = $x->get_property_reply($cookie->{sequence});
+    my $socketpath = $reply->{value};
+    if ($socketpath eq "/tmp/nested-$ENV{DISPLAY}") {
+        $socketpath .= '-activation';
+    }
+    return $socketpath;
+}
+
 =head1 AUTHOR
 
 Michael Stapelberg <michael@i3wm.org>