Initial revision
[wmaker-crm.git] / src / superfluous.c
blob44909460e77ca5a233647f65b81c7b1a75dca216
1 /*
2 * WindowMaker 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 <wraster.h>
32 #include "WindowMaker.h"
33 #include "screen.h"
34 #include "superfluous.h"
35 #include "dock.h"
36 #include "wcore.h"
37 #include "framewin.h"
38 #include "window.h"
41 extern WPreferences wPreferences;
44 #ifdef SPEAKER_SOUND
45 static void
46 play(Display *dpy, int pitch, int delay)
48 XKeyboardControl kc;
50 kc.bell_pitch = pitch;
51 kc.bell_percent = 50;
52 kc.bell_duration = delay;
53 XChangeKeyboardControl(dpy, KBBellPitch|KBBellDuration|KBBellPercent,&kc);
54 XBell(dpy, 50);
55 XFlush(dpy);
56 wusleep(delay);
58 #endif
61 void
62 DoKaboom(WScreen *scr, Window win, int x, int y)
64 int i, j, k;
65 int sw=scr->scr_width, sh=scr->scr_height;
66 short px[PIECES], py[PIECES];
67 char pvx[PIECES], pvy[PIECES];
68 char ax[PIECES], ay[PIECES];
69 Pixmap tmp;
70 XImage *img;
72 img=XGetImage(dpy, win, 0, 0, wPreferences.icon_size,
73 wPreferences.icon_size, AllPlanes, ZPixmap);
74 XUnmapWindow(dpy,win);
75 if (!img)
76 return;
77 XSetClipMask(dpy, scr->copy_gc, None);
78 tmp = XCreatePixmap(dpy, scr->root_win, wPreferences.icon_size,
79 wPreferences.icon_size, scr->depth);
80 XPutImage(dpy, tmp, scr->copy_gc, img, 0, 0, 0, 0, wPreferences.icon_size,
81 wPreferences.icon_size);
82 XDestroyImage(img);
83 for (i=0,k=0; i<wPreferences.icon_size/PSIZE; i++) {
84 for (j=0; j<wPreferences.icon_size/PSIZE; j++) {
85 if (rand()%3) {
86 ax[k]=i;
87 ay[k]=j;
88 px[k]=x+i*PSIZE;
89 py[k]=y+j*PSIZE;
90 pvx[k]=rand()%7-3;
91 #ifdef SPREAD_ICON
92 pvy[k]=rand()%7-3;
93 #else
94 pvy[k]=-12-rand()%6;
95 #endif
96 k++;
97 } else {
98 ax[k]=-1;
102 j=k;
103 while (k>0) {
104 for (i=0; i<j; i++) {
105 if (ax[i]>=0) {
106 px[i]+=pvx[i];
107 py[i]+=pvy[i];
108 #ifdef SPREAD_ICON
109 pvx[i]+=(pvx[i]>0 ? 2 : -2);
110 pvy[i]+=(pvy[i]>0 ? 2 : -2);
111 /* The following are nice, but too slow.
112 * The animation can have an unknown duration, depending
113 * on what rand() returns. Until the animation ends, the user
114 * cannot do anything, which is not too good. -Dan
116 /*pvx[i]+=rand()%5-2;
117 pvy[i]+=rand()%5-2;*/
119 #else
120 pvy[i]++;
121 #endif
122 if (px[i]<-wPreferences.icon_size || px[i]>sw || py[i]>sh
123 #ifdef SPREAD_ICON
124 || px[i]<0 || py[i]<0
125 #endif
127 ax[i]=-1;
128 k--;
129 } else {
130 XCopyArea(dpy, tmp, scr->root_win, scr->copy_gc,
131 ax[i]*PSIZE, ay[i]*PSIZE,
132 PSIZE, PSIZE, px[i], py[i]);
136 #ifdef SPEAKER_SOUND
137 play(dpy, 100+rand()%250, 12);
138 #else
139 # if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
140 wusleep(MINIATURIZE_ANIMATION_DELAY_Z*2);
141 # endif
142 #endif
143 for (i=0; i<j; i++) {
144 if (ax[i]>=0) {
145 XClearArea(dpy, scr->root_win, px[i], py[i], PSIZE, PSIZE, 1);
149 XFreePixmap(dpy, tmp);
154 Pixmap
155 MakeGhostDock(WDock *dock, int sx, int dx, int y)
157 WScreen *scr = dock->screen_ptr;
158 XImage *img;
159 RImage *back, *dock_image;
160 Pixmap pixmap;
161 int i, virtual_tiles, h, j, n;
162 unsigned long red_mask, green_mask, blue_mask;
164 virtual_tiles = 0;
165 for (i=0; i<dock->max_icons; i++) {
166 if (dock->icon_array[i]!=NULL &&
167 dock->icon_array[i]->yindex > virtual_tiles)
168 virtual_tiles = dock->icon_array[i]->yindex;
170 virtual_tiles++;
171 h = virtual_tiles * wPreferences.icon_size;
172 h = (y + h > scr->scr_height) ? scr->scr_height-y : h;
173 virtual_tiles = h / wPreferences.icon_size; /* The visible ones */
174 if (h % wPreferences.icon_size)
175 virtual_tiles++; /* There is one partially visible tile at end */
177 img=XGetImage(dpy, scr->root_win, dx, y, wPreferences.icon_size, h,
178 AllPlanes, ZPixmap);
179 if (!img)
180 return None;
182 red_mask = img->red_mask;
183 green_mask = img->green_mask;
184 blue_mask = img->blue_mask;
186 back = RCreateImageFromXImage(scr->rcontext, img, NULL);
187 XDestroyImage(img);
188 if (!back) {
189 return None;
192 for (i=0;i<dock->max_icons;i++) {
193 if (dock->icon_array[i]!=NULL &&
194 dock->icon_array[i]->yindex < virtual_tiles) {
195 Pixmap which;
196 j = dock->icon_array[i]->yindex * wPreferences.icon_size;
197 n = (h - j < wPreferences.icon_size) ? h - j :
198 wPreferences.icon_size;
199 if (dock->icon_array[i]->icon->pixmap)
200 which = dock->icon_array[i]->icon->pixmap;
201 else
202 which = dock->icon_array[i]->icon->core->window;
204 img=XGetImage(dpy, which, 0, 0, wPreferences.icon_size, n,
205 AllPlanes, ZPixmap);
207 if (!img){
208 RDestroyImage(back);
209 return None;
211 img->red_mask = red_mask;
212 img->green_mask = green_mask;
213 img->blue_mask = blue_mask;
215 dock_image = RCreateImageFromXImage(scr->rcontext, img, NULL);
216 XDestroyImage(img);
217 if (!dock_image) {
218 RDestroyImage(back);
219 return None;
221 RCombineAreaWithOpaqueness(back, dock_image, 0, 0,
222 wPreferences.icon_size, n,
223 0, j, 30 * 256 / 100);
224 RDestroyImage(dock_image);
229 RConvertImage(scr->rcontext, back, &pixmap);
231 RDestroyImage(back);
233 return pixmap;
237 Pixmap
238 MakeGhostIcon(WScreen *scr, Drawable drawable)
240 RImage *back;
241 RColor color;
242 Pixmap pixmap;
245 if (!drawable)
246 return None;
248 back = RCreateImageFromDrawable(scr->rcontext, drawable, None);
249 if (!back)
250 return None;
252 color.red = 0xff;
253 color.green = 0xff;
254 color.blue = 0xff;
255 color.alpha = 200;
257 RClearImage(back, &color);
258 RConvertImage(scr->rcontext, back, &pixmap);
260 RDestroyImage(back);
262 return pixmap;
267 #ifdef WINDOW_BIRTH_ZOOM
268 void
269 DoWindowBirth(WWindow *wwin)
271 int width = wwin->frame->core->width;
272 int height = wwin->frame->core->height;
273 int w = WMIN(width, 20);
274 int h = WMIN(height, 20);
275 int x, y;
276 int dw, dh;
277 int i;
279 dw = (width-w)/WINDOW_BIRTH_STEPS;
280 dh = (height-h)/WINDOW_BIRTH_STEPS;
282 x = wwin->frame_x + (width-w)/2;
283 y = wwin->frame_y + (height-h)/2;
285 XMoveResizeWindow(dpy, wwin->frame->core->window, x, y, w, h);
287 XMapWindow(dpy, wwin->frame->core->window);
289 XFlush(dpy);
290 for (i=0; i<WINDOW_BIRTH_STEPS; i++) {
291 x -= dw/2 + dw%2;
292 y -= dh/2 + dh%2;
293 w += dw;
294 h += dh;
295 XMoveResizeWindow(dpy, wwin->frame->core->window, x, y, w, h);
296 XFlush(dpy);
299 XMoveResizeWindow(dpy, wwin->frame->core->window,
300 wwin->frame_x, wwin->frame_y, width, height);
301 XFlush(dpy);
303 #else
304 void
305 DoWindowBirth(WWindow *wwin)
307 /* dummy stub */
309 #endif