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 #endif /* DEMATERIALIZE_ICON */
149 #ifdef NORMAL_ICON_KABOOM
151 DoKaboom(WScreen
*scr
, Window win
, int x
, int y
)
154 int sw
=scr
->scr_width
, sh
=scr
->scr_height
;
155 #define KAB_PRECISION 4
158 #ifdef ICON_KABOOM_EXTRA
159 short ptx
[2][PIECES
], pty
[2][PIECES
];
162 char pvx
[PIECES
], pvy
[PIECES
];
163 /* in MkLinux/PPC gcc seems to think that char is unsigned? */
164 signed char ax
[PIECES
], ay
[PIECES
];
167 XSetClipMask(dpy
, scr
->copy_gc
, None
);
168 tmp
= XCreatePixmap(dpy
, scr
->root_win
, wPreferences
.icon_size
,
169 wPreferences
.icon_size
, scr
->depth
);
170 if (scr
->w_visual
== DefaultVisual(dpy
, scr
->screen
))
171 XCopyArea(dpy
, win
, tmp
, scr
->copy_gc
, 0, 0, wPreferences
.icon_size
,
172 wPreferences
.icon_size
, 0, 0);
176 image
= XGetImage(dpy
, win
, 0, 0, wPreferences
.icon_size
,
177 wPreferences
.icon_size
, AllPlanes
, ZPixmap
);
179 XUnmapWindow(dpy
, win
);
182 XPutImage(dpy
, tmp
, scr
->copy_gc
, image
, 0, 0, 0, 0,
183 wPreferences
.icon_size
, wPreferences
.icon_size
);
184 XDestroyImage(image
);
187 for (i
=0,k
=0; i
<wPreferences
.icon_size
/ICON_KABOOM_PIECE_SIZE
&& k
<PIECES
;
189 for (j
=0; j
<wPreferences
.icon_size
/ICON_KABOOM_PIECE_SIZE
&& k
<PIECES
;
194 px
[k
]=(x
+i
*ICON_KABOOM_PIECE_SIZE
)<<KAB_PRECISION
;
195 py
[k
]=y
+j
*ICON_KABOOM_PIECE_SIZE
;
196 pvx
[k
]=rand()%(1<<(KAB_PRECISION
+3))-(1<<(KAB_PRECISION
+3))/2;
198 #ifdef ICON_KABOOM_EXTRA
199 for (ll
=0; ll
<2; ll
++) {
211 XUnmapWindow(dpy
, win
);
217 if (XCheckTypedEvent(dpy
, ButtonPress
, &foo
)) {
218 XPutBackEvent(dpy
, &foo
);
219 XClearWindow(dpy
, scr
->root_win
);
223 for (i
=0; i
<j
; i
++) {
225 int _px
= px
[i
]>>KAB_PRECISION
;
226 #ifdef ICON_KABOOM_EXTRA
227 XClearArea(dpy
, scr
->root_win
, ptx
[1][i
], pty
[1][i
],
228 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
231 ptx
[1][i
] = ptx
[0][i
];
232 pty
[1][i
] = pty
[0][i
];
236 XClearArea(dpy
, scr
->root_win
, _px
, py
[i
],
237 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
242 _px
= px
[i
]>>KAB_PRECISION
;
244 if (_px
<-wPreferences
.icon_size
|| _px
>sw
|| py
[i
]>=sh
) {
245 #ifdef ICON_KABOOM_EXTRA
246 if (py
[i
]>sh
&& _px
<sw
&& _px
>0) {
247 pvy
[i
] = -(pvy
[i
]/2);
248 if (abs(pvy
[i
]) > 3) {
249 py
[i
] = sh
-ICON_KABOOM_PIECE_SIZE
;
250 XCopyArea(dpy
, tmp
, scr
->root_win
, scr
->copy_gc
,
251 ax
[i
]*ICON_KABOOM_PIECE_SIZE
,
252 ay
[i
]*ICON_KABOOM_PIECE_SIZE
,
253 ICON_KABOOM_PIECE_SIZE
,
254 ICON_KABOOM_PIECE_SIZE
,
263 for (ll
=0; ll
<2; ll
++)
264 XClearArea(dpy
, scr
->root_win
, ptx
[ll
][i
], pty
[ll
][i
],
265 ICON_KABOOM_PIECE_SIZE
,
266 ICON_KABOOM_PIECE_SIZE
, False
);
269 #else /* !ICON_KABOOM_EXTRA */
272 #endif /* !ICON_KABOOM_EXTRA */
274 XCopyArea(dpy
, tmp
, scr
->root_win
, scr
->copy_gc
,
275 ax
[i
]*ICON_KABOOM_PIECE_SIZE
, ay
[i
]*ICON_KABOOM_PIECE_SIZE
,
276 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
284 play(dpy
, 100+rand()%250, 12);
286 # if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
287 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
*2);
292 XFreePixmap(dpy
, tmp
);
294 #endif /* NORMAL_ICON_KABOOM */
298 MakeGhostDock(WDock
*dock
, int sx
, int dx
, int y
)
300 WScreen
*scr
= dock
->screen_ptr
;
302 RImage
*back
, *dock_image
;
304 int i
, virtual_tiles
, h
, j
, n
;
305 unsigned long red_mask
, green_mask
, blue_mask
;
308 for (i
=0; i
<dock
->max_icons
; i
++) {
309 if (dock
->icon_array
[i
]!=NULL
&&
310 dock
->icon_array
[i
]->yindex
> virtual_tiles
)
311 virtual_tiles
= dock
->icon_array
[i
]->yindex
;
314 h
= virtual_tiles
* wPreferences
.icon_size
;
315 h
= (y
+ h
> scr
->scr_height
) ? scr
->scr_height
-y
: h
;
316 virtual_tiles
= h
/ wPreferences
.icon_size
; /* The visible ones */
317 if (h
% wPreferences
.icon_size
)
318 virtual_tiles
++; /* There is one partially visible tile at end */
320 img
=XGetImage(dpy
, scr
->root_win
, dx
, y
, wPreferences
.icon_size
, h
,
325 red_mask
= img
->red_mask
;
326 green_mask
= img
->green_mask
;
327 blue_mask
= img
->blue_mask
;
329 back
= RCreateImageFromXImage(scr
->rcontext
, img
, NULL
);
335 for (i
=0;i
<dock
->max_icons
;i
++) {
336 if (dock
->icon_array
[i
]!=NULL
&&
337 dock
->icon_array
[i
]->yindex
< virtual_tiles
) {
339 j
= dock
->icon_array
[i
]->yindex
* wPreferences
.icon_size
;
340 n
= (h
- j
< wPreferences
.icon_size
) ? h
- j
:
341 wPreferences
.icon_size
;
342 if (dock
->icon_array
[i
]->icon
->pixmap
)
343 which
= dock
->icon_array
[i
]->icon
->pixmap
;
345 which
= dock
->icon_array
[i
]->icon
->core
->window
;
347 img
=XGetImage(dpy
, which
, 0, 0, wPreferences
.icon_size
, n
,
354 img
->red_mask
= red_mask
;
355 img
->green_mask
= green_mask
;
356 img
->blue_mask
= blue_mask
;
358 dock_image
= RCreateImageFromXImage(scr
->rcontext
, img
, NULL
);
364 RCombineAreaWithOpaqueness(back
, dock_image
, 0, 0,
365 wPreferences
.icon_size
, n
,
366 0, j
, 30 * 256 / 100);
367 RDestroyImage(dock_image
);
372 RConvertImage(scr
->rcontext
, back
, &pixmap
);
381 MakeGhostIcon(WScreen
*scr
, Drawable drawable
)
391 back
= RCreateImageFromDrawable(scr
->rcontext
, drawable
, None
);
400 RClearImage(back
, &color
);
401 RConvertImage(scr
->rcontext
, back
, &pixmap
);
410 #ifdef WINDOW_BIRTH_ZOOM
412 DoWindowBirth(WWindow
*wwin
)
414 int width
= wwin
->frame
->core
->width
;
415 int height
= wwin
->frame
->core
->height
;
416 int w
= WMIN(width
, 20);
417 int h
= WMIN(height
, 20);
421 time_t time0
= time(NULL
);
423 dw
= (width
-w
)/WINDOW_BIRTH_STEPS
;
424 dh
= (height
-h
)/WINDOW_BIRTH_STEPS
;
426 x
= wwin
->frame_x
+ (width
-w
)/2;
427 y
= wwin
->frame_y
+ (height
-h
)/2;
429 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
, x
, y
, w
, h
);
431 XMapWindow(dpy
, wwin
->frame
->core
->window
);
434 for (i
=0; i
<WINDOW_BIRTH_STEPS
; i
++) {
439 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
, x
, y
, w
, h
);
442 if (time(NULL
)-time0
> MAX_ANIMATION_TIME
)
446 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
,
447 wwin
->frame_x
, wwin
->frame_y
, width
, height
);
452 DoWindowBirth(WWindow
*wwin
)
461 static WMPixmap
*data
[12];
465 loadData(WScreen
*scr
)
472 f
= fopen(PKGDATADIR
"/xtree.dat", "r");
476 image
= RCreateImage(50, 50, False
);
482 for (i
= 0; i
< 12; i
++) {
483 if (fread(image
->data
[0], 50*50, 1, f
)!=1) {
486 if (fread(image
->data
[1], 50*50, 1, f
)!=1) {
489 if (fread(image
->data
[2], 50*50, 1, f
)!=1) {
492 if (!RConvertImage(scr
->rcontext
, image
, &(d
[i
]))) {
496 RDestroyImage(image
);
500 for (i
=0; i
<12; i
++) {
501 data
[i
] = WMCreatePixmapFromXPixmaps(scr
->wmscreen
, d
[i
], None
, 50, 50,
508 RDestroyImage(image
);
513 XFreePixmap(dpy
, d
[i
]);
521 DoXThing(WWindow
*wwin
)
523 static int order
= 0;
527 return data
[order
% 12];
532 InitXThing(WScreen
*scr
)
543 if ((l
->tm_mon
!=12||l
->tm_mday
<24||l
->tm_mday
>26)) {
555 #endif /* SILLYNESS */
558 #ifdef GHOST_WINDOW_MOVE
560 InitGhostWindowMove(WScreen
*scr
)
565 ximg
= RGetXImage(scr
->rcontext
, scr
->root_win
, 0, 0,
566 scr
->scr_width
, scr
->scr_height
);
567 img
= RCreateImageFromXImage(scr
->rcontext
, ximg
->image
, NULL
);
568 RDestroyXImage(dpy
, ximg
);
573 #endif /* GHOST_WINDOW_MOVE */