Remove 'ghost window move' code
[wmaker-crm.git] / src / superfluous.c
blob395af7625df9f14c224ff4ac7d25d29af2952b89
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"
45 extern WPreferences wPreferences;
47 #ifdef DEMATERIALIZE_ICON
48 void DoKaboom(WScreen * scr, Window win, int x, int y)
50 RImage *icon;
51 RImage *back;
52 RImage *image;
53 Pixmap pixmap;
54 XImage *ximage;
55 GC gc;
56 XGCValues gcv;
57 int i;
58 int w, h;
59 int run;
60 XEvent event;
62 h = w = wPreferences.icon_size;
63 if (x < 0 || x + w > scr->scr_width || y < 0 || y + h > scr->scr_height)
64 return;
66 icon = RCreateImageFromDrawable(scr->rcontext, win, None);
67 if (!icon)
68 return;
70 gcv.foreground = scr->white_pixel;
71 gcv.background = scr->black_pixel;
72 gcv.graphics_exposures = False;
73 gcv.subwindow_mode = IncludeInferiors;
74 gc = XCreateGC(dpy, scr->w_win, GCForeground | GCBackground | GCSubwindowMode | GCGraphicsExposures, &gcv);
76 XGrabServer(dpy);
77 RConvertImage(scr->rcontext, icon, &pixmap);
78 XUnmapWindow(dpy, win);
80 ximage = XGetImage(dpy, scr->root_win, x, y, w, h, AllPlanes, ZPixmap);
81 XCopyArea(dpy, pixmap, scr->root_win, gc, 0, 0, w, h, x, y);
82 XFreePixmap(dpy, pixmap);
84 back = RCreateImageFromXImage(scr->rcontext, ximage, NULL);
85 XDestroyImage(ximage);
86 if (!back) {
87 RReleaseImage(icon);
88 return;
91 for (i = 0, run = 0; i < DEMATERIALIZE_STEPS; i++) {
92 XEvent foo;
93 if (!run && XCheckTypedEvent(dpy, ButtonPress, &foo)) {
94 run = 1;
95 XPutBackEvent(dpy, &foo);
97 image = RCloneImage(back);
98 RCombineImagesWithOpaqueness(image, icon,
99 (DEMATERIALIZE_STEPS - 1 - i) * 256 / (DEMATERIALIZE_STEPS + 2));
100 RConvertImage(scr->rcontext, image, &pixmap);
101 XCopyArea(dpy, pixmap, scr->root_win, gc, 0, 0, w, h, x, y);
102 XFreePixmap(dpy, pixmap);
103 XFlush(dpy);
104 if (!run)
105 wusleep(1000);
108 while (XCheckTypedEvent(dpy, MotionNotify, &event)) {
110 XFlush(dpy);
112 XUngrabServer(dpy);
113 XFreeGC(dpy, gc);
114 RReleaseImage(icon);
115 RReleaseImage(back);
117 #endif /* DEMATERIALIZE_ICON */
119 #ifdef NORMAL_ICON_KABOOM
120 void DoKaboom(WScreen * scr, Window win, int x, int y)
122 int i, j, k;
123 int sw = scr->scr_width, sh = scr->scr_height;
124 #define KAB_PRECISION 4
125 int px[PIECES];
126 short py[PIECES];
127 #ifdef ICON_KABOOM_EXTRA
128 short ptx[2][PIECES], pty[2][PIECES];
129 int ll;
130 #endif
131 char pvx[PIECES], pvy[PIECES];
132 /* in MkLinux/PPC gcc seems to think that char is unsigned? */
133 signed char ax[PIECES], ay[PIECES];
134 Pixmap tmp;
136 XSetClipMask(dpy, scr->copy_gc, None);
137 tmp = XCreatePixmap(dpy, scr->root_win, wPreferences.icon_size, wPreferences.icon_size, scr->depth);
138 if (scr->w_visual == DefaultVisual(dpy, scr->screen))
139 XCopyArea(dpy, win, tmp, scr->copy_gc, 0, 0, wPreferences.icon_size, wPreferences.icon_size, 0, 0);
140 else {
141 XImage *image;
143 image = XGetImage(dpy, win, 0, 0, wPreferences.icon_size,
144 wPreferences.icon_size, AllPlanes, ZPixmap);
145 if (!image) {
146 XUnmapWindow(dpy, win);
147 return;
149 XPutImage(dpy, tmp, scr->copy_gc, image, 0, 0, 0, 0,
150 wPreferences.icon_size, wPreferences.icon_size);
151 XDestroyImage(image);
154 for (i = 0, k = 0; i < wPreferences.icon_size / ICON_KABOOM_PIECE_SIZE && k < PIECES; i++) {
155 for (j = 0; j < wPreferences.icon_size / ICON_KABOOM_PIECE_SIZE && k < PIECES; j++) {
156 if (rand() % 2) {
157 ax[k] = i;
158 ay[k] = j;
159 px[k] = (x + i * ICON_KABOOM_PIECE_SIZE) << KAB_PRECISION;
160 py[k] = y + j * ICON_KABOOM_PIECE_SIZE;
161 pvx[k] = rand() % (1 << (KAB_PRECISION + 3)) - (1 << (KAB_PRECISION + 3)) / 2;
162 pvy[k] = -15 - rand() % 7;
163 #ifdef ICON_KABOOM_EXTRA
164 for (ll = 0; ll < 2; ll++) {
165 ptx[ll][k] = px[k];
166 pty[ll][k] = py[k];
168 #endif
169 k++;
170 } else {
171 ax[k] = -1;
176 XUnmapWindow(dpy, win);
178 j = k;
179 while (k > 0) {
180 XEvent foo;
182 if (XCheckTypedEvent(dpy, ButtonPress, &foo)) {
183 XPutBackEvent(dpy, &foo);
184 XClearWindow(dpy, scr->root_win);
185 break;
188 for (i = 0; i < j; i++) {
189 if (ax[i] >= 0) {
190 int _px = px[i] >> KAB_PRECISION;
191 #ifdef ICON_KABOOM_EXTRA
192 XClearArea(dpy, scr->root_win, ptx[1][i], pty[1][i],
193 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE, False);
195 ptx[1][i] = ptx[0][i];
196 pty[1][i] = pty[0][i];
197 ptx[0][i] = _px;
198 pty[0][i] = py[i];
199 #else
200 XClearArea(dpy, scr->root_win, _px, py[i],
201 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE, False);
202 #endif
203 px[i] += pvx[i];
204 py[i] += pvy[i];
205 _px = px[i] >> KAB_PRECISION;
206 pvy[i]++;
207 if (_px < -wPreferences.icon_size || _px > sw || py[i] >= sh) {
208 #ifdef ICON_KABOOM_EXTRA
209 if (py[i] > sh && _px < sw && _px > 0) {
210 pvy[i] = -(pvy[i] / 2);
211 if (abs(pvy[i]) > 3) {
212 py[i] = sh - ICON_KABOOM_PIECE_SIZE;
213 XCopyArea(dpy, tmp, scr->root_win, scr->copy_gc,
214 ax[i] * ICON_KABOOM_PIECE_SIZE,
215 ay[i] * ICON_KABOOM_PIECE_SIZE,
216 ICON_KABOOM_PIECE_SIZE,
217 ICON_KABOOM_PIECE_SIZE, _px, py[i]);
218 } else {
219 ax[i] = -1;
221 } else {
222 ax[i] = -1;
224 if (ax[i] < 0) {
225 for (ll = 0; ll < 2; ll++)
226 XClearArea(dpy, scr->root_win, ptx[ll][i], pty[ll][i],
227 ICON_KABOOM_PIECE_SIZE,
228 ICON_KABOOM_PIECE_SIZE, False);
229 k--;
231 #else /* !ICON_KABOOM_EXTRA */
232 ax[i] = -1;
233 k--;
234 #endif /* !ICON_KABOOM_EXTRA */
235 } else {
236 XCopyArea(dpy, tmp, scr->root_win, scr->copy_gc,
237 ax[i] * ICON_KABOOM_PIECE_SIZE, ay[i] * ICON_KABOOM_PIECE_SIZE,
238 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE, _px, py[i]);
243 XFlush(dpy);
245 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
246 wusleep(MINIATURIZE_ANIMATION_DELAY_Z * 2);
247 #endif
250 XFreePixmap(dpy, tmp);
252 #endif /* NORMAL_ICON_KABOOM */
254 Pixmap MakeGhostDock(WDock * dock, int sx, int dx, int y)
256 WScreen *scr = dock->screen_ptr;
257 XImage *img;
258 RImage *back, *dock_image;
259 Pixmap pixmap;
260 int i, virtual_tiles, h, j, n;
261 unsigned long red_mask, green_mask, blue_mask;
263 virtual_tiles = 0;
264 for (i = 0; i < dock->max_icons; i++) {
265 if (dock->icon_array[i] != NULL && dock->icon_array[i]->yindex > virtual_tiles)
266 virtual_tiles = dock->icon_array[i]->yindex;
268 virtual_tiles++;
269 h = virtual_tiles * wPreferences.icon_size;
270 h = (y + h > scr->scr_height) ? scr->scr_height - y : h;
271 virtual_tiles = h / wPreferences.icon_size; /* The visible ones */
272 if (h % wPreferences.icon_size)
273 virtual_tiles++; /* There is one partially visible tile at end */
275 img = XGetImage(dpy, scr->root_win, dx, y, wPreferences.icon_size, h, AllPlanes, ZPixmap);
276 if (!img)
277 return None;
279 red_mask = img->red_mask;
280 green_mask = img->green_mask;
281 blue_mask = img->blue_mask;
283 back = RCreateImageFromXImage(scr->rcontext, img, NULL);
284 XDestroyImage(img);
285 if (!back) {
286 return None;
289 for (i = 0; i < dock->max_icons; i++) {
290 if (dock->icon_array[i] != NULL && dock->icon_array[i]->yindex < virtual_tiles) {
291 Pixmap which;
292 j = dock->icon_array[i]->yindex * wPreferences.icon_size;
293 n = (h - j < wPreferences.icon_size) ? h - j : wPreferences.icon_size;
294 if (dock->icon_array[i]->icon->pixmap)
295 which = dock->icon_array[i]->icon->pixmap;
296 else
297 which = dock->icon_array[i]->icon->core->window;
299 img = XGetImage(dpy, which, 0, 0, wPreferences.icon_size, n, AllPlanes, ZPixmap);
301 if (!img) {
302 RReleaseImage(back);
303 return None;
305 img->red_mask = red_mask;
306 img->green_mask = green_mask;
307 img->blue_mask = blue_mask;
309 dock_image = RCreateImageFromXImage(scr->rcontext, img, NULL);
310 XDestroyImage(img);
311 if (!dock_image) {
312 RReleaseImage(back);
313 return None;
315 RCombineAreaWithOpaqueness(back, dock_image, 0, 0,
316 wPreferences.icon_size, n, 0, j, 30 * 256 / 100);
317 RReleaseImage(dock_image);
321 RConvertImage(scr->rcontext, back, &pixmap);
323 RReleaseImage(back);
325 return pixmap;
328 Pixmap MakeGhostIcon(WScreen * scr, Drawable drawable)
330 RImage *back;
331 RColor color;
332 Pixmap pixmap;
334 if (!drawable)
335 return None;
337 back = RCreateImageFromDrawable(scr->rcontext, drawable, None);
338 if (!back)
339 return None;
341 color.red = 0xff;
342 color.green = 0xff;
343 color.blue = 0xff;
344 color.alpha = 200;
346 RClearImage(back, &color);
347 RConvertImage(scr->rcontext, back, &pixmap);
349 RReleaseImage(back);
351 return pixmap;
354 #ifdef WINDOW_BIRTH_ZOOM
355 void DoWindowBirth(WWindow * wwin)
357 int width = wwin->frame->core->width;
358 int height = wwin->frame->core->height;
359 int w = WMIN(width, 20);
360 int h = WMIN(height, 20);
361 int x, y;
362 int dw, dh;
363 int i;
364 time_t time0 = time(NULL);
366 dw = (width - w) / WINDOW_BIRTH_STEPS;
367 dh = (height - h) / WINDOW_BIRTH_STEPS;
369 x = wwin->frame_x + (width - w) / 2;
370 y = wwin->frame_y + (height - h) / 2;
372 XMoveResizeWindow(dpy, wwin->frame->core->window, x, y, w, h);
374 XMapWindow(dpy, wwin->frame->core->window);
376 XFlush(dpy);
377 for (i = 0; i < WINDOW_BIRTH_STEPS; i++) {
378 x -= dw / 2 + dw % 2;
379 y -= dh / 2 + dh % 2;
380 w += dw;
381 h += dh;
382 XMoveResizeWindow(dpy, wwin->frame->core->window, x, y, w, h);
383 XFlush(dpy);
384 /* a timeout */
385 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
386 break;
389 XMoveResizeWindow(dpy, wwin->frame->core->window, wwin->frame_x, wwin->frame_y, width, height);
390 XFlush(dpy);
392 #else
393 #ifdef WINDOW_BIRTH_ZOOM2
394 extern void animateResize();
396 void DoWindowBirth(WWindow * wwin)
398 /* dummy stub */
400 int center_x, center_y;
401 int width = wwin->frame->core->width;
402 int height = wwin->frame->core->height;
403 int w = WMIN(width, 20);
404 int h = WMIN(height, 20);
405 WScreen *scr = wwin->screen_ptr;
407 center_x = wwin->frame_x + (width - w) / 2;
408 center_y = wwin->frame_y + (height - h) / 2;
410 animateResize(scr, center_x, center_y, 1, 1, wwin->frame_x, wwin->frame_y, width, height, 0);
412 #else
413 void DoWindowBirth(WWindow * wwin)
415 /* dummy stub */
417 #endif
418 #endif
420 #ifdef SILLYNESS
421 static WMPixmap *data[12];
423 static Bool loadData(WScreen * scr)
425 FILE *f;
426 int i;
427 RImage *image;
428 Pixmap d[12];
430 f = fopen(PKGDATADIR "/xtree.dat", "rb");
431 if (!f)
432 return False;
434 image = RCreateImage(50, 50, False);
435 if (!image) {
436 fclose(f);
437 return False;
440 for (i = 0; i < 12; i++) {
441 if (fread(image->data, 50 * 50 * 3, 1, f) != 1) {
442 goto error;
444 if (!RConvertImage(scr->rcontext, image, &(d[i]))) {
445 goto error;
448 RReleaseImage(image);
450 fclose(f);
452 for (i = 0; i < 12; i++) {
453 data[i] = WMCreatePixmapFromXPixmaps(scr->wmscreen, d[i], None, 50, 50, scr->w_depth);
456 return True;
458 error:
459 RReleaseImage(image);
461 fclose(f);
463 while (--i > 0) {
464 XFreePixmap(dpy, d[i]);
467 return False;
470 WMPixmap *DoXThing(WWindow * wwin)
472 static int order = 0;
474 order++;
476 return data[order % 12];
479 Bool InitXThing(WScreen * scr)
481 time_t t;
482 struct tm *l;
483 static int i = 0;
485 t = time(NULL);
486 l = localtime(&t);
487 if ((l->tm_mon != 11 || l->tm_mday < 24 || l->tm_mday > 26))
488 return False;
490 if (i)
491 return True;
493 if (!loadData(scr))
494 return False;
496 i = 1;
498 return True;
501 #endif /* SILLYNESS */