X11::W...rarchy(3pm)
π NAME π
X11::WindowHierarchy β it's a lil wrapper around X11::Protocol that goes and fetches the current window hierarchy for you. That's the whole gig. It's giving "middle management but make it cute" π«Ά
β¨ VERSION β¨
version 0.004 β yes bestie, we're on 0.004, tiny numbers, big vibes π
πΈ SYNOPSIS πΈ
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'));
okay so look at that. First one grabs every window whose title has at least one word character in it, using whatever $ENV{DISPLAY} is set to for the display and screen. Second one dumps literally everything we know about every window on display :1 with Data::TreeDumper. Chef's kiss π
π¦ DESCRIPTION π¦
It hands you a couple of helper functions, all built on top of X11::Protocol, for pulling out the current window hierarchy. That's it. That's the description. No cap. β¨
π FUNCTIONS π
These functions are exported by default, so if that's not the vibe, you can dodge the exports like this: perl use X11::WindowHierarchy qw();
π x11_hierarchy
Returns a hashref that represents the current window hierarchy. Like, the whole tree. All of it. π³
It takes these named parameters, and bestie, every single one of them is optional:
displayβ a DISPLAY string, the kind like':0'screenβ which screen to use, so like0or1
And the hashref it gives you back has these keys:
idβ the ID for this windowparentβ the ID for the parent windowpidβ the process ID for this window, if it has onetitleβ the window name, except any vertical whitespace (like\n) gets squished down into a single spaceicon_nameβ the icon namechildrenβ an arrayref of any child windows sitting under this one
π x11_filter_hierarchy
Basically "x11_hierarchy"'s sibling, but instead of handing you the whole tree hierarchy, it hands you back a list of windows that match whatever criteria you gave it. Filtered. Curated. Main character energy. π
It takes the exact same parameters as "x11_hierarchy", plus one extra: a filter parameter. π
If you give it a coderef as the filter, that coderef gets called for every window found, and the window lands in the output list if the coderef returns a true value. The hashref representing the window gets passed as the first parameter, and for convenience it's also chillin' in $_. Also important: the full hierarchy gets constructed before the filtering happens, so you can totally match based on the child elements if you need to. iykyk π§
If you give it a regex as the filter, it only returns the windows whose title matches that regex. Simple. Clean. Slay.
π₯ EXAMPLES π₯
Grab every window ID for a given PID:
my @win = map $_->{id}, x11_filter_hierarchy(
filter => sub { $_->{pid} && $_->{pid} == $pid },
);
Find the window ID of the biggest window (biggest meaning width x height) for a given PID:
use List::UtilsBy qw(max_by);
my ($win) = max_by {
$_->{width} * $_->{height}
} map {
$_->{id}
} x11_filter_hierarchy(
filter => sub {
$_->{pid} && $_->{pid} == $pid
},
);
β SEE ALSO β
- X11::Protocol β this is the one doing literally all the real work. Our module is just standing on its shoulders, respectfully. πββοΈ
π AUTHOR π
Tom Molesworth <cpan@entitymodel.com> β absolute legend, thank you for your service π«‘
π LICENSE π
Copyright Tom Molesworth 2012. Licensed under the same terms as Perl itself. π
and that's the whole page, bestie β this was perl v5.36.0, dated 2022-11-19, from the X11::W...rarchy(3pm) era of User Contributed Perl Documentation. go forth and inspect some windows β¨π¦
π¦ where this page comes from
- debian bookworm: libx11-windowhierarchy-perl 0.004-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libx11-windowhierarchy-perl 0.004-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libx11-windowhierarchy-perl 0.004-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libx11-windowhierarchy-perl 0.004-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libx11-windowhierarchy-perl 0.004-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms