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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.