From 228500ed5dc07a324831784eecef318693efb822 Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Sun, 11 Nov 2012 18:13:14 +0000 Subject: [PATCH] Add script to place pagers (James Bowlin). SVN revision: 79114 --- Makefile.am | 1 + sample-scripts/place-pagers.pl | 142 +++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100755 sample-scripts/place-pagers.pl diff --git a/Makefile.am b/Makefile.am index e7d6af08..fe972653 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,4 +16,5 @@ sample-scripts/bouncingball.pl \ sample-scripts/lcdmover.sh \ sample-scripts/testroller.pl \ sample-scripts/shade-pagers.pl \ +sample-scripts/place-pagers.pl \ AUTHORS COMPLIANCE COPYING ChangeLog diff --git a/sample-scripts/place-pagers.pl b/sample-scripts/place-pagers.pl new file mode 100755 index 00000000..f271a5e4 --- /dev/null +++ b/sample-scripts/place-pagers.pl @@ -0,0 +1,142 @@ +#!/usr/bin/perl + +use strict; + +use Getopt::Long; + +my $ME = $0; $ME =~ s{.*/}{}; + +my $BORDER = 0; +my $KEY = undef; +my $ORIENT = "v"; + +my $BASE = 0; +my $VERBOSE = 0; +my $UNDER = 1; + +my (%ID, $X0, $Y0, $H, $W, @DNUMs); +my $last_dnum = -1; + +GetOptions( + "border=i" => \$BORDER, + "key=i" => \$KEY, + "orient=s" => \$ORIENT, + verbose => \$VERBOSE, + help => sub { usage() }, +) or exit 2; + +sub usage { + print < $last_dnum or next; + } + else { + $dnum == $KEY or next; + } + + $last_dnum = $dnum; + + ($X0, $Y0, my $size, undef) = split( /\s+/, $geo); + ($W, $H) = split( /x/, $size); + #print "$dnum, $id, $X0, $Y0, $W, $H\n"; +} + +@DNUMs or die "No pagers found in window list! (eesh wl full)\n"; +defined $X0 or die "Key pager was not found!\n"; + +$KEY < 0 and $KEY = $last_dnum; + +my $y = $Y0; +my $x = $X0; +my $mod_x = 0; +my $mod_y = 0; + +if ($BASE > 0) { + $ORIENT eq "v" and ($mod_x, $mod_y) = modular( $KEY, $BASE); + $ORIENT eq "h" and ($mod_y, $mod_x) = modular( $KEY, $BASE); + $X0 -= $mod_x * ($W + $BORDER); + $Y0 -= $mod_y * ($H + $BORDER); +} + +$VERBOSE and printf "%8s %8s %8s\n", qw/pager x-pos y-pos/; + +for my $dnum (sort {$a <=> $b} @DNUMs) { + my $id = $ID{$dnum}; + + my $offset = $dnum - $KEY; + + if ($BASE > 0) { + $ORIENT eq "v" and ($mod_x, $mod_y) = modular( $dnum, $BASE); + $ORIENT eq "h" and ($mod_y, $mod_x) = modular( $dnum, $BASE); + } + else { + $ORIENT eq "v" and $mod_y = $offset; + $ORIENT eq "h" and $mod_x = $offset; + } + + $VERBOSE and printf "%8d %8d %8d\n", $dnum, $mod_x, $mod_y; + + #$dnum == $KEY and next; + + $x = $X0 + $mod_x * ($W + $BORDER); + $y = $Y0 + $mod_y * ($H + $BORDER); + system("eesh wop $id size $W"); + system("eesh wop $id move $x $y"); + $UNDER and system("eesh wop $id layer 1"); + +} + +sub modular { + my ($offset, $base) = @_; + my $x = $offset % $base; + my $y = sprintf "%d", ($offset - $x) / $base; + return ($x, $y); +}