2 * Copyright (c) 1999-2005 Alfredo K. Kojima, Alban Hertroys
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include <X11/extensions/shape.h>
26 #include <X11/Xatom.h>
31 extern struct DAContext
*_daContext
;
39 /* Function prototype */
40 Bool
_daMakePixmap(daXpmSource source
,
41 char **data
, Pixmap
*pixmap
, Pixmap
*mask
,
42 unsigned short *width
, unsigned short *height
);
47 DASetShapeWithOffset(Pixmap shapeMask
, int x_ofs
, int y_ofs
)
49 DASetShapeWithOffsetForWindow(DAWindow
, shapeMask
, x_ofs
, y_ofs
);
53 DASetShapeWithOffsetForWindow(Window window
, Pixmap shapeMask
,
56 XShapeCombineMask(DADisplay
, window
, ShapeBounding
, -x_ofs
, -y_ofs
,
62 DASetPixmap(Pixmap pixmap
)
64 DASetPixmapForWindow(DAWindow
, pixmap
);
68 DASetPixmapForWindow(Window window
, Pixmap pixmap
)
70 XSetWindowBackgroundPixmap(DADisplay
, window
, pixmap
);
71 XClearWindow(DADisplay
, window
);
78 return (XCreatePixmap(DADisplay
, DAWindow
,
79 _daContext
->width
, _daContext
->height
,
86 return (XCreatePixmap(DADisplay
, DAWindow
,
87 _daContext
->width
, _daContext
->height
,
92 DAMakeShapeFromData(char *data
, unsigned int width
, unsigned int height
)
94 return (XCreateBitmapFromData(DADisplay
, DAWindow
, data
,
99 DAMakeShapeFromFile(char *filename
)
102 unsigned int width
, height
;
103 int result
, x_hot
, y_hot
;
105 result
= XReadBitmapFile(DADisplay
, DAWindow
, filename
, &width
, &height
,
106 &shape
, &x_hot
, &y_hot
);
109 case BitmapOpenFailed
:
110 DAWarning("bitmap file %s cannot be opened.", filename
);
113 case BitmapFileInvalid
:
114 DAWarning("bitmap file %s not valid.", filename
);
118 DAWarning("insufficient memory to open bitmap file %s.",
127 DAMakePixmapFromData(char **data
, Pixmap
*pixmap
, Pixmap
*mask
,
128 unsigned short *width
, unsigned short *height
)
130 return _daMakePixmap(daXpmSourceData
, data
,
136 DAMakePixmapFromFile(char *filename
, Pixmap
*pixmap
, Pixmap
*mask
,
137 unsigned short *width
, unsigned short *height
)
139 if (access(filename
, R_OK
) < 0)
142 return _daMakePixmap(daXpmSourceFile
, (char **)filename
,
150 _daMakePixmap(daXpmSource source
,
151 char **data
, Pixmap
*pixmap
, Pixmap
*mask
,
152 unsigned short *width
, unsigned short *height
)
154 XpmAttributes xpmAttr
;
156 xpmAttr
.valuemask
= XpmCloseness
;
157 xpmAttr
.closeness
= 40000;
160 if (source
== daXpmSourceData
161 && (XpmCreatePixmapFromData(
162 DADisplay
, DAWindow
, data
, pixmap
, mask
, &xpmAttr
) != 0))
165 else if (source
== daXpmSourceFile
166 && (XpmReadFileToPixmap(
167 DADisplay
, DAWindow
, (char *)data
, pixmap
, mask
, &xpmAttr
) != 0))
170 *width
= xpmAttr
.width
;
171 *height
= xpmAttr
.height
;