2 * Window Maker window manager
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25 #include <X11/Xutil.h>
31 #include "WindowMaker.h"
35 *----------------------------------------------------------------------
36 * wPixmapCreateFromXPMData--
37 * Creates a WPixmap structure and initializes it with the supplied
41 * A WPixmap structure or NULL on failure.
44 * DEF_XPM_CLOSENESS specifies the XpmCloseness
45 *----------------------------------------------------------------------
47 WPixmap *wPixmapCreateFromXPMData(WScreen * scr, char **data)
52 image = RGetImageFromXPMData(scr->rcontext, data);
56 pix = wmalloc(sizeof(WPixmap));
57 memset(pix, 0, sizeof(WPixmap));
59 RConvertImageMask(scr->rcontext, image, &pix->image, &pix->mask, 128);
61 pix->width = image->width;
62 pix->height = image->height;
63 pix->depth = scr->w_depth;
71 *----------------------------------------------------------------------
72 * wPixmapCreateFromXBMData--
73 * Creates a WPixmap structure and initializes it with the supplied
74 * XBM structure data, size and mask.
77 * A WPixmap structure or NULL on failure.
79 *----------------------------------------------------------------------
81 WPixmap *wPixmapCreateFromXBMData(WScreen * scr, char *data, char *mask,
82 int width, int height, unsigned long fg, unsigned long bg)
86 pix = wmalloc(sizeof(WPixmap));
87 memset(pix, 0, sizeof(WPixmap));
88 pix->image = XCreatePixmapFromBitmapData(dpy, scr->w_win, data, width, height, fg, bg, scr->w_depth);
89 if (pix->image == None) {
94 pix->mask = XCreateBitmapFromData(dpy, scr->w_win, mask, width, height);
100 pix->depth = scr->w_depth;
105 WPixmap *wPixmapCreateFromBitmap(WScreen * scr, Pixmap bitmap, Pixmap mask, unsigned long fg, unsigned long bg)
112 unsigned int width, height, baz, d;
114 if (!XGetGeometry(dpy, bitmap, &foo, &bar, &bar, &width, &height, &baz, &d) || d != 1) {
117 img = XGetImage(dpy, bitmap, 0, 0, width, height, AllPlanes, XYPixmap);
121 img2 = XCreateImage(dpy, scr->w_visual, scr->w_depth, ZPixmap, 0, NULL, width, height, 8, 0);
127 pixmap = XCreatePixmap(dpy, scr->w_win, width, height, scr->w_depth);
128 if (pixmap == None) {
134 img2->data = wmalloc(height * img2->bytes_per_line);
136 for (y = 0; y < height; y++) {
137 for (x = 0; x < width; x++) {
138 if (XGetPixel(img, x, y) == 0) {
139 XPutPixel(img2, x, y, bg);
141 XPutPixel(img2, x, y, fg);
145 XSetClipMask(dpy, scr->copy_gc, None);
146 XPutImage(dpy, pixmap, scr->copy_gc, img2, 0, 0, 0, 0, width, height);
150 pix = wmalloc(sizeof(WPixmap));
151 memset(pix, 0, sizeof(WPixmap));
155 pix->height = height;
156 pix->depth = scr->w_depth;
161 WPixmap *wPixmapCreate(WScreen * scr, Pixmap image, Pixmap mask)
166 unsigned int width, height, depth, baz;
168 pix = wmalloc(sizeof(WPixmap));
169 memset(pix, 0, sizeof(WPixmap));
172 if (!XGetGeometry(dpy, image, &foo, &bar, &bar, &width, &height, &baz, &depth)) {
173 wwarning("XGetGeometry() failed during wPixmapCreate()");
178 pix->height = height;
185 *----------------------------------------------------------------------
186 * wPixmapLoadXBMFile--
187 * Creates a WPixmap structure and loads a XBM file into it with
188 * an optional mask file. If a mask is not wanted, mask_path should be
192 * A WPixmap structure or NULL on failure.
195 * If the mask bitmap is not successfully loaded the operation
196 * continues as no mask was supplied.
197 *----------------------------------------------------------------------
199 WPixmap *wPixmapLoadXBMFile(WScreen * scr, char *path, char *mask_path)
207 pix = wmalloc(sizeof(WPixmap));
208 memset(pix, 0, sizeof(WPixmap));
210 if (XReadBitmapFile(dpy, scr->w_win, path, (unsigned *)&(pix->width),
211 (unsigned *)&(pix->height), &(pix->image), &junk, &junk) != BitmapSuccess) {
215 if (mask_path != NULL) {
216 if (XReadBitmapFile(dpy, scr->w_win, path, (unsigned *)&junk,
217 (unsigned *)&junk, &(pix->mask), &junk, &junk) != BitmapSuccess) {
218 wwarning(_("could not load mask bitmap file \"%s\". Won't use mask"), mask_path);
231 *----------------------------------------------------------------------
233 * Destroys a WPixmap structure and the pixmap/mask it holds.
237 *----------------------------------------------------------------------
239 void wPixmapDestroy(WPixmap * pix)
242 if (pix->mask && !pix->client_owned_mask) {
243 XFreePixmap(dpy, pix->mask);
246 if (pix->image && !pix->client_owned) {
247 XFreePixmap(dpy, pix->image);