Change to the linux kernel coding style
[wmaker-crm.git] / src / superfluous.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/*
9af1c6c4 dan1998-10-21 14:43:47 +00002 * Window Maker window manager
6830b057 dan2004-10-12 21:28:27 +00003 *
4153e2fd dan2003-01-16 23:30:45 +00004 * Copyright (c) 1997-2003 Alfredo K. Kojima
5 * Copyright (c) 1998-2003 Dan Pascu
6830b057 dan2004-10-12 21:28:27 +00006 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00007 * 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.
11 *
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.
16 *
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
6830b057 dan2004-10-12 21:28:27 +000019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
9d2e6ef9 scottc1998-09-29 22:36:29 +000020 * USA.
21 */
22
23#include "wconfig.h"
24
25#include <X11/Xlib.h>
26#include <X11/Xutil.h>
27
28#include <stdlib.h>
29#include <unistd.h>
4b609a4d kojima1999-04-16 02:07:45 +000030#include <math.h>
9af1c6c4 dan1998-10-21 14:43:47 +000031#include <time.h>
32
9d2e6ef9 scottc1998-09-29 22:36:29 +000033#include <wraster.h>
34
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"
416e3a82 dan1999-01-25 19:06:50 +000042#include "icon.h"
43#include "appicon.h"
9d2e6ef9 scottc1998-09-29 22:36:29 +000044
9d2e6ef9 scottc1998-09-29 22:36:29 +000045extern WPreferences wPreferences;
46
9d2e6ef9 scottc1998-09-29 22:36:29 +000047#ifdef SPEAKER_SOUND
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020048static void play(Display * dpy, int pitch, int delay)
9d2e6ef9 scottc1998-09-29 22:36:29 +000049{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020050 XKeyboardControl kc;
51
52 kc.bell_pitch = pitch;
53 kc.bell_percent = 50;
54 kc.bell_duration = delay;
55 XChangeKeyboardControl(dpy, KBBellPitch | KBBellDuration | KBBellPercent, &kc);
56 XBell(dpy, 50);
57 XFlush(dpy);
58 wusleep(delay);
9d2e6ef9 scottc1998-09-29 22:36:29 +000059}
60#endif
61
9af1c6c4 dan1998-10-21 14:43:47 +000062#ifdef DEMATERIALIZE_ICON
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020063void DoKaboom(WScreen * scr, Window win, int x, int y)
9af1c6c4 dan1998-10-21 14:43:47 +000064{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020065 RImage *icon;
66 RImage *back;
67 RImage *image;
68 Pixmap pixmap;
69 XImage *ximage;
70 GC gc;
71 XGCValues gcv;
72 int i;
73 int w, h;
74 int run;
75 XEvent event;
76
77 h = w = wPreferences.icon_size;
78 if (x < 0 || x + w > scr->scr_width || y < 0 || y + h > scr->scr_height)
79 return;
80
81 icon = RCreateImageFromDrawable(scr->rcontext, win, None);
82 if (!icon)
83 return;
84
85 gcv.foreground = scr->white_pixel;
86 gcv.background = scr->black_pixel;
87 gcv.graphics_exposures = False;
88 gcv.subwindow_mode = IncludeInferiors;
89 gc = XCreateGC(dpy, scr->w_win, GCForeground | GCBackground | GCSubwindowMode | GCGraphicsExposures, &gcv);
90
91 XGrabServer(dpy);
92 RConvertImage(scr->rcontext, icon, &pixmap);
93 XUnmapWindow(dpy, win);
94
95 ximage = XGetImage(dpy, scr->root_win, x, y, w, h, AllPlanes, ZPixmap);
96 XCopyArea(dpy, pixmap, scr->root_win, gc, 0, 0, w, h, x, y);
97 XFreePixmap(dpy, pixmap);
98
99 back = RCreateImageFromXImage(scr->rcontext, ximage, NULL);
100 XDestroyImage(ximage);
101 if (!back) {
102 RReleaseImage(icon);
103 return;
104 }
105
106 for (i = 0, run = 0; i < DEMATERIALIZE_STEPS; i++) {
107 XEvent foo;
108 if (!run && XCheckTypedEvent(dpy, ButtonPress, &foo)) {
109 run = 1;
110 XPutBackEvent(dpy, &foo);
111 }
112 image = RCloneImage(back);
113 RCombineImagesWithOpaqueness(image, icon,
114 (DEMATERIALIZE_STEPS - 1 - i) * 256 / (DEMATERIALIZE_STEPS + 2));
115 RConvertImage(scr->rcontext, image, &pixmap);
116 XCopyArea(dpy, pixmap, scr->root_win, gc, 0, 0, w, h, x, y);
117 XFreePixmap(dpy, pixmap);
118 XFlush(dpy);
119 if (!run)
120 wusleep(1000);
121 }
122
123 while (XCheckTypedEvent(dpy, MotionNotify, &event)) {
124 }
125 XFlush(dpy);
126
127 XUngrabServer(dpy);
128 XFreeGC(dpy, gc);
129 RReleaseImage(icon);
130 RReleaseImage(back);
9af1c6c4 dan1998-10-21 14:43:47 +0000131}
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200132#endif /* DEMATERIALIZE_ICON */
4b609a4d kojima1999-04-16 02:07:45 +0000133
134#ifdef NORMAL_ICON_KABOOM
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200135void DoKaboom(WScreen * scr, Window win, int x, int y)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000136{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200137 int i, j, k;
138 int sw = scr->scr_width, sh = scr->scr_height;
9af1c6c4 dan1998-10-21 14:43:47 +0000139#define KAB_PRECISION 4
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200140 int px[PIECES];
141 short py[PIECES];
9af1c6c4 dan1998-10-21 14:43:47 +0000142#ifdef ICON_KABOOM_EXTRA
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200143 short ptx[2][PIECES], pty[2][PIECES];
144 int ll;
9af1c6c4 dan1998-10-21 14:43:47 +0000145#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200146 char pvx[PIECES], pvy[PIECES];
147 /* in MkLinux/PPC gcc seems to think that char is unsigned? */
148 signed char ax[PIECES], ay[PIECES];
149 Pixmap tmp;
150
151 XSetClipMask(dpy, scr->copy_gc, None);
152 tmp = XCreatePixmap(dpy, scr->root_win, wPreferences.icon_size, wPreferences.icon_size, scr->depth);
153 if (scr->w_visual == DefaultVisual(dpy, scr->screen))
154 XCopyArea(dpy, win, tmp, scr->copy_gc, 0, 0, wPreferences.icon_size, wPreferences.icon_size, 0, 0);
155 else {
156 XImage *image;
157
158 image = XGetImage(dpy, win, 0, 0, wPreferences.icon_size,
159 wPreferences.icon_size, AllPlanes, ZPixmap);
160 if (!image) {
161 XUnmapWindow(dpy, win);
162 return;
163 }
164 XPutImage(dpy, tmp, scr->copy_gc, image, 0, 0, 0, 0,
165 wPreferences.icon_size, wPreferences.icon_size);
166 XDestroyImage(image);
167 }
168
169 for (i = 0, k = 0; i < wPreferences.icon_size / ICON_KABOOM_PIECE_SIZE && k < PIECES; i++) {
170 for (j = 0; j < wPreferences.icon_size / ICON_KABOOM_PIECE_SIZE && k < PIECES; j++) {
171 if (rand() % 2) {
172 ax[k] = i;
173 ay[k] = j;
174 px[k] = (x + i * ICON_KABOOM_PIECE_SIZE) << KAB_PRECISION;
175 py[k] = y + j * ICON_KABOOM_PIECE_SIZE;
176 pvx[k] = rand() % (1 << (KAB_PRECISION + 3)) - (1 << (KAB_PRECISION + 3)) / 2;
177 pvy[k] = -15 - rand() % 7;
9af1c6c4 dan1998-10-21 14:43:47 +0000178#ifdef ICON_KABOOM_EXTRA
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200179 for (ll = 0; ll < 2; ll++) {
180 ptx[ll][k] = px[k];
181 pty[ll][k] = py[k];
182 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000183#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200184 k++;
185 } else {
186 ax[k] = -1;
187 }
188 }
189 }
190
191 XUnmapWindow(dpy, win);
192
193 j = k;
194 while (k > 0) {
195 XEvent foo;
196
197 if (XCheckTypedEvent(dpy, ButtonPress, &foo)) {
198 XPutBackEvent(dpy, &foo);
199 XClearWindow(dpy, scr->root_win);
200 break;
201 }
202
203 for (i = 0; i < j; i++) {
204 if (ax[i] >= 0) {
205 int _px = px[i] >> KAB_PRECISION;
9af1c6c4 dan1998-10-21 14:43:47 +0000206#ifdef ICON_KABOOM_EXTRA
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200207 XClearArea(dpy, scr->root_win, ptx[1][i], pty[1][i],
208 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE, False);
209
210 ptx[1][i] = ptx[0][i];
211 pty[1][i] = pty[0][i];
212 ptx[0][i] = _px;
213 pty[0][i] = py[i];
9af1c6c4 dan1998-10-21 14:43:47 +0000214#else
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200215 XClearArea(dpy, scr->root_win, _px, py[i],
216 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE, False);
9af1c6c4 dan1998-10-21 14:43:47 +0000217#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200218 px[i] += pvx[i];
219 py[i] += pvy[i];
220 _px = px[i] >> KAB_PRECISION;
221 pvy[i]++;
222 if (_px < -wPreferences.icon_size || _px > sw || py[i] >= sh) {
9af1c6c4 dan1998-10-21 14:43:47 +0000223#ifdef ICON_KABOOM_EXTRA
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200224 if (py[i] > sh && _px < sw && _px > 0) {
225 pvy[i] = -(pvy[i] / 2);
226 if (abs(pvy[i]) > 3) {
227 py[i] = sh - ICON_KABOOM_PIECE_SIZE;
228 XCopyArea(dpy, tmp, scr->root_win, scr->copy_gc,
229 ax[i] * ICON_KABOOM_PIECE_SIZE,
230 ay[i] * ICON_KABOOM_PIECE_SIZE,
231 ICON_KABOOM_PIECE_SIZE,
232 ICON_KABOOM_PIECE_SIZE, _px, py[i]);
233 } else {
234 ax[i] = -1;
235 }
236 } else {
237 ax[i] = -1;
238 }
239 if (ax[i] < 0) {
240 for (ll = 0; ll < 2; ll++)
241 XClearArea(dpy, scr->root_win, ptx[ll][i], pty[ll][i],
242 ICON_KABOOM_PIECE_SIZE,
243 ICON_KABOOM_PIECE_SIZE, False);
244 k--;
245 }
246#else /* !ICON_KABOOM_EXTRA */
247 ax[i] = -1;
248 k--;
249#endif /* !ICON_KABOOM_EXTRA */
250 } else {
251 XCopyArea(dpy, tmp, scr->root_win, scr->copy_gc,
252 ax[i] * ICON_KABOOM_PIECE_SIZE, ay[i] * ICON_KABOOM_PIECE_SIZE,
253 ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE, _px, py[i]);
254 }
255 }
256 }
257
258 XFlush(dpy);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000259#ifdef SPEAKER_SOUND
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200260 play(dpy, 100 + rand() % 250, 12);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000261#else
6830b057 dan2004-10-12 21:28:27 +0000262# if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200263 wusleep(MINIATURIZE_ANIMATION_DELAY_Z * 2);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000264# endif
265#endif
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200266 }
6830b057 dan2004-10-12 21:28:27 +0000267
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200268 XFreePixmap(dpy, tmp);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000269}
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200270#endif /* NORMAL_ICON_KABOOM */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000271
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200272Pixmap MakeGhostDock(WDock * dock, int sx, int dx, int y)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000273{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200274 WScreen *scr = dock->screen_ptr;
275 XImage *img;
276 RImage *back, *dock_image;
277 Pixmap pixmap;
278 int i, virtual_tiles, h, j, n;
279 unsigned long red_mask, green_mask, blue_mask;
280
281 virtual_tiles = 0;
282 for (i = 0; i < dock->max_icons; i++) {
283 if (dock->icon_array[i] != NULL && dock->icon_array[i]->yindex > virtual_tiles)
284 virtual_tiles = dock->icon_array[i]->yindex;
285 }
286 virtual_tiles++;
287 h = virtual_tiles * wPreferences.icon_size;
288 h = (y + h > scr->scr_height) ? scr->scr_height - y : h;
289 virtual_tiles = h / wPreferences.icon_size; /* The visible ones */
290 if (h % wPreferences.icon_size)
291 virtual_tiles++; /* There is one partially visible tile at end */
292
293 img = XGetImage(dpy, scr->root_win, dx, y, wPreferences.icon_size, h, AllPlanes, ZPixmap);
294 if (!img)
295 return None;
296
297 red_mask = img->red_mask;
298 green_mask = img->green_mask;
299 blue_mask = img->blue_mask;
300
301 back = RCreateImageFromXImage(scr->rcontext, img, NULL);
302 XDestroyImage(img);
303 if (!back) {
304 return None;
305 }
306
307 for (i = 0; i < dock->max_icons; i++) {
308 if (dock->icon_array[i] != NULL && dock->icon_array[i]->yindex < virtual_tiles) {
309 Pixmap which;
310 j = dock->icon_array[i]->yindex * wPreferences.icon_size;
311 n = (h - j < wPreferences.icon_size) ? h - j : 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;
316
317 img = XGetImage(dpy, which, 0, 0, wPreferences.icon_size, n, AllPlanes, ZPixmap);
318
319 if (!img) {
320 RReleaseImage(back);
321 return None;
322 }
323 img->red_mask = red_mask;
324 img->green_mask = green_mask;
325 img->blue_mask = blue_mask;
326
327 dock_image = RCreateImageFromXImage(scr->rcontext, img, NULL);
328 XDestroyImage(img);
329 if (!dock_image) {
330 RReleaseImage(back);
331 return None;
332 }
333 RCombineAreaWithOpaqueness(back, dock_image, 0, 0,
334 wPreferences.icon_size, n, 0, j, 30 * 256 / 100);
335 RReleaseImage(dock_image);
336 }
337 }
338
339 RConvertImage(scr->rcontext, back, &pixmap);
340
341 RReleaseImage(back);
342
343 return pixmap;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000344}
345
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200346Pixmap MakeGhostIcon(WScreen * scr, Drawable drawable)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000347{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200348 RImage *back;
349 RColor color;
350 Pixmap pixmap;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000351
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200352 if (!drawable)
353 return None;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000354
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200355 back = RCreateImageFromDrawable(scr->rcontext, drawable, None);
356 if (!back)
357 return None;
6830b057 dan2004-10-12 21:28:27 +0000358
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200359 color.red = 0xff;
360 color.green = 0xff;
361 color.blue = 0xff;
362 color.alpha = 200;
6830b057 dan2004-10-12 21:28:27 +0000363
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200364 RClearImage(back, &color);
365 RConvertImage(scr->rcontext, back, &pixmap);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000366
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200367 RReleaseImage(back);
6830b057 dan2004-10-12 21:28:27 +0000368
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200369 return pixmap;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000370}
371
9d2e6ef9 scottc1998-09-29 22:36:29 +0000372#ifdef WINDOW_BIRTH_ZOOM
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200373void DoWindowBirth(WWindow * wwin)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000374{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200375 int width = wwin->frame->core->width;
376 int height = wwin->frame->core->height;
377 int w = WMIN(width, 20);
378 int h = WMIN(height, 20);
379 int x, y;
380 int dw, dh;
381 int i;
382 time_t time0 = time(NULL);
383
384 dw = (width - w) / WINDOW_BIRTH_STEPS;
385 dh = (height - h) / WINDOW_BIRTH_STEPS;
386
387 x = wwin->frame_x + (width - w) / 2;
388 y = wwin->frame_y + (height - h) / 2;
389
390 XMoveResizeWindow(dpy, wwin->frame->core->window, x, y, w, h);
391
392 XMapWindow(dpy, wwin->frame->core->window);
393
394 XFlush(dpy);
395 for (i = 0; i < WINDOW_BIRTH_STEPS; i++) {
396 x -= dw / 2 + dw % 2;
397 y -= dh / 2 + dh % 2;
398 w += dw;
399 h += dh;
400 XMoveResizeWindow(dpy, wwin->frame->core->window, x, y, w, h);
401 XFlush(dpy);
402 /* a timeout */
403 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
404 break;
405 }
406
407 XMoveResizeWindow(dpy, wwin->frame->core->window, wwin->frame_x, wwin->frame_y, width, height);
408 XFlush(dpy);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000409}
410#else
fa994f62 kojima2001-08-20 18:11:40 +0000411#ifdef WINDOW_BIRTH_ZOOM2
412extern void animateResize();
413
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200414void DoWindowBirth(WWindow * wwin)
fa994f62 kojima2001-08-20 18:11:40 +0000415{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200416 /* dummy stub */
fa994f62 kojima2001-08-20 18:11:40 +0000417
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200418 int center_x, center_y;
419 int width = wwin->frame->core->width;
420 int height = wwin->frame->core->height;
421 int w = WMIN(width, 20);
422 int h = WMIN(height, 20);
423 WScreen *scr = wwin->screen_ptr;
fa994f62 kojima2001-08-20 18:11:40 +0000424
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200425 center_x = wwin->frame_x + (width - w) / 2;
426 center_y = wwin->frame_y + (height - h) / 2;
fa994f62 kojima2001-08-20 18:11:40 +0000427
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200428 animateResize(scr, center_x, center_y, 1, 1, wwin->frame_x, wwin->frame_y, width, height, 0);
fa994f62 kojima2001-08-20 18:11:40 +0000429}
430#else
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200431void DoWindowBirth(WWindow * wwin)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000432{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200433 /* dummy stub */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000434}
435#endif
fa994f62 kojima2001-08-20 18:11:40 +0000436#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +0000437
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200438#ifdef SILLYNESS
439static WMPixmap *data[12];
416e3a82 dan1999-01-25 19:06:50 +0000440
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200441static Bool loadData(WScreen * scr)
442{
443 FILE *f;
444 int i;
445 RImage *image;
446 Pixmap d[12];
416e3a82 dan1999-01-25 19:06:50 +0000447
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200448 f = fopen(PKGDATADIR "/xtree.dat", "rb");
449 if (!f)
450 return False;
3c046182 kojima1999-09-16 02:58:56 +0000451
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200452 image = RCreateImage(50, 50, False);
453 if (!image) {
454 fclose(f);
455 return False;
456 }
3c046182 kojima1999-09-16 02:58:56 +0000457
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200458 for (i = 0; i < 12; i++) {
459 if (fread(image->data, 50 * 50 * 3, 1, f) != 1) {
460 goto error;
461 }
462 if (!RConvertImage(scr->rcontext, image, &(d[i]))) {
463 goto error;
464 }
465 }
466 RReleaseImage(image);
3c046182 kojima1999-09-16 02:58:56 +0000467
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200468 fclose(f);
416e3a82 dan1999-01-25 19:06:50 +0000469
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200470 for (i = 0; i < 12; i++) {
471 data[i] = WMCreatePixmapFromXPixmaps(scr->wmscreen, d[i], None, 50, 50, scr->w_depth);
472 }
416e3a82 dan1999-01-25 19:06:50 +0000473
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200474 return True;
416e3a82 dan1999-01-25 19:06:50 +0000475
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200476 error:
477 RReleaseImage(image);
416e3a82 dan1999-01-25 19:06:50 +0000478
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200479 fclose(f);
416e3a82 dan1999-01-25 19:06:50 +0000480
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200481 while (--i > 0) {
482 XFreePixmap(dpy, d[i]);
483 }
484
485 return False;
416e3a82 dan1999-01-25 19:06:50 +0000486}
487
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200488WMPixmap *DoXThing(WWindow * wwin)
489{
490 static int order = 0;
491
492 order++;
416e3a82 dan1999-01-25 19:06:50 +0000493
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200494 return data[order % 12];
495}
496
497Bool InitXThing(WScreen * scr)
416e3a82 dan1999-01-25 19:06:50 +0000498{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200499 time_t t;
500 struct tm *l;
501 static int i = 0;
416e3a82 dan1999-01-25 19:06:50 +0000502
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200503 if (i)
504 return True;
416e3a82 dan1999-01-25 19:06:50 +0000505
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200506 t = time(NULL);
507 l = localtime(&t);
508 if ((l->tm_mon != 11 || l->tm_mday < 24 || l->tm_mday > 26)) {
509 return False;
510 }
e7495baf dan1999-02-17 11:06:40 +0000511
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200512 if (!loadData(scr))
513 return False;
416e3a82 dan1999-01-25 19:06:50 +0000514
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200515 i = 1;
6830b057 dan2004-10-12 21:28:27 +0000516
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200517 return True;
416e3a82 dan1999-01-25 19:06:50 +0000518}
519
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200520#endif /* SILLYNESS */
7f9f8894 kojima1999-03-15 23:41:22 +0000521
522#ifdef GHOST_WINDOW_MOVE
c2dee60f kojima1999-06-02 20:44:16 +0000523
524typedef struct {
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200525 WScreen *scr;
c2dee60f kojima1999-06-02 20:44:16 +0000526
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200527 int width, height;
c2dee60f kojima1999-06-02 20:44:16 +0000528
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200529 int iniX, iniY;
530 int boxX, boxY;
c2dee60f kojima1999-06-02 20:44:16 +0000531
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200532 Window window;
c2dee60f kojima1999-06-02 20:44:16 +0000533
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200534 RXImage *winImage;
c2dee60f kojima1999-06-02 20:44:16 +0000535
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200536 RXImage *backImage;
c2dee60f kojima1999-06-02 20:44:16 +0000537
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200538 /* the combined image */
539 RXImage *image;
540 Pixmap pixmap;
c2dee60f kojima1999-06-02 20:44:16 +0000541
542} _GhostWindowData;
543
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200544_GhostWindowData *InitGhostWindowMove(WWindow * wwin)
7f9f8894 kojima1999-03-15 23:41:22 +0000545{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200546 _GhostWindowData *gdata;
547 WScreen *scr = wwin->screen_ptr;
548 unsigned short *ptr;
549 unsigned short mask;
550 int i;
c2dee60f kojima1999-06-02 20:44:16 +0000551
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200552 gdata = wmalloc(sizeof(_GhostWindowData));
c2dee60f kojima1999-06-02 20:44:16 +0000553
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200554 gdata->width = wwin->frame->core->width;
555 gdata->height = wwin->frame->core->height;
7f9f8894 kojima1999-03-15 23:41:22 +0000556
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200557 gdata->iniX = wwin->frame_x;
558 gdata->iniY = wwin->frame_y;
7f9f8894 kojima1999-03-15 23:41:22 +0000559
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200560 gdata->boxX = wwin->frame_x;
561 gdata->boxY = wwin->frame_y;
c2dee60f kojima1999-06-02 20:44:16 +0000562
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200563 gdata->window =
564 XCreateSimpleWindow(dpy, scr->root_win, wwin->frame_x, wwin->frame_y,
565 gdata->width, gdata->height, 0, 0, 0);
c2dee60f kojima1999-06-02 20:44:16 +0000566
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200567 gdata->winImage = RGetXImage(scr->rcontext, wwin->frame->core->window, 0, 0, gdata->width, gdata->height);
c2dee60f kojima1999-06-02 20:44:16 +0000568
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200569 gdata->backImage = RCreateXImage(scr->rcontext, scr->w_depth, gdata->width, gdata->height);
c2dee60f kojima1999-06-02 20:44:16 +0000570
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200571 memcpy(gdata->backImage->image->data, gdata->winImage->image->data,
572 gdata->winImage->image->bytes_per_line * gdata->height);
3c046182 kojima1999-09-16 02:58:56 +0000573
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200574 gdata->image = RCreateXImage(scr->rcontext, scr->w_depth, gdata->width, gdata->height);
3c046182 kojima1999-09-16 02:58:56 +0000575
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200576 ptr = (unsigned short *)gdata->winImage->image->data;
3c046182 kojima1999-09-16 02:58:56 +0000577
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200578 mask = 0x7b00 | 0x3d0 | 0x1e;
3c046182 kojima1999-09-16 02:58:56 +0000579
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200580 for (i = 0; i < gdata->winImage->image->bytes_per_line * gdata->height; i++, ptr++) {
3c046182 kojima1999-09-16 02:58:56 +0000581
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200582 *ptr &= mask;
583 }
c2dee60f kojima1999-06-02 20:44:16 +0000584
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200585 return gdata;
7f9f8894 kojima1999-03-15 23:41:22 +0000586}
587
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200588static void mergeGhostWindow(_GhostWindowData * gdata)
3c046182 kojima1999-09-16 02:58:56 +0000589{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200590 register unsigned short *ptrw, *ptrb, *ptr;
591 int count;
592 int i;
3c046182 kojima1999-09-16 02:58:56 +0000593
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200594 ptr = (unsigned short *)gdata->image->image->data;
595 ptrw = (unsigned short *)gdata->winImage->image->data;
596 ptrb = (unsigned short *)gdata->backImage->image->data;
3c046182 kojima1999-09-16 02:58:56 +0000597
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200598 count = gdata->winImage->image->bytes_per_line * gdata->height;
3c046182 kojima1999-09-16 02:58:56 +0000599
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200600 while (count--) {
601 *ptr = (*ptrw + *ptrb) >> 1;
3c046182 kojima1999-09-16 02:58:56 +0000602
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200603 ptr++;
604 ptrw++;
605 ptrb++;
606 }
3c046182 kojima1999-09-16 02:58:56 +0000607}
608
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200609void UpdateGhostWindowMove(void *data, int x, int y)
c2dee60f kojima1999-06-02 20:44:16 +0000610{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200611 _GhostWindowData *gdata = (_GhostWindowData *) data;
612 WScreen *scr = gdata->scr;
613
614 /* no intersection of new background with current */
615 if (x + gdata->width <= gdata->boxX
616 || x >= gdata->boxX + gdata->width
617 || y + gdata->height <= gdata->boxY || y >= gdata->boxY + gdata->height) {
618 int i;
619
620 RDestroyXImage(gdata->backImage);
621
622 gdata->backImage = RGetXImage(scr->rcontext, scr->root_win, x, y, gdata->width, gdata->height);
623
624 ptr = (unsigned short *)gdata->backImage->image->data;
625
626 mask = 0x7b00 | 0x3d0 | 0x1e;
627
628 for (i = 0; i < gdata->winImage->image->bytes_per_line * gdata->height; i++, ptr++) {
629
630 *ptr &= mask;
631 }
632 } else {
633 int hx, hw, hy, hh;
634 int vx, vw, vy, vh;
635 int i, j;
636 unsigned char *backP = gdata->backImage->image->data;
637 unsigned char *winP = gdata->winImage->image->data;
638 int backLineLen = gdata->backImage->image->bytes_per_line;
639 int winLineLen = gdata->winImage->image->bytes_per_line;
640
641 /* 1st move the area of the current backImage that overlaps
642 * the new backImage to it's new position */
643
644 if (x < gdata->boxX) {
645 vx = x + gdata->width;
646 vw = gdata->width - vx;
647 } else if (x > gdata->boxX) {
648 vw = gdata->boxX + gdata->width - x;
649 vx = gdata->boxX - vw;
650 } else {
651 vx = 0;
652 vw = gdata->width;
653 }
654
655 if (y < gdata->boxY) {
656 vy = y + gdata->height;
657 vh = gdata->height - vy;
658 } else if (y > gdata->boxY) {
659 vh = gdata->boxY + gdata->height - y;
660 vy = gdata->boxY - vh;
661 } else {
662 vy = 0;
663 vh = gdata->height;
664 }
665
666 if (y < gdata->boxY) {
667 int dy = vy - gdata->boxY;
668
669 if (x < gdata->boxX) {
670 for (i = vh - 1; i >= 0; i--) {
671 memmove(&backP[(i + dy) * backLineLen + 2 * vx],
672 &backP[i * backLineLen], 2 * vw);
673 }
674 } else { /* if (x > gdata->boxX) */
675
676 for (i = vh - 1; i >= 0; i--) {
677 memmove(&backP[(i + dy) * backLineLen],
678 &backP[i * backLineLen + 2 * vx], 2 * vw);
679 }
680 }
681 } else { /*if (y > gdata->boxY) */
682
683 int dy = gdata->boxY - vy;
684
685 if (x < gdata->boxX) {
686 for (i = 0; i < vh - 1; i++) {
687 memmove(&backP[i * backLineLen + 2 * vx],
688 &backP[(i + dy) * backLineLen], 2 * vw);
689 }
690 } else { /*if (x > gdata->boxX) */
691
692 for (i = 0; i < vh - 1; i++) {
693 memmove(&backP[i * backLineLen],
694 &backP[(i + dy) * backLineLen + 2 * vx], 2 * vw);
695 }
696 }
697 }
698
699 /* 2nd grab the background image from the screen and copy to the
700 * buffer. also maskout the lsb of rgb in each pixel of grabbed data */
701
702 if (y < gdata->boxY) {
703 vy = y;
704 vh = gdata->boxY - vy;
705
706 hy = y + vh;
707 hh = gdata->height - vh;
708 } else if (y > gdata->boxY) {
709 vy = gdata->boxY + gdata->height;
710 vh = vy - (y + gdata->height);
711
712 hy = y;
713 hh = y - gdata->boxY;
714 } else {
715 vy = vh = 0;
716
717 hy = y;
718 hh = gdata->height;
719 }
720
721 if (x < gdata->boxX) {
722 hx = x;
723 hw = gdata->boxX - hx;
724 } else if (x > gdata->boxX) {
725 hx = gdata->boxX + gdata->width;
726 hw = hx - (x + gdata->width);
727 } else {
728 hx = hw = 0;
729
730 vx = x;
731 vw = gdata->width;
732 }
733
734 /* 1st the top/bottom part */
735
736 /* 2nd the left/right part */
737 }
738
739 mergeGhostWindow(gdata);
c2dee60f kojima1999-06-02 20:44:16 +0000740}
741
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200742#endif /* GHOST_WINDOW_MOVE */