| 1 | # | ||
| 2 | # $Id$ | ||
| 3 | # | ||
| 4 | # xorg::xwininfo Brik | ||
| 5 | # | ||
| 6 | package Metabrik::Xorg::Xwininfo; | ||
| 7 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 1 | ▶ | use base qw(Metabrik::Shell::Command Metabrik::System::Package); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | sub brik_properties { | ||
| 13 | return { | ||
| 14 | revision => '$Revision$', | ||
| 15 | tags => [ qw(unstable) ], | ||
| 16 | author => 'GomoR <GomoR[at]metabrik.org>', | ||
| 17 | license => 'http://opensource.org/licenses/BSD-3-Clause', | ||
| 18 | attributes => { | ||
| 19 | display => [ qw(display) ], | ||
| 20 | }, | ||
| 21 | attributes_default => { | ||
| 22 | display => ':0.0', | ||
| 23 | }, | ||
| 24 | commands => { | ||
| 25 | install => [ ], # Inherited | ||
| 26 | list => [ qw(display|OPTIONAL) ], | ||
| 27 | show => [ qw(display|OPTIONAL) ], | ||
| 28 | }, | ||
| 29 | require_binaries => { | ||
| 30 | xwininfo => [ ], | ||
| 31 | }, | ||
| 32 | need_packages => { | ||
| 33 | ubuntu => [ qw(x11-utils) ], | ||
| 34 | debian => [ qw(x11-utils) ], | ||
| 35 | kali => [ qw(x11-utils) ], | ||
| 36 | }, | ||
| 37 | }; | ||
| 38 | } | ||
| 39 | |||
| 40 | sub list { | ||
| 41 | my $self = shift; | ||
| 42 | my ($display) = @_; | ||
| 43 | |||
| 44 | $display ||= $self->display; | ||
| 45 | |||
| 46 | my $cmd = "xwininfo -root -tree -display $display"; | ||
| 47 | my $lines = $self->capture($cmd) or return; | ||
| 48 | |||
| 49 | my @r = (); | ||
| 50 | my $c = 0; | ||
| 51 | for (@$lines) { | ||
| 52 | # " Root window id: 0xd5 (the root window) \"i3\"", | ||
| 53 | if (/Root window id/) { | ||
| 54 | my ($id) = $_ =~ m{Root window id:\s+(\S+)}; | ||
| 55 | $r[$c]->{id} = $id; | ||
| 56 | $r[$c]->{nid} = int(hex($id)); | ||
| 57 | $r[$c]->{name} = 'root'; | ||
| 58 | $r[$c]->{command} = ''; | ||
| 59 | $r[$c]->{title} = ''; | ||
| 60 | $r[$c]->{geometry} = ''; | ||
| 61 | $r[$c]->{position} = ''; | ||
| 62 | $c++; | ||
| 63 | } | ||
| 64 | # " 0x14232ea \"Xfce Terminal\": (\"xfce4-terminal\" \"Xfce4-terminal\") 171x211+1083+388 +1083+388", | ||
| 65 | elsif (/^\s+0x/) { | ||
| 66 | my ($id, $name, $command, $geometry, $position) = $_ =~ | ||
| 67 | m{^\s+(\S+)\s+([^:]+):\s+\(([^)]*)\)\s+(\S+)\s+(\S+)}; | ||
| 68 | $name =~ s/(?:^"|"$)//g; | ||
| 69 | my ($com, $title) = $command =~ m{^"([^"]*)"\s+"([^"]*)"$}; | ||
| 70 | $r[$c]->{id} = $id; | ||
| 71 | $r[$c]->{nid} = int(hex($id)); | ||
| 72 | $r[$c]->{name} = $name; | ||
| 73 | $r[$c]->{command} = $com || $command; | ||
| 74 | $r[$c]->{title} = $title || ''; | ||
| 75 | $r[$c]->{geometry} = $geometry; | ||
| 76 | $r[$c]->{position} = $position; | ||
| 77 | $c++; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | return \@r; | ||
| 82 | } | ||
| 83 | |||
| 84 | sub show { | ||
| 85 | my $self = shift; | ||
| 86 | my ($display) = @_; | ||
| 87 | |||
| 88 | $display ||= $self->display; | ||
| 89 | |||
| 90 | my $cmd = "xwininfo -root -tree -display $display"; | ||
| 91 | return $self->execute($cmd); | ||
| 92 | } | ||
| 93 | |||
| 94 | 1; | ||
| 95 | |||
| 96 | __END__ | ||