Make AddMouseRegion's index unsigned
[dockapps.git] / libdockapp / src / dashaped.c
blob94ccefca444efbd83d18b3ebcfbafe0399bb75d8
1 /*
2 * Copyright (c) 2002-2005 Alban G. 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 <assert.h>
24 #include <string.h>
26 #include "dockapp.h"
27 #include "daargs.h"
30 * DAShapedPixmap functions
33 /* Local typedef */
34 typedef enum {
35 daShapeSourceData,
36 daShapeSourceFile
37 } daShapeSource;
39 /* local functions */
40 void setGCs(DAShapedPixmap *dasp);
41 DAShapedPixmap *_daMakeShapedPixmap(daShapeSource source, char **data);
43 extern struct DAContext *_daContext;
45 /* Create a new shaped pixmap with width & height of dockapp window */
46 DAShapedPixmap *
47 DAMakeShapedPixmap()
49 DAShapedPixmap *dasp = malloc(sizeof(DAShapedPixmap));
51 if (dasp == NULL)
52 return NULL;
54 memset(dasp, 0, sizeof(DAShapedPixmap));
55 dasp->pixmap = DAMakePixmap();
56 dasp->shape = DAMakeShape();
57 dasp->geometry.width = _daContext->width;
58 dasp->geometry.height = _daContext->height;
60 setGCs(dasp);
61 DASPClear(dasp);
63 return dasp;
67 /* Create a new shaped pixmap from XPM-data */
68 DAShapedPixmap *
69 DAMakeShapedPixmapFromData(char **data)
71 return _daMakeShapedPixmap(daShapeSourceData, data);
75 /* Create a new shaped pixmap from XPM-data */
76 DAShapedPixmap *
77 DAMakeShapedPixmapFromFile(char *filename)
79 return _daMakeShapedPixmap(daShapeSourceFile, (char **)filename);
83 /* Free memory reserved for a shaped pixmap */
84 void
85 DAFreeShapedPixmap(DAShapedPixmap *dasp)
87 assert(dasp);
89 XFreePixmap(DADisplay, dasp->pixmap);
90 XFreePixmap(DADisplay, dasp->shape);
91 XFreeGC(DADisplay, dasp->shapeGC);
93 free(dasp);
96 /* Copy shape-mask and pixmap-data from an area in one shaped pixmap
97 * into another shaped pixmap */
98 void
99 DASPCopyArea(DAShapedPixmap *src, DAShapedPixmap *dst, int x1, int y1, int w, int h, int x2, int y2)
101 assert(src != NULL && dst != NULL);
103 XCopyPlane(DADisplay, src->shape, dst->shape, src->shapeGC, x1, y1, w, h, x2, y2, 1);
104 XCopyArea(DADisplay, src->pixmap, dst->pixmap, src->drawGC, x1, y1, w, h, x2, y2);
108 /* Clear a shaped pixmap */
109 void
110 DASPClear(DAShapedPixmap *dasp)
112 XGCValues gcv;
114 assert(dasp != NULL);
116 gcv.foreground = 0;
117 XChangeGC(DADisplay, dasp->shapeGC, GCForeground, &gcv);
119 /* Clear pixmaps */
120 XFillRectangle(DADisplay, dasp->pixmap,
121 DAClearGC, 0, 0, dasp->geometry.width, dasp->geometry.height);
122 XFillRectangle(DADisplay, dasp->shape,
123 dasp->shapeGC, 0, 0, dasp->geometry.width, dasp->geometry.height);
125 gcv.foreground = 1;
126 XChangeGC(DADisplay, dasp->shapeGC, GCForeground, &gcv);
130 /* Show the pixmap in the dockapp-window */
131 void
132 DASPSetPixmap(DAShapedPixmap *dasp)
134 DASPSetPixmapForWindow(DAWindow, dasp);
137 void
138 DASPSetPixmapForWindow(Window window, DAShapedPixmap *dasp)
140 assert(dasp != NULL);
142 DASetShapeForWindow(window, dasp->shape);
143 DASetPixmapForWindow(window, dasp->pixmap);
147 void
148 setGCs(DAShapedPixmap *dasp)
150 XGCValues gcv;
152 dasp->drawGC = DAGC;
153 dasp->clearGC = DAClearGC;
155 /* create GC for bit-plane operations in shapes */
156 gcv.graphics_exposures = False;
157 gcv.foreground = 1;
158 gcv.background = 0;
159 gcv.plane_mask = 1;
161 dasp->shapeGC = XCreateGC(
162 DADisplay,
163 dasp->shape,
164 GCGraphicsExposures|GCForeground|GCBackground|GCPlaneMask,
165 &gcv);
170 /* Create a new shaped pixmap using specified method */
171 DAShapedPixmap *
172 _daMakeShapedPixmap(daShapeSource source, char **data)
174 Bool success;
175 DAShapedPixmap *dasp = malloc(sizeof(DAShapedPixmap));
177 if (dasp == NULL)
178 return NULL;
180 memset(dasp, 0, sizeof(DAShapedPixmap));
182 if (source == daShapeSourceData)
183 success = DAMakePixmapFromData(data, &dasp->pixmap, &dasp->shape,
184 &dasp->geometry.width, &dasp->geometry.height);
185 else
186 success = DAMakePixmapFromFile((char *)data, &dasp->pixmap, &dasp->shape,
187 &dasp->geometry.width, &dasp->geometry.height);
189 if (!success)
190 return NULL;
192 setGCs(dasp);
194 return dasp;