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
)
83 h
= w
= wPreferences
.icon_size
;
84 if (x
< 0 || x
+ w
> scr
->scr_width
|| y
< 0 || y
+ h
> scr
->scr_height
)
87 icon
= RCreateImageFromDrawable(scr
->rcontext
, win
, None
);
91 gcv
.foreground
= scr
->white_pixel
;
92 gcv
.background
= scr
->black_pixel
;
93 gcv
.graphics_exposures
= False
;
94 gcv
.subwindow_mode
= IncludeInferiors
;
95 gc
= XCreateGC(dpy
, scr
->w_win
, GCForeground
|GCBackground
|GCSubwindowMode
96 |GCGraphicsExposures
, &gcv
);
100 RConvertImage(scr
->rcontext
, icon
, &pixmap
);
101 XUnmapWindow(dpy
, win
);
103 ximage
= XGetImage(dpy
, scr
->root_win
, x
, y
, w
, h
, AllPlanes
, ZPixmap
);
104 XCopyArea(dpy
, pixmap
, scr
->root_win
, gc
, 0, 0, w
, h
, x
, y
);
105 XFreePixmap(dpy
,pixmap
);
107 back
= RCreateImageFromXImage(scr
->rcontext
, ximage
, NULL
);
108 XDestroyImage(ximage
);
115 for (i
=0,run
=0; i
<DEMATERIALIZE_STEPS
; i
++) {
117 if (!run
&& XCheckTypedEvent(dpy
, ButtonPress
, &foo
)) {
119 XPutBackEvent(dpy
, &foo
);
121 image
= RCloneImage(back
);
122 RCombineImagesWithOpaqueness(image
, icon
,
123 (DEMATERIALIZE_STEPS
-1-i
)*256/(DEMATERIALIZE_STEPS
+2));
124 RConvertImage(scr
->rcontext
, image
, &pixmap
);
125 XCopyArea(dpy
, pixmap
, scr
->root_win
, gc
, 0, 0, w
, h
, x
, y
);
126 XFreePixmap(dpy
, pixmap
);
128 if(!run
) wusleep(1000);
131 while (XCheckTypedEvent(dpy
, MotionNotify
, &event
)) {
133 XPutBackEvent(dpy
, &event
);
141 #endif /* DEMATERIALIZE_ICON */
148 #ifdef NORMAL_ICON_KABOOM
150 DoKaboom(WScreen
*scr
, Window win
, int x
, int y
)
153 int sw
=scr
->scr_width
, sh
=scr
->scr_height
;
154 #define KAB_PRECISION 4
157 #ifdef ICON_KABOOM_EXTRA
158 short ptx
[2][PIECES
], pty
[2][PIECES
];
161 char pvx
[PIECES
], pvy
[PIECES
];
162 /* in MkLinux/PPC gcc seems to think that char is unsigned? */
163 signed char ax
[PIECES
], ay
[PIECES
];
166 XSetClipMask(dpy
, scr
->copy_gc
, None
);
167 tmp
= XCreatePixmap(dpy
, scr
->root_win
, wPreferences
.icon_size
,
168 wPreferences
.icon_size
, scr
->depth
);
169 if (scr
->w_visual
== DefaultVisual(dpy
, scr
->screen
))
170 XCopyArea(dpy
, win
, tmp
, scr
->copy_gc
, 0, 0, wPreferences
.icon_size
,
171 wPreferences
.icon_size
, 0, 0);
175 image
= XGetImage(dpy
, win
, 0, 0, wPreferences
.icon_size
,
176 wPreferences
.icon_size
, AllPlanes
, ZPixmap
);
178 XUnmapWindow(dpy
, win
);
181 XPutImage(dpy
, tmp
, scr
->copy_gc
, image
, 0, 0, 0, 0,
182 wPreferences
.icon_size
, wPreferences
.icon_size
);
183 XDestroyImage(image
);
186 for (i
=0,k
=0; i
<wPreferences
.icon_size
/ICON_KABOOM_PIECE_SIZE
&& k
<PIECES
;
188 for (j
=0; j
<wPreferences
.icon_size
/ICON_KABOOM_PIECE_SIZE
&& k
<PIECES
;
193 px
[k
]=(x
+i
*ICON_KABOOM_PIECE_SIZE
)<<KAB_PRECISION
;
194 py
[k
]=y
+j
*ICON_KABOOM_PIECE_SIZE
;
195 pvx
[k
]=rand()%(1<<(KAB_PRECISION
+3))-(1<<(KAB_PRECISION
+3))/2;
197 #ifdef ICON_KABOOM_EXTRA
198 for (ll
=0; ll
<2; ll
++) {
210 XUnmapWindow(dpy
, win
);
216 if (XCheckTypedEvent(dpy
, ButtonPress
, &foo
)) {
217 XPutBackEvent(dpy
, &foo
);
218 XClearWindow(dpy
, scr
->root_win
);
222 for (i
=0; i
<j
; i
++) {
224 int _px
= px
[i
]>>KAB_PRECISION
;
225 #ifdef ICON_KABOOM_EXTRA
226 XClearArea(dpy
, scr
->root_win
, ptx
[1][i
], pty
[1][i
],
227 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
230 ptx
[1][i
] = ptx
[0][i
];
231 pty
[1][i
] = pty
[0][i
];
235 XClearArea(dpy
, scr
->root_win
, _px
, py
[i
],
236 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
241 _px
= px
[i
]>>KAB_PRECISION
;
243 if (_px
<-wPreferences
.icon_size
|| _px
>sw
|| py
[i
]>=sh
) {
244 #ifdef ICON_KABOOM_EXTRA
245 if (py
[i
]>sh
&& _px
<sw
&& _px
>0) {
246 pvy
[i
] = -(pvy
[i
]/2);
247 if (abs(pvy
[i
]) > 3) {
248 py
[i
] = sh
-ICON_KABOOM_PIECE_SIZE
;
249 XCopyArea(dpy
, tmp
, scr
->root_win
, scr
->copy_gc
,
250 ax
[i
]*ICON_KABOOM_PIECE_SIZE
,
251 ay
[i
]*ICON_KABOOM_PIECE_SIZE
,
252 ICON_KABOOM_PIECE_SIZE
,
253 ICON_KABOOM_PIECE_SIZE
,
262 for (ll
=0; ll
<2; ll
++)
263 XClearArea(dpy
, scr
->root_win
, ptx
[ll
][i
], pty
[ll
][i
],
264 ICON_KABOOM_PIECE_SIZE
,
265 ICON_KABOOM_PIECE_SIZE
, False
);
268 #else /* !ICON_KABOOM_EXTRA */
271 #endif /* !ICON_KABOOM_EXTRA */
273 XCopyArea(dpy
, tmp
, scr
->root_win
, scr
->copy_gc
,
274 ax
[i
]*ICON_KABOOM_PIECE_SIZE
, ay
[i
]*ICON_KABOOM_PIECE_SIZE
,
275 ICON_KABOOM_PIECE_SIZE
, ICON_KABOOM_PIECE_SIZE
,
283 play(dpy
, 100+rand()%250, 12);
285 # if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
286 wusleep(MINIATURIZE_ANIMATION_DELAY_Z
*2);
291 XFreePixmap(dpy
, tmp
);
293 #endif /* NORMAL_ICON_KABOOM */
297 MakeGhostDock(WDock
*dock
, int sx
, int dx
, int y
)
299 WScreen
*scr
= dock
->screen_ptr
;
301 RImage
*back
, *dock_image
;
303 int i
, virtual_tiles
, h
, j
, n
;
304 unsigned long red_mask
, green_mask
, blue_mask
;
307 for (i
=0; i
<dock
->max_icons
; i
++) {
308 if (dock
->icon_array
[i
]!=NULL
&&
309 dock
->icon_array
[i
]->yindex
> virtual_tiles
)
310 virtual_tiles
= dock
->icon_array
[i
]->yindex
;
313 h
= virtual_tiles
* wPreferences
.icon_size
;
314 h
= (y
+ h
> scr
->scr_height
) ? scr
->scr_height
-y
: h
;
315 virtual_tiles
= h
/ wPreferences
.icon_size
; /* The visible ones */
316 if (h
% wPreferences
.icon_size
)
317 virtual_tiles
++; /* There is one partially visible tile at end */
319 img
=XGetImage(dpy
, scr
->root_win
, dx
, y
, wPreferences
.icon_size
, h
,
324 red_mask
= img
->red_mask
;
325 green_mask
= img
->green_mask
;
326 blue_mask
= img
->blue_mask
;
328 back
= RCreateImageFromXImage(scr
->rcontext
, img
, NULL
);
334 for (i
=0;i
<dock
->max_icons
;i
++) {
335 if (dock
->icon_array
[i
]!=NULL
&&
336 dock
->icon_array
[i
]->yindex
< virtual_tiles
) {
338 j
= dock
->icon_array
[i
]->yindex
* wPreferences
.icon_size
;
339 n
= (h
- j
< wPreferences
.icon_size
) ? h
- j
:
340 wPreferences
.icon_size
;
341 if (dock
->icon_array
[i
]->icon
->pixmap
)
342 which
= dock
->icon_array
[i
]->icon
->pixmap
;
344 which
= dock
->icon_array
[i
]->icon
->core
->window
;
346 img
=XGetImage(dpy
, which
, 0, 0, wPreferences
.icon_size
, n
,
353 img
->red_mask
= red_mask
;
354 img
->green_mask
= green_mask
;
355 img
->blue_mask
= blue_mask
;
357 dock_image
= RCreateImageFromXImage(scr
->rcontext
, img
, NULL
);
363 RCombineAreaWithOpaqueness(back
, dock_image
, 0, 0,
364 wPreferences
.icon_size
, n
,
365 0, j
, 30 * 256 / 100);
366 RDestroyImage(dock_image
);
371 RConvertImage(scr
->rcontext
, back
, &pixmap
);
380 MakeGhostIcon(WScreen
*scr
, Drawable drawable
)
390 back
= RCreateImageFromDrawable(scr
->rcontext
, drawable
, None
);
399 RClearImage(back
, &color
);
400 RConvertImage(scr
->rcontext
, back
, &pixmap
);
409 #ifdef WINDOW_BIRTH_ZOOM
411 DoWindowBirth(WWindow
*wwin
)
413 int width
= wwin
->frame
->core
->width
;
414 int height
= wwin
->frame
->core
->height
;
415 int w
= WMIN(width
, 20);
416 int h
= WMIN(height
, 20);
420 time_t time0
= time(NULL
);
422 dw
= (width
-w
)/WINDOW_BIRTH_STEPS
;
423 dh
= (height
-h
)/WINDOW_BIRTH_STEPS
;
425 x
= wwin
->frame_x
+ (width
-w
)/2;
426 y
= wwin
->frame_y
+ (height
-h
)/2;
428 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
, x
, y
, w
, h
);
430 XMapWindow(dpy
, wwin
->frame
->core
->window
);
433 for (i
=0; i
<WINDOW_BIRTH_STEPS
; i
++) {
438 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
, x
, y
, w
, h
);
441 if (time(NULL
)-time0
> MAX_ANIMATION_TIME
)
445 XMoveResizeWindow(dpy
, wwin
->frame
->core
->window
,
446 wwin
->frame_x
, wwin
->frame_y
, width
, height
);
451 DoWindowBirth(WWindow
*wwin
)
460 static WMPixmap
*data
[12];
464 loadData(WScreen
*scr
)
471 f
= fopen(PKGDATADIR
"/xtree.dat", "r");
475 image
= RCreateImage(50, 50, False
);
481 for (i
= 0; i
< 12; i
++) {
482 if (fread(image
->data
[0], 50*50, 1, f
)!=1) {
485 if (fread(image
->data
[1], 50*50, 1, f
)!=1) {
488 if (fread(image
->data
[2], 50*50, 1, f
)!=1) {
491 if (!RConvertImage(scr
->rcontext
, image
, &(d
[i
]))) {
495 RDestroyImage(image
);
499 for (i
=0; i
<12; i
++) {
500 data
[i
] = WMCreatePixmapFromXPixmaps(scr
->wmscreen
, d
[i
], None
, 50, 50,
507 RDestroyImage(image
);
512 XFreePixmap(dpy
, d
[i
]);
520 DoXThing(WWindow
*wwin
)
522 static int order
= 0;
526 return data
[order
% 12];
531 InitXThing(WScreen
*scr
)
542 if ((l
->tm_mon
!=12||l
->tm_mday
<24||l
->tm_mday
>26)) {
554 #endif /* SILLYNESS */
557 #ifdef GHOST_WINDOW_MOVE
559 InitGhostWindowMove(WScreen
*scr
)
564 ximg
= RGetXImage(scr
->rcontext
, scr
->root_win
, 0, 0,
565 scr
->scr_width
, scr
->scr_height
);
566 img
= RCreateImageFromXImage(scr
->rcontext
, ximg
->image
, NULL
);
567 RDestroyXImage(dpy
, ximg
);
572 #endif /* GHOST_WINDOW_MOVE */