Change to the linux kernel coding style
[wmaker-crm.git] / src / superfluous.c
1 /*
2  *  Window Maker window manager
3  *
4  *  Copyright (c) 1997-2003 Alfredo K. Kojima
5  *  Copyright (c) 1998-2003 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.
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
19  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20  *  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>
30 #include <math.h>
31 #include <time.h>
32
33 #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"
42 #include "icon.h"
43 #include "appicon.h"
44
45 extern WPreferences wPreferences;
46
47 #ifdef SPEAKER_SOUND
48 static void play(Display * dpy, int pitch, int delay)
49 {
50         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);
59 }
60 #endif
61
62 #ifdef DEMATERIALIZE_ICON
63 void DoKaboom(WScreen * scr, Window win, int x, int y)
64 {
65         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);
131 }
132 #endif                          /* DEMATERIALIZE_ICON */
133
134 #ifdef NORMAL_ICON_KABOOM
135 void DoKaboom(WScreen * scr, Window win, int x, int y)
136 {
137         int i, j, k;
138         int sw = scr->scr_width, sh = scr->scr_height;
139 #define KAB_PRECISION   4
140         int px[PIECES];
141         short py[PIECES];
142 #ifdef ICON_KABOOM_EXTRA
143         short ptx[2][PIECES], pty[2][PIECES];
144         int ll;
145 #endif
146         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;
178 #ifdef ICON_KABOOM_EXTRA
179                                 for (ll = 0; ll < 2; ll++) {
180                                         ptx[ll][k] = px[k];
181                                         pty[ll][k] = py[k];
182                                 }
183 #endif
184                                 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;
206 #ifdef ICON_KABOOM_EXTRA
207                                 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];
214 #else
215                                 XClearArea(dpy, scr->root_win, _px, py[i],
216                                            ICON_KABOOM_PIECE_SIZE, ICON_KABOOM_PIECE_SIZE, False);
217 #endif
218                                 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) {
223 #ifdef ICON_KABOOM_EXTRA
224                                         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);
259 #ifdef SPEAKER_SOUND
260                 play(dpy, 100 + rand() % 250, 12);
261 #else
262 # if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
263                 wusleep(MINIATURIZE_ANIMATION_DELAY_Z * 2);
264 # endif
265 #endif
266         }
267
268         XFreePixmap(dpy, tmp);
269 }
270 #endif                          /* NORMAL_ICON_KABOOM */
271
272 Pixmap MakeGhostDock(WDock * dock, int sx, int dx, int y)
273 {
274         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;
344 }
345
346 Pixmap MakeGhostIcon(WScreen * scr, Drawable drawable)
347 {
348         RImage *back;
349         RColor color;
350         Pixmap pixmap;
351
352         if (!drawable)
353                 return None;
354
355         back = RCreateImageFromDrawable(scr->rcontext, drawable, None);
356         if (!back)
357                 return None;
358
359         color.red = 0xff;
360         color.green = 0xff;
361         color.blue = 0xff;
362         color.alpha = 200;
363
364         RClearImage(back, &color);
365         RConvertImage(scr->rcontext, back, &pixmap);
366
367         RReleaseImage(back);
368
369         return pixmap;
370 }
371
372 #ifdef WINDOW_BIRTH_ZOOM
373 void DoWindowBirth(WWindow * wwin)
374 {
375         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);
409 }
410 #else
411 #ifdef WINDOW_BIRTH_ZOOM2
412 extern void animateResize();
413
414 void DoWindowBirth(WWindow * wwin)
415 {
416         /* dummy stub */
417
418         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;
424
425         center_x = wwin->frame_x + (width - w) / 2;
426         center_y = wwin->frame_y + (height - h) / 2;
427
428         animateResize(scr, center_x, center_y, 1, 1, wwin->frame_x, wwin->frame_y, width, height, 0);
429 }
430 #else
431 void DoWindowBirth(WWindow * wwin)
432 {
433         /* dummy stub */
434 }
435 #endif
436 #endif
437
438 #ifdef SILLYNESS
439 static WMPixmap *data[12];
440
441 static Bool loadData(WScreen * scr)
442 {
443         FILE *f;
444         int i;
445         RImage *image;
446         Pixmap d[12];
447
448         f = fopen(PKGDATADIR "/xtree.dat", "rb");
449         if (!f)
450                 return False;
451
452         image = RCreateImage(50, 50, False);
453         if (!image) {
454                 fclose(f);
455                 return False;
456         }
457
458         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);
467
468         fclose(f);
469
470         for (i = 0; i < 12; i++) {
471                 data[i] = WMCreatePixmapFromXPixmaps(scr->wmscreen, d[i], None, 50, 50, scr->w_depth);
472         }
473
474         return True;
475
476  error:
477         RReleaseImage(image);
478
479         fclose(f);
480
481         while (--i > 0) {
482                 XFreePixmap(dpy, d[i]);
483         }
484
485         return False;
486 }
487
488 WMPixmap *DoXThing(WWindow * wwin)
489 {
490         static int order = 0;
491
492         order++;
493
494         return data[order % 12];
495 }
496
497 Bool InitXThing(WScreen * scr)
498 {
499         time_t t;
500         struct tm *l;
501         static int i = 0;
502
503         if (i)
504                 return True;
505
506         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         }
511
512         if (!loadData(scr))
513                 return False;
514
515         i = 1;
516
517         return True;
518 }
519
520 #endif                          /* SILLYNESS */
521
522 #ifdef GHOST_WINDOW_MOVE
523
524 typedef struct {
525         WScreen *scr;
526
527         int width, height;
528
529         int iniX, iniY;
530         int boxX, boxY;
531
532         Window window;
533
534         RXImage *winImage;
535
536         RXImage *backImage;
537
538         /* the combined image */
539         RXImage *image;
540         Pixmap pixmap;
541
542 } _GhostWindowData;
543
544 _GhostWindowData *InitGhostWindowMove(WWindow * wwin)
545 {
546         _GhostWindowData *gdata;
547         WScreen *scr = wwin->screen_ptr;
548         unsigned short *ptr;
549         unsigned short mask;
550         int i;
551
552         gdata = wmalloc(sizeof(_GhostWindowData));
553
554         gdata->width = wwin->frame->core->width;
555         gdata->height = wwin->frame->core->height;
556
557         gdata->iniX = wwin->frame_x;
558         gdata->iniY = wwin->frame_y;
559
560         gdata->boxX = wwin->frame_x;
561         gdata->boxY = wwin->frame_y;
562
563         gdata->window =
564             XCreateSimpleWindow(dpy, scr->root_win, wwin->frame_x, wwin->frame_y,
565                                 gdata->width, gdata->height, 0, 0, 0);
566
567         gdata->winImage = RGetXImage(scr->rcontext, wwin->frame->core->window, 0, 0, gdata->width, gdata->height);
568
569         gdata->backImage = RCreateXImage(scr->rcontext, scr->w_depth, gdata->width, gdata->height);
570
571         memcpy(gdata->backImage->image->data, gdata->winImage->image->data,
572                gdata->winImage->image->bytes_per_line * gdata->height);
573
574         gdata->image = RCreateXImage(scr->rcontext, scr->w_depth, gdata->width, gdata->height);
575
576         ptr = (unsigned short *)gdata->winImage->image->data;
577
578         mask = 0x7b00 | 0x3d0 | 0x1e;
579
580         for (i = 0; i < gdata->winImage->image->bytes_per_line * gdata->height; i++, ptr++) {
581
582                 *ptr &= mask;
583         }
584
585         return gdata;
586 }
587
588 static void mergeGhostWindow(_GhostWindowData * gdata)
589 {
590         register unsigned short *ptrw, *ptrb, *ptr;
591         int count;
592         int i;
593
594         ptr = (unsigned short *)gdata->image->image->data;
595         ptrw = (unsigned short *)gdata->winImage->image->data;
596         ptrb = (unsigned short *)gdata->backImage->image->data;
597
598         count = gdata->winImage->image->bytes_per_line * gdata->height;
599
600         while (count--) {
601                 *ptr = (*ptrw + *ptrb) >> 1;
602
603                 ptr++;
604                 ptrw++;
605                 ptrb++;
606         }
607 }
608
609 void UpdateGhostWindowMove(void *data, int x, int y)
610 {
611         _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);
740 }
741
742 #endif                          /* GHOST_WINDOW_MOVE */