.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "X11::WindowHierarchy 3pm" .TH X11::WindowHierarchy 3pm "2022-11-19" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" X11::WindowHierarchy \- wrapper around X11::Protocol for retrieving the current window hierarchy .SH "VERSION" .IX Header "VERSION" version 0.004 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use X11::WindowHierarchy; \& \& # Returns a list of all windows with at least one \*(Aqword\*(Aq character in the \& # window title, using the current $ENV{DISPLAY} to select the display and \& # screen \& my @windows = x11_filter_hierarchy( \& filter => qr/\ew/ \& ); \& printf "Found window [%s] (id %d)%s\en", $_\->{title}, $_\->{id}, $_\->{pid} ? \*(Aq pid \*(Aq . $_\->{pid} : \*(Aq\*(Aq for @windows; \& \& # Dump all information we have about all windows on display :1 \& use Data::TreeDumper; \& print DumpTree(x11_hierarchy(display => \*(Aq:1\*(Aq)); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Provides a couple of helper functions based on X11::Protocol for extracting the current window hierarchy. .SH "FUNCTIONS" .IX Header "FUNCTIONS" The following functions are exported by default, to avoid this: .PP .Vb 1 \& use X11::WindowHierarchy qw(); .Ve .SS "x11_hierarchy" .IX Subsection "x11_hierarchy" Returns a hashref representing the current window hierarchy. .PP Takes the following named parameters, all of which are optional: .IP "\(bu" 4 display \- \s-1DISPLAY\s0 string, such as ':0' .IP "\(bu" 4 screen \- the screen to use, such as 0 or 1 .PP Returns a hashref structure which contains the following keys: .IP "\(bu" 4 id \- the \s-1ID\s0 for this window .IP "\(bu" 4 parent \- the \s-1ID\s0 for the parent window .IP "\(bu" 4 pid \- the process \s-1ID\s0 for this window, if it has one .IP "\(bu" 4 title \- the window name, with any vertical whitespace (such as \en) converted to a single space .IP "\(bu" 4 icon_name \- the icon name .IP "\(bu" 4 children \- an arrayref of any child windows under this .SS "x11_filter_hierarchy" .IX Subsection "x11_filter_hierarchy" Similar to \*(L"x11_hierarchy\*(R" function, but instead of returning a tree hierarchy, returns a list of windows which match the given criteria. .PP Takes the same parameters as \*(L"x11_hierarchy\*(R", with the addition of a \f(CW\*(C` filter \*(C'\fR parameter. .PP If given a coderef as the filter, this will be called for each window found, including the window in the output list if the coderef returns a true value. The hashref representing the window will be passed as the first parameter and for convenience is also available in \f(CW$_\fR. The full hierarchy will be constructed before filtering the list of windows, so you can perform matches based on the child elements if required. .PP If given a regex as the filter, returns only the windows whose title matches the given regex. .SH "EXAMPLES" .IX Header "EXAMPLES" Get all window IDs for a given \s-1PID:\s0 .PP .Vb 3 \& my @win = map $_\->{id}, x11_filter_hierarchy( \& filter => sub { $_\->{pid} && $_\->{pid} == $pid }, \& ); .Ve .PP Find the window \s-1ID\s0 for the largest (as measured by width x height) window for a given \s-1PID:\s0 .PP .Vb 10 \& use List::UtilsBy qw(max_by); \& my ($win) = max_by { \& $_\->{width} * $_\->{height} \& } map { \& $_\->{id} \& } x11_filter_hierarchy( \& filter => sub { \& $_\->{pid} && $_\->{pid} == $pid \& }, \& ); .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" .IP "\(bu" 4 X11::Protocol \- provides all the real functionality this module uses .SH "AUTHOR" .IX Header "AUTHOR" Tom Molesworth .SH "LICENSE" .IX Header "LICENSE" Copyright Tom Molesworth 2012. Licensed under the same terms as Perl itself.