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
);
90 gcv
.foreground
= scr
->white_pixel
;
91 gcv
.background
= scr
->black_pixel
;
92 gcv
.graphics_exposures
= False
;
93 gcv
.subwindow_mode
= IncludeInferiors
;
94 gc
= XCreateGC(dpy
, scr
->w_win
, GCForeground
|GCBackground
|GCSubwindowMode
95 |GCGraphicsExposures
, &gcv
);
99 RConvertImage(scr
->rcontext
, icon
, &pixmap
);
100 XUnmapWindow(dpy
, win
);
102 ximage
= XGetImage(dpy
, scr
->root_win
, x
, y
, w
, h
, AllPlanes
, ZPixmap
);
103 XCopyArea(dpy
, pixmap
, scr
->root_win
, gc
, 0, 0, w
, h
, x
, y
);
104 XFreePixmap(dpy
,pixmap
);
106 back
= RCreateImageFromXImage(scr
->rcontext
, ximage
, NULL
);
107 XDestroyImage(ximage
);
114 for (i
=0,run
=0; i
<DEMATERIALIZE_STEPS
; i
++) {
116 if (!run
&& XCheckTypedEvent(dpy
, ButtonPress
, &foo
)) {
118 XPutBackEvent(dpy
, &foo
);
120 image
= RCloneImage(back
);
121 RCombineImagesWithOpaqueness(image
, icon
,
122 (DEMATERIALIZE_STEPS
-1-i
)*256/(DEMATERIALIZE_STEPS
+2));
123 RConvertImage(scr
->rcontext
, image
, &pixmap
);
124 XCopyArea(dpy
, pixmap
, scr
->root_win
, gc
, 0, 0, w
, h
, x
, y
);
125 XFreePixmap(dpy
, pixmap
);
127 if(!run
) wusleep(1000);
136 #endif /* DEMATERIALIZE_ICON */
143 #ifdef NORMAL_ICON_KABOOM
145 DoKaboom(WScreen
*scr
, Window win
, int x
, int y
)
148 int sw
=scr
->scr_width
, sh
=scr
->scr_height
;
149 #define KAB_PRECISION 4
152 #ifdef ICON_KABOOM_EXTRA
153 short ptx
[2][PIECES
], pty
[2][PIECES
];
156 char pvx
[PIECES
], pvy
[PIECES
];
157 /* in MkLinux/PPC gcc seems to think that char is unsigned? */
158 signed char ax
[PIECES
], ay
[PIECES
];
161 XSetClipMask(dpy
, scr
->copy_gc
, None
);
162 tmp
= XCreatePixmap(dpy
, scr
->root_win
, wPreferences
.icon_size
,
163 wPreferences
.icon_size
, scr
->depth
);
164 if (scr
->w_visual
== DefaultVisual(dpy
, scr
->screen
))
165 XCopyArea(dpy
, win
, tmp
, scr
->copy_gc
, 0, 0, wPreferences
.icon_size
,
166 wPreferences
.icon_size
, 0, 0);
170 image
= XGetImage(dpy
, win
, 0, 0, wPreferences
.icon_size
,
171 wPreferences
.icon_size
, AllPlanes
, ZPixmap
);
173 XUnmapWindow(dpy
, win
);
176 XPutImage(dpy
, tmp
, scr
->copy_gc
, image
, 0, 0, 0, 0,
177 wPreferences
.icon_size
, wPreferences
.icon_size
);
178 XDestroyImage(image
);
181 for (i
=0,k
=0; i
<wPreferences
.icon_size
/ICON_KABOOM_PIECE_SIZE
&& k
<PIECES
;
183 for (j
=0; j
<wPreferences
.icon_size
/ICON_KABOOM_PIECE_SIZE
&& k
<PIECES
;
188 px
[k
]=(x
+i
*ICON_KABOOM_PIECE_SIZE
)<<KAB_PRECISION
;
189 py
[k
]=y
+j
*ICON_KABOOM_PIECE_SIZE
;
190 pvx
[k
]=rand()%(1<<(KAB_PRECISION
+3))-(1<<(KAB_PRECISION
+3))/2;
192 #ifdef ICON_KABOOM_EXTRA
193 for (ll
=0; ll
<2; ll
++) {
205 XUnmapWindow(dpy
, win
);
211 if (XCheckTypedEvent(dpy
, ButtonPress
, &foo
)) {
212 XPutBackEvent(dpy
, &foo
);
213 XClearWindow(dpy
, scr
->root_win
);
217 for (i
=0; i
<j
; i
++) {
219 int _px
= px
[i
]>>KAB_PRECISION
;
220 #ifdef ICON_KABOOM_EXTRA
221 XClearArea(dpy
, scr
->root_win
, ptx
[1][i
], pty
[1][i
],
222 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
225 ptx
[1][i
] = ptx
[0][i
];
226 pty
[1][i
] = pty
[0][i
];
230 XClearArea(dpy
, scr
->root_win
, _px
, py
[i
],
231 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
236 _px
= px
[i
]>>KAB_PRECISION
;
238 if (_px
<-wPreferences
.icon_size
|| _px
>sw
|| py
[i
]>=sh
) {
239 #ifdef ICON_KABOOM_EXTRA
240 if (py
[i
]>sh
&& _px
<sw
&& _px
>0) {
241 pvy
[i
] = -(pvy
[i
]/2);
242 if (abs(pvy
[i
]) > 3) {
243 py
[i
] = sh
-ICON_KABOOM_PIECE_SIZE
;
244 XCopyArea(dpy
, tmp
, scr
->root_win
, scr
->copy_gc
,
245 ax
[i
]*ICON_KABOOM_PIECE_SIZE
,
246 ay
[i
]*ICON_KABOOM_PIECE_SIZE
,
247 ICON_KABOOM_PIECE_SIZE
,
248 ICON_KABOOM_PIECE_SIZE
,
257 for (ll
=0; ll
<2; ll
++)
258 XClearArea(dpy
, scr
->root_win
, ptx
[ll
][i
], pty
[ll
][i
],
259 ICON_KABOOM_PIECE_SIZE
,
260 ICON_KABOOM_PIECE_SIZE
, False
);
263 #else /* !ICON_KABOOM_EXTRA */
266 #endif /* !ICON_KABOOM_EXTRA */
268 XCopyArea(dpy
, tmp
, scr
->root_win
, scr
->copy_gc
,
269 ax
[i
]*ICON_KABOOM_PIECE_SIZE
, ay
[i
]*ICON_KABOOM_PIECE_SIZE
,
270 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
278 play(dpy
, 100+rand()%250, 12);
280 # if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
281 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
*2);
286 XFreePixmap(dpy
, tmp
);
288 #endif /* NORMAL_ICON_KABOOM */
292 MakeGhostDock(WDock
*dock
, int sx
, int dx
, int y
)
294 WScreen
*scr
= dock
->screen_ptr
;
296 RImage
*back
, *dock_image
;
298 int i
, virtual_tiles
, h
, j
, n
;
299 unsigned long red_mask
, green_mask
, blue_mask
;
302 for (i
=0; i
<dock
->max_icons
; i
++) {
303 if (dock
->icon_array
[i
]!=NULL
&&
304 dock
->icon_array
[i
]->yindex
> virtual_tiles
)
305 virtual_tiles
= dock
->icon_array
[i
]->yindex
;
308 h
= virtual_tiles
* wPreferences
.icon_size
;
309 h
= (y
+ h
> scr
->scr_height
) ? scr
->scr_height
-y
: h
;
310 virtual_tiles
= h
/ wPreferences
.icon_size
; /* The visible ones */
311 if (h
% wPreferences
.icon_size
)
312 virtual_tiles
++; /* There is one partially visible tile at end */
314 img
=XGetImage(dpy
, scr
->root_win
, dx
, y
, wPreferences
.icon_size
, h
,
319 red_mask
= img
->red_mask
;
320 green_mask
= img
->green_mask
;
321 blue_mask
= img
->blue_mask
;
323 back
= RCreateImageFromXImage(scr
->rcontext
, img
, NULL
);
329 for (i
=0;i
<dock
->max_icons
;i
++) {
330 if (dock
->icon_array
[i
]!=NULL
&&
331 dock
->icon_array
[i
]->yindex
< virtual_tiles
) {
333 j
= dock
->icon_array
[i
]->yindex
* wPreferences
.icon_size
;
334 n
= (h
- j
< wPreferences
.icon_size
) ? h
- j
:
335 wPreferences
.icon_size
;
336 if (dock
->icon_array
[i
]->icon
->pixmap
)
337 which
= dock
->icon_array
[i
]->icon
->pixmap
;
339 which
= dock
->icon_array
[i
]->icon
->core
->window
;
341 img
=XGetImage(dpy
, which
, 0, 0, wPreferences
.icon_size
, n
,
348 img
->red_mask
= red_mask
;
349 img
->green_mask
= green_mask
;
350 img
->blue_mask
= blue_mask
;
352 dock_image
= RCreateImageFromXImage(scr
->rcontext
, img
, NULL
);
358 RCombineAreaWithOpaqueness(back
, dock_image
, 0, 0,
359 wPreferences
.icon_size
, n
,
360 0, j
, 30 * 256 / 100);
361 RDestroyImage(dock_image
);
366 RConvertImage(scr
->rcontext
, back
, &pixmap
);
375 MakeGhostIcon(WScreen
*scr
, Drawable drawable
)
385 back
= RCreateImageFromDrawable(scr
->rcontext
, drawable
, None
);
394 RClearImage(back
, &color
);
395 RConvertImage(scr
->rcontext
, back
, &pixmap
);
404 #ifdef WINDOW_BIRTH_ZOOM
406 DoWindowBirth(WWindow
*wwin
)
408 int width
= wwin
->frame
->core
->width
;
409 int height
= wwin
->frame
->core
->height
;
410 int w
= WMIN(width
, 20);
411 int h
= WMIN(height
, 20);
415 time_t time0
= time(NULL
);
417 dw
= (width
-w
)/WINDOW_BIRTH_STEPS
;
418 dh
= (height
-h
)/WINDOW_BIRTH_STEPS
;
420 x
= wwin
->frame_x
+ (width
-w
)/2;
421 y
= wwin
->frame_y
+ (height
-h
)/2;
423 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
, x
, y
, w
, h
);
425 XMapWindow(dpy
, wwin
->frame
->core
->window
);
428 for (i
=0; i
<WINDOW_BIRTH_STEPS
; i
++) {
433 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
, x
, y
, w
, h
);
436 if (time(NULL
)-time0
> MAX_ANIMATION_TIME
)
440 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
,
441 wwin
->frame_x
, wwin
->frame_y
, width
, height
);
446 DoWindowBirth(WWindow
*wwin
)
455 static WMPixmap
*data
[12];
459 loadData(WScreen
*scr
)
466 f
= fopen(PKGDATADIR
"/xtree.dat", "r");
470 image
= RCreateImage(50, 50, False
);
476 for (i
= 0; i
< 12; i
++) {
477 if (fread(image
->data
[0], 50*50, 1, f
)!=1) {
480 if (fread(image
->data
[1], 50*50, 1, f
)!=1) {
483 if (fread(image
->data
[2], 50*50, 1, f
)!=1) {
486 if (!RConvertImage(scr
->rcontext
, image
, &(d
[i
]))) {
490 RDestroyImage(image
);
494 for (i
=0; i
<12; i
++) {
495 data
[i
] = WMCreatePixmapFromXPixmaps(scr
->wmscreen
, d
[i
], None
, 50, 50,
502 RDestroyImage(image
);
507 XFreePixmap(dpy
, d
[i
]);
515 DoXThing(WWindow
*wwin
)
517 static int order
= 0;
521 return data
[order
% 12];
526 InitXThing(WScreen
*scr
)
537 if ((l
->tm_mon
!=12||l
->tm_mday
<24||l
->tm_mday
>26)) {
549 #endif /* SILLYNESS */
552 #ifdef GHOST_WINDOW_MOVE
554 InitGhostWindowMove(WScreen
*scr
)
559 ximg
= RGetXImage(scr
->rcontext
, scr
->root_win
, 0, 0,
560 scr
->scr_width
, scr
->scr_height
);
561 img
= RCreateImageFromXImage(scr
->rcontext
, ximg
->image
, NULL
);
562 RDestroyXImage(dpy
, ximg
);
567 #endif /* GHOST_WINDOW_MOVE */