2 * Window Maker window manager
4 * Copyright (c) 1997, 1998 Alfredo K. Kojima
5 * Copyright (c) 1997, 1998 Dan Pascu
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.
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.
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,
26 #include <X11/Xutil.h>
35 #include "WindowMaker.h"
37 #include "superfluous.h"
46 extern WPreferences wPreferences
;
51 play(Display
*dpy
, int pitch
, int delay
)
55 kc
.bell_pitch
= pitch
;
57 kc
.bell_duration
= delay
;
58 XChangeKeyboardControl(dpy
, KBBellPitch
|KBBellDuration
|KBBellPercent
,&kc
);
67 #ifdef DEMATERIALIZE_ICON
69 DoKaboom(WScreen
*scr
, Window win
, int x
, int y
)
82 h
= w
= wPreferences
.icon_size
;
83 if (x
< 0 || x
+ w
> scr
->scr_width
|| y
< 0 || y
+ h
> scr
->scr_height
)
86 icon
= RCreateImageFromDrawable(scr
->rcontext
, win
, None
);
91 XUnmapWindow(dpy
, win
);
94 ximage
= XGetImage(dpy
, scr
->root_win
, x
, y
, w
, h
, AllPlanes
, ZPixmap
);
95 back
= RCreateImageFromXImage(scr
->rcontext
, ximage
, NULL
);
96 XDestroyImage(ximage
);
102 gcv
.foreground
= scr
->white_pixel
;
103 gcv
.background
= scr
->black_pixel
;
104 gcv
.graphics_exposures
= False
;
105 gcv
.subwindow_mode
= IncludeInferiors
;
106 gc
= XCreateGC(dpy
, scr
->w_win
, GCForeground
|GCBackground
|GCSubwindowMode
107 |GCGraphicsExposures
, &gcv
);
110 XSetClipMask(dpy, scr->copy_gc, None);
113 for (i
=0,run
=0; i
<DEMATERIALIZE_STEPS
; i
++) {
115 if (!run
&& XCheckTypedEvent(dpy
, ButtonPress
, &foo
)) {
117 XPutBackEvent(dpy
, &foo
);
119 XClearWindow(dpy, scr->root_win);
123 image
= RCloneImage(back
);
124 RCombineImagesWithOpaqueness(image
, icon
,
125 (DEMATERIALIZE_STEPS
-1-i
)*256/(DEMATERIALIZE_STEPS
+2));
126 RConvertImage(scr
->rcontext
, image
, &pixmap
);
127 XCopyArea(dpy
, pixmap
, scr
->root_win
, gc
, 0, 0, w
, h
, x
, y
);
128 XFreePixmap(dpy
, pixmap
);
130 if(!run
) wusleep(1000);
133 XClearArea(dpy, scr->root_win, x, y, w, h, False);
142 #else /* !DEMATERIALIZE_ICON */
144 DoKaboom(WScreen
*scr
, Window win
, int x
, int y
)
147 int sw
=scr
->scr_width
, sh
=scr
->scr_height
;
148 #define KAB_PRECISION 4
151 #ifdef ICON_KABOOM_EXTRA
152 short ptx
[2][PIECES
], pty
[2][PIECES
];
155 char pvx
[PIECES
], pvy
[PIECES
];
156 /* in MkLinux/PPC gcc seems to think that char is unsigned? */
157 signed char ax
[PIECES
], ay
[PIECES
];
160 XSetClipMask(dpy
, scr
->copy_gc
, None
);
161 tmp
= XCreatePixmap(dpy
, scr
->root_win
, wPreferences
.icon_size
,
162 wPreferences
.icon_size
, scr
->depth
);
163 if (scr
->w_visual
== DefaultVisual(dpy
, scr
->screen
))
164 XCopyArea(dpy
, win
, tmp
, scr
->copy_gc
, 0, 0, wPreferences
.icon_size
,
165 wPreferences
.icon_size
, 0, 0);
169 image
= XGetImage(dpy
, win
, 0, 0, wPreferences
.icon_size
,
170 wPreferences
.icon_size
, AllPlanes
, ZPixmap
);
172 XUnmapWindow(dpy
, win
);
175 XPutImage(dpy
, tmp
, scr
->copy_gc
, image
, 0, 0, 0, 0,
176 wPreferences
.icon_size
, wPreferences
.icon_size
);
177 XDestroyImage(image
);
180 for (i
=0,k
=0; i
<wPreferences
.icon_size
/ICON_KABOOM_PIECE_SIZE
&& k
<PIECES
;
182 for (j
=0; j
<wPreferences
.icon_size
/ICON_KABOOM_PIECE_SIZE
&& k
<PIECES
;
187 px
[k
]=(x
+i
*ICON_KABOOM_PIECE_SIZE
)<<KAB_PRECISION
;
188 py
[k
]=y
+j
*ICON_KABOOM_PIECE_SIZE
;
189 pvx
[k
]=rand()%(1<<(KAB_PRECISION
+3))-(1<<(KAB_PRECISION
+3))/2;
191 #ifdef ICON_KABOOM_EXTRA
192 for (ll
=0; ll
<2; ll
++) {
204 XUnmapWindow(dpy
, win
);
210 if (XCheckTypedEvent(dpy
, ButtonPress
, &foo
)) {
211 XPutBackEvent(dpy
, &foo
);
212 XClearWindow(dpy
, scr
->root_win
);
216 for (i
=0; i
<j
; i
++) {
218 int _px
= px
[i
]>>KAB_PRECISION
;
219 #ifdef ICON_KABOOM_EXTRA
220 XClearArea(dpy
, scr
->root_win
, ptx
[1][i
], pty
[1][i
],
221 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
224 ptx
[1][i
] = ptx
[0][i
];
225 pty
[1][i
] = pty
[0][i
];
229 XClearArea(dpy
, scr
->root_win
, _px
, py
[i
],
230 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
235 _px
= px
[i
]>>KAB_PRECISION
;
237 if (_px
<-wPreferences
.icon_size
|| _px
>sw
|| py
[i
]>=sh
) {
238 #ifdef ICON_KABOOM_EXTRA
239 if (py
[i
]>sh
&& _px
<sw
&& _px
>0) {
240 pvy
[i
] = -(pvy
[i
]/2);
241 if (abs(pvy
[i
]) > 3) {
242 py
[i
] = sh
-ICON_KABOOM_PIECE_SIZE
;
243 XCopyArea(dpy
, tmp
, scr
->root_win
, scr
->copy_gc
,
244 ax
[i
]*ICON_KABOOM_PIECE_SIZE
,
245 ay
[i
]*ICON_KABOOM_PIECE_SIZE
,
246 ICON_KABOOM_PIECE_SIZE
,
247 ICON_KABOOM_PIECE_SIZE
,
256 for (ll
=0; ll
<2; ll
++)
257 XClearArea(dpy
, scr
->root_win
, ptx
[ll
][i
], pty
[ll
][i
],
258 ICON_KABOOM_PIECE_SIZE
,
259 ICON_KABOOM_PIECE_SIZE
, False
);
262 #else /* !ICON_KABOOM_EXTRA */
265 #endif /* !ICON_KABOOM_EXTRA */
267 XCopyArea(dpy
, tmp
, scr
->root_win
, scr
->copy_gc
,
268 ax
[i
]*ICON_KABOOM_PIECE_SIZE
, ay
[i
]*ICON_KABOOM_PIECE_SIZE
,
269 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
277 play(dpy
, 100+rand()%250, 12);
279 # if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
280 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
*2);
285 XFreePixmap(dpy
, tmp
);
287 #endif /* !DEMATERIALIZE_ICON */
291 MakeGhostDock(WDock
*dock
, int sx
, int dx
, int y
)
293 WScreen
*scr
= dock
->screen_ptr
;
295 RImage
*back
, *dock_image
;
297 int i
, virtual_tiles
, h
, j
, n
;
298 unsigned long red_mask
, green_mask
, blue_mask
;
301 for (i
=0; i
<dock
->max_icons
; i
++) {
302 if (dock
->icon_array
[i
]!=NULL
&&
303 dock
->icon_array
[i
]->yindex
> virtual_tiles
)
304 virtual_tiles
= dock
->icon_array
[i
]->yindex
;
307 h
= virtual_tiles
* wPreferences
.icon_size
;
308 h
= (y
+ h
> scr
->scr_height
) ? scr
->scr_height
-y
: h
;
309 virtual_tiles
= h
/ wPreferences
.icon_size
; /* The visible ones */
310 if (h
% wPreferences
.icon_size
)
311 virtual_tiles
++; /* There is one partially visible tile at end */
313 img
=XGetImage(dpy
, scr
->root_win
, dx
, y
, wPreferences
.icon_size
, h
,
318 red_mask
= img
->red_mask
;
319 green_mask
= img
->green_mask
;
320 blue_mask
= img
->blue_mask
;
322 back
= RCreateImageFromXImage(scr
->rcontext
, img
, NULL
);
328 for (i
=0;i
<dock
->max_icons
;i
++) {
329 if (dock
->icon_array
[i
]!=NULL
&&
330 dock
->icon_array
[i
]->yindex
< virtual_tiles
) {
332 j
= dock
->icon_array
[i
]->yindex
* wPreferences
.icon_size
;
333 n
= (h
- j
< wPreferences
.icon_size
) ? h
- j
:
334 wPreferences
.icon_size
;
335 if (dock
->icon_array
[i
]->icon
->pixmap
)
336 which
= dock
->icon_array
[i
]->icon
->pixmap
;
338 which
= dock
->icon_array
[i
]->icon
->core
->window
;
340 img
=XGetImage(dpy
, which
, 0, 0, wPreferences
.icon_size
, n
,
347 img
->red_mask
= red_mask
;
348 img
->green_mask
= green_mask
;
349 img
->blue_mask
= blue_mask
;
351 dock_image
= RCreateImageFromXImage(scr
->rcontext
, img
, NULL
);
357 RCombineAreaWithOpaqueness(back
, dock_image
, 0, 0,
358 wPreferences
.icon_size
, n
,
359 0, j
, 30 * 256 / 100);
360 RDestroyImage(dock_image
);
365 RConvertImage(scr
->rcontext
, back
, &pixmap
);
374 MakeGhostIcon(WScreen
*scr
, Drawable drawable
)
384 back
= RCreateImageFromDrawable(scr
->rcontext
, drawable
, None
);
393 RClearImage(back
, &color
);
394 RConvertImage(scr
->rcontext
, back
, &pixmap
);
403 #ifdef WINDOW_BIRTH_ZOOM
405 DoWindowBirth(WWindow
*wwin
)
407 int width
= wwin
->frame
->core
->width
;
408 int height
= wwin
->frame
->core
->height
;
409 int w
= WMIN(width
, 20);
410 int h
= WMIN(height
, 20);
414 time_t time0
= time(NULL
);
416 dw
= (width
-w
)/WINDOW_BIRTH_STEPS
;
417 dh
= (height
-h
)/WINDOW_BIRTH_STEPS
;
419 x
= wwin
->frame_x
+ (width
-w
)/2;
420 y
= wwin
->frame_y
+ (height
-h
)/2;
422 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
, x
, y
, w
, h
);
424 XMapWindow(dpy
, wwin
->frame
->core
->window
);
427 for (i
=0; i
<WINDOW_BIRTH_STEPS
; i
++) {
432 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
, x
, y
, w
, h
);
435 if (time(NULL
)-time0
> MAX_ANIMATION_TIME
)
439 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
,
440 wwin
->frame_x
, wwin
->frame_y
, width
, height
);
445 DoWindowBirth(WWindow
*wwin
)
454 static WMPixmap
*data
[12];
458 loadData(WScreen
*scr
)
465 f
= fopen(PKGDATADIR
"/xtree.dat", "r");
469 image
= RCreateImage(50, 50, False
);
475 for (i
= 0; i
< 12; i
++) {
476 if (fread(image
->data
[0], 50*50, 1, f
)!=1) {
479 if (fread(image
->data
[1], 50*50, 1, f
)!=1) {
482 if (fread(image
->data
[2], 50*50, 1, f
)!=1) {
485 if (!RConvertImage(scr
->rcontext
, image
, &(d
[i
]))) {
489 RDestroyImage(image
);
493 for (i
=0; i
<12; i
++) {
494 data
[i
] = WMCreatePixmapFromXPixmaps(scr
->wmscreen
, d
[i
], None
, 50, 50,
501 RDestroyImage(image
);
506 XFreePixmap(dpy
, d
[i
]);
514 DoXThing(WWindow
*wwin
)
516 static int order
= 0;
520 return data
[order
% 12];
525 InitXThing(WScreen
*scr
)
536 if ((l
->tm_mon
!=12||l
->tm_mday
<24||l
->tm_mday
>26)) {
548 #endif /* SILLYNESS */
551 #ifdef GHOST_WINDOW_MOVE
553 InitGhostWindowMove(WScreen
*scr
)
558 ximg
= RGetXImage(scr
->rcontext
, scr
->root_win
, 0, 0,
559 scr
->scr_width
, scr
->scr_height
);
560 img
= RCreateImageFromXImage(scr
->rcontext
, ximg
->image
, NULL
);
561 RDestroyXImage(dpy
, ximg
);
566 #endif /* GHOST_WINDOW_MOVE */