Add function prototypes in action.h and include it in superfluous.c
[wmaker-crm.git] / src / superfluous.c
blob84082218604eb40315d48600743cd29c6ee2ac1b
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 DEMATERIALIZE_ICON
49 void DoKaboom(WScreen * scr, Window win, int x, int y)
51 RImage *icon;
52 RImage *back;
53 RImage *image;
54 Pixmap pixmap;
55 XImage *ximage;
56 GC gc;
57 XGCValues gcv;
58 int i;
59 int w, h;
60 int run;
61 XEvent event;
63 h = w = wPreferences.icon_size;
64 if (x < 0 || x + w > scr->scr_width || y < 0 || y + h > scr->scr_height)
65 return;
67 icon = RCreateImageFromDrawable(scr->rcontext, win, None);
68 if (!icon)
69 return;
71 gcv.foreground = scr->white_pixel;
72 gcv.background = scr->black_pixel;
73 gcv.graphics_exposures = False;
74 gcv.subwindow_mode = IncludeInferiors;
75 gc = XCreateGC(dpy, scr->w_win, GCForeground | GCBackground | GCSubwindowMode | GCGraphicsExposures, &gcv);
77 XGrabServer(dpy);
78 RConvertImage(scr->rcontext, icon, &pixmap);
79 XUnmapWindow(dpy, win);
81 ximage = XGetImage(dpy, scr->root_win, x, y, w, h, AllPlanes, ZPixmap);
82 XCopyArea(dpy, pixmap, scr->root_win, gc, 0, 0, w, h, x, y);
83 XFreePixmap(dpy, pixmap);
85 back = RCreateImageFromXImage(scr->rcontext, ximage, NULL);
86 XDestroyImage(ximage);
87 if (!back) {
88 RReleaseImage(icon);
89 return;
92 for (i = 0, run = 0; i < DEMATERIALIZE_STEPS; i++) {
93 XEvent foo;
94 if (!run && XCheckTypedEvent(dpy, ButtonPress, &foo)) {
95 run = 1;
96 XPutBackEvent(dpy, &foo);
98 image = RCloneImage(back);
99 RCombineImagesWithOpaqueness(image, icon,
100 (DEMATERIALIZE_STEPS - 1 - i) * 256 / (DEMATERIALIZE_STEPS + 2));
101 RConvertImage(scr->rcontext, image, &pixmap);
102 XCopyArea(dpy, pixmap, scr->root_win, gc, 0, 0, w, h, x, y);
103 XFreePixmap(dpy, pixmap);
104 XFlush(dpy);
105 if (!run)
106 wusleep(1000);
109 while (XCheckTypedEvent(dpy, MotionNotify, &event)) {
111 XFlush(dpy);
113 XUngrabServer(dpy);
114 XFreeGC(dpy, gc);
115 RReleaseImage(icon);
116 RReleaseImage(back);
118 #endif /* DEMATERIALIZE_ICON */
120 #ifdef NORMAL_ICON_KABOOM
121 void DoKaboom(WScreen * scr, Window win, int x, int y)
123 int i, j, k;
124 int sw = scr->scr_width, sh = scr->scr_height;
125 #define KAB_PRECISION 4
126 int px[PIECES];
127 short py[PIECES];
128 #ifdef ICON_KABOOM_EXTRA
129 short ptx[2][PIECES], pty[2][PIECES];
130 int ll;
131 #endif
132 char pvx[PIECES], pvy[PIECES];
133 /* in MkLinux/PPC gcc seems to think that char is unsigned? */
134 signed char ax[PIECES], ay[PIECES];
135 Pixmap tmp;
137 XSetClipMask(dpy, scr->copy_gc, None);
138 tmp = XCreatePixmap(dpy, scr->root_win, wPreferences.icon_size, wPreferences.icon_size, scr->depth);
139 if (scr->w_visual == DefaultVisual(dpy, scr->screen))
140 XCopyArea(dpy, win, tmp, scr->copy_gc, 0, 0, wPreferences.icon_size, wPreferences.icon_size, 0, 0);
141 else {
142 XImage *image;
144 image = XGetImage(dpy, win, 0, 0, wPreferences.icon_size,
145 wPreferences.icon_size, AllPlanes, ZPixmap);
146 if (!image) {
147 XUnmapWindow(dpy, win);
148 return;
150 XPutImage(dpy, tmp, scr->copy_gc, image, 0, 0, 0, 0,
151 wPreferences.icon_size, wPreferences.icon_size);
152 XDestroyImage(image);
155 for (i = 0, k = 0; i < wPreferences.icon_size / ICON_KABOOM_PIECE_SIZE && k < PIECES; i++) {
156 for (j = 0; j < wPreferences.icon_size / ICON_KABOOM_PIECE_SIZE && k < PIECES; j++) {
157 if (rand() % 2) {
158 ax[k] = i;
159 ay[k] = j;
160 px[k] = (x + i * ICON_KABOOM_PIECE_SIZE) << KAB_PRECISION;
161 py[k] = y + j * ICON_KABOOM_PIECE_SIZE;
162 pvx[k] = rand() % (1 << (KAB_PRECISION + 3)) - (1 << (KAB_PRECISION + 3)) / 2;
163 pvy[k] = -15 - rand() % 7;
164 #ifdef ICON_KABOOM_EXTRA
165 for (ll = 0; ll < 2; ll++) {
166 ptx[ll][k] = px[k];
167 pty[ll][k] = py[k];
169 #endif
170 k++;
171 } else {
172 ax[k] = -1;
177 XUnmapWindow(dpy, win);
179 j = k;
180 while (k > 0) {
181 XEvent foo;
183 if (XCheckTypedEvent(dpy, ButtonPress, &foo)) {
184 XPutBackEvent(dpy, &foo);
185 XClearWindow(dpy, scr->root_win);
186 break;
189 for (i = 0; i < j; i++) {
190 if (ax[i] >= 0) {
191 int _px = px[i] >> KAB_PRECISION;
192 #ifdef ICON_KABOOM_EXTRA
193 XClearArea(dpy, scr->root_win, ptx[1][i], pty[1][i],
194 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE, False);
196 ptx[1][i] = ptx[0][i];
197 pty[1][i] = pty[0][i];
198 ptx[0][i] = _px;
199 pty[0][i] = py[i];
200 #else
201 XClearArea(dpy, scr->root_win, _px, py[i],
202 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE, False);
203 #endif
204 px[i] += pvx[i];
205 py[i] += pvy[i];
206 _px = px[i] >> KAB_PRECISION;
207 pvy[i]++;
208 if (_px < -wPreferences.icon_size || _px > sw || py[i] >= sh) {
209 #ifdef ICON_KABOOM_EXTRA
210 if (py[i] > sh && _px < sw && _px > 0) {
211 pvy[i] = -(pvy[i] / 2);
212 if (abs(pvy[i]) > 3) {
213 py[i] = sh - ICON_KABOOM_PIECE_SIZE;
214 XCopyArea(dpy, tmp, scr->root_win, scr->copy_gc,
215 ax[i] * ICON_KABOOM_PIECE_SIZE,
216 ay[i] * ICON_KABOOM_PIECE_SIZE,
217 ICON_KABOOM_PIECE_SIZE,
218 ICON_KABOOM_PIECE_SIZE, _px, py[i]);
219 } else {
220 ax[i] = -1;
222 } else {
223 ax[i] = -1;
225 if (ax[i] < 0) {
226 for (ll = 0; ll < 2; ll++)
227 XClearArea(dpy, scr->root_win, ptx[ll][i], pty[ll][i],
228 ICON_KABOOM_PIECE_SIZE,
229 ICON_KABOOM_PIECE_SIZE, False);
230 k--;
232 #else /* !ICON_KABOOM_EXTRA */
233 ax[i] = -1;
234 k--;
235 #endif /* !ICON_KABOOM_EXTRA */
236 } else {
237 XCopyArea(dpy, tmp, scr->root_win, scr->copy_gc,
238 ax[i] * ICON_KABOOM_PIECE_SIZE, ay[i] * ICON_KABOOM_PIECE_SIZE,
239 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE, _px, py[i]);
244 XFlush(dpy);
246 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
247 wusleep(MINIATURIZE_ANIMATION_DELAY_Z * 2);
248 #endif
251 XFreePixmap(dpy, tmp);
253 #endif /* NORMAL_ICON_KABOOM */
255 Pixmap MakeGhostDock(WDock * dock, int sx, int dx, int y)
257 WScreen *scr = dock->screen_ptr;
258 XImage *img;
259 RImage *back, *dock_image;
260 Pixmap pixmap;
261 int i, virtual_tiles, h, j, n;
262 unsigned long red_mask, green_mask, blue_mask;
264 virtual_tiles = 0;
265 for (i = 0; i < dock->max_icons; i++) {
266 if (dock->icon_array[i] != NULL && dock->icon_array[i]->yindex > virtual_tiles)
267 virtual_tiles = dock->icon_array[i]->yindex;
269 virtual_tiles++;
270 h = virtual_tiles * wPreferences.icon_size;
271 h = (y + h > scr->scr_height) ? scr->scr_height - y : h;
272 virtual_tiles = h / wPreferences.icon_size; /* The visible ones */
273 if (h % wPreferences.icon_size)
274 virtual_tiles++; /* There is one partially visible tile at end */
276 img = XGetImage(dpy, scr->root_win, dx, y, wPreferences.icon_size, h, AllPlanes, ZPixmap);
277 if (!img)
278 return None;
280 red_mask = img->red_mask;
281 green_mask = img->green_mask;
282 blue_mask = img->blue_mask;
284 back = RCreateImageFromXImage(scr->rcontext, img, NULL);
285 XDestroyImage(img);
286 if (!back) {
287 return None;
290 for (i = 0; i < dock->max_icons; i++) {
291 if (dock->icon_array[i] != NULL && dock->icon_array[i]->yindex < virtual_tiles) {
292 Pixmap which;
293 j = dock->icon_array[i]->yindex * wPreferences.icon_size;
294 n = (h - j < wPreferences.icon_size) ? h - j : wPreferences.icon_size;
295 if (dock->icon_array[i]->icon->pixmap)
296 which = dock->icon_array[i]->icon->pixmap;
297 else
298 which = dock->icon_array[i]->icon->core->window;
300 img = XGetImage(dpy, which, 0, 0, wPreferences.icon_size, n, AllPlanes, ZPixmap);
302 if (!img) {
303 RReleaseImage(back);
304 return None;
306 img->red_mask = red_mask;
307 img->green_mask = green_mask;
308 img->blue_mask = blue_mask;
310 dock_image = RCreateImageFromXImage(scr->rcontext, img, NULL);
311 XDestroyImage(img);
312 if (!dock_image) {
313 RReleaseImage(back);
314 return None;
316 RCombineAreaWithOpaqueness(back, dock_image, 0, 0,
317 wPreferences.icon_size, n, 0, j, 30 * 256 / 100);
318 RReleaseImage(dock_image);
322 RConvertImage(scr->rcontext, back, &pixmap);
324 RReleaseImage(back);
326 return pixmap;
329 Pixmap MakeGhostIcon(WScreen * scr, Drawable drawable)
331 RImage *back;
332 RColor color;
333 Pixmap pixmap;
335 if (!drawable)
336 return None;
338 back = RCreateImageFromDrawable(scr->rcontext, drawable, None);
339 if (!back)
340 return None;
342 color.red = 0xff;
343 color.green = 0xff;
344 color.blue = 0xff;
345 color.alpha = 200;
347 RClearImage(back, &color);
348 RConvertImage(scr->rcontext, back, &pixmap);
350 RReleaseImage(back);
352 return pixmap;
355 #ifdef WINDOW_BIRTH_ZOOM
357 void DoWindowBirth(WWindow *wwin)
359 int center_x, center_y;
360 int width = wwin->frame->core->width;
361 int height = wwin->frame->core->height;
362 int w = WMIN(width, 20);
363 int h = WMIN(height, 20);
364 WScreen *scr = wwin->screen_ptr;
366 center_x = wwin->frame_x + (width - w) / 2;
367 center_y = wwin->frame_y + (height - h) / 2;
369 animateResize(scr, center_x, center_y, 1, 1, wwin->frame_x, wwin->frame_y, width, height);
371 #else
372 void DoWindowBirth(WWindow *wwin)
374 /* dummy stub */
376 #endif
378 #ifdef SILLYNESS
379 static WMPixmap *data[12];
381 static Bool loadData(WScreen * scr)
383 FILE *f;
384 int i;
385 RImage *image;
386 Pixmap d[12];
388 f = fopen(PKGDATADIR "/xtree.dat", "rb");
389 if (!f)
390 return False;
392 image = RCreateImage(50, 50, False);
393 if (!image) {
394 fclose(f);
395 return False;
398 for (i = 0; i < 12; i++) {
399 if (fread(image->data, 50 * 50 * 3, 1, f) != 1) {
400 goto error;
402 if (!RConvertImage(scr->rcontext, image, &(d[i]))) {
403 goto error;
406 RReleaseImage(image);
408 fclose(f);
410 for (i = 0; i < 12; i++) {
411 data[i] = WMCreatePixmapFromXPixmaps(scr->wmscreen, d[i], None, 50, 50, scr->w_depth);
414 return True;
416 error:
417 RReleaseImage(image);
419 fclose(f);
421 while (--i > 0) {
422 XFreePixmap(dpy, d[i]);
425 return False;
428 WMPixmap *DoXThing(WWindow * wwin)
430 static int order = 0;
432 order++;
434 return data[order % 12];
437 Bool InitXThing(WScreen * scr)
439 time_t t;
440 struct tm *l;
441 static int i = 0;
443 t = time(NULL);
444 l = localtime(&t);
445 if ((l->tm_mon != 11 || l->tm_mday < 24 || l->tm_mday > 26))
446 return False;
448 if (i)
449 return True;
451 if (!loadData(scr))
452 return False;
454 i = 1;
456 return True;
459 #endif /* SILLYNESS */