2 * Window Maker window manager
4 * Copyright (c) 1997, 1998 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"
37 *----------------------------------------------------------------------
38 * wPixmapCreateFromXPMData--
39 * Creates a WPixmap structure and initializes it with the supplied
43 * A WPixmap structure or NULL on failure.
46 * DEF_XPM_CLOSENESS specifies the XpmCloseness
47 *----------------------------------------------------------------------
50 wPixmapCreateFromXPMData(WScreen
*scr
, char **data
)
55 image
= RGetImageFromXPMData(scr
->rcontext
, data
);
59 pix
= wmalloc(sizeof(WPixmap
));
60 memset(pix
, 0, sizeof(WPixmap
));
62 RConvertImageMask(scr
->rcontext
, image
, &pix
->image
, &pix
->mask
, 128);
64 pix
->width
= image
->width
;
65 pix
->height
= image
->height
;
66 pix
->depth
= scr
->w_depth
;
75 *----------------------------------------------------------------------
76 * wPixmapCreateFromXBMData--
77 * Creates a WPixmap structure and initializes it with the supplied
78 * XBM structure data, size and mask.
81 * A WPixmap structure or NULL on failure.
83 *----------------------------------------------------------------------
86 wPixmapCreateFromXBMData(WScreen
*scr
, char *data
, char *mask
,
87 int width
, int height
, unsigned long fg
,
92 pix
= wmalloc(sizeof(WPixmap
));
93 memset(pix
, 0, sizeof(WPixmap
));
94 pix
->image
= XCreatePixmapFromBitmapData(dpy
, scr
->w_win
, data
, width
,
95 height
, fg
, bg
, scr
->w_depth
);
96 if (pix
->image
==None
) {
101 pix
->mask
= XCreateBitmapFromData(dpy
, scr
->w_win
, mask
, width
,
107 pix
->height
= height
;
108 pix
->depth
= scr
->w_depth
;
115 wPixmapCreateFromBitmap(WScreen
*scr
, Pixmap bitmap
, Pixmap mask
,
116 unsigned long fg
, unsigned long bg
)
123 unsigned int width
, height
, baz
, d
;
125 if (!XGetGeometry(dpy
, bitmap
, &foo
, &bar
, &bar
, &width
, &height
, &baz
,
129 img
= XGetImage(dpy
, bitmap
, 0, 0, width
, height
, AllPlanes
, XYPixmap
);
133 img2
=XCreateImage(dpy
, scr
->w_visual
, scr
->w_depth
, ZPixmap
,
134 0, NULL
, width
, height
, 8, 0);
140 pixmap
= XCreatePixmap(dpy
, scr
->w_win
, width
, height
, scr
->w_depth
);
147 img2
->data
= wmalloc(height
* img2
->bytes_per_line
);
149 for (y
=0; y
<height
; y
++) {
150 for (x
=0; x
<width
; x
++) {
151 if (XGetPixel(img
, x
, y
)==0) {
152 XPutPixel(img2
, x
, y
, bg
);
154 XPutPixel(img2
, x
, y
, fg
);
158 XSetClipMask(dpy
, scr
->copy_gc
, None
);
159 XPutImage(dpy
, pixmap
, scr
->copy_gc
, img2
, 0, 0, 0, 0, width
, height
);
163 pix
= wmalloc(sizeof(WPixmap
));
164 memset(pix
, 0, sizeof(WPixmap
));
168 pix
->height
= height
;
169 pix
->depth
= scr
->w_depth
;
175 wPixmapCreate(WScreen
*scr
, Pixmap image
, Pixmap mask
)
180 unsigned int width
, height
, depth
, baz
;
182 pix
= wmalloc(sizeof(WPixmap
));
183 memset(pix
, 0, sizeof(WPixmap
));
186 if (!XGetGeometry(dpy
, image
, &foo
, &bar
, &bar
, &width
, &height
, &baz
,
188 wwarning("XGetGeometry() failed during wPixmapCreate()");
193 pix
->height
= height
;
200 *----------------------------------------------------------------------
201 * wPixmapLoadXBMFile--
202 * Creates a WPixmap structure and loads a XBM file into it with
203 * an optional mask file. If a mask is not wanted, mask_path should be
207 * A WPixmap structure or NULL on failure.
210 * If the mask bitmap is not successfully loaded the operation
211 * continues as no mask was supplied.
212 *----------------------------------------------------------------------
215 wPixmapLoadXBMFile(WScreen
*scr
, char *path
, char *mask_path
)
220 if (!path
) return NULL
;
222 pix
= wmalloc(sizeof(WPixmap
));
223 memset(pix
, 0, sizeof(WPixmap
));
225 if (XReadBitmapFile(dpy
, scr
->w_win
, path
, (unsigned *)&(pix
->width
),
226 (unsigned *)&(pix
->height
),
227 &(pix
->image
), &junk
, &junk
)!=BitmapSuccess
) {
231 if (mask_path
!=NULL
) {
232 if (XReadBitmapFile(dpy
, scr
->w_win
, path
, (unsigned *)&junk
,
233 (unsigned *)&junk
, &(pix
->mask
),
234 &junk
, &junk
) !=BitmapSuccess
) {
235 wwarning(_("could not load mask bitmap file \"%s\". Won't use mask"),
249 *----------------------------------------------------------------------
251 * Destroys a WPixmap structure and the pixmap/mask it holds.
255 *----------------------------------------------------------------------
258 wPixmapDestroy(WPixmap
*pix
)
261 if (pix
->mask
&& !pix
->client_owned_mask
) {
262 XFreePixmap(dpy
, pix
->mask
);
265 if (pix
->image
&& !pix
->client_owned
) {
266 XFreePixmap(dpy
, pix
->image
);