show workspace name when changing workspace
[wmaker-crm.git] / src / superfluous.c
blobec1f1db7d4254ea1b196a88dea7bbae7d4df7f75
1 /*
2 * Window Maker window manager
3 *
4 * Copyright (c) 1997, 1998 Alfredo K. Kojima
5 * Copyright (c) 1997, 1998 Dan Pascu
6 *
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"
46 extern WPreferences wPreferences;
49 #ifdef SPEAKER_SOUND
50 static void
51 play(Display *dpy, int pitch, int delay)
53 XKeyboardControl kc;
55 kc.bell_pitch = pitch;
56 kc.bell_percent = 50;
57 kc.bell_duration = delay;
58 XChangeKeyboardControl(dpy, KBBellPitch|KBBellDuration|KBBellPercent,&kc);
59 XBell(dpy, 50);
60 XFlush(dpy);
61 wusleep(delay);
63 #endif
67 #ifdef DEMATERIALIZE_ICON
68 void
69 DoKaboom(WScreen *scr, Window win, int x, int y)
71 RImage *icon;
72 RImage *back;
73 RImage *image;
74 Pixmap pixmap;
75 XImage *ximage;
76 GC gc;
77 XGCValues gcv;
78 int i;
79 int w, h;
80 int run;
82 h = w = wPreferences.icon_size;
83 if (x < 0 || x + w > scr->scr_width || y < 0 || y + h > scr->scr_height)
84 return;
86 icon = RCreateImageFromDrawable(scr->rcontext, win, None);
87 if (!icon)
88 return;
90 gcv.foreground = scr->white_pixel;
91 gcv.background = scr->black_pixel;
92 gcv.graphics_exposures = False;
93 gcv.subwindow_mode = IncludeInferiors;
94 gc = XCreateGC(dpy, scr->w_win, GCForeground|GCBackground|GCSubwindowMode
95 |GCGraphicsExposures, &gcv);
98 XGrabServer(dpy);
99 RConvertImage(scr->rcontext, icon, &pixmap);
100 XUnmapWindow(dpy, win);
102 ximage = XGetImage(dpy, scr->root_win, x, y, w, h, AllPlanes, ZPixmap);
103 XCopyArea(dpy, pixmap, scr->root_win, gc, 0, 0, w, h, x, y);
104 XFreePixmap(dpy,pixmap);
106 back = RCreateImageFromXImage(scr->rcontext, ximage, NULL);
107 XDestroyImage(ximage);
108 if (!back) {
109 RDestroyImage(icon);
110 return;
114 for (i=0,run=0; i<DEMATERIALIZE_STEPS; i++) {
115 XEvent foo;
116 if (!run && XCheckTypedEvent(dpy, ButtonPress, &foo)) {
117 run=1;
118 XPutBackEvent(dpy, &foo);
120 image = RCloneImage(back);
121 RCombineImagesWithOpaqueness(image, icon,
122 (DEMATERIALIZE_STEPS-1-i)*256/(DEMATERIALIZE_STEPS+2));
123 RConvertImage(scr->rcontext, image, &pixmap);
124 XCopyArea(dpy, pixmap, scr->root_win, gc, 0, 0, w, h, x, y);
125 XFreePixmap(dpy, pixmap);
126 XFlush(dpy);
127 if(!run) wusleep(1000);
129 XFlush(dpy);
131 XUngrabServer(dpy);
132 XFreeGC(dpy, gc);
133 RDestroyImage(icon);
134 RDestroyImage(back);
136 #endif /* DEMATERIALIZE_ICON */
143 #ifdef NORMAL_ICON_KABOOM
144 void
145 DoKaboom(WScreen *scr, Window win, int x, int y)
147 int i, j, k;
148 int sw=scr->scr_width, sh=scr->scr_height;
149 #define KAB_PRECISION 4
150 int px[PIECES];
151 short py[PIECES];
152 #ifdef ICON_KABOOM_EXTRA
153 short ptx[2][PIECES], pty[2][PIECES];
154 int ll;
155 #endif
156 char pvx[PIECES], pvy[PIECES];
157 /* in MkLinux/PPC gcc seems to think that char is unsigned? */
158 signed char ax[PIECES], ay[PIECES];
159 Pixmap tmp;
161 XSetClipMask(dpy, scr->copy_gc, None);
162 tmp = XCreatePixmap(dpy, scr->root_win, wPreferences.icon_size,
163 wPreferences.icon_size, scr->depth);
164 if (scr->w_visual == DefaultVisual(dpy, scr->screen))
165 XCopyArea(dpy, win, tmp, scr->copy_gc, 0, 0, wPreferences.icon_size,
166 wPreferences.icon_size, 0, 0);
167 else {
168 XImage *image;
170 image = XGetImage(dpy, win, 0, 0, wPreferences.icon_size,
171 wPreferences.icon_size, AllPlanes, ZPixmap);
172 if (!image) {
173 XUnmapWindow(dpy, win);
174 return;
176 XPutImage(dpy, tmp, scr->copy_gc, image, 0, 0, 0, 0,
177 wPreferences.icon_size, wPreferences.icon_size);
178 XDestroyImage(image);
181 for (i=0,k=0; i<wPreferences.icon_size/ICON_KABOOM_PIECE_SIZE && k<PIECES;
182 i++) {
183 for (j=0; j<wPreferences.icon_size/ICON_KABOOM_PIECE_SIZE && k<PIECES;
184 j++) {
185 if (rand()%2) {
186 ax[k]=i;
187 ay[k]=j;
188 px[k]=(x+i*ICON_KABOOM_PIECE_SIZE)<<KAB_PRECISION;
189 py[k]=y+j*ICON_KABOOM_PIECE_SIZE;
190 pvx[k]=rand()%(1<<(KAB_PRECISION+3))-(1<<(KAB_PRECISION+3))/2;
191 pvy[k]=-15-rand()%7;
192 #ifdef ICON_KABOOM_EXTRA
193 for (ll=0; ll<2; ll++) {
194 ptx[ll][k] = px[k];
195 pty[ll][k] = py[k];
197 #endif
198 k++;
199 } else {
200 ax[k]=-1;
205 XUnmapWindow(dpy, win);
207 j=k;
208 while (k>0) {
209 XEvent foo;
211 if (XCheckTypedEvent(dpy, ButtonPress, &foo)) {
212 XPutBackEvent(dpy, &foo);
213 XClearWindow(dpy, scr->root_win);
214 break;
217 for (i=0; i<j ; i++) {
218 if (ax[i]>=0) {
219 int _px = px[i]>>KAB_PRECISION;
220 #ifdef ICON_KABOOM_EXTRA
221 XClearArea(dpy, scr->root_win, ptx[1][i], pty[1][i],
222 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE,
223 False);
225 ptx[1][i] = ptx[0][i];
226 pty[1][i] = pty[0][i];
227 ptx[0][i] = _px;
228 pty[0][i] = py[i];
229 #else
230 XClearArea(dpy, scr->root_win, _px, py[i],
231 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE,
232 False);
233 #endif
234 px[i]+=pvx[i];
235 py[i]+=pvy[i];
236 _px = px[i]>>KAB_PRECISION;
237 pvy[i]++;
238 if (_px<-wPreferences.icon_size || _px>sw || py[i]>=sh) {
239 #ifdef ICON_KABOOM_EXTRA
240 if (py[i]>sh && _px<sw && _px>0) {
241 pvy[i] = -(pvy[i]/2);
242 if (abs(pvy[i]) > 3) {
243 py[i] = sh-ICON_KABOOM_PIECE_SIZE;
244 XCopyArea(dpy, tmp, scr->root_win, scr->copy_gc,
245 ax[i]*ICON_KABOOM_PIECE_SIZE,
246 ay[i]*ICON_KABOOM_PIECE_SIZE,
247 ICON_KABOOM_PIECE_SIZE,
248 ICON_KABOOM_PIECE_SIZE,
249 _px, py[i]);
250 } else {
251 ax[i] = -1;
253 } else {
254 ax[i] = -1;
256 if (ax[i]<0) {
257 for (ll=0; ll<2; ll++)
258 XClearArea(dpy, scr->root_win, ptx[ll][i], pty[ll][i],
259 ICON_KABOOM_PIECE_SIZE,
260 ICON_KABOOM_PIECE_SIZE, False);
261 k--;
263 #else /* !ICON_KABOOM_EXTRA */
264 ax[i]=-1;
265 k--;
266 #endif /* !ICON_KABOOM_EXTRA */
267 } else {
268 XCopyArea(dpy, tmp, scr->root_win, scr->copy_gc,
269 ax[i]*ICON_KABOOM_PIECE_SIZE, ay[i]*ICON_KABOOM_PIECE_SIZE,
270 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE,
271 _px, py[i]);
276 XFlush(dpy);
277 #ifdef SPEAKER_SOUND
278 play(dpy, 100+rand()%250, 12);
279 #else
280 # if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
281 wusleep(MINIATURIZE_ANIMATION_DELAY_Z*2);
282 # endif
283 #endif
286 XFreePixmap(dpy, tmp);
288 #endif /* NORMAL_ICON_KABOOM */
291 Pixmap
292 MakeGhostDock(WDock *dock, int sx, int dx, int y)
294 WScreen *scr = dock->screen_ptr;
295 XImage *img;
296 RImage *back, *dock_image;
297 Pixmap pixmap;
298 int i, virtual_tiles, h, j, n;
299 unsigned long red_mask, green_mask, blue_mask;
301 virtual_tiles = 0;
302 for (i=0; i<dock->max_icons; i++) {
303 if (dock->icon_array[i]!=NULL &&
304 dock->icon_array[i]->yindex > virtual_tiles)
305 virtual_tiles = dock->icon_array[i]->yindex;
307 virtual_tiles++;
308 h = virtual_tiles * wPreferences.icon_size;
309 h = (y + h > scr->scr_height) ? scr->scr_height-y : h;
310 virtual_tiles = h / wPreferences.icon_size; /* The visible ones */
311 if (h % wPreferences.icon_size)
312 virtual_tiles++; /* There is one partially visible tile at end */
314 img=XGetImage(dpy, scr->root_win, dx, y, wPreferences.icon_size, h,
315 AllPlanes, ZPixmap);
316 if (!img)
317 return None;
319 red_mask = img->red_mask;
320 green_mask = img->green_mask;
321 blue_mask = img->blue_mask;
323 back = RCreateImageFromXImage(scr->rcontext, img, NULL);
324 XDestroyImage(img);
325 if (!back) {
326 return None;
329 for (i=0;i<dock->max_icons;i++) {
330 if (dock->icon_array[i]!=NULL &&
331 dock->icon_array[i]->yindex < virtual_tiles) {
332 Pixmap which;
333 j = dock->icon_array[i]->yindex * wPreferences.icon_size;
334 n = (h - j < wPreferences.icon_size) ? h - j :
335 wPreferences.icon_size;
336 if (dock->icon_array[i]->icon->pixmap)
337 which = dock->icon_array[i]->icon->pixmap;
338 else
339 which = dock->icon_array[i]->icon->core->window;
341 img=XGetImage(dpy, which, 0, 0, wPreferences.icon_size, n,
342 AllPlanes, ZPixmap);
344 if (!img){
345 RDestroyImage(back);
346 return None;
348 img->red_mask = red_mask;
349 img->green_mask = green_mask;
350 img->blue_mask = blue_mask;
352 dock_image = RCreateImageFromXImage(scr->rcontext, img, NULL);
353 XDestroyImage(img);
354 if (!dock_image) {
355 RDestroyImage(back);
356 return None;
358 RCombineAreaWithOpaqueness(back, dock_image, 0, 0,
359 wPreferences.icon_size, n,
360 0, j, 30 * 256 / 100);
361 RDestroyImage(dock_image);
366 RConvertImage(scr->rcontext, back, &pixmap);
368 RDestroyImage(back);
370 return pixmap;
374 Pixmap
375 MakeGhostIcon(WScreen *scr, Drawable drawable)
377 RImage *back;
378 RColor color;
379 Pixmap pixmap;
382 if (!drawable)
383 return None;
385 back = RCreateImageFromDrawable(scr->rcontext, drawable, None);
386 if (!back)
387 return None;
389 color.red = 0xff;
390 color.green = 0xff;
391 color.blue = 0xff;
392 color.alpha = 200;
394 RClearImage(back, &color);
395 RConvertImage(scr->rcontext, back, &pixmap);
397 RDestroyImage(back);
399 return pixmap;
404 #ifdef WINDOW_BIRTH_ZOOM
405 void
406 DoWindowBirth(WWindow *wwin)
408 int width = wwin->frame->core->width;
409 int height = wwin->frame->core->height;
410 int w = WMIN(width, 20);
411 int h = WMIN(height, 20);
412 int x, y;
413 int dw, dh;
414 int i;
415 time_t time0 = time(NULL);
417 dw = (width-w)/WINDOW_BIRTH_STEPS;
418 dh = (height-h)/WINDOW_BIRTH_STEPS;
420 x = wwin->frame_x + (width-w)/2;
421 y = wwin->frame_y + (height-h)/2;
423 XMoveResizeWindow(dpy, wwin->frame->core->window, x, y, w, h);
425 XMapWindow(dpy, wwin->frame->core->window);
427 XFlush(dpy);
428 for (i=0; i<WINDOW_BIRTH_STEPS; i++) {
429 x -= dw/2 + dw%2;
430 y -= dh/2 + dh%2;
431 w += dw;
432 h += dh;
433 XMoveResizeWindow(dpy, wwin->frame->core->window, x, y, w, h);
434 XFlush(dpy);
435 /* a timeout */
436 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
437 break;
440 XMoveResizeWindow(dpy, wwin->frame->core->window,
441 wwin->frame_x, wwin->frame_y, width, height);
442 XFlush(dpy);
444 #else
445 void
446 DoWindowBirth(WWindow *wwin)
448 /* dummy stub */
450 #endif
454 #ifdef SILLYNESS
455 static WMPixmap *data[12];
458 static Bool
459 loadData(WScreen *scr)
461 FILE *f;
462 int i;
463 RImage *image;
464 Pixmap d[12];
466 f = fopen(PKGDATADIR"/xtree.dat", "r");
467 if (!f)
468 return False;
470 image = RCreateImage(50, 50, False);
471 if (!image) {
472 fclose(f);
473 return False;
476 for (i = 0; i < 12; i++) {
477 if (fread(image->data[0], 50*50, 1, f)!=1) {
478 goto error;
480 if (fread(image->data[1], 50*50, 1, f)!=1) {
481 goto error;
483 if (fread(image->data[2], 50*50, 1, f)!=1) {
484 goto error;
486 if (!RConvertImage(scr->rcontext, image, &(d[i]))) {
487 goto error;
490 RDestroyImage(image);
492 fclose(f);
494 for (i=0; i<12; i++) {
495 data[i] = WMCreatePixmapFromXPixmaps(scr->wmscreen, d[i], None, 50, 50,
496 scr->w_depth);
499 return True;
501 error:
502 RDestroyImage(image);
504 fclose(f);
506 while (--i > 0) {
507 XFreePixmap(dpy, d[i]);
510 return False;
514 WMPixmap*
515 DoXThing(WWindow *wwin)
517 static int order = 0;
519 order++;
521 return data[order % 12];
525 Bool
526 InitXThing(WScreen *scr)
528 time_t t;
529 struct tm *l;
530 static int i = 0;
532 if (i)
533 return True;
535 t = time(NULL);
536 l = localtime(&t);
537 if ((l->tm_mon!=12||l->tm_mday<24||l->tm_mday>26)) {
538 return False;
541 if (!loadData(scr))
542 return False;
544 i = 1;
546 return True;
549 #endif /* SILLYNESS */
552 #ifdef GHOST_WINDOW_MOVE
553 RImage*
554 InitGhostWindowMove(WScreen *scr)
556 RXImage *ximg;
557 RImage *img;
559 ximg = RGetXImage(scr->rcontext, scr->root_win, 0, 0,
560 scr->scr_width, scr->scr_height);
561 img = RCreateImageFromXImage(scr->rcontext, ximg->image, NULL);
562 RDestroyXImage(dpy, ximg);
564 return img;
567 #endif /* GHOST_WINDOW_MOVE */