libdockapp: Remove CVS cruft.
[dockapps.git] / libdockapp / src / dapixmap.c
blob39b9e47b3d6c9df406a511888d0cb7213952efde
1 /*
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.
23 #include <X11/Xlib.h>
24 #include <X11/xpm.h>
25 #include <X11/extensions/shape.h>
26 #include <X11/Xatom.h>
28 #include "dockapp.h"
29 #include "daargs.h"
31 extern struct DAContext *_daContext;
33 /* Local typedef */
34 typedef enum {
35 daXpmSourceData,
36 daXpmSourceFile
37 } daXpmSource;
39 /* Function prototype */
40 Bool _daMakePixmap(daXpmSource source,
41 char **data, Pixmap *pixmap, Pixmap *mask,
42 unsigned short *width, unsigned short *height);
46 void
47 DASetShapeWithOffset(Pixmap shapeMask, int x_ofs, int y_ofs)
49 DASetShapeWithOffsetForWindow(DAWindow, shapeMask, x_ofs, y_ofs);
52 void
53 DASetShapeWithOffsetForWindow(Window window, Pixmap shapeMask,
54 int x_ofs, int y_ofs)
56 XShapeCombineMask(DADisplay, window, ShapeBounding, -x_ofs, -y_ofs,
57 shapeMask, ShapeSet);
58 XFlush(DADisplay);
61 void
62 DASetPixmap(Pixmap pixmap)
64 DASetPixmapForWindow(DAWindow, pixmap);
67 void
68 DASetPixmapForWindow(Window window, Pixmap pixmap)
70 XSetWindowBackgroundPixmap(DADisplay, window, pixmap);
71 XClearWindow(DADisplay, window);
72 XFlush(DADisplay);
75 Pixmap
76 DAMakePixmap(void)
78 return (XCreatePixmap(DADisplay, DAWindow,
79 _daContext->width, _daContext->height,
80 DADepth));
83 Pixmap
84 DAMakeShape(void)
86 return (XCreatePixmap(DADisplay, DAWindow,
87 _daContext->width, _daContext->height,
88 1));
91 Bool
92 DAMakePixmapFromData(char **data, Pixmap *pixmap, Pixmap *mask,
93 unsigned short *width, unsigned short *height)
95 return _daMakePixmap(daXpmSourceData, data,
96 pixmap, mask,
97 width, height);
100 Bool
101 DAMakePixmapFromFile(char *filename, Pixmap *pixmap, Pixmap *mask,
102 unsigned short *width, unsigned short *height)
104 if (access(filename, R_OK) < 0)
105 return False;
107 return _daMakePixmap(daXpmSourceFile, (char**)filename,
108 pixmap, mask,
109 width, height);
114 Bool
115 _daMakePixmap(daXpmSource source,
116 char **data, Pixmap *pixmap, Pixmap *mask,
117 unsigned short *width, unsigned short *height)
119 XpmAttributes xpmAttr;
121 xpmAttr.valuemask = XpmCloseness;
122 xpmAttr.closeness = 40000;
125 if (source == daXpmSourceData
126 && (XpmCreatePixmapFromData(
127 DADisplay, DAWindow, data, pixmap, mask, &xpmAttr) != 0))
128 return False;
130 else if (source == daXpmSourceFile
131 && (XpmReadFileToPixmap(
132 DADisplay, DAWindow, (char*)data, pixmap, mask, &xpmAttr) != 0))
133 return False;
135 *width = xpmAttr.width;
136 *height = xpmAttr.height;
138 return True;