Updating to version 0.20.2
[wmaker-crm.git] / src / actions.c
blob6caa2db53fb8ca2716d9a984e1b0a0378e9b75a5
1 /* action.c- misc. window commands (miniaturize, hide etc.)
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
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,
20 * USA.
22 #include "wconfig.h"
24 #include <X11/Xlib.h>
25 #include <X11/Xutil.h>
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <unistd.h>
29 #include <math.h>
30 #include <time.h>
32 #include "WindowMaker.h"
33 #include "wcore.h"
34 #include "framewin.h"
35 #include "window.h"
36 #include "client.h"
37 #include "icon.h"
38 #include "funcs.h"
39 #include "application.h"
40 #include "actions.h"
41 #include "stacking.h"
42 #include "appicon.h"
43 #include "dock.h"
44 #include "appmenu.h"
45 #include "winspector.h"
47 #ifdef WMSOUND
48 #include "wmsound.h"
49 #endif
52 /****** Global Variables ******/
53 extern Time LastTimestamp;
54 extern Time LastFocusChange;
56 extern Cursor wCursor[WCUR_LAST];
58 extern WPreferences wPreferences;
60 extern Atom _XA_WM_TAKE_FOCUS;
62 /******* Local Variables *******/
63 static struct {
64 int steps;
65 int delay;
66 } shadePars[5] = {
67 {SHADE_STEPS_UF, SHADE_DELAY_UF},
68 {SHADE_STEPS_F, SHADE_DELAY_F},
69 {SHADE_STEPS_M, SHADE_DELAY_M},
70 {SHADE_STEPS_S, SHADE_DELAY_S},
71 {SHADE_STEPS_U, SHADE_DELAY_U}};
73 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
74 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
77 static int ignoreTimestamp=0;
80 #ifdef ANIMATIONS
81 static void
82 processEvents(int event_count)
84 XEvent event;
87 * This is a hack. When animations are enabled, processing of
88 * events ocurred during a animation are delayed until it's end.
89 * Calls that consider the TimeStamp, like XSetInputFocus(), will
90 * fail because the TimeStamp is too old. Then, for example, if
91 * the user changes window focus while a miniaturize animation is
92 * in course, the window will not get focus properly after the end
93 * of the animation. This tries to workaround it by passing CurrentTime
94 * as the TimeStamp for XSetInputFocus() for all events ocurred during
95 * the animation.
97 ignoreTimestamp=1;
98 while (event_count--) {
99 WMNextEvent(dpy, &event);
100 WMHandleEvent(&event);
102 ignoreTimestamp=0;
104 #endif /* ANIMATIONS */
108 *----------------------------------------------------------------------
109 * wSetFocusTo--
110 * Changes the window focus to the one passed as argument.
111 * If the window to focus is not already focused, it will be brought
112 * to the head of the list of windows. Previously focused window is
113 * unfocused.
115 * Side effects:
116 * Window list may be reordered and the window focus is changed.
118 *----------------------------------------------------------------------
120 void
121 wSetFocusTo(WScreen *scr, WWindow *wwin)
123 WWindow *focused=scr->focused_window;
124 WWindow *owner = NULL;
125 int timestamp=LastTimestamp;
126 WApplication *oapp=NULL, *napp=NULL;
127 int wasfocused;
129 LastFocusChange = timestamp;
131 if (ignoreTimestamp)
132 timestamp=CurrentTime;
134 if (focused)
135 oapp = wApplicationOf(focused->main_window);
137 if (wwin==NULL) {
138 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
139 if (focused) {
140 wWindowUnfocus(focused);
142 if (oapp) {
143 wAppMenuUnmap(oapp->menu);
144 #ifdef NEWAPPICON
145 wApplicationDeactivate(oapp);
146 #endif
148 return;
150 wasfocused = wwin->flags.focused;
151 napp = wApplicationOf(wwin->main_window);
153 /* remember last workspace where the app has been */
154 if (napp)
155 napp->last_workspace = wwin->screen_ptr->current_workspace;
157 if (wwin->window_flags.no_focusable)
158 return;
160 if (wwin->flags.mapped) {
161 /* install colormap if colormap mode is lock mode */
162 if (wPreferences.colormap_mode==WKF_CLICK)
163 wColormapInstallForWindow(scr, wwin);
165 /* set input focus */
166 switch (wwin->focus_mode) {
167 case WFM_NO_INPUT:
168 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
169 break;
171 case WFM_PASSIVE:
172 case WFM_LOCALLY_ACTIVE:
173 XSetInputFocus(dpy, wwin->client_win, RevertToParent, timestamp);
174 break;
176 case WFM_GLOBALLY_ACTIVE:
177 break;
179 XFlush(dpy);
180 if (wwin->protocols.TAKE_FOCUS) {
181 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
183 XSync(dpy, False);
184 } else {
185 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
188 /* if this is not the focused window focus it */
189 if (focused!=wwin) {
190 int foo=0;
192 if (wwin->client_win == focused->transient_for)
193 wwin->flags.semi_focused = 0;
194 else if (wwin->transient_for == focused->client_win)
195 focused->flags.semi_focused = 1;
197 if (wwin->transient_for
198 && wwin->transient_for == focused->transient_for) {
199 owner = wWindowFor(wwin->transient_for);
200 if (owner && owner->flags.semi_focused) {
201 foo=1;
202 /* this is to override the unfocusing of the mainwindow
203 * in the next wWindowUnfocus() and avoid flickering */
204 owner->flags.semi_focused = 0;
207 /* unfocus previous window */
208 wWindowUnfocus(focused);
209 if (foo) {
210 owner->flags.semi_focused = 1;
212 /* change the focus window list order */
213 if (wwin->prev)
214 wwin->prev->next=wwin->next;
215 if (wwin->next)
216 wwin->next->prev=wwin->prev;
218 wwin->prev = focused;
219 focused->next = wwin;
220 wwin->next = NULL;
221 scr->focused_window = wwin;
223 if (oapp && oapp != napp) {
224 wAppMenuUnmap(oapp->menu);
225 #ifdef NEWAPPICON
226 wApplicationDeactivate(oapp);
227 #endif
230 if ((owner=wWindowFor(wwin->transient_for))
231 && !owner->flags.semi_focused) {
232 owner->flags.semi_focused = 1;
233 wWindowUnfocus(owner);
235 wWindowFocus(wwin);
236 if (napp && !wasfocused) {
237 wAppMenuMap(napp->menu, wwin);
238 #ifdef NEWAPPICON
239 wApplicationActivate(napp);
240 #endif
242 XFlush(dpy);
246 void
247 wShadeWindow(WWindow *wwin)
249 XWindowAttributes attribs;
250 time_t time0 = time(NULL);
251 #ifdef ANIMATIONS
252 int y, s, w, h;
253 #endif
255 if (wwin->flags.shaded)
256 return;
258 XLowerWindow(dpy, wwin->client_win);
260 #ifdef WMSOUND
261 wSoundPlay(WMSOUND_SHADE);
262 #endif
264 #ifdef ANIMATIONS
265 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
266 && !wPreferences.no_animations) {
267 /* do the shading animation */
268 h = wwin->frame->core->height;
269 s = h/SHADE_STEPS;
270 if (s < 1) s=1;
271 w = wwin->frame->core->width;
272 y = wwin->frame->top_width;
273 while (h>wwin->frame->top_width+1) {
274 XMoveWindow(dpy, wwin->client_win, 0, y);
275 XResizeWindow(dpy, wwin->frame->core->window, w, h);
276 XSync(dpy, 0);
277 if (SHADE_DELAY > 0)
278 wusleep(SHADE_DELAY*1000L);
279 h-=s;
280 y-=s;
282 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
283 break;
285 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
287 #endif /* ANIMATIONS */
290 wwin->flags.skip_next_animation = 0;
291 XGetWindowAttributes(dpy, wwin->client_win, &attribs);
292 wwin->flags.shaded=1;
293 wwin->flags.mapped=0;
294 /* prevent window withdrawal when getting UnmapNotify */
295 XSelectInput(dpy, wwin->client_win,
296 attribs.your_event_mask & ~StructureNotifyMask);
297 XUnmapWindow(dpy, wwin->client_win);
298 XSelectInput(dpy, wwin->client_win, attribs.your_event_mask);
300 /* for the client it's just like iconification */
301 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
302 wwin->frame->top_width-1);
303 wClientSetState(wwin, IconicState, None);
305 /* update window list to reflect shaded state */
306 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
308 #ifdef ANIMATIONS
309 if (!wwin->screen_ptr->flags.startup) {
310 /* Look at processEvents() for reason of this code. */
311 XSync(dpy, 0);
312 processEvents(XPending(dpy));
314 #endif
318 void
319 wUnshadeWindow(WWindow *wwin)
321 time_t time0 = time(NULL);
322 #ifdef ANIMATIONS
323 int y, s, w, h;
324 #endif /* ANIMATIONS */
327 if (!wwin->flags.shaded)
328 return;
330 wwin->flags.shaded=0;
331 wwin->flags.mapped=1;
332 XMapWindow(dpy, wwin->client_win);
334 #ifdef WMSOUND
335 wSoundPlay(WMSOUND_UNSHADE);
336 #endif
338 #ifdef ANIMATIONS
339 if (!wPreferences.no_animations && !wwin->flags.skip_next_animation) {
340 /* do the shading animation */
341 h = wwin->frame->top_width + wwin->frame->bottom_width;
342 y = wwin->frame->top_width - wwin->client.height;
343 s = abs(y)/SHADE_STEPS;
344 if (s<1) s=1;
345 w = wwin->frame->core->width;
346 XMoveWindow(dpy, wwin->client_win, 0, y);
347 if (s>0) {
348 while (h < wwin->client.height + wwin->frame->top_width
349 + wwin->frame->bottom_width) {
350 XResizeWindow(dpy, wwin->frame->core->window, w, h);
351 XMoveWindow(dpy, wwin->client_win, 0, y);
352 XSync(dpy, 0);
353 if (SHADE_DELAY > 0)
354 wusleep(SHADE_DELAY*2000L/3);
355 h+=s;
356 y+=s;
358 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
359 break;
362 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
364 #endif /* ANIMATIONS */
367 wwin->flags.skip_next_animation = 0;
368 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
369 wwin->frame->top_width + wwin->client.height
370 + wwin->frame->bottom_width);
372 wClientSetState(wwin, NormalState, None);
373 /* if the window is focused, set the focus again as it was disabled during
374 * shading */
375 if (wwin->flags.focused)
376 wSetFocusTo(wwin->screen_ptr, wwin);
378 /* update window list to reflect unshaded state */
379 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
383 void
384 wMaximizeWindow(WWindow *wwin, int directions)
386 int new_width, new_height, new_x, new_y;
388 if (wwin->flags.shaded) {
389 wwin->flags.skip_next_animation = 1;
390 wUnshadeWindow(wwin);
392 wwin->flags.maximized = directions;
393 wwin->old_geometry.width = wwin->client.width;
394 wwin->old_geometry.height = wwin->client.height;
395 wwin->old_geometry.x = wwin->frame_x;
396 wwin->old_geometry.y = wwin->frame_y;
397 if (directions & MAX_HORIZONTAL) {
398 new_width = wwin->screen_ptr->scr_width-FRAME_BORDER_WIDTH*2;
400 new_x = 0;
401 if ((wPreferences.icon_yard & IY_VERT)
402 && wPreferences.no_window_over_icons) {
404 new_width -= wPreferences.icon_size;
405 if (!(wPreferences.icon_yard & IY_RIGHT))
406 new_x += wPreferences.icon_size;
408 #if 0
409 if (wPreferences.no_window_under_dock
410 && wwin->screen_ptr->dock) {
411 new_width -= wPreferences.icon_size + DOCK_EXTRA_SPACE;
412 if (!wwin->screen_ptr->dock->on_right_side)
413 new_x += wPreferences.icon_size + DOCK_EXTRA_SPACE;
415 #endif
416 if (wwin->screen_ptr->dock && !wwin->screen_ptr->dock->lowered) {
417 new_width -= wPreferences.icon_size + DOCK_EXTRA_SPACE;
418 if (!wwin->screen_ptr->dock->on_right_side)
419 new_x += wPreferences.icon_size + DOCK_EXTRA_SPACE;
421 } else {
422 new_x = wwin->frame_x;
423 new_width = wwin->frame->core->width;
426 if (directions & MAX_VERTICAL) {
427 new_height = wwin->screen_ptr->scr_height-FRAME_BORDER_WIDTH*2;
428 new_y = 0;
429 if (!(wPreferences.icon_yard & IY_VERT)
430 && wPreferences.no_window_over_icons) {
432 new_height -= wPreferences.icon_size;
434 if (wPreferences.icon_yard & IY_TOP)
435 new_y += wPreferences.icon_size;
437 } else {
438 new_y = wwin->frame_y;
439 new_height = wwin->frame->core->height;
441 new_height -= wwin->frame->top_width+wwin->frame->bottom_width;
443 wWindowConstrainSize(wwin, &new_width, &new_height);
444 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
446 #ifdef WMSOUND
447 wSoundPlay(WMSOUND_MAXIMIZE);
448 #endif
452 void
453 wUnmaximizeWindow(WWindow *wwin)
455 int restore_x, restore_y;
457 if (wwin->flags.shaded) {
458 wwin->flags.skip_next_animation = 1;
459 wUnshadeWindow(wwin);
461 restore_x = (wwin->flags.maximized & MAX_HORIZONTAL) ?
462 wwin->old_geometry.x : wwin->frame_x;
463 restore_y = (wwin->flags.maximized & MAX_VERTICAL) ?
464 wwin->old_geometry.y : wwin->frame_y;
465 wwin->flags.maximized = 0;
466 wWindowConfigure(wwin, restore_x, restore_y,
467 wwin->old_geometry.width, wwin->old_geometry.height);
469 #ifdef WMSOUND
470 wSoundPlay(WMSOUND_UNMAXIMIZE);
471 #endif
474 #ifdef ANIMATIONS
475 static void
476 animateResizeFlip(WScreen *scr, int x, int y, int w, int h,
477 int fx, int fy, int fw, int fh, int steps)
479 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
480 float cx, cy, cw, ch;
481 float xstep, ystep, wstep, hstep;
482 XPoint points[5];
483 float dx, dch, midy;
484 float angle, final_angle, delta;
486 xstep = (float)(fx-x)/steps;
487 ystep = (float)(fy-y)/steps;
488 wstep = (float)(fw-w)/steps;
489 hstep = (float)(fh-h)/steps;
491 cx = (float)x;
492 cy = (float)y;
493 cw = (float)w;
494 ch = (float)h;
496 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_F;
497 delta = (float)(final_angle/FRAMES);
498 for (angle=0;; angle+=delta) {
499 if (angle > final_angle)
500 angle = final_angle;
502 dx = (cw/10) - ((cw/5) * sin(angle));
503 dch = (ch/2) * cos(angle);
504 midy = cy + (ch/2);
506 points[0].x = cx + dx; points[0].y = midy - dch;
507 points[1].x = cx + cw - dx; points[1].y = points[0].y;
508 points[2].x = cx + cw + dx; points[2].y = midy + dch;
509 points[3].x = cx - dx; points[3].y = points[2].y;
510 points[4].x = points[0].x; points[4].y = points[0].y;
512 XGrabServer(dpy);
513 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
514 XFlush(dpy);
515 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
516 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
517 #endif
519 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
520 XUngrabServer(dpy);
521 cx+=xstep;
522 cy+=ystep;
523 cw+=wstep;
524 ch+=hstep;
525 if (angle >= final_angle)
526 break;
529 XFlush(dpy);
531 #undef FRAMES
534 static void
535 animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
536 int fx, int fy, int fw, int fh, int steps)
538 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
539 float cx, cy, cw, ch;
540 float xstep, ystep, wstep, hstep;
541 XPoint points[5];
542 float angle, final_angle, a, d, delta;
544 x += w/2;
545 y += h/2;
546 fx += fw/2;
547 fy += fh/2;
549 xstep = (float)(fx-x)/steps;
550 ystep = (float)(fy-y)/steps;
551 wstep = (float)(fw-w)/steps;
552 hstep = (float)(fh-h)/steps;
554 cx = (float)x;
555 cy = (float)y;
556 cw = (float)w;
557 ch = (float)h;
559 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
560 delta = (float)(final_angle/FRAMES);
561 for (angle=0;; angle+=delta) {
562 if (angle > final_angle)
563 angle = final_angle;
565 a = atan(ch/cw);
566 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
568 points[0].x = cx+cos(angle-a)*d;
569 points[0].y = cy+sin(angle-a)*d;
570 points[1].x = cx+cos(angle+a)*d;
571 points[1].y = cy+sin(angle+a)*d;
572 points[2].x = cx+cos(angle-a+WM_PI)*d;
573 points[2].y = cy+sin(angle-a+WM_PI)*d;
574 points[3].x = cx+cos(angle+a+WM_PI)*d;
575 points[3].y = cy+sin(angle+a+WM_PI)*d;
576 points[4].x = cx+cos(angle-a)*d;
577 points[4].y = cy+sin(angle-a)*d;
578 XGrabServer(dpy);
579 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
580 XFlush(dpy);
581 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
582 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
583 #endif
585 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
586 XUngrabServer(dpy);
587 cx+=xstep;
588 cy+=ystep;
589 cw+=wstep;
590 ch+=hstep;
591 if (angle >= final_angle)
592 break;
595 XFlush(dpy);
597 #undef FRAMES
600 static void
601 animateResizeZoom(WScreen *scr, int x, int y, int w, int h,
602 int fx, int fy, int fw, int fh, int steps)
604 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
605 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
606 float xstep, ystep, wstep, hstep;
607 int i, j;
609 xstep = (float)(fx-x)/steps;
610 ystep = (float)(fy-y)/steps;
611 wstep = (float)(fw-w)/steps;
612 hstep = (float)(fh-h)/steps;
614 for (j=0; j<FRAMES; j++) {
615 cx[j] = (float)x;
616 cy[j] = (float)y;
617 cw[j] = (float)w;
618 ch[j] = (float)h;
620 XGrabServer(dpy);
621 for (i=0; i<steps; i++) {
622 for (j=0; j<FRAMES; j++) {
623 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
624 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
626 XFlush(dpy);
627 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
628 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
629 #endif
630 for (j=0; j<FRAMES; j++) {
631 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
632 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
633 if (j<FRAMES-1) {
634 cx[j]=cx[j+1];
635 cy[j]=cy[j+1];
636 cw[j]=cw[j+1];
637 ch[j]=ch[j+1];
638 } else {
639 cx[j]+=xstep;
640 cy[j]+=ystep;
641 cw[j]+=wstep;
642 ch[j]+=hstep;
647 for (j=0; j<FRAMES; j++) {
648 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
649 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
651 XFlush(dpy);
652 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
653 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
654 #endif
655 for (j=0; j<FRAMES; j++) {
656 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
657 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
660 XUngrabServer(dpy);
662 #undef FRAMES
665 static void
666 animateResize(WScreen *scr, int x, int y, int w, int h,
667 int fx, int fy, int fw, int fh, int hiding)
669 int style = wPreferences.iconification_style; /* Catch the value */
670 int steps, k;
672 if (style == WIS_NONE)
673 return;
675 k = (hiding ? 2 : 3);
676 switch(style) {
677 case WIS_TWIST:
678 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
679 if (steps>0)
680 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
681 break;
682 case WIS_FLIP:
683 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
684 if (steps>0)
685 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
686 break;
687 case WIS_ZOOM:
688 default:
689 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
690 if (steps>0)
691 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
692 break;
695 #endif /* ANIMATIONS */
698 static void
699 flushExpose()
701 XEvent tmpev;
703 while (XCheckTypedEvent(dpy, Expose, &tmpev))
704 WMHandleEvent(&tmpev);
705 XSync(dpy, 0);
708 static void
709 unmapTransientsFor(WWindow *wwin)
711 WWindow *tmp;
712 XWindowAttributes attribs;
715 tmp = wwin->screen_ptr->focused_window;
716 while (tmp) {
717 /* unmap the transients for this transient */
718 if (tmp!=wwin && tmp->transient_for == wwin->client_win
719 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
720 || tmp->flags.shaded)) {
721 unmapTransientsFor(tmp);
722 XGetWindowAttributes(dpy, tmp->client_win, &attribs);
723 tmp->flags.miniaturized=1;
724 if (!tmp->flags.shaded) {
725 tmp->flags.mapped=0;
726 XSelectInput(dpy, tmp->client_win,
727 attribs.your_event_mask & ~StructureNotifyMask);
728 XUnmapWindow(dpy, tmp->client_win);
729 XSelectInput(dpy, tmp->client_win, attribs.your_event_mask);
731 XUnmapWindow(dpy, tmp->frame->core->window);
732 if (!tmp->flags.shaded)
733 wClientSetState(tmp, IconicState, None);
734 UpdateSwitchMenu(wwin->screen_ptr, tmp, ACTION_CHANGE_STATE);
736 tmp = tmp->prev;
741 static void
742 mapTransientsFor(WWindow *wwin)
744 WWindow *tmp;
746 tmp = wwin->screen_ptr->focused_window;
747 while (tmp) {
748 /* recursively map the transients for this transient */
749 if (tmp!=wwin && tmp->transient_for == wwin->client_win
750 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
751 && tmp->icon==NULL) {
752 mapTransientsFor(tmp);
753 tmp->flags.miniaturized=0;
754 if (!tmp->flags.shaded) {
755 tmp->flags.mapped=1;
756 XMapWindow(dpy, tmp->client_win);
758 XMapWindow(dpy, tmp->frame->core->window);
759 tmp->flags.semi_focused = 0;
760 if (!tmp->flags.shaded)
761 wClientSetState(tmp, NormalState, None);
762 UpdateSwitchMenu(wwin->screen_ptr, tmp, ACTION_CHANGE_STATE);
764 tmp = tmp->prev;
769 static void
770 setupIconGrabs(WIcon *icon)
772 /* setup passive grabs on the icon */
773 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
774 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
775 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
776 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
777 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
778 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
779 XSync(dpy, 0);
783 static WWindow*
784 recursiveTransientFor(WWindow *wwin)
786 int i;
788 if (!wwin)
789 return None;
791 /* hackish way to detect transient_for cycle */
792 i = wwin->screen_ptr->window_count+1;
794 while (wwin && wwin->transient_for != None && i>0) {
795 wwin = wWindowFor(wwin->transient_for);
796 i--;
798 if (i==0 && wwin) {
799 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
800 wwin->frame->title);
801 return NULL;
804 return wwin;
808 static void
809 removeIconGrabs(WIcon *icon)
811 /* remove passive grabs on the icon */
812 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
813 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
814 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
815 XSync(dpy, 0);
819 void
820 wIconifyWindow(WWindow *wwin)
822 XWindowAttributes attribs;
823 int present;
826 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
827 /* the window doesn't exist anymore */
828 return;
831 if (wwin->flags.miniaturized)
832 return;
834 if (wwin->transient_for!=None) {
835 WWindow *owner = wWindowFor(wwin->transient_for);
837 if (owner && owner->flags.miniaturized)
838 return;
841 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
843 /* if the window is in another workspace, simplify process */
844 if (present) {
845 /* icon creation may take a while */
846 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
847 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
848 GrabModeAsync, None, None, CurrentTime);
851 if (!wwin->flags.icon_moved) {
852 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y);
854 wwin->icon = wIconCreate(wwin);
856 wwin->flags.miniaturized=1;
857 wwin->flags.mapped=0;
859 /* unmap transients */
861 unmapTransientsFor(wwin);
863 if (present) {
864 #ifdef WMSOUND
865 wSoundPlay(WMSOUND_ICONIFY);
866 #endif
868 XUngrabPointer(dpy, CurrentTime);
869 /* prevent window withdrawal when getting UnmapNotify */
870 XSelectInput(dpy, wwin->client_win,
871 attribs.your_event_mask & ~StructureNotifyMask);
872 XUnmapWindow(dpy, wwin->client_win);
873 XSelectInput(dpy, wwin->client_win, attribs.your_event_mask);
874 XUnmapWindow(dpy, wwin->frame->core->window);
875 /* let all Expose events arrive so that we can repaint
876 * something before the animation starts (and the server is grabbed) */
877 XSync(dpy, 0);
878 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
879 flushExpose();
880 #ifdef ANIMATIONS
881 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
882 && !wPreferences.no_animations) {
883 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
884 wwin->frame->core->width, wwin->frame->core->height,
885 wwin->icon_x, wwin->icon_y,
886 wwin->icon->core->width, wwin->icon->core->height,
887 False);
889 #endif
892 wwin->flags.skip_next_animation = 0;
893 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
894 wwin->window_flags.omnipresent || wPreferences.sticky_icons)
895 XMapWindow(dpy, wwin->icon->core->window);
896 AddToStackList(wwin->icon->core);
897 #ifndef STRICTNS
898 wLowerFrame(wwin->icon->core);
899 #endif
901 if (present) {
902 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
903 setupIconGrabs(wwin->icon);
904 if ((wwin->flags.focused
905 || (owner && wwin->client_win == owner->client_win))
906 && wPreferences.focus_mode==WKF_CLICK) {
907 WWindow *tmp;
909 tmp = wwin->prev;
910 while (tmp) {
911 if (!tmp->window_flags.no_focusable
912 && !(tmp->flags.hidden||tmp->flags.miniaturized))
913 break;
914 tmp = tmp->prev;
916 wSetFocusTo(wwin->screen_ptr, tmp);
917 } else if (wPreferences.focus_mode!=WKF_CLICK) {
918 wSetFocusTo(wwin->screen_ptr, NULL);
921 #ifdef ANIMATIONS
922 if (!wwin->screen_ptr->flags.startup) {
923 Window clientwin = wwin->client_win;
925 XSync(dpy, 0);
926 processEvents(XPending(dpy));
928 /* the window can disappear while doing the processEvents() */
929 if (!wWindowFor(clientwin))
930 return;
932 #endif
936 if (wwin->flags.selected)
937 wIconSelect(wwin->icon);
939 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
945 void
946 wDeiconifyWindow(WWindow *wwin)
948 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
950 if (!wwin->flags.miniaturized)
951 return;
953 if (wwin->transient_for != None) {
954 WWindow *owner = recursiveTransientFor(wwin);
955 wDeiconifyWindow(owner);
956 wSetFocusTo(wwin->screen_ptr, wwin);
957 wRaiseFrame(wwin->frame->core);
958 return;
961 wwin->flags.miniaturized=0;
962 if (!wwin->flags.shaded)
963 wwin->flags.mapped=1;
965 if (wwin->icon->selected)
966 wIconSelect(wwin->icon);
968 XUnmapWindow(dpy, wwin->icon->core->window);
970 #ifdef WMSOUND
971 wSoundPlay(WMSOUND_DEICONIFY);
972 #endif
974 /* if the window is in another workspace, do it silently */
975 #ifdef ANIMATIONS
976 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
977 && !wwin->flags.skip_next_animation) {
978 animateResize(wwin->screen_ptr, wwin->icon_x, wwin->icon_y,
979 wwin->icon->core->width, wwin->icon->core->height,
980 wwin->frame_x, wwin->frame_y,
981 wwin->frame->core->width, wwin->frame->core->height,
982 False);
984 #endif /* ANIMATIONS */
985 wwin->flags.skip_next_animation = 0;
986 XGrabServer(dpy);
987 if (!wwin->flags.shaded) {
988 XMapWindow(dpy, wwin->client_win);
990 XMapWindow(dpy, wwin->frame->core->window);
991 wRaiseFrame(wwin->frame->core);
992 if (!wwin->flags.shaded) {
993 wClientSetState(wwin, NormalState, None);
995 mapTransientsFor(wwin);
996 RemoveFromStackList(wwin->icon->core);
997 removeIconGrabs(wwin->icon);
998 wIconDestroy(wwin->icon);
999 wwin->icon = NULL;
1001 XUngrabServer(dpy);
1002 if (wPreferences.focus_mode==WKF_CLICK
1003 || wPreferences.focus_mode==WKF_SLOPPY)
1004 wSetFocusTo(wwin->screen_ptr, wwin);
1006 #ifdef ANIMATIONS
1007 if (!wwin->screen_ptr->flags.startup) {
1008 Window clientwin = wwin->client_win;
1010 XSync(dpy, 0);
1011 processEvents(XPending(dpy));
1013 if (!wWindowFor(clientwin))
1014 return;
1016 #endif
1018 if (wPreferences.auto_arrange_icons) {
1019 wArrangeIcons(wwin->screen_ptr, True);
1022 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1028 static void
1029 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1031 XWindowAttributes attribs;
1034 if (wwin->flags.miniaturized) {
1035 XUnmapWindow(dpy, wwin->icon->core->window);
1036 wwin->flags.hidden = 1;
1037 wwin->icon->mapped = 0;
1038 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1039 return;
1042 if (wwin->flags.inspector_open) {
1043 WWindow *pwin = wwin->inspector->frame;
1045 XGetWindowAttributes(dpy, pwin->client_win, &attribs);
1046 pwin->flags.hidden = 1;
1047 pwin->flags.mapped = 0;
1048 /* prevent window withdrawal when getting UnmapNotify */
1049 XSelectInput(dpy, pwin->client_win,
1050 attribs.your_event_mask & ~StructureNotifyMask);
1051 XUnmapWindow(dpy, pwin->client_win);
1052 XSelectInput(dpy, pwin->client_win, attribs.your_event_mask);
1054 XUnmapWindow(dpy, pwin->frame->core->window);
1055 wClientSetState(pwin, IconicState, icon->icon_win);
1058 XGetWindowAttributes(dpy, wwin->client_win, &attribs);
1060 wwin->flags.hidden = 1;
1061 wwin->flags.mapped = 0;
1063 /* prevent window withdrawal when getting UnmapNotify */
1064 XSelectInput(dpy, wwin->client_win,
1065 attribs.your_event_mask & ~StructureNotifyMask);
1066 XUnmapWindow(dpy, wwin->client_win);
1067 XSelectInput(dpy, wwin->client_win, attribs.your_event_mask);
1069 XUnmapWindow(dpy, wwin->frame->core->window);
1070 wClientSetState(wwin, IconicState, icon->icon_win);
1071 flushExpose();
1072 #ifdef WMSOUND
1073 wSoundPlay(WMSOUND_HIDE);
1074 #endif
1075 #ifdef ANIMATIONS
1076 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1077 !wwin->flags.skip_next_animation && animate) {
1078 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1079 wwin->frame->core->width, wwin->frame->core->height,
1080 icon_x, icon_y, icon->core->width, icon->core->height,
1081 True);
1083 #endif
1084 wwin->flags.skip_next_animation = 0;
1086 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1091 void
1092 wHideOtherApplications(WWindow *awin)
1094 WWindow *wwin;
1095 WApplication *tapp;
1096 #ifdef REDUCE_APPICONS
1097 char *tinstance, *tclass;
1098 unsigned int brokenwin = 0, match = 0;
1099 #endif
1101 if (!awin)
1102 return;
1103 wwin = awin->screen_ptr->focused_window;
1105 #ifdef REDUCE_APPICONS
1106 if (awin->wm_instance == NULL || awin->wm_class == NULL)
1107 brokenwin++;
1108 #endif
1110 while (wwin) {
1111 if (wwin!=awin
1112 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1113 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1114 && !wwin->flags.internal_window
1115 && (!wwin->flags.inspector_open || wwin->inspector->frame!=awin)
1116 && !wwin->window_flags.no_hide_others) {
1118 #ifdef REDUCE_APPICONS
1119 match = 0;
1120 if (!brokenwin) {
1121 if ((tinstance = wwin->wm_instance) == NULL)
1122 tinstance = "";
1123 if ((tclass = wwin->wm_class) == NULL)
1124 tclass = "";
1125 if ((strcmp(awin->wm_instance, tinstance) == 0) &&
1126 (strcmp(awin->wm_class, tclass) == 0) )
1127 match++;
1129 #endif
1131 if (wwin->main_window==None || wwin->window_flags.no_appicon) {
1132 if (!wwin->window_flags.no_miniaturizable) {
1133 wwin->flags.skip_next_animation = 1;
1134 wIconifyWindow(wwin);
1136 } else if (wwin->main_window!=None
1137 #ifndef REDUCE_APPICONS
1138 && awin->main_window != wwin->main_window) {
1139 #else
1140 && (awin->main_window != wwin->main_window && !match)) {
1141 #endif
1142 tapp = wApplicationOf(wwin->main_window);
1143 if (tapp) {
1144 tapp->flags.skip_next_animation = 1;
1145 wHideApplication(tapp);
1146 } else {
1147 if (!wwin->window_flags.no_miniaturizable) {
1148 wwin->flags.skip_next_animation = 1;
1149 wIconifyWindow(wwin);
1154 wwin = wwin->prev;
1157 wSetFocusTo(awin->screen_ptr, awin);
1163 void
1164 wHideApplication(WApplication *wapp)
1166 #ifdef REDUCE_APPICONS
1167 WApplication *tapp;
1168 char *tinstance, *tclass;
1169 unsigned int nowmhints = 0, matchwmhints = 0, matchworkspace = 0;
1170 #endif
1171 WScreen *scr;
1172 WWindow *wlist;
1173 int hadfocus;
1175 if (!wapp) {
1176 wwarning("trying to hide a non grouped window");
1177 return;
1179 if (!wapp->main_window_desc) {
1180 wwarning("group leader not found for window group");
1181 return;
1183 #ifdef REDUCE_APPICONS
1184 if ((wapp->main_window_desc->wm_instance == NULL) ||
1185 (wapp->main_window_desc->wm_class == NULL))
1186 nowmhints++;
1187 #endif
1188 scr = wapp->main_window_desc->screen_ptr;
1189 hadfocus = 0;
1190 wlist = scr->focused_window;
1191 if (!wlist)
1192 return;
1194 if (wlist->main_window == wapp->main_window)
1195 wapp->last_focused = wlist;
1196 else
1197 wapp->last_focused = NULL;
1198 while (wlist) {
1199 #ifdef REDUCE_APPICONS
1200 matchwmhints = matchworkspace = 0;
1201 if (!nowmhints) {
1202 tapp = wApplicationOf(wlist->main_window);
1203 tinstance = tclass = NULL;
1204 if (tapp) {
1205 if (tapp->main_window_desc) {
1206 tinstance = tapp->main_window_desc->wm_instance;
1207 tclass = tapp->main_window_desc->wm_class;
1210 if (tapp == NULL || tinstance == NULL || tclass == NULL) {
1211 /* Should never reach here */
1212 tinstance = "";
1213 tclass = "";
1215 if ((strcmp(tinstance, wapp->main_window_desc->wm_instance) == 0) &&
1216 (strcmp(tclass, wapp->main_window_desc->wm_class) == 0) )
1217 matchwmhints++;
1219 if (wlist->frame) {
1220 if (wlist->frame->workspace == wapp->main_window_desc->screen_ptr->current_workspace)
1221 matchworkspace++;
1223 if ((wlist->main_window == wapp->main_window || matchwmhints) &&
1224 matchworkspace) {
1225 #ifdef I_HATE_THIS
1227 #endif
1228 #else
1229 if (wlist->main_window == wapp->main_window) {
1230 #endif
1231 if (wlist->flags.focused) {
1232 hadfocus = 1;
1234 if (wapp->app_icon)
1235 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1236 wapp->app_icon->y_pos, wlist,
1237 !wapp->flags.skip_next_animation);
1239 wlist = wlist->prev;
1242 wapp->flags.skip_next_animation = 0;
1244 if (hadfocus) {
1245 if (wPreferences.focus_mode==WKF_CLICK) {
1246 wlist = scr->focused_window;
1247 while (wlist) {
1248 if (!wlist->window_flags.no_focusable && !wlist->flags.hidden
1249 && (wlist->flags.mapped || wlist->flags.shaded))
1250 break;
1251 wlist = wlist->prev;
1253 wSetFocusTo(scr, wlist);
1254 } else {
1255 wSetFocusTo(scr, NULL);
1259 wapp->flags.hidden = 1;
1265 static void
1266 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1267 int bringToCurrentWS)
1269 if (bringToCurrentWS)
1270 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1272 wwin->flags.hidden=0;
1273 wwin->flags.mapped=1;
1275 #ifdef WMSOUND
1276 wSoundPlay(WMSOUND_UNHIDE);
1277 #endif
1278 #ifdef ANIMATIONS
1279 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1280 && animate) {
1281 animateResize(wwin->screen_ptr, icon_x, icon_y,
1282 icon->core->width, icon->core->height,
1283 wwin->frame_x, wwin->frame_y,
1284 wwin->frame->core->width, wwin->frame->core->height,
1285 True);
1287 #endif
1288 wwin->flags.skip_next_animation = 0;
1289 XMapWindow(dpy, wwin->client_win);
1290 XMapWindow(dpy, wwin->frame->core->window);
1291 wClientSetState(wwin, NormalState, None);
1292 wRaiseFrame(wwin->frame->core);
1293 if (wwin->flags.inspector_open) {
1294 WWindow *pwin = wwin->inspector->frame;
1296 pwin->flags.hidden = 0;
1297 pwin->flags.mapped = 1;
1298 XMapWindow(dpy, pwin->client_win);
1299 XMapWindow(dpy, pwin->frame->core->window);
1300 wClientSetState(pwin, NormalState, None);
1303 UpdateSwitchMenu(wwin->screen_ptr, wwin, ACTION_CHANGE_STATE);
1307 void
1308 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1310 WScreen *scr;
1311 WWindow *wlist, *next;
1312 WWindow *focused=NULL;
1313 #ifdef REDUCE_APPICONS
1314 char *tinstance, *tclass;
1315 unsigned int nowmhints = 0, matchwmhints = 0, matchworkspace = 0;
1316 #endif
1318 if (!wapp) {
1319 return;
1322 #ifdef REDUCE_APPICONS
1323 if ((wapp->main_window_desc->wm_class == NULL) ||
1324 (wapp->main_window_desc->wm_instance == NULL))
1325 nowmhints++;
1326 #endif
1328 scr = wapp->main_window_desc->screen_ptr;
1329 wlist = scr->focused_window;
1330 if (!wlist) return;
1331 /* goto beginning of list */
1332 while (wlist->prev)
1333 wlist = wlist->prev;
1335 while (wlist) {
1336 next = wlist->next;
1338 #ifndef REDUCE_APPICONS
1339 if (wlist->main_window == wapp->main_window) {
1340 #else
1341 matchwmhints = matchworkspace = 0;
1342 if (!nowmhints) {
1343 if ((tinstance = wlist->wm_instance) == NULL)
1344 tinstance = "";
1345 if ((tclass = wlist->wm_class) == NULL)
1346 tclass = "";
1347 if ((strcmp(tinstance, wapp->main_window_desc->wm_instance) == 0)
1348 && (strcmp(tclass, wapp->main_window_desc->wm_class) == 0) )
1349 matchwmhints++;
1351 if (wlist->frame) {
1352 if (wlist->frame->workspace == wapp->main_window_desc->screen_ptr->current_workspace)
1353 matchworkspace++;
1356 if ((wlist->main_window == wapp->main_window || matchwmhints) &&
1357 matchworkspace) {
1358 #endif
1359 if (wlist->flags.focused)
1360 focused = wlist;
1361 else if (!focused || !focused->flags.focused)
1362 focused = wlist;
1364 if (wlist->flags.miniaturized && wlist->icon) {
1365 if (bringToCurrentWS || wPreferences.sticky_icons
1366 || wlist->frame->workspace == scr->current_workspace) {
1367 if (!wlist->icon->mapped) {
1368 XMapWindow(dpy, wlist->icon->core->window);
1369 wlist->icon->mapped = 1;
1371 wlist->flags.hidden = 0;
1372 UpdateSwitchMenu(scr, wlist, ACTION_CHANGE_STATE);
1373 if (wlist->frame->workspace != scr->current_workspace)
1374 wWindowChangeWorkspace(wlist, scr->current_workspace);
1376 if (miniwindows) {
1377 wDeiconifyWindow(wlist);
1379 } else if (wlist->flags.hidden) {
1380 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1381 wapp->app_icon->y_pos, wlist,
1382 !wapp->flags.skip_next_animation,
1383 bringToCurrentWS);
1384 } else {
1385 if (bringToCurrentWS
1386 && wlist->frame->workspace != scr->current_workspace) {
1387 wWindowChangeWorkspace(wlist, scr->current_workspace);
1389 wRaiseFrame(wlist->frame->core);
1392 wlist = next;
1395 wapp->flags.skip_next_animation = 0;
1396 wapp->flags.hidden = 0;
1398 if (focused)
1399 wSetFocusTo(scr, focused);
1400 else if (wapp->last_focused && wapp->last_focused->flags.mapped)
1401 wSetFocusTo(scr, wapp->last_focused);
1402 wapp->last_focused = NULL;
1403 if (wPreferences.auto_arrange_icons) {
1404 wArrangeIcons(scr, True);
1410 void
1411 wShowAllWindows(WScreen *scr)
1413 WWindow *wwin, *old_foc;
1414 WApplication *wapp;
1416 old_foc = wwin = scr->focused_window;
1417 while (wwin) {
1418 if (!wwin->flags.internal_window &&
1419 (scr->current_workspace == wwin->frame->workspace
1420 || wwin->window_flags.omnipresent)) {
1421 if (wwin->flags.miniaturized) {
1422 wwin->flags.skip_next_animation = 1;
1423 wDeiconifyWindow(wwin);
1424 } else if (wwin->flags.hidden) {
1425 wapp = wApplicationOf(wwin->main_window);
1426 if (wapp) {
1427 wUnhideApplication(wapp, False, False);
1428 } else {
1429 wwin->flags.skip_next_animation = 1;
1430 wDeiconifyWindow(wwin);
1434 wwin = wwin->prev;
1436 wSetFocusTo(scr, old_foc);
1437 /*wRaiseFrame(old_foc->frame->core);*/
1441 void
1442 wRefreshDesktop(WScreen *scr)
1444 Window win;
1445 XSetWindowAttributes attr;
1447 attr.backing_store = NotUseful;
1448 attr.save_under = False;
1449 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1450 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1451 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1452 &attr);
1453 XMapRaised(dpy, win);
1454 XDestroyWindow(dpy, win);
1455 XFlush(dpy);
1459 void
1460 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1462 WWindow *wwin;
1463 WAppIcon *aicon;
1464 int pf; /* primary axis */
1465 int sf; /* secondary axis */
1466 int fullW;
1467 int fullH;
1468 int pi, si;
1469 int sx1, sx2, sy1, sy2; /* screen boundary */
1470 int sw, sh;
1471 int xo, yo;
1472 int xs, ys;
1473 int isize = wPreferences.icon_size;
1476 * Find out screen boundaries.
1478 sx1 = 0;
1479 sy1 = 0;
1480 sx2 = scr->scr_width;
1481 sy2 = scr->scr_height;
1482 if (scr->dock) {
1483 if (scr->dock->on_right_side)
1484 sx2 -= isize + DOCK_EXTRA_SPACE;
1485 else
1486 sx1 += isize + DOCK_EXTRA_SPACE;
1489 sw = isize * (scr->scr_width/isize);
1490 sh = isize * (scr->scr_height/isize);
1491 fullW = (sx2-sx1)/isize;
1492 fullH = (sy2-sy1)/isize;
1494 /* icon yard boundaries */
1495 if (wPreferences.icon_yard & IY_VERT) {
1496 pf = fullH;
1497 sf = fullW;
1498 } else {
1499 pf = fullW;
1500 sf = fullH;
1502 if (wPreferences.icon_yard & IY_RIGHT) {
1503 xo = sx2 - isize;
1504 xs = -1;
1505 } else {
1506 xo = sx1;
1507 xs = 1;
1509 if (wPreferences.icon_yard & IY_TOP) {
1510 yo = sy1;
1511 ys = 1;
1512 } else {
1513 yo = sy2 - isize;
1514 ys = -1;
1517 /* arrange icons putting the most recently focused window
1518 * as the last icon */
1519 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1520 : xo + xs*(pi*isize))
1521 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1522 : yo + ys*(si*isize))
1524 /* arrange application icons */
1525 aicon = scr->app_icon_list;
1526 /* reverse them to avoid unnecessarily sliding of icons */
1527 while (aicon && aicon->next)
1528 aicon = aicon->next;
1530 pi = 0;
1531 si = 0;
1532 while (aicon) {
1533 if (!aicon->docked) {
1534 if (aicon->x_pos != X || aicon->y_pos != Y) {
1535 #ifdef ANIMATIONS
1536 if (!wPreferences.no_animations) {
1537 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1538 X, Y);
1540 #endif /* ANIMATIONS */
1542 wAppIconMove(aicon, X, Y);
1543 pi++;
1545 /* we reversed the order so we use prev */
1546 aicon = aicon->prev;
1547 if (pi >= pf) {
1548 pi=0;
1549 si++;
1553 /* arrange miniwindows */
1555 wwin = scr->focused_window;
1556 /* reverse them to avoid unnecessarily shuffling */
1557 while (wwin && wwin->prev)
1558 wwin = wwin->prev;
1560 while (wwin) {
1561 if (wwin->icon && wwin->flags.miniaturized &&
1562 (wwin->frame->workspace==scr->current_workspace ||
1563 wwin->window_flags.omnipresent ||
1564 wPreferences.sticky_icons)) {
1566 if (arrangeAll || !wwin->flags.icon_moved) {
1567 if (wwin->icon_x != X || wwin->icon_y != Y) {
1568 #ifdef ANIMATIONS
1569 if (wPreferences.no_animations) {
1570 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1571 } else {
1572 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1573 wwin->icon_y, X, Y);
1575 #else
1576 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1577 #endif /* ANIMATIONS */
1579 wwin->icon_x = X;
1580 wwin->icon_y = Y;
1581 wwin->flags.icon_moved = 0;
1582 pi++;
1585 /* we reversed the order, so we use next */
1586 wwin = wwin->next;
1587 if (pi >= pf) {
1588 pi=0;
1589 si++;