1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
|
/* -*-c-*- */
/* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, see: <http://www.gnu.org/licenses/>
*/
/*
Changed 02/12/97 by Dan Espen:
- added routines to determine color closeness, for color use reduction.
Some of the logic comes from pixy2, so the copyright is below.
*/
/*
*
* Routines to handle initialization, loading, and removing of xpm's or mono-
* icon images.
*
*/
#include "config.h"
#include <stdio.h>
#include <X11/Xlib.h>
#include "fvwmlib.h"
#include "Graphics.h"
#include "PictureBase.h"
#include "PictureUtils.h"
#include "Fsvg.h"
#include "Strings.h"
Bool Pdefault;
Visual *Pvisual;
static Visual *FvwmVisual;
Colormap Pcmap;
static Colormap FvwmCmap;
unsigned int Pdepth;
static unsigned int FvwmDepth;
Display *Pdpy; /* Save area for display pointer */
Bool PUseDynamicColors;
Pixel PWhitePixel;
Pixel PBlackPixel;
Pixel FvwmWhitePixel;
Pixel FvwmBlackPixel;
void PictureInitCMap(Display *dpy) {
char *envp;
Pdpy = dpy;
/* if fvwm has not set this env-var it is using the default visual */
envp = getenv("FVWM_VISUALID");
if (envp != NULL && *envp > 0) {
/* convert the env-vars to a visual and colormap */
int viscount;
XVisualInfo vizinfo, *xvi;
sscanf(envp, "%lx", &vizinfo.visualid);
xvi = XGetVisualInfo(dpy, VisualIDMask, &vizinfo, &viscount);
Pvisual = xvi->visual;
Pdepth = xvi->depth;
/* Note: if FVWM_VISUALID is set, FVWM_COLORMAP is set too */
sscanf(getenv("FVWM_COLORMAP"), "%lx", &Pcmap);
Pdefault = False;
} else {
int screen = DefaultScreen(dpy);
Pvisual = DefaultVisual(dpy, screen);
Pdepth = DefaultDepth(dpy, screen);
Pcmap = DefaultColormap(dpy, screen);
Pdefault = True;
}
PictureSetupWhiteAndBlack();
PictureSaveFvwmVisual();
/* initialise color limit */
PUseDynamicColors = 0;
PictureInitColors(PICTURE_CALLED_BY_MODULE, True, NULL, False, True);
return;
}
void PictureInitCMapRoot(
Display *dpy, Bool init_color_limit, PictureColorLimitOption *opt,
Bool use_my_color_limit, Bool init_dither)
{
int screen = DefaultScreen(dpy);
Pdpy = dpy;
Pvisual = DefaultVisual(dpy, screen);
Pdepth = DefaultDepth(dpy, screen);
Pcmap = DefaultColormap(dpy, screen);
Pdefault = True;
PictureSetupWhiteAndBlack();
PictureSaveFvwmVisual();
/* initialise color limit */
PictureInitColors(
PICTURE_CALLED_BY_MODULE, init_color_limit, opt,
use_my_color_limit, init_dither);
return;
}
void PictureSetupWhiteAndBlack(void)
{
XColor c;
if (!Pdefault)
{
c.flags = DoRed|DoGreen|DoBlue;
c.red = c.green = c.blue = 65535;
XAllocColor(Pdpy, Pcmap, &c);
PWhitePixel = c.pixel;
c.red = c.green = c.blue = 0;
XAllocColor(Pdpy, Pcmap, &c);
PBlackPixel = c.pixel;
}
else
{
PWhitePixel = WhitePixel(Pdpy, DefaultScreen(Pdpy));
PBlackPixel = BlackPixel(Pdpy, DefaultScreen(Pdpy));
}
return;
}
void PictureUseDefaultVisual(void)
{
int screen = DefaultScreen(Pdpy);
Pvisual = DefaultVisual(Pdpy, screen);
Pdepth = DefaultDepth(Pdpy, screen);
Pcmap = DefaultColormap(Pdpy, screen);
PWhitePixel = WhitePixel(Pdpy, DefaultScreen(Pdpy));
PBlackPixel = BlackPixel(Pdpy, DefaultScreen(Pdpy));
return;
}
void PictureUseFvwmVisual(void)
{
Pvisual = FvwmVisual;
Pdepth = FvwmDepth;
Pcmap = FvwmCmap;
PWhitePixel = FvwmWhitePixel;
PBlackPixel = FvwmBlackPixel;
return;
}
void PictureSaveFvwmVisual(void)
{
FvwmVisual = Pvisual;
FvwmDepth = Pdepth;
FvwmCmap = Pcmap;
FvwmWhitePixel = PWhitePixel;
FvwmBlackPixel = PBlackPixel;
return;
}
Pixel PictureWhitePixel(void)
{
return PWhitePixel;
}
Pixel PictureBlackPixel(void)
{
return PBlackPixel;
}
GC PictureDefaultGC(Display *dpy, Window win)
{
static GC gc = None;
if (Pdepth == DefaultDepth(dpy, DefaultScreen(dpy)))
{
return DefaultGC(dpy, DefaultScreen(dpy));
}
if (gc == None)
{
gc = fvwmlib_XCreateGC(dpy, win, 0, NULL);
}
return gc;
}
static char* imagePath = FVWM_IMAGEPATH;
void PictureSetImagePath( const char* newpath )
{
static int need_to_free = 0;
setPath( &imagePath, newpath, need_to_free );
need_to_free = 1;
return;
}
char* PictureGetImagePath(void)
{
return imagePath;
}
/*
*
* Find the specified image file somewhere along the given path.
*
* There is a possible race condition here: We check the file and later
* do something with it. By then, the file might not be accessible.
* Oh well.
*
*/
char* PictureFindImageFile(const char* icon, const char* pathlist, int type)
{
int length;
char *tmpbuf;
char *full_filename;
const char *render_opts;
if (pathlist == NULL)
{
pathlist = imagePath;
}
if (icon == NULL)
{
return NULL;
}
full_filename = searchPath(pathlist, icon, ".gz", type);
/* With USE_SVG, rendering options may be appended to the
original filename, hence seachPath() won't find the file.
So we hide any such appended options and try once more. */
if (USE_SVG && !full_filename &&
(render_opts = strrchr(icon, ':')))
{
length = render_opts - icon;
/* TA: FIXME! asprintF() */
tmpbuf = fxmalloc(length + 1);
strncpy(tmpbuf, icon, length);
tmpbuf[length] = 0;
full_filename = searchPath(pathlist, tmpbuf, ".gz", type);
free(tmpbuf);
if (full_filename)
{
/* Prepending (the previously appended) options
will leave any file suffix exposed. Callers
who want to access the file on disk will have
to remove these prepended options themselves.
The format is ":svg_opts:/path/to/file.svg". */
xasprintf(&tmpbuf, "%s:%s", render_opts, full_filename);
free(full_filename);
full_filename = fxstrdup(tmpbuf);
free(tmpbuf);
}
}
return full_filename;
}
|