- Properly fixed the color change in the Appearance panel preview box
[wmaker-crm.git] / src / actions.c
blobec6eb6b67ff1e63830a1a53abf7da02ba5b9a645
1 /* action.c- misc. window commands (miniaturize, hide etc.)
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997-2002 Alfredo K. Kojima
6 * Copyright (c) 1998-2002 Dan Pascu
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #include "wconfig.h"
27 #include <X11/Xlib.h>
28 #include <X11/Xutil.h>
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <unistd.h>
32 #include <math.h>
33 #include <time.h>
35 #include "WindowMaker.h"
36 #include "wcore.h"
37 #include "framewin.h"
38 #include "window.h"
39 #include "client.h"
40 #include "icon.h"
41 #include "funcs.h"
42 #include "application.h"
43 #include "actions.h"
44 #include "stacking.h"
45 #include "appicon.h"
46 #include "dock.h"
47 #include "appmenu.h"
48 #include "winspector.h"
49 #include "workspace.h"
50 #include "wsound.h"
51 #include "xinerama.h"
53 #ifdef GNOME_STUFF
54 # include "gnome.h"
55 #endif
56 #ifdef KWM_HINTS
57 # include "kwm.h"
58 #endif
62 /****** Global Variables ******/
63 extern Time LastTimestamp;
64 extern Time LastFocusChange;
66 extern Cursor wCursor[WCUR_LAST];
68 extern WPreferences wPreferences;
70 extern Atom _XA_WM_TAKE_FOCUS;
73 /******* Local Variables *******/
74 static struct {
75 int steps;
76 int delay;
77 } shadePars[5] = {
78 {SHADE_STEPS_UF, SHADE_DELAY_UF},
79 {SHADE_STEPS_F, SHADE_DELAY_F},
80 {SHADE_STEPS_M, SHADE_DELAY_M},
81 {SHADE_STEPS_S, SHADE_DELAY_S},
82 {SHADE_STEPS_US, SHADE_DELAY_US}};
84 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
85 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
88 static int ignoreTimestamp=0;
91 #ifdef ANIMATIONS
92 static void
93 processEvents(int event_count)
95 XEvent event;
98 * This is a hack. When animations are enabled, processing of
99 * events ocurred during a animation are delayed until it's end.
100 * Calls that consider the TimeStamp, like XSetInputFocus(), will
101 * fail because the TimeStamp is too old. Then, for example, if
102 * the user changes window focus while a miniaturize animation is
103 * in course, the window will not get focus properly after the end
104 * of the animation. This tries to workaround it by passing CurrentTime
105 * as the TimeStamp for XSetInputFocus() for all events ocurred during
106 * the animation.
108 ignoreTimestamp=1;
109 while (XPending(dpy) && event_count--) {
110 WMNextEvent(dpy, &event);
111 WMHandleEvent(&event);
113 ignoreTimestamp=0;
115 #endif /* ANIMATIONS */
120 *----------------------------------------------------------------------
121 * wSetFocusTo--
122 * Changes the window focus to the one passed as argument.
123 * If the window to focus is not already focused, it will be brought
124 * to the head of the list of windows. Previously focused window is
125 * unfocused.
127 * Side effects:
128 * Window list may be reordered and the window focus is changed.
130 *----------------------------------------------------------------------
132 void
133 wSetFocusTo(WScreen *scr, WWindow *wwin)
135 static WScreen *old_scr=NULL;
137 WWindow *old_focused;
138 WWindow *focused=scr->focused_window;
139 int timestamp=LastTimestamp;
140 WApplication *oapp=NULL, *napp=NULL;
141 int wasfocused;
143 if (!old_scr)
144 old_scr=scr;
145 old_focused=old_scr->focused_window;
147 LastFocusChange = timestamp;
150 * This is a hack, because XSetInputFocus() should have a proper
151 * timestamp instead of CurrentTime but it seems that some times
152 * clients will not receive focus properly that way.
153 if (ignoreTimestamp)
155 timestamp = CurrentTime;
157 if (old_focused)
158 oapp = wApplicationOf(old_focused->main_window);
160 if (wwin == NULL) {
161 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
162 if (old_focused) {
163 wWindowUnfocus(old_focused);
165 if (oapp) {
166 wAppMenuUnmap(oapp->menu);
167 #ifdef NEWAPPICON
168 wApplicationDeactivate(oapp);
169 #endif
172 WMPostNotificationName(WMNChangedFocus, NULL, (void*)True);
173 return;
174 } else if (old_scr != scr && old_focused) {
175 wWindowUnfocus(old_focused);
178 wasfocused = wwin->flags.focused;
179 napp = wApplicationOf(wwin->main_window);
181 /* remember last workspace where the app has been */
182 if (napp) {
183 /*napp->last_workspace = wwin->screen_ptr->current_workspace;*/
184 napp->last_workspace = wwin->frame->workspace;
187 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
188 /* install colormap if colormap mode is lock mode */
189 if (wPreferences.colormap_mode==WCM_CLICK)
190 wColormapInstallForWindow(scr, wwin);
192 /* set input focus */
193 switch (wwin->focus_mode) {
194 case WFM_NO_INPUT:
195 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
196 break;
198 case WFM_PASSIVE:
199 case WFM_LOCALLY_ACTIVE:
200 XSetInputFocus(dpy, wwin->client_win, RevertToParent, timestamp);
201 break;
203 case WFM_GLOBALLY_ACTIVE:
204 break;
206 XFlush(dpy);
207 if (wwin->protocols.TAKE_FOCUS) {
208 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
210 XSync(dpy, False);
211 } else {
212 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
214 if (WFLAGP(wwin, no_focusable))
215 return;
217 /* if this is not the focused window focus it */
218 if (focused!=wwin) {
219 /* change the focus window list order */
220 if (wwin->prev)
221 wwin->prev->next = wwin->next;
223 if (wwin->next)
224 wwin->next->prev = wwin->prev;
226 wwin->prev = focused;
227 focused->next = wwin;
228 wwin->next = NULL;
229 scr->focused_window = wwin;
231 if (oapp && oapp != napp) {
232 wAppMenuUnmap(oapp->menu);
233 #ifdef NEWAPPICON
234 wApplicationDeactivate(oapp);
235 #endif
239 wWindowFocus(wwin, focused);
241 if (napp && !wasfocused) {
242 #ifdef USER_MENU
243 wUserMenuRefreshInstances(napp->menu, wwin);
244 #endif /* USER_MENU */
246 if (wwin->flags.mapped)
247 wAppMenuMap(napp->menu, wwin);
248 #ifdef NEWAPPICON
249 wApplicationActivate(napp);
250 #endif
253 XFlush(dpy);
254 old_scr=scr;
258 void
259 wShadeWindow(WWindow *wwin)
261 time_t time0;
262 #ifdef ANIMATIONS
263 int y, s, w, h;
264 #endif
266 if (wwin->flags.shaded)
267 return;
269 time0 = time(NULL);
271 XLowerWindow(dpy, wwin->client_win);
273 wSoundPlay(WSOUND_SHADE);
275 #ifdef ANIMATIONS
276 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
277 && !wPreferences.no_animations) {
278 /* do the shading animation */
279 h = wwin->frame->core->height;
280 s = h/SHADE_STEPS;
281 if (s < 1) s=1;
282 w = wwin->frame->core->width;
283 y = wwin->frame->top_width;
284 while (h>wwin->frame->top_width+1) {
285 XMoveWindow(dpy, wwin->client_win, 0, y);
286 XResizeWindow(dpy, wwin->frame->core->window, w, h);
287 XFlush(dpy);
289 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
290 break;
292 if (SHADE_DELAY > 0) {
293 wusleep(SHADE_DELAY*1000L);
294 } else {
295 wusleep(10);
297 h-=s;
298 y-=s;
300 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
302 #endif /* ANIMATIONS */
304 wwin->flags.skip_next_animation = 0;
305 wwin->flags.shaded = 1;
306 wwin->flags.mapped = 0;
307 /* prevent window withdrawal when getting UnmapNotify */
308 XSelectInput(dpy, wwin->client_win,
309 wwin->event_mask & ~StructureNotifyMask);
310 XUnmapWindow(dpy, wwin->client_win);
311 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
313 /* for the client it's just like iconification */
314 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
315 wwin->frame->top_width - 1);
317 wwin->client.y = wwin->frame_y - wwin->client.height
318 + wwin->frame->top_width;
319 wWindowSynthConfigureNotify(wwin);
322 wClientSetState(wwin, IconicState, None);
325 WMPostNotificationName(WMNChangedState, wwin, "shade");
327 #ifdef ANIMATIONS
328 if (!wwin->screen_ptr->flags.startup) {
329 /* Look at processEvents() for reason of this code. */
330 XSync(dpy, 0);
331 processEvents(XPending(dpy));
333 #endif
337 void
338 wUnshadeWindow(WWindow *wwin)
340 time_t time0;
341 #ifdef ANIMATIONS
342 int y, s, w, h;
343 #endif /* ANIMATIONS */
346 if (!wwin->flags.shaded)
347 return;
349 time0 = time(NULL);
351 wwin->flags.shaded = 0;
352 wwin->flags.mapped = 1;
353 XMapWindow(dpy, wwin->client_win);
355 wSoundPlay(WSOUND_UNSHADE);
357 #ifdef ANIMATIONS
358 if (!wPreferences.no_animations && !wwin->flags.skip_next_animation) {
359 /* do the shading animation */
360 h = wwin->frame->top_width + wwin->frame->bottom_width;
361 y = wwin->frame->top_width - wwin->client.height;
362 s = abs(y)/SHADE_STEPS;
363 if (s<1) s=1;
364 w = wwin->frame->core->width;
365 XMoveWindow(dpy, wwin->client_win, 0, y);
366 if (s>0) {
367 while (h < wwin->client.height + wwin->frame->top_width
368 + wwin->frame->bottom_width) {
369 XResizeWindow(dpy, wwin->frame->core->window, w, h);
370 XMoveWindow(dpy, wwin->client_win, 0, y);
371 XFlush(dpy);
372 if (SHADE_DELAY > 0) {
373 wusleep(SHADE_DELAY*2000L/3);
374 } else {
375 wusleep(10);
377 h+=s;
378 y+=s;
380 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
381 break;
384 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
386 #endif /* ANIMATIONS */
388 wwin->flags.skip_next_animation = 0;
389 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
390 wwin->frame->top_width + wwin->client.height
391 + wwin->frame->bottom_width);
393 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
394 wWindowSynthConfigureNotify(wwin);
397 wClientSetState(wwin, NormalState, None);
399 /* if the window is focused, set the focus again as it was disabled during
400 * shading */
401 if (wwin->flags.focused)
402 wSetFocusTo(wwin->screen_ptr, wwin);
404 WMPostNotificationName(WMNChangedState, wwin, "shade");
408 void
409 wMaximizeWindow(WWindow *wwin, int directions)
411 int new_width, new_height, new_x, new_y;
412 WArea usableArea = wwin->screen_ptr->totalUsableArea;
413 WArea totalArea;
415 if (WFLAGP(wwin, no_resizable))
416 return;
418 totalArea.x1 = 0;
419 totalArea.y1 = 0;
420 totalArea.x2 = wwin->screen_ptr->scr_width;
421 totalArea.y2 = wwin->screen_ptr->scr_height;
423 if (wwin->screen_ptr->xine_count > 0
424 && !(directions & MAX_IGNORE_XINERAMA)) {
425 WScreen *scr = wwin->screen_ptr;
426 WMRect rect;
427 int head;
429 /* XXX:
430 if ( keyboard) {
431 rect.pos.x = wwin->frame_x;
432 rect.pos.y = wwin->frame_y;
433 rect.size.width = wwin->frame->core->width;
434 rect.size.height = wwin->frame->core->height;
436 head = wGetHeadForRect(scr, rect);
437 } else
439 head = wGetHeadForPointerLocation(scr);
441 rect = wGetRectForHead(scr, head);
443 usableArea = wGetUsableAreaForHead(scr, head, &totalArea);
446 if (WFLAGP(wwin, full_maximize)) {
447 usableArea = totalArea;
450 if (wwin->flags.shaded) {
451 wwin->flags.skip_next_animation = 1;
452 wUnshadeWindow(wwin);
454 wwin->flags.maximized = directions;
455 wwin->old_geometry.width = wwin->client.width;
456 wwin->old_geometry.height = wwin->client.height;
457 wwin->old_geometry.x = wwin->frame_x;
458 wwin->old_geometry.y = wwin->frame_y;
460 #ifdef KWM_HINTS
461 wKWMUpdateClientGeometryRestore(wwin);
462 #endif
464 if (directions & MAX_HORIZONTAL) {
466 new_width = (usableArea.x2-usableArea.x1)-FRAME_BORDER_WIDTH*2;
467 new_x = usableArea.x1;
469 } else {
471 new_x = wwin->frame_x;
472 new_width = wwin->frame->core->width;
476 if (directions & MAX_VERTICAL) {
478 new_height = (usableArea.y2-usableArea.y1)-FRAME_BORDER_WIDTH*2;
479 new_y = usableArea.y1;
480 if (WFLAGP(wwin, full_maximize)) {
481 new_y -= wwin->frame->top_width;
482 new_height += wwin->frame->bottom_width - 1;
484 } else {
485 new_y = wwin->frame_y;
486 new_height = wwin->frame->core->height;
489 if (!WFLAGP(wwin, full_maximize)) {
490 new_height -= wwin->frame->top_width+wwin->frame->bottom_width;
493 wWindowConstrainSize(wwin, &new_width, &new_height);
495 wWindowCropSize(wwin, usableArea.x2-usableArea.x1,
496 usableArea.y2-usableArea.y1,
497 &new_width, &new_height);
499 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
502 WMPostNotificationName(WMNChangedState, wwin, "maximize");
504 wSoundPlay(WSOUND_MAXIMIZE);
508 void
509 wUnmaximizeWindow(WWindow *wwin)
511 int restore_x, restore_y;
513 if (!wwin->flags.maximized)
514 return;
516 if (wwin->flags.shaded) {
517 wwin->flags.skip_next_animation = 1;
518 wUnshadeWindow(wwin);
520 restore_x = (wwin->flags.maximized & MAX_HORIZONTAL) ?
521 wwin->old_geometry.x : wwin->frame_x;
522 restore_y = (wwin->flags.maximized & MAX_VERTICAL) ?
523 wwin->old_geometry.y : wwin->frame_y;
524 wwin->flags.maximized = 0;
525 wWindowConfigure(wwin, restore_x, restore_y,
526 wwin->old_geometry.width, wwin->old_geometry.height);
528 WMPostNotificationName(WMNChangedState, wwin, "maximize");
530 wSoundPlay(WSOUND_UNMAXIMIZE);
533 #ifdef ANIMATIONS
534 static void
535 animateResizeFlip(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_F)
539 float cx, cy, cw, ch;
540 float xstep, ystep, wstep, hstep;
541 XPoint points[5];
542 float dx, dch, midy;
543 float angle, final_angle, delta;
545 xstep = (float)(fx-x)/steps;
546 ystep = (float)(fy-y)/steps;
547 wstep = (float)(fw-w)/steps;
548 hstep = (float)(fh-h)/steps;
550 cx = (float)x;
551 cy = (float)y;
552 cw = (float)w;
553 ch = (float)h;
555 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_F;
556 delta = (float)(final_angle/FRAMES);
557 for (angle=0;; angle+=delta) {
558 if (angle > final_angle)
559 angle = final_angle;
561 dx = (cw/10) - ((cw/5) * sin(angle));
562 dch = (ch/2) * cos(angle);
563 midy = cy + (ch/2);
565 points[0].x = cx + dx; points[0].y = midy - dch;
566 points[1].x = cx + cw - dx; points[1].y = points[0].y;
567 points[2].x = cx + cw + dx; points[2].y = midy + dch;
568 points[3].x = cx - dx; points[3].y = points[2].y;
569 points[4].x = points[0].x; points[4].y = points[0].y;
571 XGrabServer(dpy);
572 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
573 XFlush(dpy);
574 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
575 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
576 #else
577 wusleep(10);
578 #endif
580 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
581 XUngrabServer(dpy);
582 cx+=xstep;
583 cy+=ystep;
584 cw+=wstep;
585 ch+=hstep;
586 if (angle >= final_angle)
587 break;
590 XFlush(dpy);
592 #undef FRAMES
595 static void
596 animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
597 int fx, int fy, int fw, int fh, int steps)
599 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
600 float cx, cy, cw, ch;
601 float xstep, ystep, wstep, hstep;
602 XPoint points[5];
603 float angle, final_angle, a, d, delta;
605 x += w/2;
606 y += h/2;
607 fx += fw/2;
608 fy += fh/2;
610 xstep = (float)(fx-x)/steps;
611 ystep = (float)(fy-y)/steps;
612 wstep = (float)(fw-w)/steps;
613 hstep = (float)(fh-h)/steps;
615 cx = (float)x;
616 cy = (float)y;
617 cw = (float)w;
618 ch = (float)h;
620 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
621 delta = (float)(final_angle/FRAMES);
622 for (angle=0;; angle+=delta) {
623 if (angle > final_angle)
624 angle = final_angle;
626 a = atan(ch/cw);
627 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
629 points[0].x = cx+cos(angle-a)*d;
630 points[0].y = cy+sin(angle-a)*d;
631 points[1].x = cx+cos(angle+a)*d;
632 points[1].y = cy+sin(angle+a)*d;
633 points[2].x = cx+cos(angle-a+WM_PI)*d;
634 points[2].y = cy+sin(angle-a+WM_PI)*d;
635 points[3].x = cx+cos(angle+a+WM_PI)*d;
636 points[3].y = cy+sin(angle+a+WM_PI)*d;
637 points[4].x = cx+cos(angle-a)*d;
638 points[4].y = cy+sin(angle-a)*d;
639 XGrabServer(dpy);
640 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
641 XFlush(dpy);
642 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
643 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
644 #else
645 wusleep(10);
646 #endif
648 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
649 XUngrabServer(dpy);
650 cx+=xstep;
651 cy+=ystep;
652 cw+=wstep;
653 ch+=hstep;
654 if (angle >= final_angle)
655 break;
658 XFlush(dpy);
660 #undef FRAMES
663 static void
664 animateResizeZoom(WScreen *scr, int x, int y, int w, int h,
665 int fx, int fy, int fw, int fh, int steps)
667 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
668 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
669 float xstep, ystep, wstep, hstep;
670 int i, j;
672 xstep = (float)(fx-x)/steps;
673 ystep = (float)(fy-y)/steps;
674 wstep = (float)(fw-w)/steps;
675 hstep = (float)(fh-h)/steps;
677 for (j=0; j<FRAMES; j++) {
678 cx[j] = (float)x;
679 cy[j] = (float)y;
680 cw[j] = (float)w;
681 ch[j] = (float)h;
683 XGrabServer(dpy);
684 for (i=0; i<steps; i++) {
685 for (j=0; j<FRAMES; j++) {
686 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
687 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
689 XFlush(dpy);
690 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
691 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
692 #else
693 wusleep(10);
694 #endif
695 for (j=0; j<FRAMES; j++) {
696 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
697 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
698 if (j<FRAMES-1) {
699 cx[j]=cx[j+1];
700 cy[j]=cy[j+1];
701 cw[j]=cw[j+1];
702 ch[j]=ch[j+1];
703 } else {
704 cx[j]+=xstep;
705 cy[j]+=ystep;
706 cw[j]+=wstep;
707 ch[j]+=hstep;
712 for (j=0; j<FRAMES; j++) {
713 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
714 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
716 XFlush(dpy);
717 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
718 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
719 #else
720 wusleep(10);
721 #endif
722 for (j=0; j<FRAMES; j++) {
723 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
724 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
727 XUngrabServer(dpy);
729 #undef FRAMES
732 void
733 animateResize(WScreen *scr, int x, int y, int w, int h,
734 int fx, int fy, int fw, int fh, int hiding)
736 int style = wPreferences.iconification_style; /* Catch the value */
737 int steps, k;
739 if (style == WIS_NONE)
740 return;
742 if (style == WIS_RANDOM) {
743 style = rand()%3;
746 k = (hiding ? 2 : 3);
747 switch(style) {
748 case WIS_TWIST:
749 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
750 if (steps>0)
751 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
752 break;
753 case WIS_FLIP:
754 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
755 if (steps>0)
756 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
757 break;
758 case WIS_ZOOM:
759 default:
760 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
761 if (steps>0)
762 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
763 break;
766 #endif /* ANIMATIONS */
769 static void
770 flushExpose()
772 XEvent tmpev;
774 while (XCheckTypedEvent(dpy, Expose, &tmpev))
775 WMHandleEvent(&tmpev);
776 XSync(dpy, 0);
779 static void
780 unmapTransientsFor(WWindow *wwin)
782 WWindow *tmp;
785 tmp = wwin->screen_ptr->focused_window;
786 while (tmp) {
787 /* unmap the transients for this transient */
788 if (tmp!=wwin && tmp->transient_for == wwin->client_win
789 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
790 || tmp->flags.shaded)) {
791 unmapTransientsFor(tmp);
792 tmp->flags.miniaturized = 1;
793 if (!tmp->flags.shaded) {
794 wWindowUnmap(tmp);
795 } else {
796 XUnmapWindow(dpy, tmp->frame->core->window);
799 if (!tmp->flags.shaded)
801 wClientSetState(tmp, IconicState, None);
803 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
805 tmp = tmp->prev;
810 static void
811 mapTransientsFor(WWindow *wwin)
813 WWindow *tmp;
815 tmp = wwin->screen_ptr->focused_window;
816 while (tmp) {
817 /* recursively map the transients for this transient */
818 if (tmp!=wwin && tmp->transient_for == wwin->client_win
819 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
820 && tmp->icon==NULL) {
821 mapTransientsFor(tmp);
822 tmp->flags.miniaturized = 0;
823 if (!tmp->flags.shaded) {
824 wWindowMap(tmp);
825 } else {
826 XMapWindow(dpy, tmp->frame->core->window);
828 tmp->flags.semi_focused = 0;
830 if (!tmp->flags.shaded)
832 wClientSetState(tmp, NormalState, None);
834 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
836 tmp = tmp->prev;
840 #if 0
841 static void
842 setupIconGrabs(WIcon *icon)
844 /* setup passive grabs on the icon */
845 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
846 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
847 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
848 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
849 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
850 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
851 XSync(dpy, 0);
853 #endif
855 static WWindow*
856 recursiveTransientFor(WWindow *wwin)
858 int i;
860 if (!wwin)
861 return None;
863 /* hackish way to detect transient_for cycle */
864 i = wwin->screen_ptr->window_count+1;
866 while (wwin && wwin->transient_for != None && i>0) {
867 wwin = wWindowFor(wwin->transient_for);
868 i--;
870 if (i==0 && wwin) {
871 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
872 wwin->frame->title);
873 return NULL;
876 return wwin;
879 #if 0
880 static void
881 removeIconGrabs(WIcon *icon)
883 /* remove passive grabs on the icon */
884 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
885 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
886 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
887 XSync(dpy, 0);
889 #endif
892 void
893 wIconifyWindow(WWindow *wwin)
895 XWindowAttributes attribs;
896 int present;
899 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
900 /* the window doesn't exist anymore */
901 return;
904 if (wwin->flags.miniaturized) {
905 return;
908 if (wwin->transient_for!=None &&
909 wwin->transient_for!=wwin->screen_ptr->root_win) {
910 WWindow *owner = wWindowFor(wwin->transient_for);
912 if (owner && owner->flags.miniaturized)
913 return;
916 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
918 /* if the window is in another workspace, simplify process */
919 if (present) {
920 /* icon creation may take a while */
921 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
922 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
923 GrabModeAsync, None, None, CurrentTime);
926 if (!wPreferences.disable_miniwindows) {
927 if (!wwin->flags.icon_moved) {
928 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y);
930 wwin->icon = wIconCreate(wwin);
932 wwin->icon->mapped = 1;
935 wwin->flags.miniaturized = 1;
936 wwin->flags.mapped = 0;
938 /* unmap transients */
940 unmapTransientsFor(wwin);
942 if (present) {
943 wSoundPlay(WSOUND_ICONIFY);
945 XUngrabPointer(dpy, CurrentTime);
946 wWindowUnmap(wwin);
947 /* let all Expose events arrive so that we can repaint
948 * something before the animation starts (and the server is grabbed) */
949 XSync(dpy, 0);
951 if (wPreferences.disable_miniwindows)
952 wClientSetState(wwin, IconicState, None);
953 else
954 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
956 flushExpose();
957 #ifdef ANIMATIONS
958 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
959 && !wPreferences.no_animations) {
960 int ix, iy, iw, ih;
962 if (!wPreferences.disable_miniwindows) {
963 ix = wwin->icon_x;
964 iy = wwin->icon_y;
965 iw = wwin->icon->core->width;
966 ih = wwin->icon->core->height;
967 } else {
968 #ifdef KWM_HINTS
969 WArea area;
971 if (wKWMGetIconGeometry(wwin, &area)) {
972 ix = area.x1;
973 iy = area.y1;
974 iw = area.x2 - ix;
975 ih = area.y2 - iy;
976 } else
977 #endif /* KWM_HINTS */
979 ix = 0;
980 iy = 0;
981 iw = wwin->screen_ptr->scr_width;
982 ih = wwin->screen_ptr->scr_height;
985 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
986 wwin->frame->core->width, wwin->frame->core->height,
987 ix, iy, iw, ih, False);
989 #endif
992 wwin->flags.skip_next_animation = 0;
994 if (!wPreferences.disable_miniwindows) {
996 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
997 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
999 XMapWindow(dpy, wwin->icon->core->window);
1001 AddToStackList(wwin->icon->core);
1003 wLowerFrame(wwin->icon->core);
1006 if (present) {
1007 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1010 * It doesn't seem to be working and causes button event hangup
1011 * when deiconifying a transient window.
1012 setupIconGrabs(wwin->icon);
1014 if ((wwin->flags.focused
1015 || (owner && wwin->client_win == owner->client_win))
1016 && wPreferences.focus_mode==WKF_CLICK) {
1017 WWindow *tmp;
1019 tmp = wwin->prev;
1020 while (tmp) {
1021 if (!WFLAGP(tmp, no_focusable)
1022 && !(tmp->flags.hidden||tmp->flags.miniaturized)
1023 && (wwin->frame->workspace == tmp->frame->workspace))
1024 break;
1025 tmp = tmp->prev;
1027 wSetFocusTo(wwin->screen_ptr, tmp);
1028 } else if (wPreferences.focus_mode!=WKF_CLICK) {
1029 wSetFocusTo(wwin->screen_ptr, NULL);
1032 #ifdef ANIMATIONS
1033 if (!wwin->screen_ptr->flags.startup) {
1034 Window clientwin = wwin->client_win;
1036 XSync(dpy, 0);
1037 processEvents(XPending(dpy));
1039 /* the window can disappear while doing the processEvents() */
1040 if (!wWindowFor(clientwin))
1041 return;
1043 #endif
1047 if (wwin->flags.selected && !wPreferences.disable_miniwindows)
1048 wIconSelect(wwin->icon);
1050 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1056 void
1057 wDeiconifyWindow(WWindow *wwin)
1059 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1061 if (!wwin->flags.miniaturized)
1062 return;
1064 if (wwin->transient_for != None
1065 && wwin->transient_for != wwin->screen_ptr->root_win) {
1066 WWindow *owner = recursiveTransientFor(wwin);
1068 if (owner && owner->flags.miniaturized) {
1069 wDeiconifyWindow(owner);
1070 wSetFocusTo(wwin->screen_ptr, wwin);
1071 wRaiseFrame(wwin->frame->core);
1072 return;
1076 wwin->flags.miniaturized = 0;
1077 if (!wwin->flags.shaded)
1078 wwin->flags.mapped = 1;
1080 if (!wPreferences.disable_miniwindows && wwin->icon != NULL) {
1081 if (wwin->icon->selected)
1082 wIconSelect(wwin->icon);
1084 XUnmapWindow(dpy, wwin->icon->core->window);
1087 wSoundPlay(WSOUND_DEICONIFY);
1089 /* if the window is in another workspace, do it silently */
1090 #ifdef ANIMATIONS
1091 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1092 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1093 int ix, iy, iw, ih;
1095 if (!wPreferences.disable_miniwindows) {
1096 ix = wwin->icon_x;
1097 iy = wwin->icon_y;
1098 iw = wwin->icon->core->width;
1099 ih = wwin->icon->core->height;
1100 } else {
1101 #ifdef KWM_HINTS
1102 WArea area;
1104 if (wKWMGetIconGeometry(wwin, &area)) {
1105 ix = area.x1;
1106 iy = area.y1;
1107 iw = area.x2 - ix;
1108 ih = area.y2 - iy;
1109 } else
1110 #endif /* KWM_HINTS */
1112 ix = 0;
1113 iy = 0;
1114 iw = wwin->screen_ptr->scr_width;
1115 ih = wwin->screen_ptr->scr_height;
1118 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1119 wwin->frame_x, wwin->frame_y,
1120 wwin->frame->core->width, wwin->frame->core->height,
1121 False);
1123 #endif /* ANIMATIONS */
1124 wwin->flags.skip_next_animation = 0;
1125 XGrabServer(dpy);
1126 if (!wwin->flags.shaded) {
1127 XMapWindow(dpy, wwin->client_win);
1129 XMapWindow(dpy, wwin->frame->core->window);
1130 wRaiseFrame(wwin->frame->core);
1131 if (!wwin->flags.shaded) {
1132 wClientSetState(wwin, NormalState, None);
1134 mapTransientsFor(wwin);
1136 if (!wPreferences.disable_miniwindows && wwin->icon != NULL) {
1137 RemoveFromStackList(wwin->icon->core);
1138 /* removeIconGrabs(wwin->icon);*/
1139 wIconDestroy(wwin->icon);
1140 wwin->icon = NULL;
1142 XUngrabServer(dpy);
1144 if (wPreferences.focus_mode==WKF_CLICK)
1145 wSetFocusTo(wwin->screen_ptr, wwin);
1147 #ifdef ANIMATIONS
1148 if (!wwin->screen_ptr->flags.startup) {
1149 Window clientwin = wwin->client_win;
1151 XSync(dpy, 0);
1152 processEvents(XPending(dpy));
1154 if (!wWindowFor(clientwin))
1155 return;
1157 #endif
1159 if (wPreferences.auto_arrange_icons) {
1160 wArrangeIcons(wwin->screen_ptr, True);
1163 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1165 /* In case we were shaded and iconified, also unshade */
1166 wUnshadeWindow(wwin);
1171 static void
1172 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1174 if (wwin->flags.miniaturized) {
1175 if (wwin->icon) {
1176 XUnmapWindow(dpy, wwin->icon->core->window);
1177 wwin->icon->mapped = 0;
1179 wwin->flags.hidden = 1;
1181 WMPostNotificationName(WMNChangedState, wwin, "hide");
1182 return;
1185 if (wwin->flags.inspector_open) {
1186 wHideInspectorForWindow(wwin);
1189 wwin->flags.hidden = 1;
1190 wWindowUnmap(wwin);
1192 wClientSetState(wwin, IconicState, icon->icon_win);
1193 flushExpose();
1194 wSoundPlay(WSOUND_HIDE);
1195 #ifdef ANIMATIONS
1196 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1197 !wwin->flags.skip_next_animation && animate) {
1198 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1199 wwin->frame->core->width, wwin->frame->core->height,
1200 icon_x, icon_y, icon->core->width, icon->core->height,
1201 True);
1203 #endif
1204 wwin->flags.skip_next_animation = 0;
1206 WMPostNotificationName(WMNChangedState, wwin, "hide");
1211 void
1212 wHideOtherApplications(WWindow *awin)
1214 WWindow *wwin;
1215 WApplication *tapp;
1217 if (!awin)
1218 return;
1219 wwin = awin->screen_ptr->focused_window;
1222 while (wwin) {
1223 if (wwin!=awin
1224 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1225 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1226 && !wwin->flags.internal_window
1227 && wGetWindowOfInspectorForWindow(wwin) != awin
1228 && !WFLAGP(wwin, no_hide_others)) {
1230 if (wwin->main_window==None || WFLAGP(wwin, no_appicon)) {
1231 if (!WFLAGP(wwin, no_miniaturizable)) {
1232 wwin->flags.skip_next_animation = 1;
1233 wIconifyWindow(wwin);
1235 } else if (wwin->main_window!=None
1236 && awin->main_window != wwin->main_window) {
1237 tapp = wApplicationOf(wwin->main_window);
1238 if (tapp) {
1239 tapp->flags.skip_next_animation = 1;
1240 wHideApplication(tapp);
1241 } else {
1242 if (!WFLAGP(wwin, no_miniaturizable)) {
1243 wwin->flags.skip_next_animation = 1;
1244 wIconifyWindow(wwin);
1249 wwin = wwin->prev;
1252 wSetFocusTo(awin->screen_ptr, awin);
1258 void
1259 wHideApplication(WApplication *wapp)
1261 WScreen *scr;
1262 WWindow *wlist;
1263 int hadfocus;
1265 if (!wapp) {
1266 wwarning("trying to hide a non grouped window");
1267 return;
1269 if (!wapp->main_window_desc) {
1270 wwarning("group leader not found for window group");
1271 return;
1273 scr = wapp->main_window_desc->screen_ptr;
1274 hadfocus = 0;
1275 wlist = scr->focused_window;
1276 if (!wlist)
1277 return;
1279 if (wlist->main_window == wapp->main_window)
1280 wapp->last_focused = wlist;
1281 else
1282 wapp->last_focused = NULL;
1283 while (wlist) {
1284 if (wlist->main_window == wapp->main_window) {
1285 if (wlist->flags.focused) {
1286 hadfocus = 1;
1288 if (wapp->app_icon)
1289 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1290 wapp->app_icon->y_pos, wlist,
1291 !wapp->flags.skip_next_animation);
1293 wlist = wlist->prev;
1296 wapp->flags.skip_next_animation = 0;
1298 if (hadfocus) {
1299 if (wPreferences.focus_mode==WKF_CLICK) {
1300 wlist = scr->focused_window;
1301 while (wlist) {
1302 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1303 && (wlist->flags.mapped || wlist->flags.shaded))
1304 break;
1305 wlist = wlist->prev;
1307 wSetFocusTo(scr, wlist);
1308 } else {
1309 wSetFocusTo(scr, NULL);
1313 wapp->flags.hidden = 1;
1315 if(wPreferences.auto_arrange_icons) {
1316 wArrangeIcons(scr, True);
1318 #ifdef HIDDENDOT
1319 if (wapp->app_icon)
1320 wAppIconPaint(wapp->app_icon);
1321 #endif
1327 static void
1328 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1329 int bringToCurrentWS)
1331 if (bringToCurrentWS)
1332 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1334 wwin->flags.hidden=0;
1336 wSoundPlay(WSOUND_UNHIDE);
1337 #ifdef ANIMATIONS
1338 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1339 && animate) {
1340 animateResize(wwin->screen_ptr, icon_x, icon_y,
1341 icon->core->width, icon->core->height,
1342 wwin->frame_x, wwin->frame_y,
1343 wwin->frame->core->width, wwin->frame->core->height,
1344 True);
1346 #endif
1347 wwin->flags.skip_next_animation = 0;
1348 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1349 XMapWindow(dpy, wwin->client_win);
1350 XMapWindow(dpy, wwin->frame->core->window);
1351 wClientSetState(wwin, NormalState, None);
1352 wwin->flags.mapped=1;
1353 wRaiseFrame(wwin->frame->core);
1355 if (wwin->flags.inspector_open) {
1356 wUnhideInspectorForWindow(wwin);
1359 WMPostNotificationName(WMNChangedState, wwin, "hide");
1363 void
1364 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1366 WScreen *scr;
1367 WWindow *wlist, *next;
1368 WWindow *focused=NULL;
1370 if (!wapp) {
1371 return;
1373 scr = wapp->main_window_desc->screen_ptr;
1374 wlist = scr->focused_window;
1375 if (!wlist) return;
1376 /* goto beginning of list */
1377 while (wlist->prev)
1378 wlist = wlist->prev;
1380 while (wlist) {
1381 next = wlist->next;
1383 if (wlist->main_window == wapp->main_window) {
1384 if (wlist->flags.focused)
1385 focused = wlist;
1386 else if (!focused || !focused->flags.focused)
1387 focused = wlist;
1389 if (wlist->flags.miniaturized && wlist->icon) {
1390 if (bringToCurrentWS || wPreferences.sticky_icons
1391 || wlist->frame->workspace == scr->current_workspace) {
1392 if (!wlist->icon->mapped) {
1393 XMapWindow(dpy, wlist->icon->core->window);
1394 wlist->icon->mapped = 1;
1396 wlist->flags.hidden = 0;
1398 WMPostNotificationName(WMNChangedState, wlist, "hide");
1400 if (wlist->frame->workspace != scr->current_workspace)
1401 wWindowChangeWorkspace(wlist, scr->current_workspace);
1403 if (miniwindows) {
1404 wDeiconifyWindow(wlist);
1406 } else if (wlist->flags.hidden) {
1407 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1408 wapp->app_icon->y_pos, wlist,
1409 !wapp->flags.skip_next_animation,
1410 bringToCurrentWS);
1411 } else {
1412 if (bringToCurrentWS
1413 && wlist->frame->workspace != scr->current_workspace) {
1414 wWindowChangeWorkspace(wlist, scr->current_workspace);
1416 wRaiseFrame(wlist->frame->core);
1419 wlist = next;
1422 wapp->flags.skip_next_animation = 0;
1423 wapp->flags.hidden = 0;
1425 if (focused)
1426 wSetFocusTo(scr, focused);
1427 else if (wapp->last_focused && wapp->last_focused->flags.mapped)
1428 wSetFocusTo(scr, wapp->last_focused);
1429 wapp->last_focused = NULL;
1430 if (wPreferences.auto_arrange_icons) {
1431 wArrangeIcons(scr, True);
1433 #ifdef HIDDENDOT
1434 wAppIconPaint(wapp->app_icon);
1435 #endif
1440 void
1441 wShowAllWindows(WScreen *scr)
1443 WWindow *wwin, *old_foc;
1444 WApplication *wapp;
1446 old_foc = wwin = scr->focused_window;
1447 while (wwin) {
1448 if (!wwin->flags.internal_window &&
1449 (scr->current_workspace == wwin->frame->workspace
1450 || IS_OMNIPRESENT(wwin))) {
1451 if (wwin->flags.miniaturized) {
1452 wwin->flags.skip_next_animation = 1;
1453 wDeiconifyWindow(wwin);
1454 } else if (wwin->flags.hidden) {
1455 wapp = wApplicationOf(wwin->main_window);
1456 if (wapp) {
1457 wUnhideApplication(wapp, False, False);
1458 } else {
1459 wwin->flags.skip_next_animation = 1;
1460 wDeiconifyWindow(wwin);
1464 wwin = wwin->prev;
1466 wSetFocusTo(scr, old_foc);
1467 /*wRaiseFrame(old_foc->frame->core);*/
1471 void
1472 wRefreshDesktop(WScreen *scr)
1474 Window win;
1475 XSetWindowAttributes attr;
1477 attr.backing_store = NotUseful;
1478 attr.save_under = False;
1479 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1480 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1481 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1482 &attr);
1483 XMapRaised(dpy, win);
1484 XDestroyWindow(dpy, win);
1485 XFlush(dpy);
1489 void
1490 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1492 WWindow *wwin;
1493 WAppIcon *aicon;
1494 int pf; /* primary axis */
1495 int sf; /* secondary axis */
1496 int fullW;
1497 int fullH;
1498 int pi, si;
1499 int sx1, sx2, sy1, sy2; /* screen boundary */
1500 int sw, sh;
1501 int xo, yo;
1502 int xs, ys;
1503 int isize = wPreferences.icon_size;
1506 * Find out screen boundaries.
1510 * Allows each head to have miniwindows
1512 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1514 sx1 = rect.pos.x;
1515 sy1 = rect.pos.y;
1516 sw = rect.size.width;
1517 sh = rect.size.height;
1518 sx2 = sx1 + sw;
1519 sy2 = sy1 + sh;
1520 if (scr->dock) {
1521 if (scr->dock->on_right_side)
1522 sx2 -= isize + DOCK_EXTRA_SPACE;
1523 else
1524 sx1 += isize + DOCK_EXTRA_SPACE;
1527 #if 0
1528 sw = isize * (scr->scr_width/isize);
1529 sh = isize * (scr->scr_height/isize);
1530 #else
1531 sw = isize * (sw/isize);
1532 sh = isize * (sh/isize);
1533 #endif
1534 fullW = (sx2-sx1)/isize;
1535 fullW = (sx2-sx1)/isize;
1536 fullH = (sy2-sy1)/isize;
1538 /* icon yard boundaries */
1539 if (wPreferences.icon_yard & IY_VERT) {
1540 pf = fullH;
1541 sf = fullW;
1542 } else {
1543 pf = fullW;
1544 sf = fullH;
1546 if (wPreferences.icon_yard & IY_RIGHT) {
1547 xo = sx2 - isize;
1548 xs = -1;
1549 } else {
1550 xo = sx1;
1551 xs = 1;
1553 if (wPreferences.icon_yard & IY_TOP) {
1554 yo = sy1;
1555 ys = 1;
1556 } else {
1557 yo = sy2 - isize;
1558 ys = -1;
1561 /* arrange icons putting the most recently focused window
1562 * as the last icon */
1563 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1564 : xo + xs*(pi*isize))
1565 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1566 : yo + ys*(si*isize))
1568 /* arrange application icons */
1569 aicon = scr->app_icon_list;
1570 /* reverse them to avoid unnecessarily sliding of icons */
1571 while (aicon && aicon->next)
1572 aicon = aicon->next;
1574 pi = 0;
1575 si = 0;
1576 while (aicon) {
1577 if (!aicon->docked) {
1578 if (aicon->x_pos != X || aicon->y_pos != Y) {
1579 #ifdef ANIMATIONS
1580 if (!wPreferences.no_animations) {
1581 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1582 X, Y);
1584 #endif /* ANIMATIONS */
1586 wAppIconMove(aicon, X, Y);
1587 pi++;
1589 /* we reversed the order so we use prev */
1590 aicon = aicon->prev;
1591 if (pi >= pf) {
1592 pi=0;
1593 si++;
1597 /* arrange miniwindows */
1599 wwin = scr->focused_window;
1600 /* reverse them to avoid unnecessarily shuffling */
1601 while (wwin && wwin->prev)
1602 wwin = wwin->prev;
1604 while (wwin) {
1605 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1606 (wwin->frame->workspace==scr->current_workspace ||
1607 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1609 if (arrangeAll || !wwin->flags.icon_moved) {
1610 if (wwin->icon_x != X || wwin->icon_y != Y) {
1611 #ifdef ANIMATIONS
1612 if (wPreferences.no_animations) {
1613 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1614 } else {
1615 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1616 wwin->icon_y, X, Y);
1618 #else
1619 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1620 #endif /* ANIMATIONS */
1622 wwin->icon_x = X;
1623 wwin->icon_y = Y;
1624 pi++;
1627 if (arrangeAll) {
1628 wwin->flags.icon_moved = 0;
1630 /* we reversed the order, so we use next */
1631 wwin = wwin->next;
1632 if (pi >= pf) {
1633 pi=0;
1634 si++;
1640 void
1641 wSelectWindow(WWindow *wwin, Bool flag)
1643 WScreen *scr = wwin->screen_ptr;
1645 if (flag) {
1646 wwin->flags.selected = 1;
1647 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1649 if (WFLAGP(wwin, no_border)) {
1650 XSetWindowBorderWidth(dpy, wwin->frame->core->window,
1651 FRAME_BORDER_WIDTH);
1654 if (!scr->selected_windows)
1655 scr->selected_windows = WMCreateArray(4);
1656 WMAddToArray(scr->selected_windows, wwin);
1657 } else {
1658 wwin->flags.selected = 0;
1659 XSetWindowBorder(dpy, wwin->frame->core->window,
1660 scr->frame_border_pixel);
1662 if (WFLAGP(wwin, no_border)) {
1663 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1666 if (scr->selected_windows) {
1667 WMRemoveFromArray(scr->selected_windows, wwin);
1673 void
1674 wMakeWindowVisible(WWindow *wwin)
1676 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1677 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1679 if (wwin->flags.shaded) {
1680 wUnshadeWindow(wwin);
1682 if (wwin->flags.hidden) {
1683 WApplication *app;
1685 app = wApplicationOf(wwin->main_window);
1686 if (app)
1687 wUnhideApplication(app, False, False);
1688 } else if (wwin->flags.miniaturized) {
1689 wDeiconifyWindow(wwin);
1690 } else {
1691 if (!WFLAGP(wwin, no_focusable))
1692 wSetFocusTo(wwin->screen_ptr, wwin);
1693 wRaiseFrame(wwin->frame->core);