KDE enhancements, menu appearance enhancement
[wmaker-crm.git] / src / superfluous.c
blobc2ef844e5973f4b896d5529eac6752de14f613ba
1 /*
2 * Window Maker window manager
3 *
4 * Copyright (c) 1997, 1998 Alfredo K. Kojima
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 * USA.
22 #include "wconfig.h"
24 #include <X11/Xlib.h>
25 #include <X11/Xutil.h>
27 #include <stdlib.h>
28 #include <unistd.h>
30 #include <time.h>
32 #include <wraster.h>
34 #include "WindowMaker.h"
35 #include "screen.h"
36 #include "superfluous.h"
37 #include "dock.h"
38 #include "wcore.h"
39 #include "framewin.h"
40 #include "window.h"
41 #include "icon.h"
42 #include "appicon.h"
45 extern WPreferences wPreferences;
48 #ifdef SPEAKER_SOUND
49 static void
50 play(Display *dpy, int pitch, int delay)
52 XKeyboardControl kc;
54 kc.bell_pitch = pitch;
55 kc.bell_percent = 50;
56 kc.bell_duration = delay;
57 XChangeKeyboardControl(dpy, KBBellPitch|KBBellDuration|KBBellPercent,&kc);
58 XBell(dpy, 50);
59 XFlush(dpy);
60 wusleep(delay);
62 #endif
66 #ifdef DEMATERIALIZE_ICON
67 void
68 DoKaboom(WScreen *scr, Window win, int x, int y)
70 RImage *icon;
71 RImage *back;
72 RImage *image;
73 Pixmap pixmap;
74 XImage *ximage;
75 int i;
76 int w, h;
78 h = w = wPreferences.icon_size;
79 if (x < 0 || x + w > scr->scr_width || y < 0 || y + h > scr->scr_height)
80 return;
82 icon = RCreateImageFromDrawable(scr->rcontext, win, None);
83 if (!icon)
84 return;
86 XUnmapWindow(dpy, win);
87 XSync(dpy, False);
89 ximage = XGetImage(dpy, scr->root_win, x, y, w, h, AllPlanes, ZPixmap);
90 back = RCreateImageFromXImage(scr->rcontext, ximage, NULL);
91 XDestroyImage(ximage);
92 if (!back) {
93 RDestroyImage(icon);
94 return;
97 for (i=0; i<DEMATERIALIZE_STEPS; i++) {
98 XEvent foo;
99 if (XCheckTypedEvent(dpy, ButtonPress, &foo)) {
100 XPutBackEvent(dpy, &foo);
101 XClearWindow(dpy, scr->root_win);
102 break;
104 image = RCloneImage(back);
105 RCombineImagesWithOpaqueness(image, icon,
106 (DEMATERIALIZE_STEPS-1-i)*256/(DEMATERIALIZE_STEPS+2));
107 RConvertImage(scr->rcontext, image, &pixmap);
108 XCopyArea(dpy, pixmap, scr->root_win, scr->copy_gc, 0, 0, w, h, x, y);
109 XFreePixmap(dpy, pixmap);
110 XFlush(dpy);
111 wusleep(1000);
113 XClearArea(dpy, scr->root_win, x, y, w, h, False);
114 XFlush(dpy);
116 RDestroyImage(icon);
117 RDestroyImage(back);
119 #else /* !DEMATERIALIZE_ICON */
120 void
121 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,
139 wPreferences.icon_size, scr->depth);
140 if (scr->w_visual == DefaultVisual(dpy, scr->screen))
141 XCopyArea(dpy, win, tmp, scr->copy_gc, 0, 0, wPreferences.icon_size,
142 wPreferences.icon_size, 0, 0);
143 else {
144 XImage *image;
146 image = XGetImage(dpy, win, 0, 0, wPreferences.icon_size,
147 wPreferences.icon_size, AllPlanes, ZPixmap);
148 if (!image) {
149 XUnmapWindow(dpy, win);
150 return;
152 XPutImage(dpy, tmp, scr->copy_gc, image, 0, 0, 0, 0,
153 wPreferences.icon_size, wPreferences.icon_size);
154 XDestroyImage(image);
157 for (i=0,k=0; i<wPreferences.icon_size/ICON_KABOOM_PIECE_SIZE && k<PIECES;
158 i++) {
159 for (j=0; j<wPreferences.icon_size/ICON_KABOOM_PIECE_SIZE && k<PIECES;
160 j++) {
161 if (rand()%2) {
162 ax[k]=i;
163 ay[k]=j;
164 px[k]=(x+i*ICON_KABOOM_PIECE_SIZE)<<KAB_PRECISION;
165 py[k]=y+j*ICON_KABOOM_PIECE_SIZE;
166 pvx[k]=rand()%(1<<(KAB_PRECISION+3))-(1<<(KAB_PRECISION+3))/2;
167 pvy[k]=-15-rand()%7;
168 #ifdef ICON_KABOOM_EXTRA
169 for (ll=0; ll<2; ll++) {
170 ptx[ll][k] = px[k];
171 pty[ll][k] = py[k];
173 #endif
174 k++;
175 } else {
176 ax[k]=-1;
181 XUnmapWindow(dpy, win);
183 j=k;
184 while (k>0) {
185 XEvent foo;
187 if (XCheckTypedEvent(dpy, ButtonPress, &foo)) {
188 XPutBackEvent(dpy, &foo);
189 XClearWindow(dpy, scr->root_win);
190 break;
193 for (i=0; i<j ; i++) {
194 if (ax[i]>=0) {
195 int _px = px[i]>>KAB_PRECISION;
196 #ifdef ICON_KABOOM_EXTRA
197 XClearArea(dpy, scr->root_win, ptx[1][i], pty[1][i],
198 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE,
199 False);
201 ptx[1][i] = ptx[0][i];
202 pty[1][i] = pty[0][i];
203 ptx[0][i] = _px;
204 pty[0][i] = py[i];
205 #else
206 XClearArea(dpy, scr->root_win, _px, py[i],
207 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE,
208 False);
209 #endif
210 px[i]+=pvx[i];
211 py[i]+=pvy[i];
212 _px = px[i]>>KAB_PRECISION;
213 pvy[i]++;
214 if (_px<-wPreferences.icon_size || _px>sw || py[i]>=sh) {
215 #ifdef ICON_KABOOM_EXTRA
216 if (py[i]>sh && _px<sw && _px>0) {
217 pvy[i] = -(pvy[i]/2);
218 if (abs(pvy[i]) > 3) {
219 py[i] = sh-ICON_KABOOM_PIECE_SIZE;
220 XCopyArea(dpy, tmp, scr->root_win, scr->copy_gc,
221 ax[i]*ICON_KABOOM_PIECE_SIZE,
222 ay[i]*ICON_KABOOM_PIECE_SIZE,
223 ICON_KABOOM_PIECE_SIZE,
224 ICON_KABOOM_PIECE_SIZE,
225 _px, py[i]);
226 } else {
227 ax[i] = -1;
229 } else {
230 ax[i] = -1;
232 if (ax[i]<0) {
233 for (ll=0; ll<2; ll++)
234 XClearArea(dpy, scr->root_win, ptx[ll][i], pty[ll][i],
235 ICON_KABOOM_PIECE_SIZE,
236 ICON_KABOOM_PIECE_SIZE, False);
237 k--;
239 #else /* !ICON_KABOOM_EXTRA */
240 ax[i]=-1;
241 k--;
242 #endif /* !ICON_KABOOM_EXTRA */
243 } else {
244 XCopyArea(dpy, tmp, scr->root_win, scr->copy_gc,
245 ax[i]*ICON_KABOOM_PIECE_SIZE, ay[i]*ICON_KABOOM_PIECE_SIZE,
246 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE,
247 _px, py[i]);
252 XFlush(dpy);
253 #ifdef SPEAKER_SOUND
254 play(dpy, 100+rand()%250, 12);
255 #else
256 # if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
257 wusleep(MINIATURIZE_ANIMATION_DELAY_Z*2);
258 # endif
259 #endif
262 XFreePixmap(dpy, tmp);
264 #endif /* !DEMATERIALIZE_ICON */
267 Pixmap
268 MakeGhostDock(WDock *dock, int sx, int dx, int y)
270 WScreen *scr = dock->screen_ptr;
271 XImage *img;
272 RImage *back, *dock_image;
273 Pixmap pixmap;
274 int i, virtual_tiles, h, j, n;
275 unsigned long red_mask, green_mask, blue_mask;
277 virtual_tiles = 0;
278 for (i=0; i<dock->max_icons; i++) {
279 if (dock->icon_array[i]!=NULL &&
280 dock->icon_array[i]->yindex > virtual_tiles)
281 virtual_tiles = dock->icon_array[i]->yindex;
283 virtual_tiles++;
284 h = virtual_tiles * wPreferences.icon_size;
285 h = (y + h > scr->scr_height) ? scr->scr_height-y : h;
286 virtual_tiles = h / wPreferences.icon_size; /* The visible ones */
287 if (h % wPreferences.icon_size)
288 virtual_tiles++; /* There is one partially visible tile at end */
290 img=XGetImage(dpy, scr->root_win, dx, y, wPreferences.icon_size, h,
291 AllPlanes, ZPixmap);
292 if (!img)
293 return None;
295 red_mask = img->red_mask;
296 green_mask = img->green_mask;
297 blue_mask = img->blue_mask;
299 back = RCreateImageFromXImage(scr->rcontext, img, NULL);
300 XDestroyImage(img);
301 if (!back) {
302 return None;
305 for (i=0;i<dock->max_icons;i++) {
306 if (dock->icon_array[i]!=NULL &&
307 dock->icon_array[i]->yindex < virtual_tiles) {
308 Pixmap which;
309 j = dock->icon_array[i]->yindex * wPreferences.icon_size;
310 n = (h - j < wPreferences.icon_size) ? h - j :
311 wPreferences.icon_size;
312 if (dock->icon_array[i]->icon->pixmap)
313 which = dock->icon_array[i]->icon->pixmap;
314 else
315 which = dock->icon_array[i]->icon->core->window;
317 img=XGetImage(dpy, which, 0, 0, wPreferences.icon_size, n,
318 AllPlanes, ZPixmap);
320 if (!img){
321 RDestroyImage(back);
322 return None;
324 img->red_mask = red_mask;
325 img->green_mask = green_mask;
326 img->blue_mask = blue_mask;
328 dock_image = RCreateImageFromXImage(scr->rcontext, img, NULL);
329 XDestroyImage(img);
330 if (!dock_image) {
331 RDestroyImage(back);
332 return None;
334 RCombineAreaWithOpaqueness(back, dock_image, 0, 0,
335 wPreferences.icon_size, n,
336 0, j, 30 * 256 / 100);
337 RDestroyImage(dock_image);
342 RConvertImage(scr->rcontext, back, &pixmap);
344 RDestroyImage(back);
346 return pixmap;
350 Pixmap
351 MakeGhostIcon(WScreen *scr, Drawable drawable)
353 RImage *back;
354 RColor color;
355 Pixmap pixmap;
358 if (!drawable)
359 return None;
361 back = RCreateImageFromDrawable(scr->rcontext, drawable, None);
362 if (!back)
363 return None;
365 color.red = 0xff;
366 color.green = 0xff;
367 color.blue = 0xff;
368 color.alpha = 200;
370 RClearImage(back, &color);
371 RConvertImage(scr->rcontext, back, &pixmap);
373 RDestroyImage(back);
375 return pixmap;
380 #ifdef WINDOW_BIRTH_ZOOM
381 void
382 DoWindowBirth(WWindow *wwin)
384 int width = wwin->frame->core->width;
385 int height = wwin->frame->core->height;
386 int w = WMIN(width, 20);
387 int h = WMIN(height, 20);
388 int x, y;
389 int dw, dh;
390 int i;
391 time_t time0 = time(NULL);
393 dw = (width-w)/WINDOW_BIRTH_STEPS;
394 dh = (height-h)/WINDOW_BIRTH_STEPS;
396 x = wwin->frame_x + (width-w)/2;
397 y = wwin->frame_y + (height-h)/2;
399 XMoveResizeWindow(dpy, wwin->frame->core->window, x, y, w, h);
401 XMapWindow(dpy, wwin->frame->core->window);
403 XFlush(dpy);
404 for (i=0; i<WINDOW_BIRTH_STEPS; i++) {
405 x -= dw/2 + dw%2;
406 y -= dh/2 + dh%2;
407 w += dw;
408 h += dh;
409 XMoveResizeWindow(dpy, wwin->frame->core->window, x, y, w, h);
410 XFlush(dpy);
411 /* a timeout */
412 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
413 break;
416 XMoveResizeWindow(dpy, wwin->frame->core->window,
417 wwin->frame_x, wwin->frame_y, width, height);
418 XFlush(dpy);
420 #else
421 void
422 DoWindowBirth(WWindow *wwin)
424 /* dummy stub */
426 #endif
430 #ifdef SILLYNESS
431 static WMPixmap *data[12];
434 static Bool
435 loadData(WScreen *scr)
437 FILE *f;
438 int i;
439 RImage *image;
440 Pixmap d[12];
442 f = fopen(PKGDATADIR"/xtree.dat", "r");
443 if (!f)
444 return False;
446 image = RCreateImage(50, 50, False);
447 if (!image) {
448 fclose(f);
449 return False;
452 for (i = 0; i < 12; i++) {
453 if (fread(image->data[0], 50*50, 1, f)!=1) {
454 goto error;
456 if (fread(image->data[1], 50*50, 1, f)!=1) {
457 goto error;
459 if (fread(image->data[2], 50*50, 1, f)!=1) {
460 goto error;
462 if (!RConvertImage(scr->rcontext, image, &(d[i]))) {
463 goto error;
466 RDestroyImage(image);
468 fclose(f);
470 for (i=0; i<12; i++) {
471 data[i] = WMCreatePixmapFromXPixmaps(scr->wmscreen, d[i], None, 50, 50,
472 scr->w_depth);
475 return True;
477 error:
478 RDestroyImage(image);
480 fclose(f);
482 while (--i > 0) {
483 XFreePixmap(dpy, d[i]);
486 return False;
490 WMPixmap*
491 DoXThing(WWindow *wwin)
493 static int order = 0;
495 order++;
497 return data[order % 12];
501 Bool
502 InitXThing(WScreen *scr)
504 time_t t;
505 struct tm *l;
506 static int i = 0;
508 if (i)
509 return True;
511 t = time(NULL);
512 l = localtime(&t);
513 if ((l->tm_mon!=12||l->tm_mday<24||l->tm_mday>26)) {
514 return False;
517 if (!loadData(scr))
518 return False;
520 i = 1;
522 return True;
525 #endif /* SILLYNESS */
528 #ifdef GHOST_WINDOW_MOVE
529 RImage*
530 InitGhostWindowMove(WScreen *scr)
532 RXImage *ximg;
533 RImage *img;
535 ximg = RGetXImage(scr->rcontext, scr->root_win, 0, 0,
536 scr->scr_width, scr->scr_height);
537 img = RCreateImageFromXImage(scr->rcontext, ximg->image, NULL);
538 RDestroyXImage(dpy, ximg);
540 return img;
543 #endif /* GHOST_WINDOW_MOVE */