Remove ICON_KABOOM_EXTRA
[wmaker-crm.git] / src / superfluous.c
blob59ce334fc793bf8f91a6615ceecdb301e45d5502
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 "framewin.h"
40 #include "window.h"
41 #include "actions.h"
43 extern WPreferences wPreferences;
45 #ifdef NORMAL_ICON_KABOOM
46 void DoKaboom(WScreen * scr, Window win, int x, int y)
48 int i, j, k;
49 int sw = scr->scr_width, sh = scr->scr_height;
50 #define KAB_PRECISION 4
51 int px[PIECES];
52 short py[PIECES];
53 char pvx[PIECES], pvy[PIECES];
54 /* in MkLinux/PPC gcc seems to think that char is unsigned? */
55 signed char ax[PIECES], ay[PIECES];
56 Pixmap tmp;
58 XSetClipMask(dpy, scr->copy_gc, None);
59 tmp = XCreatePixmap(dpy, scr->root_win, wPreferences.icon_size, wPreferences.icon_size, scr->depth);
60 if (scr->w_visual == DefaultVisual(dpy, scr->screen))
61 XCopyArea(dpy, win, tmp, scr->copy_gc, 0, 0, wPreferences.icon_size, wPreferences.icon_size, 0, 0);
62 else {
63 XImage *image;
65 image = XGetImage(dpy, win, 0, 0, wPreferences.icon_size,
66 wPreferences.icon_size, AllPlanes, ZPixmap);
67 if (!image) {
68 XUnmapWindow(dpy, win);
69 return;
71 XPutImage(dpy, tmp, scr->copy_gc, image, 0, 0, 0, 0,
72 wPreferences.icon_size, wPreferences.icon_size);
73 XDestroyImage(image);
76 for (i = 0, k = 0; i < wPreferences.icon_size / ICON_KABOOM_PIECE_SIZE && k < PIECES; i++) {
77 for (j = 0; j < wPreferences.icon_size / ICON_KABOOM_PIECE_SIZE && k < PIECES; j++) {
78 if (rand() % 2) {
79 ax[k] = i;
80 ay[k] = j;
81 px[k] = (x + i * ICON_KABOOM_PIECE_SIZE) << KAB_PRECISION;
82 py[k] = y + j * ICON_KABOOM_PIECE_SIZE;
83 pvx[k] = rand() % (1 << (KAB_PRECISION + 3)) - (1 << (KAB_PRECISION + 3)) / 2;
84 pvy[k] = -15 - rand() % 7;
85 k++;
86 } else {
87 ax[k] = -1;
92 XUnmapWindow(dpy, win);
94 j = k;
95 while (k > 0) {
96 XEvent foo;
98 if (XCheckTypedEvent(dpy, ButtonPress, &foo)) {
99 XPutBackEvent(dpy, &foo);
100 XClearWindow(dpy, scr->root_win);
101 break;
104 for (i = 0; i < j; i++) {
105 if (ax[i] >= 0) {
106 int _px = px[i] >> KAB_PRECISION;
107 XClearArea(dpy, scr->root_win, _px, py[i],
108 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE, False);
109 px[i] += pvx[i];
110 py[i] += pvy[i];
111 _px = px[i] >> KAB_PRECISION;
112 pvy[i]++;
113 if (_px < -wPreferences.icon_size || _px > sw || py[i] >= sh) {
114 ax[i] = -1;
115 k--;
116 } else {
117 XCopyArea(dpy, tmp, scr->root_win, scr->copy_gc,
118 ax[i] * ICON_KABOOM_PIECE_SIZE, ay[i] * ICON_KABOOM_PIECE_SIZE,
119 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE, _px, py[i]);
124 XFlush(dpy);
125 wusleep(MINIATURIZE_ANIMATION_DELAY_Z * 2);
128 XFreePixmap(dpy, tmp);
130 #endif /* NORMAL_ICON_KABOOM */
132 Pixmap MakeGhostDock(WDock * dock, int sx, int dx, int y)
134 WScreen *scr = dock->screen_ptr;
135 XImage *img;
136 RImage *back, *dock_image;
137 Pixmap pixmap;
138 int i, virtual_tiles, h, j, n;
139 unsigned long red_mask, green_mask, blue_mask;
141 virtual_tiles = 0;
142 for (i = 0; i < dock->max_icons; i++) {
143 if (dock->icon_array[i] != NULL && dock->icon_array[i]->yindex > virtual_tiles)
144 virtual_tiles = dock->icon_array[i]->yindex;
146 virtual_tiles++;
147 h = virtual_tiles * wPreferences.icon_size;
148 h = (y + h > scr->scr_height) ? scr->scr_height - y : h;
149 virtual_tiles = h / wPreferences.icon_size; /* The visible ones */
150 if (h % wPreferences.icon_size)
151 virtual_tiles++; /* There is one partially visible tile at end */
153 img = XGetImage(dpy, scr->root_win, dx, y, wPreferences.icon_size, h, AllPlanes, ZPixmap);
154 if (!img)
155 return None;
157 red_mask = img->red_mask;
158 green_mask = img->green_mask;
159 blue_mask = img->blue_mask;
161 back = RCreateImageFromXImage(scr->rcontext, img, NULL);
162 XDestroyImage(img);
163 if (!back) {
164 return None;
167 for (i = 0; i < dock->max_icons; i++) {
168 if (dock->icon_array[i] != NULL && dock->icon_array[i]->yindex < virtual_tiles) {
169 Pixmap which;
170 j = dock->icon_array[i]->yindex * wPreferences.icon_size;
171 n = (h - j < wPreferences.icon_size) ? h - j : wPreferences.icon_size;
172 if (dock->icon_array[i]->icon->pixmap)
173 which = dock->icon_array[i]->icon->pixmap;
174 else
175 which = dock->icon_array[i]->icon->core->window;
177 img = XGetImage(dpy, which, 0, 0, wPreferences.icon_size, n, AllPlanes, ZPixmap);
179 if (!img) {
180 RReleaseImage(back);
181 return None;
183 img->red_mask = red_mask;
184 img->green_mask = green_mask;
185 img->blue_mask = blue_mask;
187 dock_image = RCreateImageFromXImage(scr->rcontext, img, NULL);
188 XDestroyImage(img);
189 if (!dock_image) {
190 RReleaseImage(back);
191 return None;
193 RCombineAreaWithOpaqueness(back, dock_image, 0, 0,
194 wPreferences.icon_size, n, 0, j, 30 * 256 / 100);
195 RReleaseImage(dock_image);
199 RConvertImage(scr->rcontext, back, &pixmap);
201 RReleaseImage(back);
203 return pixmap;
206 Pixmap MakeGhostIcon(WScreen * scr, Drawable drawable)
208 RImage *back;
209 RColor color;
210 Pixmap pixmap;
212 if (!drawable)
213 return None;
215 back = RCreateImageFromDrawable(scr->rcontext, drawable, None);
216 if (!back)
217 return None;
219 color.red = 0xff;
220 color.green = 0xff;
221 color.blue = 0xff;
222 color.alpha = 200;
224 RClearImage(back, &color);
225 RConvertImage(scr->rcontext, back, &pixmap);
227 RReleaseImage(back);
229 return pixmap;
232 #ifdef WINDOW_BIRTH_ZOOM
234 void DoWindowBirth(WWindow *wwin)
236 int center_x, center_y;
237 int width = wwin->frame->core->width;
238 int height = wwin->frame->core->height;
239 int w = WMIN(width, 20);
240 int h = WMIN(height, 20);
241 WScreen *scr = wwin->screen_ptr;
243 center_x = wwin->frame_x + (width - w) / 2;
244 center_y = wwin->frame_y + (height - h) / 2;
246 animateResize(scr, center_x, center_y, 1, 1, wwin->frame_x, wwin->frame_y, width, height);
248 #else
249 void DoWindowBirth(WWindow *wwin)
251 /* dummy stub */
253 #endif