2 * Window Maker window manager
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
5 * Copyright (c) 1998-2003 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"
45 extern WPreferences wPreferences
;
47 #ifdef DEMATERIALIZE_ICON
48 void DoKaboom(WScreen
* scr
, Window win
, int x
, int y
)
62 h
= w
= wPreferences
.icon_size
;
63 if (x
< 0 || x
+ w
> scr
->scr_width
|| y
< 0 || y
+ h
> scr
->scr_height
)
66 icon
= RCreateImageFromDrawable(scr
->rcontext
, win
, None
);
70 gcv
.foreground
= scr
->white_pixel
;
71 gcv
.background
= scr
->black_pixel
;
72 gcv
.graphics_exposures
= False
;
73 gcv
.subwindow_mode
= IncludeInferiors
;
74 gc
= XCreateGC(dpy
, scr
->w_win
, GCForeground
| GCBackground
| GCSubwindowMode
| GCGraphicsExposures
, &gcv
);
77 RConvertImage(scr
->rcontext
, icon
, &pixmap
);
78 XUnmapWindow(dpy
, win
);
80 ximage
= XGetImage(dpy
, scr
->root_win
, x
, y
, w
, h
, AllPlanes
, ZPixmap
);
81 XCopyArea(dpy
, pixmap
, scr
->root_win
, gc
, 0, 0, w
, h
, x
, y
);
82 XFreePixmap(dpy
, pixmap
);
84 back
= RCreateImageFromXImage(scr
->rcontext
, ximage
, NULL
);
85 XDestroyImage(ximage
);
91 for (i
= 0, run
= 0; i
< DEMATERIALIZE_STEPS
; i
++) {
93 if (!run
&& XCheckTypedEvent(dpy
, ButtonPress
, &foo
)) {
95 XPutBackEvent(dpy
, &foo
);
97 image
= RCloneImage(back
);
98 RCombineImagesWithOpaqueness(image
, icon
,
99 (DEMATERIALIZE_STEPS
- 1 - i
) * 256 / (DEMATERIALIZE_STEPS
+ 2));
100 RConvertImage(scr
->rcontext
, image
, &pixmap
);
101 XCopyArea(dpy
, pixmap
, scr
->root_win
, gc
, 0, 0, w
, h
, x
, y
);
102 XFreePixmap(dpy
, pixmap
);
108 while (XCheckTypedEvent(dpy
, MotionNotify
, &event
)) {
117 #endif /* DEMATERIALIZE_ICON */
119 #ifdef NORMAL_ICON_KABOOM
120 void DoKaboom(WScreen
* scr
, Window win
, int x
, int y
)
123 int sw
= scr
->scr_width
, sh
= scr
->scr_height
;
124 #define KAB_PRECISION 4
127 #ifdef ICON_KABOOM_EXTRA
128 short ptx
[2][PIECES
], pty
[2][PIECES
];
131 char pvx
[PIECES
], pvy
[PIECES
];
132 /* in MkLinux/PPC gcc seems to think that char is unsigned? */
133 signed char ax
[PIECES
], ay
[PIECES
];
136 XSetClipMask(dpy
, scr
->copy_gc
, None
);
137 tmp
= XCreatePixmap(dpy
, scr
->root_win
, wPreferences
.icon_size
, 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
, wPreferences
.icon_size
, 0, 0);
143 image
= XGetImage(dpy
, win
, 0, 0, wPreferences
.icon_size
,
144 wPreferences
.icon_size
, AllPlanes
, ZPixmap
);
146 XUnmapWindow(dpy
, win
);
149 XPutImage(dpy
, tmp
, scr
->copy_gc
, image
, 0, 0, 0, 0,
150 wPreferences
.icon_size
, wPreferences
.icon_size
);
151 XDestroyImage(image
);
154 for (i
= 0, k
= 0; i
< wPreferences
.icon_size
/ ICON_KABOOM_PIECE_SIZE
&& k
< PIECES
; i
++) {
155 for (j
= 0; j
< wPreferences
.icon_size
/ ICON_KABOOM_PIECE_SIZE
&& k
< PIECES
; j
++) {
159 px
[k
] = (x
+ i
* ICON_KABOOM_PIECE_SIZE
) << KAB_PRECISION
;
160 py
[k
] = y
+ j
* ICON_KABOOM_PIECE_SIZE
;
161 pvx
[k
] = rand() % (1 << (KAB_PRECISION
+ 3)) - (1 << (KAB_PRECISION
+ 3)) / 2;
162 pvy
[k
] = -15 - rand() % 7;
163 #ifdef ICON_KABOOM_EXTRA
164 for (ll
= 0; ll
< 2; ll
++) {
176 XUnmapWindow(dpy
, win
);
182 if (XCheckTypedEvent(dpy
, ButtonPress
, &foo
)) {
183 XPutBackEvent(dpy
, &foo
);
184 XClearWindow(dpy
, scr
->root_win
);
188 for (i
= 0; i
< j
; i
++) {
190 int _px
= px
[i
] >> KAB_PRECISION
;
191 #ifdef ICON_KABOOM_EXTRA
192 XClearArea(dpy
, scr
->root_win
, ptx
[1][i
], pty
[1][i
],
193 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
, False
);
195 ptx
[1][i
] = ptx
[0][i
];
196 pty
[1][i
] = pty
[0][i
];
200 XClearArea(dpy
, scr
->root_win
, _px
, py
[i
],
201 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
, False
);
205 _px
= px
[i
] >> KAB_PRECISION
;
207 if (_px
< -wPreferences
.icon_size
|| _px
> sw
|| py
[i
] >= sh
) {
208 #ifdef ICON_KABOOM_EXTRA
209 if (py
[i
] > sh
&& _px
< sw
&& _px
> 0) {
210 pvy
[i
] = -(pvy
[i
] / 2);
211 if (abs(pvy
[i
]) > 3) {
212 py
[i
] = sh
- ICON_KABOOM_PIECE_SIZE
;
213 XCopyArea(dpy
, tmp
, scr
->root_win
, scr
->copy_gc
,
214 ax
[i
] * ICON_KABOOM_PIECE_SIZE
,
215 ay
[i
] * ICON_KABOOM_PIECE_SIZE
,
216 ICON_KABOOM_PIECE_SIZE
,
217 ICON_KABOOM_PIECE_SIZE
, _px
, py
[i
]);
225 for (ll
= 0; ll
< 2; ll
++)
226 XClearArea(dpy
, scr
->root_win
, ptx
[ll
][i
], pty
[ll
][i
],
227 ICON_KABOOM_PIECE_SIZE
,
228 ICON_KABOOM_PIECE_SIZE
, False
);
231 #else /* !ICON_KABOOM_EXTRA */
234 #endif /* !ICON_KABOOM_EXTRA */
236 XCopyArea(dpy
, tmp
, scr
->root_win
, scr
->copy_gc
,
237 ax
[i
] * ICON_KABOOM_PIECE_SIZE
, ay
[i
] * ICON_KABOOM_PIECE_SIZE
,
238 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
, _px
, py
[i
]);
245 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
246 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
* 2);
250 XFreePixmap(dpy
, tmp
);
252 #endif /* NORMAL_ICON_KABOOM */
254 Pixmap
MakeGhostDock(WDock
* dock
, int sx
, int dx
, int y
)
256 WScreen
*scr
= dock
->screen_ptr
;
258 RImage
*back
, *dock_image
;
260 int i
, virtual_tiles
, h
, j
, n
;
261 unsigned long red_mask
, green_mask
, blue_mask
;
264 for (i
= 0; i
< dock
->max_icons
; i
++) {
265 if (dock
->icon_array
[i
] != NULL
&& dock
->icon_array
[i
]->yindex
> virtual_tiles
)
266 virtual_tiles
= dock
->icon_array
[i
]->yindex
;
269 h
= virtual_tiles
* wPreferences
.icon_size
;
270 h
= (y
+ h
> scr
->scr_height
) ? scr
->scr_height
- y
: h
;
271 virtual_tiles
= h
/ wPreferences
.icon_size
; /* The visible ones */
272 if (h
% wPreferences
.icon_size
)
273 virtual_tiles
++; /* There is one partially visible tile at end */
275 img
= XGetImage(dpy
, scr
->root_win
, dx
, y
, wPreferences
.icon_size
, h
, AllPlanes
, ZPixmap
);
279 red_mask
= img
->red_mask
;
280 green_mask
= img
->green_mask
;
281 blue_mask
= img
->blue_mask
;
283 back
= RCreateImageFromXImage(scr
->rcontext
, img
, NULL
);
289 for (i
= 0; i
< dock
->max_icons
; i
++) {
290 if (dock
->icon_array
[i
] != NULL
&& dock
->icon_array
[i
]->yindex
< virtual_tiles
) {
292 j
= dock
->icon_array
[i
]->yindex
* wPreferences
.icon_size
;
293 n
= (h
- j
< wPreferences
.icon_size
) ? h
- j
: wPreferences
.icon_size
;
294 if (dock
->icon_array
[i
]->icon
->pixmap
)
295 which
= dock
->icon_array
[i
]->icon
->pixmap
;
297 which
= dock
->icon_array
[i
]->icon
->core
->window
;
299 img
= XGetImage(dpy
, which
, 0, 0, wPreferences
.icon_size
, n
, AllPlanes
, ZPixmap
);
305 img
->red_mask
= red_mask
;
306 img
->green_mask
= green_mask
;
307 img
->blue_mask
= blue_mask
;
309 dock_image
= RCreateImageFromXImage(scr
->rcontext
, img
, NULL
);
315 RCombineAreaWithOpaqueness(back
, dock_image
, 0, 0,
316 wPreferences
.icon_size
, n
, 0, j
, 30 * 256 / 100);
317 RReleaseImage(dock_image
);
321 RConvertImage(scr
->rcontext
, back
, &pixmap
);
328 Pixmap
MakeGhostIcon(WScreen
* scr
, Drawable drawable
)
337 back
= RCreateImageFromDrawable(scr
->rcontext
, drawable
, None
);
346 RClearImage(back
, &color
);
347 RConvertImage(scr
->rcontext
, back
, &pixmap
);
354 #ifdef WINDOW_BIRTH_ZOOM
355 void DoWindowBirth(WWindow
* wwin
)
357 int width
= wwin
->frame
->core
->width
;
358 int height
= wwin
->frame
->core
->height
;
359 int w
= WMIN(width
, 20);
360 int h
= WMIN(height
, 20);
364 time_t time0
= time(NULL
);
366 dw
= (width
- w
) / WINDOW_BIRTH_STEPS
;
367 dh
= (height
- h
) / WINDOW_BIRTH_STEPS
;
369 x
= wwin
->frame_x
+ (width
- w
) / 2;
370 y
= wwin
->frame_y
+ (height
- h
) / 2;
372 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
, x
, y
, w
, h
);
374 XMapWindow(dpy
, wwin
->frame
->core
->window
);
377 for (i
= 0; i
< WINDOW_BIRTH_STEPS
; i
++) {
378 x
-= dw
/ 2 + dw
% 2;
379 y
-= dh
/ 2 + dh
% 2;
382 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
, x
, y
, w
, h
);
385 if (time(NULL
) - time0
> MAX_ANIMATION_TIME
)
389 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
, wwin
->frame_x
, wwin
->frame_y
, width
, height
);
393 #ifdef WINDOW_BIRTH_ZOOM2
394 extern void animateResize();
396 void DoWindowBirth(WWindow
* wwin
)
400 int center_x
, center_y
;
401 int width
= wwin
->frame
->core
->width
;
402 int height
= wwin
->frame
->core
->height
;
403 int w
= WMIN(width
, 20);
404 int h
= WMIN(height
, 20);
405 WScreen
*scr
= wwin
->screen_ptr
;
407 center_x
= wwin
->frame_x
+ (width
- w
) / 2;
408 center_y
= wwin
->frame_y
+ (height
- h
) / 2;
410 animateResize(scr
, center_x
, center_y
, 1, 1, wwin
->frame_x
, wwin
->frame_y
, width
, height
, 0);
413 void DoWindowBirth(WWindow
* wwin
)
421 static WMPixmap
*data
[12];
423 static Bool
loadData(WScreen
* scr
)
430 f
= fopen(PKGDATADIR
"/xtree.dat", "rb");
434 image
= RCreateImage(50, 50, False
);
440 for (i
= 0; i
< 12; i
++) {
441 if (fread(image
->data
, 50 * 50 * 3, 1, f
) != 1) {
444 if (!RConvertImage(scr
->rcontext
, image
, &(d
[i
]))) {
448 RReleaseImage(image
);
452 for (i
= 0; i
< 12; i
++) {
453 data
[i
] = WMCreatePixmapFromXPixmaps(scr
->wmscreen
, d
[i
], None
, 50, 50, scr
->w_depth
);
459 RReleaseImage(image
);
464 XFreePixmap(dpy
, d
[i
]);
470 WMPixmap
*DoXThing(WWindow
* wwin
)
472 static int order
= 0;
476 return data
[order
% 12];
479 Bool
InitXThing(WScreen
* scr
)
487 if ((l
->tm_mon
!= 11 || l
->tm_mday
< 24 || l
->tm_mday
> 26))
501 #endif /* SILLYNESS */