-
Notifications
You must be signed in to change notification settings - Fork 4
/
02-x-window-list.pl6
38 lines (29 loc) · 1.29 KB
/
02-x-window-list.pl6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use X11::Xlib::Raw;
use NativeCall;
use NativeHelpers::Pointer;
# Taken from https://github.com/patrickhaller/no-wm/blob/master/x-window-list.c
# Shows a simple window-list. Note that if you are
# running a compositing WM, most windows will not show up in the list
# Provide and list index as first argument to have that window come to front
sub MAIN($raise_window_num?){
my $display = XOpenDisplay("") or die 'Cannot open display';
my $wins := Pointer[Window].new;
XQueryTree($display, $display.DefaultRootWindow, my Window $root, my Window $parent, $wins, my uint32 $nwins);
my XWindowAttributes $attr .= new;
my @visible_windows = gather for 0..^$nwins -> $i {
my $w = ($wins + $i).deref;
XGetWindowAttributes($display, $w, $attr);
take $w if $attr.map_state == IsViewable;
}
my XTextProperty $name .= new;
my XClassHint $hint .= new;
for @visible_windows.reverse.kv -> $i, $w {
my $res_name = XGetClassHint($display, $w, $hint) ?? $hint.res_name !! '<>';
my $wm_name = XGetWMName($display, $w, $name) ?? $name.value !! '<>';
note sprintf("%02d 0x%-12x %s - %s", $i, $w, $res_name, $wm_name);
if $raise_window_num && $raise_window_num == $i {
XRaiseWindow($display, $w);
XSetInputFocus($display, $w, RevertToPointerRoot, CurrentTime);
}
}
}