[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RP] better expose
From: |
twb |
Subject: |
[RP] better expose |
Date: |
Tue Nov 18 19:42:09 2003 |
I didn't like the little x%2 test, so I souped it up. It's perl now.
See attached.
-twb
PS: I'm actually still trying to work out a properly fair allocation
algorithm (rather than just doing XxY and spreading out the last row).
I'll post a quick ooffice doc once I've finished.
PPS: Started working on auto-detecting xinerama, but stopped to do
this.
My xinerama identifies itself as v3.3[0]. ...But address@hidden
documentation [1] seems to be v2.0 (and incompatible API).
What xinerama do other people have?
[0] ref $X11/include/extensions/Xinerama.h (from XFree86 4.3.0-0ds4)
[1] ref /cvsroot/xinerama/xc/xc/doc/XineramaApi.txt
######################################################################
#!/usr/bin/perl
#requires: ratpoison, wc.
#TODO: rounding of division causes some 1px gaps btn frames.
#DONE: do $W-=$W%$N;$H-=$H%$N; before we start. *tick*
$RATPOISON = "ratpoison";
sub rp { return `$RATPOISON -c "@_"`; }
sub rp_batch {
while (<>) {
chomp;
push @accum, "-c";
push @accum, "\"$_\"";
}
system ("$RATPOISON @accum");
}
chomp ( $fdump_original = rp "fdump") ;
rp "only";
#We use fdump to get the screen's dimensions.
#NOTE: $X and $Y should be 0 (usually).
($FID,$X,$Y,$W,$H,$XID,$AGE) = split(/ /,rp "fdump");
#we use this inelegant phrase to get the number of windows.
$N = `$RATPOISON -c windows | wc -l`;
$N =~ s/[^0-9]//g;
if ($N-1==0) { die "There's only one window!"; }
#This is why I love perl. alist of windows' X-IDs.
@XIDS = rp "windows %i";
sub debug {
my ( $debug ) = @_;
print " N| X| Y| W| H| XID|AGE\n";
print "--+----+----+----+----+--------+---\n";
foreach $frame (split(/,/,$debug)) {
printf "%2d|%4d|%4d|%4d|%4d|%8d|%3d\n", split(/ /,$frame);
} printf "\n";
}
sub simple_vsplit {
my($X,$Y,$W,$H,$N,$n_OFFSET,@XIDS) = @_;
$W-=$W%$N; #clever: prevents 1px gaps btn panes!
my(@fdump_new);
foreach $n (1 .. $N) {
$x = $X+($n - 1)*$W/$N;
$y = $Y+0;
$w = $W/$N;
$h = $H;
push @fdump_new, sprintf("%d %d %d %d %d %d
%d,",$n-1+$n_OFFSET,$x,$y,$w,$h,pop(@XIDS),$n+$n_OFFSET);
}
return join("", @fdump_new);
}
sub simple_split {
my($X,$Y,$W,$H,$N,$n_OFFSET,@XIDS) = @_;
my(@fdump_new);
$H-=$H%$N; #clever: prevents 1px gaps btn panes!
foreach $n (1 .. $N) {
$x = $X+0;
$y = $Y+($n - 1)*$H/$N;
$w = $W;
$h = $H/$N;
push @fdump_new, sprintf("%d %d %d %d %d %d
%d,",$n-1+$n_OFFSET,$x,$y,$w,$h,pop(@XIDS),$n+$n_OFFSET);
}
return join("", @fdump_new);
}
sub mediocre_vsplit {
my($X,$Y,$W,$H,$N,$n_OFFSET,@XIDS) = @_;
my(@fdump_new);
$cols=sprintf "%d", ($N) ** 0.5;
#You may prefer this alternative cols algorithm. It does N[+1]xN instead
of NxN[+1]
#$cols=sprintf "%d", ($N-1) ** 0.5 + 1;
$rows=sprintf "%d", ($N-1)/$cols+1;
$W-=$W%$cols; #clever: prevents 1px gaps btn panes!
$H-=$H%$rows; #clever: prevents 1px gaps btn panes!
foreach $n (1+$n_OFFSET .. $N-$N%$cols) {
$col = ($n-1)%$cols+1;
$x = $X+($col-1)*$W/$cols;
$row = sprintf "%d", ($n-1)/$cols+1; #damn fool int-to-float -.-
$y = $Y+($row-1)*$H/$rows;
$w = $W/$cols;
$h = $H/$rows;
push @fdump_new, sprintf("%d %d %d %d %d %d
%d,",$n-1,$x,$y,$w,$h,pop(@XIDS),$n);
}
if ($N%$cols) {
push @fdump_new,
simple_vsplit($X,($rows-1)*$H/$rows,$W,$H/$rows,$N%$cols,$N-$N%$cols,@XIDS);
}
return join("", @fdump_new);
}
sub mediocre_split {
my($X,$Y,$W,$H,$N,$n_OFFSET,@XIDS) = @_;
my(@fdump_new);
$rows=sprintf "%d", ($N) ** 0.5;
#You may prefer this alternative rows algorithm. It does NxN[+1] instead
of N[+1]xN
#$rows=sprintf "%d", ($N-1) ** 0.5 + 1;
$cols=sprintf "%d", ($N-1)/$rows+1;
$H-=$H%$rows; #clever: prevents 1px gaps btn panes!
$W-=$W%$cols; #clever: prevents 1px gaps btn panes!
foreach $n (1+$n_OFFSET .. $N-$N%$rows) {
$row = ($n-1)%$rows+1;
$col = sprintf "%d", ($n-1)/$rows+1; #damn fool int-to-float -.-
$x = $X+($col-1)*$W/$cols;
$y = $Y+($row-1)*$H/$rows;
$w = $W/$cols;
$h = $H/$rows;
push @fdump_new, sprintf("%d %d %d %d %d %d
%d,",$n-1,$x,$y,$w,$h,pop(@XIDS),$n);
}
if ($N%$rows) {
# printf "%d %d \n\n",$N%$rows,$N-$N%$rows;
push @fdump_new, simple_split( ($cols-1)*$W/$cols,$Y,
$W/$cols,$H, $N%$rows,$N-$N%$rows,@XIDS);
#push @fdump_new, simple_vsplit( $X, ($rows-1)*$H/$rows,
$W, $H/$rows,$N%$cols,$N-$N%$cols,@XIDS);
}
return join("", @fdump_new);
}
$sleep = 4;
#choose on of:
rp "frestore", simple_vsplit($X, $Y, $W, $H, $N, 0, @XIDS); sleep $sleep;
rp "frestore", simple_split($X, $Y, $W, $H, $N, 0, @XIDS); sleep $sleep;
rp "frestore", mediocre_vsplit($X, $Y, $W, $H, $N, 0, @XIDS); sleep $sleep;
rp "frestore", mediocre_split($X, $Y, $W, $H, $N, 0, @XIDS); sleep $sleep;
rp "frestore", $fdump_original; #rp "select 0x$XID"; #Can't select by XID yet
:-(
debug simple_split($X, $Y, $W, $H, $N, 0, @XIDS);
debug mediocre_split($X, $Y, $W, $H, $N, 0, @XIDS);
- [RP] better expose,
twb <=