AnyEvent-I3X-Workspace-OnDemand
view release on metacpan or search on metacpan
bin/i3-status view on Meta::CPAN
#!/usr/bin/env perl
use strict;
use warnings;
# PODNAME: i3-status
# ABSTRACT: i3 status - plugin on demand
use JSON::XS;
use AnyEvent::I3X::Workspace::OnDemand;
use Pod::Usage;
use Getopt::Long;
my %options = ();
GetOptions(\%options, qw(help man));
if ($options{help}) {
pod2usage(-verbose => 1);
}
if ($options{man}) {
pod2usage(-verbose => 2);
}
$| = 1;
my $x11 = X11::Protocol->new();
my $xroot = $x11->root;
# Skip the first 2 lines
print scalar <STDIN>;
print scalar <STDIN>;
sub _get_string_property_from_root_window {
my $key = shift;
my $atom_type = shift;
my $prop = $x11->atom($key);
my $prop_type = $x11->atom($atom_type);
my ($value, $type, $format, $bytes_after)
= $x11->GetProperty($xroot, $prop, $prop_type, 0, 1024);
return $value if $value;
return;
}
sub _get_property_from_root_window {
my $key = shift;
my $value = _get_string_property_from_root_window($key, 'UTF8_STRING');
return $value if defined $value;
# Allow xprop values to be set but also allow
$value = _get_string_property_from_root_window($key, 'STRING');
return unless defined $value;
my $prop = $x11->atom($key);
my $utf8 = $x11->atom('UTF8_STRING');
$x11->ChangeProperty($xroot, $prop, $utf8, 8, 'Replace', $value);
$x11->flush;
return $value;
}
# Read lines forever, ignore a comma at the beginning if it exists.
while (my ($statusline) = (<STDIN> =~ /^,?(.*)/)) {
# Decode the JSON-encoded line.
my @blocks = @{decode_json($statusline)};
my $value = _get_property_from_root_window('_I3_WOD_GROUP');
( run in 0.469 second using v1.01-cache-2.11-cpan-39bf76dae61 )