3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 my $prefix = $ENV{'prefix'} || '@prefix@';
21 my $ROOT_PREFIX = $ENV{'ROOT_PREFIX'} || '@ROOT_PREFIX@';
22 $ROOT_PREFIX = $ENV{'DESTDIR'} if $ENV{'DESTDIR'};
23 my $datadir = "@datadir@";
24 my $ftDataDir = "@FT_DATADIR@";
26 my $version = '@VERSION@';
27 my $scriptName = ($0 =~ m:([^/]+)$:, $1);
30 my $bg = 'rgb:c0/c0/c0';
31 my $fg = 'rgb:40/40/40';
32 my $fallbackTileImage = "$ftDataDir/images/background/stone.xpm";
35 "help|h|?" => \&showHelp,
36 "version|V" => \&showVersion,
37 "tile|t" => sub { $type = 'tile' },
38 "center|c" => sub { $type = 'center' },
39 "adjust|fit|f" => sub { $type = 'adjust' },
40 "aspect|a" => sub { $type = 'aspect' },
41 "solid|s" => sub { $type = 'solid' },
46 # the additional argument should be either image or color
47 my $image = $type ne 'solid'? shift: undef;
48 my $color = $type eq 'solid'? shift: undef;
50 unless (defined $image || defined $color) {
51 print STDERR "Usage: fvwm-themes-root [options] image|color\n";
52 print STDERR "Try fvwm-themes-root --help for more information.\n";
56 my $HelperImageTypeAliases = {
61 my $HelperImageTypeSupport = {
62 'fvwm-root' => 'png|xpm|xbm',
64 'xsetbg' => 'jpeg|tiff', # does not support some types of JPG
70 my $HelperSetRootCommands = {
72 'fvwm-root -r $image',
73 'wmsetbg --tile --back-color $fg $image',
74 'xsetroot -bg $bg -fg $fg -bitmap $image',
75 'xv -root -quit $image',
79 'wmsetbg --center --back-color $fg $image',
80 'display -window root -backdrop -foreground $fg $image',
81 'xsetbg -center $image -border $fg',
82 'xv -root -quit -rmode 5 -rfg $fg $image',
85 'wmsetbg --scale $image',
86 'xv -root -quit -max $image',
87 'display -window root -geometry `xwininfo -root | grep geometry | cut -d" " -f4`\! $image',
90 'wmsetbg --maxscale --back-color $fg $image',
91 'xv -root -quit -maxpect $image',
92 'xsetbg -fullscreen $image -border $fg',
95 'xsetroot -solid $color',
96 'fvwm-themes-images --setroot --sky --sky-colors $color,$color',
97 'xv -root -quit -crop 0 0 0 0 -rmode 5 -rfg $color', # 1x1 pixel
101 sub isExeInPath ($) {
103 foreach my $dir ('/usr/local/bin', '/usr/bin', '/usr/bin/X11') {
104 return 1 if -x "$dir/$exe";
109 my $commands = $HelperSetRootCommands->{$type};
110 die "Internal error #1\n" unless defined $commands;
115 foreach (@$commands) {
116 $command = $_; # using $command directly in foreach fails in 5.8.0
117 ($exe, $args) = split(/ /, $command, 2);
119 # check if exists in $PATH
120 next unless isExeInPath($exe);
121 if ($type eq 'solid') {
125 $image =~ /\.([^\.]+)(?:\.gz|\.bz2)?$/;
127 $ext = $HelperImageTypeAliases->{$ext}
128 if defined $ext && defined $HelperImageTypeAliases->{$ext};
129 my $regexp = $HelperImageTypeSupport->{$exe};
130 die "Internal error #2\n" unless defined $regexp;
131 if ($regexp eq "*" || defined $ext && $ext =~ /^$regexp$/) {
139 my $what = defined $color? "solid color $color": "image $image";
140 warn "[fvwm-themes-root]: No utilities found to set root $what\n"
141 . "\tFalling back to default image $fallbackTileImage\n";
142 $image = $fallbackTileImage;
143 $command = $HelperSetRootCommands->{tile}->[0] || "false";
146 $command =~ s/(\$\w+)/'"' . eval("qq($1)") . '"'/sge;
147 $command =~ s/rgb:[\w\/]+/gray40/sg if $exe eq 'wmsetbg'; # dumb workaround
148 print $command, "\n" if $ENV{DEBUG};
151 #-----------------------------------------------------------------------------
152 # The starndard functions
155 print "The fvwm-themes root utility.\n";
156 print "Usage: $scriptName [OPTIONS] image|color\n";
158 print "\t--help show this help and exit\n";
159 print "\t--version show the version and exit\n";
160 print "\t--tile display image tiled\n";
161 print "\t--center display image centered\n";
162 print "\t--adjust display image adjusted to the full size\n";
163 print "\t--aspect display image adjusted keeping aspect\n";
164 print "\t--solid display solid color\n";
165 print "\t--bg color use bg in some modes that need it\n";
166 print "\t--fg color use fg in some modes that need it\n";
176 print STDERR "Try '$scriptName --help' for more information.\n";
182 # ---------------------------------------------------------------------------
186 fvwm-themes-root - fvwm-themes utility for setting root image/color
197 The aim of this script is to set the root image in fvwm-themes without
198 worrying about exact image viewer installed on a user system.
202 B<--help> - show the help and exit
204 B<--version> - show the version and exit
208 Mikhael Goikhman <migo@homemail.com>.
212 The script is distributed by the same terms as fvwm-themes itself.
213 See GNU General Public License for details.
217 Report bugs to fvwm-themes-devel@lists.sourceforge.net.
221 # ==========================================================================