Cleanup includes of wcore.h, defaults.h and pixmap.h
[wmaker-crm.git] / src / pixmap.c
blob87549d2690ff48d319d58a2d3fe7cf0edab069a2
1 /*
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,
19 * USA.
22 #include "wconfig.h"
24 #include <X11/Xlib.h>
25 #include <X11/Xutil.h>
27 #include <wraster.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include "WindowMaker.h"
32 #include "pixmap.h"
35 *----------------------------------------------------------------------
36 * wPixmapCreateFromXPMData--
37 * Creates a WPixmap structure and initializes it with the supplied
38 * XPM structure data.
40 * Returns:
41 * A WPixmap structure or NULL on failure.
43 * Notes:
44 * DEF_XPM_CLOSENESS specifies the XpmCloseness
45 *----------------------------------------------------------------------
47 WPixmap *wPixmapCreateFromXPMData(WScreen * scr, char **data)
49 RImage *image;
50 WPixmap *pix;
52 image = RGetImageFromXPMData(scr->rcontext, data);
53 if (!image)
54 return NULL;
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;
65 RReleaseImage(image);
67 return pix;
71 *----------------------------------------------------------------------
72 * wPixmapCreateFromXBMData--
73 * Creates a WPixmap structure and initializes it with the supplied
74 * XBM structure data, size and mask.
76 * Returns:
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)
84 WPixmap *pix;
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) {
90 wfree(pix);
91 return NULL;
93 if (mask) {
94 pix->mask = XCreateBitmapFromData(dpy, scr->w_win, mask, width, height);
95 } else {
96 pix->mask = None;
98 pix->width = width;
99 pix->height = height;
100 pix->depth = scr->w_depth;
101 return pix;
104 WPixmap *wPixmapCreate(WScreen * scr, Pixmap image, Pixmap mask)
106 WPixmap *pix;
107 Window foo;
108 int bar;
109 unsigned int width, height, depth, baz;
111 pix = wmalloc(sizeof(WPixmap));
112 memset(pix, 0, sizeof(WPixmap));
113 pix->image = image;
114 pix->mask = mask;
115 if (!XGetGeometry(dpy, image, &foo, &bar, &bar, &width, &height, &baz, &depth)) {
116 wwarning("XGetGeometry() failed during wPixmapCreate()");
117 wfree(pix);
118 return NULL;
120 pix->width = width;
121 pix->height = height;
122 pix->depth = depth;
123 return pix;
127 *----------------------------------------------------------------------
128 * wPixmapDestroy--
129 * Destroys a WPixmap structure and the pixmap/mask it holds.
131 * Returns:
132 * None
133 *----------------------------------------------------------------------
135 void wPixmapDestroy(WPixmap * pix)
137 if (!pix->shared) {
138 if (pix->mask && !pix->client_owned_mask) {
139 XFreePixmap(dpy, pix->mask);
142 if (pix->image && !pix->client_owned) {
143 XFreePixmap(dpy, pix->image);
146 wfree(pix);