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 for (i
=0; i
<DEMATERIALIZE_STEPS
; i
++) {
99 if (XCheckTypedEvent(dpy
, ButtonPress
, &foo
)) {
100 XPutBackEvent(dpy
, &foo
);
101 XClearWindow(dpy
, scr
->root_win
);
104 image
= RCloneImage(back
);
105 RCombineImagesWithOpaqueness(image
, icon
,
106 (DEMATERIALIZE_STEPS
-1-i
)*256/(DEMATERIALIZE_STEPS
+2));
107 RConvertImage(scr
->rcontext
, image
, &pixmap
);
108 XCopyArea(dpy
, pixmap
, scr
->root_win
, scr
->copy_gc
, 0, 0, w
, h
, x
, y
);
109 XFreePixmap(dpy
, pixmap
);
113 XClearArea(dpy
, scr
->root_win
, x
, y
, w
, h
, False
);
119 #else /* !DEMATERIALIZE_ICON */
121 DoKaboom(WScreen
*scr
, Window win
, int x
, int y
)
124 int sw
=scr
->scr_width
, sh
=scr
->scr_height
;
125 #define KAB_PRECISION 4
128 #ifdef ICON_KABOOM_EXTRA
129 short ptx
[2][PIECES
], pty
[2][PIECES
];
132 char pvx
[PIECES
], pvy
[PIECES
];
133 /* in MkLinux/PPC gcc seems to think that char is unsigned? */
134 signed char ax
[PIECES
], ay
[PIECES
];
137 XSetClipMask(dpy
, scr
->copy_gc
, None
);
138 tmp
= XCreatePixmap(dpy
, scr
->root_win
, wPreferences
.icon_size
,
139 wPreferences
.icon_size
, scr
->depth
);
140 if (scr
->w_visual
== DefaultVisual(dpy
, scr
->screen
))
141 XCopyArea(dpy
, win
, tmp
, scr
->copy_gc
, 0, 0, wPreferences
.icon_size
,
142 wPreferences
.icon_size
, 0, 0);
146 image
= XGetImage(dpy
, win
, 0, 0, wPreferences
.icon_size
,
147 wPreferences
.icon_size
, AllPlanes
, ZPixmap
);
149 XUnmapWindow(dpy
, win
);
152 XPutImage(dpy
, tmp
, scr
->copy_gc
, image
, 0, 0, 0, 0,
153 wPreferences
.icon_size
, wPreferences
.icon_size
);
154 XDestroyImage(image
);
157 for (i
=0,k
=0; i
<wPreferences
.icon_size
/ICON_KABOOM_PIECE_SIZE
&& k
<PIECES
;
159 for (j
=0; j
<wPreferences
.icon_size
/ICON_KABOOM_PIECE_SIZE
&& k
<PIECES
;
164 px
[k
]=(x
+i
*ICON_KABOOM_PIECE_SIZE
)<<KAB_PRECISION
;
165 py
[k
]=y
+j
*ICON_KABOOM_PIECE_SIZE
;
166 pvx
[k
]=rand()%(1<<(KAB_PRECISION
+3))-(1<<(KAB_PRECISION
+3))/2;
168 #ifdef ICON_KABOOM_EXTRA
169 for (ll
=0; ll
<2; ll
++) {
181 XUnmapWindow(dpy
, win
);
187 if (XCheckTypedEvent(dpy
, ButtonPress
, &foo
)) {
188 XPutBackEvent(dpy
, &foo
);
189 XClearWindow(dpy
, scr
->root_win
);
193 for (i
=0; i
<j
; i
++) {
195 int _px
= px
[i
]>>KAB_PRECISION
;
196 #ifdef ICON_KABOOM_EXTRA
197 XClearArea(dpy
, scr
->root_win
, ptx
[1][i
], pty
[1][i
],
198 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
201 ptx
[1][i
] = ptx
[0][i
];
202 pty
[1][i
] = pty
[0][i
];
206 XClearArea(dpy
, scr
->root_win
, _px
, py
[i
],
207 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
212 _px
= px
[i
]>>KAB_PRECISION
;
214 if (_px
<-wPreferences
.icon_size
|| _px
>sw
|| py
[i
]>=sh
) {
215 #ifdef ICON_KABOOM_EXTRA
216 if (py
[i
]>sh
&& _px
<sw
&& _px
>0) {
217 pvy
[i
] = -(pvy
[i
]/2);
218 if (abs(pvy
[i
]) > 3) {
219 py
[i
] = sh
-ICON_KABOOM_PIECE_SIZE
;
220 XCopyArea(dpy
, tmp
, scr
->root_win
, scr
->copy_gc
,
221 ax
[i
]*ICON_KABOOM_PIECE_SIZE
,
222 ay
[i
]*ICON_KABOOM_PIECE_SIZE
,
223 ICON_KABOOM_PIECE_SIZE
,
224 ICON_KABOOM_PIECE_SIZE
,
233 for (ll
=0; ll
<2; ll
++)
234 XClearArea(dpy
, scr
->root_win
, ptx
[ll
][i
], pty
[ll
][i
],
235 ICON_KABOOM_PIECE_SIZE
,
236 ICON_KABOOM_PIECE_SIZE
, False
);
239 #else /* !ICON_KABOOM_EXTRA */
242 #endif /* !ICON_KABOOM_EXTRA */
244 XCopyArea(dpy
, tmp
, scr
->root_win
, scr
->copy_gc
,
245 ax
[i
]*ICON_KABOOM_PIECE_SIZE
, ay
[i
]*ICON_KABOOM_PIECE_SIZE
,
246 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
254 play(dpy
, 100+rand()%250, 12);
256 # if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
257 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
*2);
262 XFreePixmap(dpy
, tmp
);
264 #endif /* !DEMATERIALIZE_ICON */
268 MakeGhostDock(WDock
*dock
, int sx
, int dx
, int y
)
270 WScreen
*scr
= dock
->screen_ptr
;
272 RImage
*back
, *dock_image
;
274 int i
, virtual_tiles
, h
, j
, n
;
275 unsigned long red_mask
, green_mask
, blue_mask
;
278 for (i
=0; i
<dock
->max_icons
; i
++) {
279 if (dock
->icon_array
[i
]!=NULL
&&
280 dock
->icon_array
[i
]->yindex
> virtual_tiles
)
281 virtual_tiles
= dock
->icon_array
[i
]->yindex
;
284 h
= virtual_tiles
* wPreferences
.icon_size
;
285 h
= (y
+ h
> scr
->scr_height
) ? scr
->scr_height
-y
: h
;
286 virtual_tiles
= h
/ wPreferences
.icon_size
; /* The visible ones */
287 if (h
% wPreferences
.icon_size
)
288 virtual_tiles
++; /* There is one partially visible tile at end */
290 img
=XGetImage(dpy
, scr
->root_win
, dx
, y
, wPreferences
.icon_size
, h
,
295 red_mask
= img
->red_mask
;
296 green_mask
= img
->green_mask
;
297 blue_mask
= img
->blue_mask
;
299 back
= RCreateImageFromXImage(scr
->rcontext
, img
, NULL
);
305 for (i
=0;i
<dock
->max_icons
;i
++) {
306 if (dock
->icon_array
[i
]!=NULL
&&
307 dock
->icon_array
[i
]->yindex
< virtual_tiles
) {
309 j
= dock
->icon_array
[i
]->yindex
* wPreferences
.icon_size
;
310 n
= (h
- j
< wPreferences
.icon_size
) ? h
- j
:
311 wPreferences
.icon_size
;
312 if (dock
->icon_array
[i
]->icon
->pixmap
)
313 which
= dock
->icon_array
[i
]->icon
->pixmap
;
315 which
= dock
->icon_array
[i
]->icon
->core
->window
;
317 img
=XGetImage(dpy
, which
, 0, 0, wPreferences
.icon_size
, n
,
324 img
->red_mask
= red_mask
;
325 img
->green_mask
= green_mask
;
326 img
->blue_mask
= blue_mask
;
328 dock_image
= RCreateImageFromXImage(scr
->rcontext
, img
, NULL
);
334 RCombineAreaWithOpaqueness(back
, dock_image
, 0, 0,
335 wPreferences
.icon_size
, n
,
336 0, j
, 30 * 256 / 100);
337 RDestroyImage(dock_image
);
342 RConvertImage(scr
->rcontext
, back
, &pixmap
);
351 MakeGhostIcon(WScreen
*scr
, Drawable drawable
)
361 back
= RCreateImageFromDrawable(scr
->rcontext
, drawable
, None
);
370 RClearImage(back
, &color
);
371 RConvertImage(scr
->rcontext
, back
, &pixmap
);
380 #ifdef WINDOW_BIRTH_ZOOM
382 DoWindowBirth(WWindow
*wwin
)
384 int width
= wwin
->frame
->core
->width
;
385 int height
= wwin
->frame
->core
->height
;
386 int w
= WMIN(width
, 20);
387 int h
= WMIN(height
, 20);
391 time_t time0
= time(NULL
);
393 dw
= (width
-w
)/WINDOW_BIRTH_STEPS
;
394 dh
= (height
-h
)/WINDOW_BIRTH_STEPS
;
396 x
= wwin
->frame_x
+ (width
-w
)/2;
397 y
= wwin
->frame_y
+ (height
-h
)/2;
399 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
, x
, y
, w
, h
);
401 XMapWindow(dpy
, wwin
->frame
->core
->window
);
404 for (i
=0; i
<WINDOW_BIRTH_STEPS
; i
++) {
409 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
, x
, y
, w
, h
);
412 if (time(NULL
)-time0
> MAX_ANIMATION_TIME
)
416 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
,
417 wwin
->frame_x
, wwin
->frame_y
, width
, height
);
422 DoWindowBirth(WWindow
*wwin
)
431 static WMPixmap
*data
[12];
435 loadData(WScreen
*scr
)
442 f
= fopen(PKGDATADIR
"/xtree.dat", "r");
446 image
= RCreateImage(50, 50, False
);
452 for (i
= 0; i
< 12; i
++) {
453 if (fread(image
->data
[0], 50*50, 1, f
)!=1) {
456 if (fread(image
->data
[1], 50*50, 1, f
)!=1) {
459 if (fread(image
->data
[2], 50*50, 1, f
)!=1) {
462 if (!RConvertImage(scr
->rcontext
, image
, &(d
[i
]))) {
466 RDestroyImage(image
);
470 for (i
=0; i
<12; i
++) {
471 data
[i
] = WMCreatePixmapFromXPixmaps(scr
->wmscreen
, d
[i
], None
, 50, 50,
478 RDestroyImage(image
);
483 XFreePixmap(dpy
, d
[i
]);
491 DoXThing(WWindow
*wwin
)
493 static int order
= 0;
497 return data
[order
% 12];
502 InitXThing(WScreen
*scr
)
513 if ((l
->tm_mon
!=12||l
->tm_mday
<24||l
->tm_mday
>26)) {
525 #endif /* SILLYNESS */
528 #ifdef GHOST_WINDOW_MOVE
530 InitGhostWindowMove(WScreen
*scr
)
535 ximg
= RGetXImage(scr
->rcontext
, scr
->root_win
, 0, 0,
536 scr
->scr_width
, scr
->scr_height
);
537 img
= RCreateImageFromXImage(scr
->rcontext
, ximg
->image
, NULL
);
538 RDestroyXImage(dpy
, ximg
);
543 #endif /* GHOST_WINDOW_MOVE */