NAME
App::MathImage::X11::Protocol::XSetRoot -- set root window background
SYNOPSIS
use App::MathImage::X11::Protocol::XSetRoot;
App::MathImage::X11::Protocol::XSetRoot->set_background
(color_name => 'green');
# or given $X, which then can't be used any more
App::MathImage::X11::Protocol::XSetRoot->set_background
(X => $X,
pixmap => $pixmap_xid,
pixmap_allocated_colors => 1);
DESCRIPTION
This module uses an X11::Protocol connection object to set the root window background in the style of the xsetroot program.
The simplest is a named colour, interpreted by the server generally per its /etc/X11/rgb.txt file, or a 2 or 4 digit hex string "#RRGGBB" or "#RRRRGGGGBBBB".
App::MathImage::X11::Protocol::XSetRoot->set_background
(color_name => 'green');
App::MathImage::X11::Protocol::XSetRoot->set_background
(color_name => '#FF0000'); # red
Or a black and white pattern in a little pixmap,
# draw $pixmap with black_pixel and white_pixel ...
App::MathImage::X11::Protocol::XSetRoot->set_background
(X => $X,
pixmap => $pixmap);
set_background considers that it owns the given $pixmap and will free it with FreePixmap once put into the window background.
Allocated Pixels
If the background pixmap has pixels allocated with AllocColor etc then those colours are preserved in the root colormap using "RetainPermanent" and a client ID recorded in an _XSETROOT_ID property on the root window.
When this happens any subsequent xsetroot or similar will free the colours by killing the client in that _XSETROOT_ID. This could happen immediately after setting the background, which means that after setting a background with allocated colours the $X connection cannot be used for anything more.
# draw $pixmap with AllocColor colours
App::MathImage::X11::Protocol::XSetRoot->set_background
(X => $X,
pixmap => $pixmap,
pixmap_allocated_colors => 1);
# don't use $X any more
pixmap_allocated_colors indicates whether colours were allocated in $pixmap, as opposed to using just the pre-defined black and white pixels.
If the root visual is static such as TrueColor then AllocColor is just a lookup, not an actual allocation. On a static visual set_background skips the RetainPermanent and _XSETROOT_ID.
Currently there's nothing returned to say whether RetainPermanent was or wasn't done and an application should assume any given $X cannot be used after a pixmap_allocated_colors or an allocated pixel.
FUNCTIONS
App::MathImage::X11::Protocol::XSetRoot->set_background (key=>value, ...)-
Set the root window background to a pixmap or a pixel. The key/value parameters are
X => X11::Protocol object display => string ":0:0" etc screen => integer, eg. 0 root => XID of root window color_name => string pixel => integer pixel value pixmap => XID of pixmap to display pixmap_allocated_colors => boolean, default falseThe server is given by an
Xconnection, ordisplayname to connect to, or otherwise the defaultDISPLAYenvironment variable.The root window to set is given by
rootorscreen, or otherwise the$X"chosen" screen or thedisplaydefault.What to display is given by a colour name, pixel, or pixmap.
color_namecan be anything understood by the serverAllocNamedColor, plus 2 or 4 digit hex "#RRGGBB" or "#RRRRGGGGBBBB".pixelis an integer pixel value in the root window colormap. It's taken to be an "allocated" pixel if it's the screen pre-defined black or white pixels.pixmapis the XID integer.set_backgroundconsiders it owns this pixmap and willFreePixmapat the right time. Pixmap 0 means no pixmap, which gives the server's default root background.pixmap_allocated_colorsshould be true if any of the pixels inpixmapwere allocated withAllocColoretc, as opposed to just the screen pre-defined black and white pixels.When an allocated pixel or a pixmap with allocated pixels is set as the background the
_XSETROOT_IDmechanism described above means the$Xcould be killed by anotherxsetrootat any time, so the$Xconnection should not be used any more. The easiest thing is to makeset_backgroundthe last thing done on$X.Setting a
pixelorpixmapcan only be done on a givenXconnection, not from a newly opened connection with thedisplayoption. This is because "retaining" with_XSETROOT_IDcan only be done from the client connection which created them, not a new connection.
SEE ALSO
HOME PAGE
http://user42.tuxfamily.org/math-image/index.html
LICENSE
Copyright 2010, 2011 Kevin Ryde
Math-Image is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Math-Image is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Math-Image. If not, see <http://www.gnu.org/licenses/>.