Remove DEMATERIALIZE_ICON code
[wmaker-crm.git] / src / superfluous.c
blob82cb28bbfbb0a4db535760565af97065f513f737
1 /*
2 * Window Maker window manager
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
5 * Copyright (c) 1998-2003 Dan Pascu
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
23 #include "wconfig.h"
25 #include <X11/Xlib.h>
26 #include <X11/Xutil.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <math.h>
31 #include <time.h>
33 #include <wraster.h>
35 #include "WindowMaker.h"
36 #include "screen.h"
37 #include "superfluous.h"
38 #include "dock.h"
39 #include "wcore.h"
40 #include "framewin.h"
41 #include "window.h"
42 #include "icon.h"
43 #include "appicon.h"
44 #include "actions.h"
46 extern WPreferences wPreferences;
48 #ifdef NORMAL_ICON_KABOOM
49 void DoKaboom(WScreen * scr, Window win, int x, int y)
51 int i, j, k;
52 int sw = scr->scr_width, sh = scr->scr_height;
53 #define KAB_PRECISION 4
54 int px[PIECES];
55 short py[PIECES];
56 #ifdef ICON_KABOOM_EXTRA
57 short ptx[2][PIECES], pty[2][PIECES];
58 int ll;
59 #endif
60 char pvx[PIECES], pvy[PIECES];
61 /* in MkLinux/PPC gcc seems to think that char is unsigned? */
62 signed char ax[PIECES], ay[PIECES];
63 Pixmap tmp;
65 XSetClipMask(dpy, scr->copy_gc, None);
66 tmp = XCreatePixmap(dpy, scr->root_win, wPreferences.icon_size, wPreferences.icon_size, scr->depth);
67 if (scr->w_visual == DefaultVisual(dpy, scr->screen))
68 XCopyArea(dpy, win, tmp, scr->copy_gc, 0, 0, wPreferences.icon_size, wPreferences.icon_size, 0, 0);
69 else {
70 XImage *image;
72 image = XGetImage(dpy, win, 0, 0, wPreferences.icon_size,
73 wPreferences.icon_size, AllPlanes, ZPixmap);
74 if (!image) {
75 XUnmapWindow(dpy, win);
76 return;
78 XPutImage(dpy, tmp, scr->copy_gc, image, 0, 0, 0, 0,
79 wPreferences.icon_size, wPreferences.icon_size);
80 XDestroyImage(image);
83 for (i = 0, k = 0; i < wPreferences.icon_size / ICON_KABOOM_PIECE_SIZE && k < PIECES; i++) {
84 for (j = 0; j < wPreferences.icon_size / ICON_KABOOM_PIECE_SIZE && k < PIECES; j++) {
85 if (rand() % 2) {
86 ax[k] = i;
87 ay[k] = j;
88 px[k] = (x + i * ICON_KABOOM_PIECE_SIZE) << KAB_PRECISION;
89 py[k] = y + j * ICON_KABOOM_PIECE_SIZE;
90 pvx[k] = rand() % (1 << (KAB_PRECISION + 3)) - (1 << (KAB_PRECISION + 3)) / 2;
91 pvy[k] = -15 - rand() % 7;
92 #ifdef ICON_KABOOM_EXTRA
93 for (ll = 0; ll < 2; ll++) {
94 ptx[ll][k] = px[k];
95 pty[ll][k] = py[k];
97 #endif
98 k++;
99 } else {
100 ax[k] = -1;
105 XUnmapWindow(dpy, win);
107 j = k;
108 while (k > 0) {
109 XEvent foo;
111 if (XCheckTypedEvent(dpy, ButtonPress, &foo)) {
112 XPutBackEvent(dpy, &foo);
113 XClearWindow(dpy, scr->root_win);
114 break;
117 for (i = 0; i < j; i++) {
118 if (ax[i] >= 0) {
119 int _px = px[i] >> KAB_PRECISION;
120 #ifdef ICON_KABOOM_EXTRA
121 XClearArea(dpy, scr->root_win, ptx[1][i], pty[1][i],
122 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE, False);
124 ptx[1][i] = ptx[0][i];
125 pty[1][i] = pty[0][i];
126 ptx[0][i] = _px;
127 pty[0][i] = py[i];
128 #else
129 XClearArea(dpy, scr->root_win, _px, py[i],
130 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE, False);
131 #endif
132 px[i] += pvx[i];
133 py[i] += pvy[i];
134 _px = px[i] >> KAB_PRECISION;
135 pvy[i]++;
136 if (_px < -wPreferences.icon_size || _px > sw || py[i] >= sh) {
137 #ifdef ICON_KABOOM_EXTRA
138 if (py[i] > sh && _px < sw && _px > 0) {
139 pvy[i] = -(pvy[i] / 2);
140 if (abs(pvy[i]) > 3) {
141 py[i] = sh - ICON_KABOOM_PIECE_SIZE;
142 XCopyArea(dpy, tmp, scr->root_win, scr->copy_gc,
143 ax[i] * ICON_KABOOM_PIECE_SIZE,
144 ay[i] * ICON_KABOOM_PIECE_SIZE,
145 ICON_KABOOM_PIECE_SIZE,
146 ICON_KABOOM_PIECE_SIZE, _px, py[i]);
147 } else {
148 ax[i] = -1;
150 } else {
151 ax[i] = -1;
153 if (ax[i] < 0) {
154 for (ll = 0; ll < 2; ll++)
155 XClearArea(dpy, scr->root_win, ptx[ll][i], pty[ll][i],
156 ICON_KABOOM_PIECE_SIZE,
157 ICON_KABOOM_PIECE_SIZE, False);
158 k--;
160 #else /* !ICON_KABOOM_EXTRA */
161 ax[i] = -1;
162 k--;
163 #endif /* !ICON_KABOOM_EXTRA */
164 } else {
165 XCopyArea(dpy, tmp, scr->root_win, scr->copy_gc,
166 ax[i] * ICON_KABOOM_PIECE_SIZE, ay[i] * ICON_KABOOM_PIECE_SIZE,
167 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE, _px, py[i]);
172 XFlush(dpy);
173 wusleep(MINIATURIZE_ANIMATION_DELAY_Z * 2);
176 XFreePixmap(dpy, tmp);
178 #endif /* NORMAL_ICON_KABOOM */
180 Pixmap MakeGhostDock(WDock * dock, int sx, int dx, int y)
182 WScreen *scr = dock->screen_ptr;
183 XImage *img;
184 RImage *back, *dock_image;
185 Pixmap pixmap;
186 int i, virtual_tiles, h, j, n;
187 unsigned long red_mask, green_mask, blue_mask;
189 virtual_tiles = 0;
190 for (i = 0; i < dock->max_icons; i++) {
191 if (dock->icon_array[i] != NULL && dock->icon_array[i]->yindex > virtual_tiles)
192 virtual_tiles = dock->icon_array[i]->yindex;
194 virtual_tiles++;
195 h = virtual_tiles * wPreferences.icon_size;
196 h = (y + h > scr->scr_height) ? scr->scr_height - y : h;
197 virtual_tiles = h / wPreferences.icon_size; /* The visible ones */
198 if (h % wPreferences.icon_size)
199 virtual_tiles++; /* There is one partially visible tile at end */
201 img = XGetImage(dpy, scr->root_win, dx, y, wPreferences.icon_size, h, AllPlanes, ZPixmap);
202 if (!img)
203 return None;
205 red_mask = img->red_mask;
206 green_mask = img->green_mask;
207 blue_mask = img->blue_mask;
209 back = RCreateImageFromXImage(scr->rcontext, img, NULL);
210 XDestroyImage(img);
211 if (!back) {
212 return None;
215 for (i = 0; i < dock->max_icons; i++) {
216 if (dock->icon_array[i] != NULL && dock->icon_array[i]->yindex < virtual_tiles) {
217 Pixmap which;
218 j = dock->icon_array[i]->yindex * wPreferences.icon_size;
219 n = (h - j < wPreferences.icon_size) ? h - j : wPreferences.icon_size;
220 if (dock->icon_array[i]->icon->pixmap)
221 which = dock->icon_array[i]->icon->pixmap;
222 else
223 which = dock->icon_array[i]->icon->core->window;
225 img = XGetImage(dpy, which, 0, 0, wPreferences.icon_size, n, AllPlanes, ZPixmap);
227 if (!img) {
228 RReleaseImage(back);
229 return None;
231 img->red_mask = red_mask;
232 img->green_mask = green_mask;
233 img->blue_mask = blue_mask;
235 dock_image = RCreateImageFromXImage(scr->rcontext, img, NULL);
236 XDestroyImage(img);
237 if (!dock_image) {
238 RReleaseImage(back);
239 return None;
241 RCombineAreaWithOpaqueness(back, dock_image, 0, 0,
242 wPreferences.icon_size, n, 0, j, 30 * 256 / 100);
243 RReleaseImage(dock_image);
247 RConvertImage(scr->rcontext, back, &pixmap);
249 RReleaseImage(back);
251 return pixmap;
254 Pixmap MakeGhostIcon(WScreen * scr, Drawable drawable)
256 RImage *back;
257 RColor color;
258 Pixmap pixmap;
260 if (!drawable)
261 return None;
263 back = RCreateImageFromDrawable(scr->rcontext, drawable, None);
264 if (!back)
265 return None;
267 color.red = 0xff;
268 color.green = 0xff;
269 color.blue = 0xff;
270 color.alpha = 200;
272 RClearImage(back, &color);
273 RConvertImage(scr->rcontext, back, &pixmap);
275 RReleaseImage(back);
277 return pixmap;
280 #ifdef WINDOW_BIRTH_ZOOM
282 void DoWindowBirth(WWindow *wwin)
284 int center_x, center_y;
285 int width = wwin->frame->core->width;
286 int height = wwin->frame->core->height;
287 int w = WMIN(width, 20);
288 int h = WMIN(height, 20);
289 WScreen *scr = wwin->screen_ptr;
291 center_x = wwin->frame_x + (width - w) / 2;
292 center_y = wwin->frame_y + (height - h) / 2;
294 animateResize(scr, center_x, center_y, 1, 1, wwin->frame_x, wwin->frame_y, width, height);
296 #else
297 void DoWindowBirth(WWindow *wwin)
299 /* dummy stub */
301 #endif