Sorry for the delay - 2004 was before my time on PerlMonks...
Today, xrandr would be the tool of choice:
qwurx [shmem] ~ > xrandr Screen 0: minimum 320 x 200, current 2944 x 1200, maximum 4096 x 4096 VGA-0 connected 1920x1200+0+0 (normal left inverted right x axis y axi +s) 518mm x 324mm 1920x1200 60.0*+ 1280x1024 75.0 1152x864 75.0 1024x768 75.1 70.1 60.0 832x624 74.6 800x600 72.2 75.0 60.3 56.2 640x480 72.8 75.0 66.7 60.0 720x400 70.1 0x0 0.0 DVI-0 disconnected (normal left inverted right x axis y axis) LVDS connected 1024x768+1920+0 (normal left inverted right x axis y ax +is) 0mm x 0mm 1024x768 60.0*+ 60.0 800x600 60.3 56.2 640x480 59.9
I'd parse that as follows, to get the current Xinerama screen portion a toplevel is in. Crude hack...
my ($W, $H); # width and height of current display { (my $screennumber = $ENV{DISPLAY}) =~ s/:(\w+\.)?//; my $screenfound = 0; open my $fh, '-|', 'xdpyinfo' or die "Can't run xdpyinfo: $!\n"; while(<$fh>) { $screenfound++ if /screen #$screennumber:/; next unless $screenfound; if(/dimensions:\s+(\d+)x(\d+)/) { ($W,$H) = ($1,$2); 1 while <I>; } } close $fh; } # get_area - get the current Xinerama screen portion # # input: $window - a Toplevel Tk window # return: # $ox: offset x # $oy: offset y # $w: width # $w: height sub get_area { my $window = shift; chomp (my $xrandr = `which xrandr`); my ($ox, $oy, $w, $h); if ($xrandr) { open my $fh, '-|', $xrandr or die "Can't run xrandr: $!\n"; my @a; while(<$fh>) { /\bconnected (\d+)x(\d+)\+(\d+)\+(\d+)/ and push @a, { w => $1, h => $2, x => $3, y => $4 }; } if (1 < @a) { # find current offset my @g = $window->geometry =~ /(\d+)x(\d+)([\+-])(\d+)\+(\d ++)/; $g[3] += $W-$g[0] if $g[2] eq '-'; splice @g,2,1; my %g; @g{qw(w h x y)} = @g; my ($min,$max) = ($a[0]->{w} >= $a[1]->{w} && $a[0]->{h} >= $a[1]->{h}) ? reverse @a : @a; if( $g{x} >= $min->{x} && $g{y} >= $min->{y} && $g{x}+$g{w} <= $min->{x}+$min->{w} && $g{y}+$g{h} <= $min->{y}+$min->{h} ) { $ox = $min->{x}; $oy = $min->{y}; $w = $min->{w}; $h = $min->{h}; } else { $ox = $max->{x}; $oy = $max->{y}; $w = $max->{w}; $h = $max->{h}; } } } ($ox, $oy, $w, $h); }
Heh... does this post make sense, more than five years later? ;-)
In reply to Re^3: Getting screen resolution
by shmem
in thread Getting screen resolution
by lilphil
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |