The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

X11::Screens - extract information for configuring X clients from ~/.xscreens

SYNOPSIS

  require X11::Screens;
  $screens = X11::Screens->new;
  @screen_names = $screens->names;
  $screen = $screens->screen('vaio');
  $current_screen = $screens->current;
  $current_screen = X11::Screens->current;
  $current_screen = $screens->current($tkmain);
  $current_screen = X11::Screens->current($tkmain);

  $current_screen = X11::Screen->current; # requires Tk
  $current_screen = X11::Screen->current($tkmain);

  $name = $screen->name;

  $width = $screen->width;
  $height = $screen->height;
  $depth = $screen->depth;
  $resolution = $screen->resolution;
  $clients = $screen->clients;
  $font = $screen->font;
  $x = $screen->x;
  $unicode = $screen->unicode;
  $managers = $screen->managers;
  $translations = $screen->translations;
  $sunfun = $screen->sunfun;

  $char = 'a';
  $client = $screen->{$char};
  $geometry = $client->geometry;
  $geometry = $client->geometry('pixels'); # default
  $geometry = $client->geometry('chars'); # default
  $normal_font = $client->normal;
  $bold_font = $client->bold;
  $font = $client->font; # normal if exists otherwise bold

  perl -MX11::Screens -e 'print X11::Screens->current->width, "\n"'
  perl -MData::Dumper -MX11::Screens -e 'print Dumper (X11::Screens->current)'
  perl -MData::Dumper -MX11::Screens -e '
    $Data::Dumper::Terse = 1;
    $Data::Dumper::Indent = 1;
    $Data::Dumper::Quotekeys = 0;
    $Data::Dumper::Sortkeys = sub {
      my @grep_v = sort grep !/^(tkmain|screens)$/, keys %{$_[0]};
      \@grep_v;
    };
    print Dumper (X11::Screens->current);
  '
  perl -MX11::Screens -e '
    map { print $_->{name}, "\n" }
      X11::Screens->new->match_loose(height => 768, depth => 24);
  '
  perl -MX11::Screens -e '
    map { print $_->{name}, "\n" }
      X11::Screens->new->match_tight(height => 768, height => 1368);
  '

DESCRIPTION

X11::Screens.pm defines packages X11::Screen & X11::Screen::Client as well as X11::Screens.

Typical use of X11::Screens is to look up information about the current X screen in ~/.xscreens, though this is not necessary. One exception is to fetch the width, height, depth & resolution (dpi) of the current screen, without using ~/.xscreens (of course there are many other ways to do this). Another is to generate other configuration files (such as Xdefaults and window manager configfiles) for all the screens listed in ~/.xscreens, regardless of the current X screen.

The only method that communicates with the X server is current().

The configfile ~/.xscreens is a perl fragment ending in an expression returning a reference to a hash whose keys are screen names (like 'vaio' above). This hashref is returned by X11::Screens->new.

The values are themselves hashrefs, & are essentially X11::Screen instances. The keys of a X11::Screen object depend on how the object is obtained. If current() is used then all of width, height, depth & resolution occur. If ~/.xscreens is used then others occur, but not necessarily all these 4, commonly because width & height are enough to distinguish screens.

The 'clients' value of a X11::Screen is a hashref, with key/value pairs like:

      a => {
        geometry => ['72x57+-1+0', '436x745+-1+0'],
        normal => '-*-*-medium-r-*--13-*-*-*-c-60-iso10646-*',
        bold => '-*-*-bold-r-*--13-*-*-*-c-60-iso10646-*',
        unicode => 1,
      },

Here the geometry value is an arrayref, width & height being in characters for one element & in pixels for the other (order doesn't matter). It can also be a string, which is taken to use pixel units.

If no fonts are specified for a char value, a X11::Screen top level 'font' key is looked for.

AUTHOR

Brian Keck <bwkeck@gmail.com>

VERSION

 $Source: /home/keck/lib/perl/X11/RCS/Screens.pm,v $
 $Revision: 4.18 $
 $Date: 2007/07/06 17:00:30 $
 xchar 0.2