2 * Window Maker window manager
4 * Copyright (c) 1997, 1998 Alfredo K. Kojima
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,
25 #include <X11/Xutil.h>
34 #include "WindowMaker.h"
36 #include "superfluous.h"
45 extern WPreferences wPreferences
;
50 play(Display
*dpy
, int pitch
, int delay
)
54 kc
.bell_pitch
= pitch
;
56 kc
.bell_duration
= delay
;
57 XChangeKeyboardControl(dpy
, KBBellPitch
|KBBellDuration
|KBBellPercent
,&kc
);
66 #ifdef DEMATERIALIZE_ICON
68 DoKaboom(WScreen
*scr
, Window win
, int x
, int y
)
78 h
= w
= wPreferences
.icon_size
;
79 if (x
< 0 || x
+ w
> scr
->scr_width
|| y
< 0 || y
+ h
> scr
->scr_height
)
82 icon
= RCreateImageFromDrawable(scr
->rcontext
, win
, None
);
86 XUnmapWindow(dpy
, win
);
89 ximage
= XGetImage(dpy
, scr
->root_win
, x
, y
, w
, h
, AllPlanes
, ZPixmap
);
90 back
= RCreateImageFromXImage(scr
->rcontext
, ximage
, NULL
);
91 XDestroyImage(ximage
);
97 XSetClipMask(dpy
, scr
->copy_gc
, None
);
99 for (i
=0; i
<DEMATERIALIZE_STEPS
; i
++) {
101 if (XCheckTypedEvent(dpy
, ButtonPress
, &foo
)) {
102 XPutBackEvent(dpy
, &foo
);
103 XClearWindow(dpy
, scr
->root_win
);
106 image
= RCloneImage(back
);
107 RCombineImagesWithOpaqueness(image
, icon
,
108 (DEMATERIALIZE_STEPS
-1-i
)*256/(DEMATERIALIZE_STEPS
+2));
109 RConvertImage(scr
->rcontext
, image
, &pixmap
);
110 XCopyArea(dpy
, pixmap
, scr
->root_win
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
);
111 XFreePixmap(dpy
, pixmap
);
115 XClearArea(dpy
, scr
->root_win
, x
, y
, w
, h
, False
);
121 #else /* !DEMATERIALIZE_ICON */
123 DoKaboom(WScreen
*scr
, Window win
, int x
, int y
)
126 int sw
=scr
->scr_width
, sh
=scr
->scr_height
;
127 #define KAB_PRECISION 4
130 #ifdef ICON_KABOOM_EXTRA
131 short ptx
[2][PIECES
], pty
[2][PIECES
];
134 char pvx
[PIECES
], pvy
[PIECES
];
135 /* in MkLinux/PPC gcc seems to think that char is unsigned? */
136 signed char ax
[PIECES
], ay
[PIECES
];
139 XSetClipMask(dpy
, scr
->copy_gc
, None
);
140 tmp
= XCreatePixmap(dpy
, scr
->root_win
, wPreferences
.icon_size
,
141 wPreferences
.icon_size
, scr
->depth
);
142 if (scr
->w_visual
== DefaultVisual(dpy
, scr
->screen
))
143 XCopyArea(dpy
, win
, tmp
, scr
->copy_gc
, 0, 0, wPreferences
.icon_size
,
144 wPreferences
.icon_size
, 0, 0);
148 image
= XGetImage(dpy
, win
, 0, 0, wPreferences
.icon_size
,
149 wPreferences
.icon_size
, AllPlanes
, ZPixmap
);
151 XUnmapWindow(dpy
, win
);
154 XPutImage(dpy
, tmp
, scr
->copy_gc
, image
, 0, 0, 0, 0,
155 wPreferences
.icon_size
, wPreferences
.icon_size
);
156 XDestroyImage(image
);
159 for (i
=0,k
=0; i
<wPreferences
.icon_size
/ICON_KABOOM_PIECE_SIZE
&& k
<PIECES
;
161 for (j
=0; j
<wPreferences
.icon_size
/ICON_KABOOM_PIECE_SIZE
&& k
<PIECES
;
166 px
[k
]=(x
+i
*ICON_KABOOM_PIECE_SIZE
)<<KAB_PRECISION
;
167 py
[k
]=y
+j
*ICON_KABOOM_PIECE_SIZE
;
168 pvx
[k
]=rand()%(1<<(KAB_PRECISION
+3))-(1<<(KAB_PRECISION
+3))/2;
170 #ifdef ICON_KABOOM_EXTRA
171 for (ll
=0; ll
<2; ll
++) {
183 XUnmapWindow(dpy
, win
);
189 if (XCheckTypedEvent(dpy
, ButtonPress
, &foo
)) {
190 XPutBackEvent(dpy
, &foo
);
191 XClearWindow(dpy
, scr
->root_win
);
195 for (i
=0; i
<j
; i
++) {
197 int _px
= px
[i
]>>KAB_PRECISION
;
198 #ifdef ICON_KABOOM_EXTRA
199 XClearArea(dpy
, scr
->root_win
, ptx
[1][i
], pty
[1][i
],
200 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
203 ptx
[1][i
] = ptx
[0][i
];
204 pty
[1][i
] = pty
[0][i
];
208 XClearArea(dpy
, scr
->root_win
, _px
, py
[i
],
209 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
214 _px
= px
[i
]>>KAB_PRECISION
;
216 if (_px
<-wPreferences
.icon_size
|| _px
>sw
|| py
[i
]>=sh
) {
217 #ifdef ICON_KABOOM_EXTRA
218 if (py
[i
]>sh
&& _px
<sw
&& _px
>0) {
219 pvy
[i
] = -(pvy
[i
]/2);
220 if (abs(pvy
[i
]) > 3) {
221 py
[i
] = sh
-ICON_KABOOM_PIECE_SIZE
;
222 XCopyArea(dpy
, tmp
, scr
->root_win
, scr
->copy_gc
,
223 ax
[i
]*ICON_KABOOM_PIECE_SIZE
,
224 ay
[i
]*ICON_KABOOM_PIECE_SIZE
,
225 ICON_KABOOM_PIECE_SIZE
,
226 ICON_KABOOM_PIECE_SIZE
,
235 for (ll
=0; ll
<2; ll
++)
236 XClearArea(dpy
, scr
->root_win
, ptx
[ll
][i
], pty
[ll
][i
],
237 ICON_KABOOM_PIECE_SIZE
,
238 ICON_KABOOM_PIECE_SIZE
, False
);
241 #else /* !ICON_KABOOM_EXTRA */
244 #endif /* !ICON_KABOOM_EXTRA */
246 XCopyArea(dpy
, tmp
, scr
->root_win
, scr
->copy_gc
,
247 ax
[i
]*ICON_KABOOM_PIECE_SIZE
, ay
[i
]*ICON_KABOOM_PIECE_SIZE
,
248 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
256 play(dpy
, 100+rand()%250, 12);
258 # if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
259 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
*2);
264 XFreePixmap(dpy
, tmp
);
266 #endif /* !DEMATERIALIZE_ICON */
270 MakeGhostDock(WDock
*dock
, int sx
, int dx
, int y
)
272 WScreen
*scr
= dock
->screen_ptr
;
274 RImage
*back
, *dock_image
;
276 int i
, virtual_tiles
, h
, j
, n
;
277 unsigned long red_mask
, green_mask
, blue_mask
;
280 for (i
=0; i
<dock
->max_icons
; i
++) {
281 if (dock
->icon_array
[i
]!=NULL
&&
282 dock
->icon_array
[i
]->yindex
> virtual_tiles
)
283 virtual_tiles
= dock
->icon_array
[i
]->yindex
;
286 h
= virtual_tiles
* wPreferences
.icon_size
;
287 h
= (y
+ h
> scr
->scr_height
) ? scr
->scr_height
-y
: h
;
288 virtual_tiles
= h
/ wPreferences
.icon_size
; /* The visible ones */
289 if (h
% wPreferences
.icon_size
)
290 virtual_tiles
++; /* There is one partially visible tile at end */
292 img
=XGetImage(dpy
, scr
->root_win
, dx
, y
, wPreferences
.icon_size
, h
,
297 red_mask
= img
->red_mask
;
298 green_mask
= img
->green_mask
;
299 blue_mask
= img
->blue_mask
;
301 back
= RCreateImageFromXImage(scr
->rcontext
, img
, NULL
);
307 for (i
=0;i
<dock
->max_icons
;i
++) {
308 if (dock
->icon_array
[i
]!=NULL
&&
309 dock
->icon_array
[i
]->yindex
< virtual_tiles
) {
311 j
= dock
->icon_array
[i
]->yindex
* wPreferences
.icon_size
;
312 n
= (h
- j
< wPreferences
.icon_size
) ? h
- j
:
313 wPreferences
.icon_size
;
314 if (dock
->icon_array
[i
]->icon
->pixmap
)
315 which
= dock
->icon_array
[i
]->icon
->pixmap
;
317 which
= dock
->icon_array
[i
]->icon
->core
->window
;
319 img
=XGetImage(dpy
, which
, 0, 0, wPreferences
.icon_size
, n
,
326 img
->red_mask
= red_mask
;
327 img
->green_mask
= green_mask
;
328 img
->blue_mask
= blue_mask
;
330 dock_image
= RCreateImageFromXImage(scr
->rcontext
, img
, NULL
);
336 RCombineAreaWithOpaqueness(back
, dock_image
, 0, 0,
337 wPreferences
.icon_size
, n
,
338 0, j
, 30 * 256 / 100);
339 RDestroyImage(dock_image
);
344 RConvertImage(scr
->rcontext
, back
, &pixmap
);
353 MakeGhostIcon(WScreen
*scr
, Drawable drawable
)
363 back
= RCreateImageFromDrawable(scr
->rcontext
, drawable
, None
);
372 RClearImage(back
, &color
);
373 RConvertImage(scr
->rcontext
, back
, &pixmap
);
382 #ifdef WINDOW_BIRTH_ZOOM
384 DoWindowBirth(WWindow
*wwin
)
386 int width
= wwin
->frame
->core
->width
;
387 int height
= wwin
->frame
->core
->height
;
388 int w
= WMIN(width
, 20);
389 int h
= WMIN(height
, 20);
393 time_t time0
= time(NULL
);
395 dw
= (width
-w
)/WINDOW_BIRTH_STEPS
;
396 dh
= (height
-h
)/WINDOW_BIRTH_STEPS
;
398 x
= wwin
->frame_x
+ (width
-w
)/2;
399 y
= wwin
->frame_y
+ (height
-h
)/2;
401 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
, x
, y
, w
, h
);
403 XMapWindow(dpy
, wwin
->frame
->core
->window
);
406 for (i
=0; i
<WINDOW_BIRTH_STEPS
; i
++) {
411 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
, x
, y
, w
, h
);
414 if (time(NULL
)-time0
> MAX_ANIMATION_TIME
)
418 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
,
419 wwin
->frame_x
, wwin
->frame_y
, width
, height
);
424 DoWindowBirth(WWindow
*wwin
)
433 static WMPixmap
*data
[12];
437 loadData(WScreen
*scr
)
444 f
= fopen(PKGDATADIR
"/xtree.dat", "r");
448 image
= RCreateImage(50, 50, False
);
454 for (i
= 0; i
< 12; i
++) {
455 if (fread(image
->data
[0], 50*50, 1, f
)!=1) {
458 if (fread(image
->data
[1], 50*50, 1, f
)!=1) {
461 if (fread(image
->data
[2], 50*50, 1, f
)!=1) {
464 if (!RConvertImage(scr
->rcontext
, image
, &(d
[i
]))) {
468 RDestroyImage(image
);
472 for (i
=0; i
<12; i
++) {
473 data
[i
] = WMCreatePixmapFromXPixmaps(scr
->wmscreen
, d
[i
], None
, 50, 50,
480 RDestroyImage(image
);
485 XFreePixmap(dpy
, d
[i
]);
493 DoXThing(WWindow
*wwin
)
495 static int order
= 0;
499 return data
[order
% 12];
504 InitXThing(WScreen
*scr
)
515 if ((l
->tm_mon
!=12||l
->tm_mday
<24||l
->tm_mday
>26)) {
527 #endif /* SILLYNESS */
530 #ifdef GHOST_WINDOW_MOVE
532 InitGhostWindowMove(WScreen
*scr
)
537 ximg
= RGetXImage(scr
->rcontext
, scr
->root_win
, 0, 0,
538 scr
->scr_width
, scr
->scr_height
);
539 img
= RCreateImageFromXImage(scr
->rcontext
, ximg
->image
, NULL
);
540 RDestroyXImage(dpy
, ximg
);
545 #endif /* GHOST_WINDOW_MOVE */