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
);
64 #ifdef DEMATERIALIZE_ICON
66 DoKaboom(WScreen
*scr
, Window win
, int x
, int y
)
76 h
= w
= wPreferences
.icon_size
;
77 if (x
< 0 || x
+ w
> scr
->scr_width
|| y
< 0 || y
+ h
> scr
->scr_height
)
80 icon
= RCreateImageFromDrawable(scr
->rcontext
, win
, None
);
84 XUnmapWindow(dpy
, win
);
87 ximage
= XGetImage(dpy
, scr
->root_win
, x
, y
, w
, h
, AllPlanes
, ZPixmap
);
88 back
= RCreateImageFromXImage(scr
->rcontext
, ximage
, NULL
);
89 XDestroyImage(ximage
);
95 for (i
=0; i
<DEMATERIALIZE_STEPS
; i
++) {
97 if (XCheckTypedWindowEvent(dpy
, scr
->root_win
, ButtonPressMask
,
99 XClearWindow(dpy
, scr
->root_win
);
102 image
= RCloneImage(back
);
103 RCombineImagesWithOpaqueness(image
, icon
,
104 (DEMATERIALIZE_STEPS
-1-i
)*256/(DEMATERIALIZE_STEPS
+2));
105 RConvertImage(scr
->rcontext
, image
, &pixmap
);
106 XCopyArea(dpy
, pixmap
, scr
->root_win
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
);
107 XFreePixmap(dpy
, pixmap
);
110 XClearArea(dpy
, scr
->root_win
, x
, y
, w
, h
, False
);
117 #else /* !DEMATERIALIZE_ICON */
119 DoKaboom(WScreen
*scr
, Window win
, int x
, int y
)
122 int sw
=scr
->scr_width
, sh
=scr
->scr_height
;
123 #define KAB_PRECISION 4
126 #ifdef ICON_KABOOM_EXTRA
127 short ptx
[2][PIECES
], pty
[2][PIECES
];
130 char pvx
[PIECES
], pvy
[PIECES
];
131 /* in MkLinux/PPC gcc seems to think that char is unsigned? */
132 signed char ax
[PIECES
], ay
[PIECES
];
135 XSetClipMask(dpy
, scr
->copy_gc
, None
);
136 tmp
= XCreatePixmap(dpy
, scr
->root_win
, wPreferences
.icon_size
,
137 wPreferences
.icon_size
, scr
->depth
);
138 if (scr
->w_visual
== DefaultVisual(dpy
, scr
->screen
))
139 XCopyArea(dpy
, win
, tmp
, scr
->copy_gc
, 0, 0, wPreferences
.icon_size
,
140 wPreferences
.icon_size
, 0, 0);
144 image
= XGetImage(dpy
, win
, 0, 0, wPreferences
.icon_size
,
145 wPreferences
.icon_size
, AllPlanes
, ZPixmap
);
147 XUnmapWindow(dpy
, win
);
150 XPutImage(dpy
, tmp
, scr
->copy_gc
, image
, 0, 0, 0, 0,
151 wPreferences
.icon_size
, wPreferences
.icon_size
);
152 XDestroyImage(image
);
155 for (i
=0,k
=0; i
<wPreferences
.icon_size
/ICON_KABOOM_PIECE_SIZE
&& k
<PIECES
;
157 for (j
=0; j
<wPreferences
.icon_size
/ICON_KABOOM_PIECE_SIZE
&& k
<PIECES
;
162 px
[k
]=(x
+i
*ICON_KABOOM_PIECE_SIZE
)<<KAB_PRECISION
;
163 py
[k
]=y
+j
*ICON_KABOOM_PIECE_SIZE
;
164 pvx
[k
]=rand()%(1<<(KAB_PRECISION
+3))-(1<<(KAB_PRECISION
+3))/2;
166 #ifdef ICON_KABOOM_EXTRA
167 for (ll
=0; ll
<2; ll
++) {
179 XUnmapWindow(dpy
, win
);
185 if (XCheckTypedEvent(dpy
, ButtonPress
, &foo
)) {
186 XPutBackEvent(dpy
, &foo
);
187 XClearWindow(dpy
, scr
->root_win
);
191 for (i
=0; i
<j
; i
++) {
193 int _px
= px
[i
]>>KAB_PRECISION
;
194 #ifdef ICON_KABOOM_EXTRA
195 XClearArea(dpy
, scr
->root_win
, ptx
[1][i
], pty
[1][i
],
196 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
199 ptx
[1][i
] = ptx
[0][i
];
200 pty
[1][i
] = pty
[0][i
];
204 XClearArea(dpy
, scr
->root_win
, _px
, py
[i
],
205 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
210 _px
= px
[i
]>>KAB_PRECISION
;
212 if (_px
<-wPreferences
.icon_size
|| _px
>sw
|| py
[i
]>=sh
) {
213 #ifdef ICON_KABOOM_EXTRA
214 if (py
[i
]>sh
&& _px
<sw
&& _px
>0) {
215 pvy
[i
] = -(pvy
[i
]/2);
216 if (abs(pvy
[i
]) > 3) {
217 py
[i
] = sh
-ICON_KABOOM_PIECE_SIZE
;
218 XCopyArea(dpy
, tmp
, scr
->root_win
, scr
->copy_gc
,
219 ax
[i
]*ICON_KABOOM_PIECE_SIZE
,
220 ay
[i
]*ICON_KABOOM_PIECE_SIZE
,
221 ICON_KABOOM_PIECE_SIZE
,
222 ICON_KABOOM_PIECE_SIZE
,
231 for (ll
=0; ll
<2; ll
++)
232 XClearArea(dpy
, scr
->root_win
, ptx
[ll
][i
], pty
[ll
][i
],
233 ICON_KABOOM_PIECE_SIZE
,
234 ICON_KABOOM_PIECE_SIZE
, False
);
237 #else /* !ICON_KABOOM_EXTRA */
240 #endif /* !ICON_KABOOM_EXTRA */
242 XCopyArea(dpy
, tmp
, scr
->root_win
, scr
->copy_gc
,
243 ax
[i
]*ICON_KABOOM_PIECE_SIZE
, ay
[i
]*ICON_KABOOM_PIECE_SIZE
,
244 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
252 play(dpy
, 100+rand()%250, 12);
254 # if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
255 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
*2);
260 XFreePixmap(dpy
, tmp
);
262 #endif /* !DEMATERIALIZE_ICON */
266 MakeGhostDock(WDock
*dock
, int sx
, int dx
, int y
)
268 WScreen
*scr
= dock
->screen_ptr
;
270 RImage
*back
, *dock_image
;
272 int i
, virtual_tiles
, h
, j
, n
;
273 unsigned long red_mask
, green_mask
, blue_mask
;
276 for (i
=0; i
<dock
->max_icons
; i
++) {
277 if (dock
->icon_array
[i
]!=NULL
&&
278 dock
->icon_array
[i
]->yindex
> virtual_tiles
)
279 virtual_tiles
= dock
->icon_array
[i
]->yindex
;
282 h
= virtual_tiles
* wPreferences
.icon_size
;
283 h
= (y
+ h
> scr
->scr_height
) ? scr
->scr_height
-y
: h
;
284 virtual_tiles
= h
/ wPreferences
.icon_size
; /* The visible ones */
285 if (h
% wPreferences
.icon_size
)
286 virtual_tiles
++; /* There is one partially visible tile at end */
288 img
=XGetImage(dpy
, scr
->root_win
, dx
, y
, wPreferences
.icon_size
, h
,
293 red_mask
= img
->red_mask
;
294 green_mask
= img
->green_mask
;
295 blue_mask
= img
->blue_mask
;
297 back
= RCreateImageFromXImage(scr
->rcontext
, img
, NULL
);
303 for (i
=0;i
<dock
->max_icons
;i
++) {
304 if (dock
->icon_array
[i
]!=NULL
&&
305 dock
->icon_array
[i
]->yindex
< virtual_tiles
) {
307 j
= dock
->icon_array
[i
]->yindex
* wPreferences
.icon_size
;
308 n
= (h
- j
< wPreferences
.icon_size
) ? h
- j
:
309 wPreferences
.icon_size
;
310 if (dock
->icon_array
[i
]->icon
->pixmap
)
311 which
= dock
->icon_array
[i
]->icon
->pixmap
;
313 which
= dock
->icon_array
[i
]->icon
->core
->window
;
315 img
=XGetImage(dpy
, which
, 0, 0, wPreferences
.icon_size
, n
,
322 img
->red_mask
= red_mask
;
323 img
->green_mask
= green_mask
;
324 img
->blue_mask
= blue_mask
;
326 dock_image
= RCreateImageFromXImage(scr
->rcontext
, img
, NULL
);
332 RCombineAreaWithOpaqueness(back
, dock_image
, 0, 0,
333 wPreferences
.icon_size
, n
,
334 0, j
, 30 * 256 / 100);
335 RDestroyImage(dock_image
);
340 RConvertImage(scr
->rcontext
, back
, &pixmap
);
349 MakeGhostIcon(WScreen
*scr
, Drawable drawable
)
359 back
= RCreateImageFromDrawable(scr
->rcontext
, drawable
, None
);
368 RClearImage(back
, &color
);
369 RConvertImage(scr
->rcontext
, back
, &pixmap
);
378 #ifdef WINDOW_BIRTH_ZOOM
380 DoWindowBirth(WWindow
*wwin
)
382 int width
= wwin
->frame
->core
->width
;
383 int height
= wwin
->frame
->core
->height
;
384 int w
= WMIN(width
, 20);
385 int h
= WMIN(height
, 20);
389 time_t time0
= time(NULL
);
391 dw
= (width
-w
)/WINDOW_BIRTH_STEPS
;
392 dh
= (height
-h
)/WINDOW_BIRTH_STEPS
;
394 x
= wwin
->frame_x
+ (width
-w
)/2;
395 y
= wwin
->frame_y
+ (height
-h
)/2;
397 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
, x
, y
, w
, h
);
399 XMapWindow(dpy
, wwin
->frame
->core
->window
);
402 for (i
=0; i
<WINDOW_BIRTH_STEPS
; i
++) {
407 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
, x
, y
, w
, h
);
410 if (time(NULL
)-time0
> MAX_ANIMATION_TIME
)
414 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
,
415 wwin
->frame_x
, wwin
->frame_y
, width
, height
);
420 DoWindowBirth(WWindow
*wwin
)
429 static WMPixmap
*data
[12];
433 loadData(WScreen
*scr
)
440 f
= fopen(PKGDATADIR
"/xtree.dat", "r");
444 image
= RCreateImage(50, 50, False
);
450 for (i
= 0; i
< 12; i
++) {
451 if (fread(image
->data
[0], 50*50, 1, f
)!=1) {
454 if (fread(image
->data
[1], 50*50, 1, f
)!=1) {
457 if (fread(image
->data
[2], 50*50, 1, f
)!=1) {
460 if (!RConvertImage(scr
->rcontext
, image
, &(d
[i
]))) {
464 RDestroyImage(image
);
468 for (i
=0; i
<12; i
++) {
469 data
[i
] = WMCreatePixmapFromXPixmaps(scr
->wmscreen
, d
[i
], None
, 50, 50,
476 RDestroyImage(image
);
481 XFreePixmap(dpy
, d
[i
]);
489 DoXThing(WWindow
*wwin
)
491 static int order
= 0;
495 return data
[order
% 12];
500 InitXThing(WScreen
*scr
)
511 if ((l
->tm_mon
!=12||l
->tm_mday
<24||l
->tm_mday
>26)) {
523 #endif /* SILLYNESS */