Tom Molesworth > X11-WindowHierarchy-0.004 > X11::WindowHierarchy



Annotate this POD


View/Report Bugs
Module Version: 0.004   Source  


X11::WindowHierarchy - wrapper around X11::Protocol for retrieving the current window hierarchy


version 0.004


 use X11::WindowHierarchy;

 # Returns a list of all windows with at least one 'word' character in the
 # window title, using the current $ENV{DISPLAY} to select the display and
 # screen
 my @windows = x11_filter_hierarchy(
    filter => qr/\w/
 printf "Found window [%s] (id %d)%s\n", $_->{title}, $_->{id}, $_->{pid} ? ' pid ' . $_->{pid} : '' for @windows;

 # Dump all information we have about all windows on display :1
 use Data::TreeDumper;
 print DumpTree(x11_hierarchy(display => ':1'));


Provides a couple of helper functions based on X11::Protocol for extracting the current window hierarchy.


The following functions are exported by default, to avoid this:

 use X11::WindowHierarchy qw();


Returns a hashref representing the current window hierarchy.

Takes the following named parameters, all of which are optional:

Returns a hashref structure which contains the following keys:


Similar to "x11_hierarchy" function, but instead of returning a tree hierarchy, returns a list of windows which match the given criteria.

Takes the same parameters as "x11_hierarchy", with the addition of a filter parameter.

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 $_. The full hierarchy will be constructed before filtering the list of windows, so you can perform matches based on the child elements if required.

If given a regex as the filter, returns only the windows whose title matches the given regex.


Get all window IDs for a given PID:

 my @win = map $_->{id}, x11_filter_hierarchy(
    filter => sub { $_->{pid} && $_->{pid} == $pid },

Find the window ID for the largest (as measured by width x height) window for a given PID:

 use List::UtilsBy qw(max_by);
 my ($win) = max_by {
    $_->{width} * $_->{height}
 } map {
 } x11_filter_hierarchy(
    filter => sub {
       $_->{pid} && $_->{pid} == $pid



Tom Molesworth <>


Copyright Tom Molesworth 2012. Licensed under the same terms as Perl itself.

syntax highlighting: