- Made dock/clip steal appicons of applications that were started from a
[wmaker-crm.git] / src / actions.c
blobc19f805cc2bf484d446eb9d4898c02430b5fc083
1 /* action.c- misc. window commands (miniaturize, hide etc.)
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998, 1999 Alfredo K. Kojima
6 * Copyright (c) 1998 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"
52 #ifdef GNOME_STUFF
53 # include "gnome.h"
54 #endif
55 #ifdef KWM_HINTS
56 # include "kwm.h"
57 #endif
61 /****** Global Variables ******/
62 extern Time LastTimestamp;
63 extern Time LastFocusChange;
65 extern Cursor wCursor[WCUR_LAST];
67 extern WPreferences wPreferences;
69 extern Atom _XA_WM_TAKE_FOCUS;
72 /******* Local Variables *******/
73 static struct {
74 int steps;
75 int delay;
76 } shadePars[5] = {
77 {SHADE_STEPS_UF, SHADE_DELAY_UF},
78 {SHADE_STEPS_F, SHADE_DELAY_F},
79 {SHADE_STEPS_M, SHADE_DELAY_M},
80 {SHADE_STEPS_S, SHADE_DELAY_S},
81 {SHADE_STEPS_US, SHADE_DELAY_US}};
83 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
84 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
87 static int ignoreTimestamp=0;
90 #ifdef ANIMATIONS
91 static void
92 processEvents(int event_count)
94 XEvent event;
97 * This is a hack. When animations are enabled, processing of
98 * events ocurred during a animation are delayed until it's end.
99 * Calls that consider the TimeStamp, like XSetInputFocus(), will
100 * fail because the TimeStamp is too old. Then, for example, if
101 * the user changes window focus while a miniaturize animation is
102 * in course, the window will not get focus properly after the end
103 * of the animation. This tries to workaround it by passing CurrentTime
104 * as the TimeStamp for XSetInputFocus() for all events ocurred during
105 * the animation.
107 ignoreTimestamp=1;
108 while (XPending(dpy) && event_count--) {
109 WMNextEvent(dpy, &event);
110 WMHandleEvent(&event);
112 ignoreTimestamp=0;
114 #endif /* ANIMATIONS */
119 *----------------------------------------------------------------------
120 * wSetFocusTo--
121 * Changes the window focus to the one passed as argument.
122 * If the window to focus is not already focused, it will be brought
123 * to the head of the list of windows. Previously focused window is
124 * unfocused.
126 * Side effects:
127 * Window list may be reordered and the window focus is changed.
129 *----------------------------------------------------------------------
131 void
132 wSetFocusTo(WScreen *scr, WWindow *wwin)
134 static WScreen *old_scr=NULL;
136 WWindow *old_focused;
137 WWindow *focused=scr->focused_window;
138 int timestamp=LastTimestamp;
139 WApplication *oapp=NULL, *napp=NULL;
140 int wasfocused;
142 if (!old_scr)
143 old_scr=scr;
144 old_focused=old_scr->focused_window;
146 LastFocusChange = timestamp;
149 * This is a hack, because XSetInputFocus() should have a proper
150 * timestamp instead of CurrentTime but it seems that some times
151 * clients will not receive focus properly that way.
152 if (ignoreTimestamp)
154 timestamp = CurrentTime;
156 if (old_focused)
157 oapp = wApplicationOf(old_focused->main_window);
159 if (wwin == NULL) {
160 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
161 if (old_focused) {
162 wWindowUnfocus(old_focused);
164 if (oapp) {
165 wAppMenuUnmap(oapp->menu);
166 #ifdef NEWAPPICON
167 wApplicationDeactivate(oapp);
168 #endif
171 WMPostNotificationName(WMNChangedFocus, NULL, (void*)True);
172 return;
173 } else if (old_scr != scr && old_focused) {
174 wWindowUnfocus(old_focused);
177 wasfocused = wwin->flags.focused;
178 napp = wApplicationOf(wwin->main_window);
180 /* remember last workspace where the app has been */
181 if (napp)
182 napp->last_workspace = wwin->screen_ptr->current_workspace;
184 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
185 /* install colormap if colormap mode is lock mode */
186 if (wPreferences.colormap_mode==WCM_CLICK)
187 wColormapInstallForWindow(scr, wwin);
189 /* set input focus */
190 switch (wwin->focus_mode) {
191 case WFM_NO_INPUT:
192 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
193 break;
195 case WFM_PASSIVE:
196 case WFM_LOCALLY_ACTIVE:
197 XSetInputFocus(dpy, wwin->client_win, RevertToParent, timestamp);
198 break;
200 case WFM_GLOBALLY_ACTIVE:
201 break;
203 XFlush(dpy);
204 if (wwin->protocols.TAKE_FOCUS) {
205 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
207 XSync(dpy, False);
208 } else {
209 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
211 if (WFLAGP(wwin, no_focusable))
212 return;
214 /* if this is not the focused window focus it */
215 if (focused!=wwin) {
216 /* change the focus window list order */
217 if (wwin->prev)
218 wwin->prev->next = wwin->next;
220 if (wwin->next)
221 wwin->next->prev = wwin->prev;
223 wwin->prev = focused;
224 focused->next = wwin;
225 wwin->next = NULL;
226 scr->focused_window = wwin;
228 if (oapp && oapp != napp) {
229 wAppMenuUnmap(oapp->menu);
230 #ifdef NEWAPPICON
231 wApplicationDeactivate(oapp);
232 #endif
236 wWindowFocus(wwin, focused);
238 if (napp && !wasfocused) {
239 #ifdef USER_MENU
240 wUserMenuRefreshInstances(napp->menu, wwin);
241 #endif /* USER_MENU */
243 if (wwin->flags.mapped)
244 wAppMenuMap(napp->menu, wwin);
245 #ifdef NEWAPPICON
246 wApplicationActivate(napp);
247 #endif
250 XFlush(dpy);
251 old_scr=scr;
255 void
256 wShadeWindow(WWindow *wwin)
258 time_t time0;
259 #ifdef ANIMATIONS
260 int y, s, w, h;
261 #endif
263 if (wwin->flags.shaded)
264 return;
266 time0 = time(NULL);
268 XLowerWindow(dpy, wwin->client_win);
270 wSoundPlay(WSOUND_SHADE);
272 #ifdef ANIMATIONS
273 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
274 && !wPreferences.no_animations) {
275 /* do the shading animation */
276 h = wwin->frame->core->height;
277 s = h/SHADE_STEPS;
278 if (s < 1) s=1;
279 w = wwin->frame->core->width;
280 y = wwin->frame->top_width;
281 while (h>wwin->frame->top_width+1) {
282 XMoveWindow(dpy, wwin->client_win, 0, y);
283 XResizeWindow(dpy, wwin->frame->core->window, w, h);
284 XFlush(dpy);
286 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
287 break;
289 if (SHADE_DELAY > 0) {
290 wusleep(SHADE_DELAY*1000L);
291 } else {
292 wusleep(10);
294 h-=s;
295 y-=s;
297 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
299 #endif /* ANIMATIONS */
301 wwin->flags.skip_next_animation = 0;
302 wwin->flags.shaded = 1;
303 wwin->flags.mapped = 0;
304 /* prevent window withdrawal when getting UnmapNotify */
305 XSelectInput(dpy, wwin->client_win,
306 wwin->event_mask & ~StructureNotifyMask);
307 XUnmapWindow(dpy, wwin->client_win);
308 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
310 /* for the client it's just like iconification */
311 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
312 wwin->frame->top_width - 1);
314 wwin->client.y = wwin->frame_y - wwin->client.height
315 + wwin->frame->top_width;
316 wWindowSynthConfigureNotify(wwin);
319 wClientSetState(wwin, IconicState, None);
322 WMPostNotificationName(WMNChangedState, wwin, "shade");
324 #ifdef ANIMATIONS
325 if (!wwin->screen_ptr->flags.startup) {
326 /* Look at processEvents() for reason of this code. */
327 XSync(dpy, 0);
328 processEvents(XPending(dpy));
330 #endif
334 void
335 wUnshadeWindow(WWindow *wwin)
337 time_t time0;
338 #ifdef ANIMATIONS
339 int y, s, w, h;
340 #endif /* ANIMATIONS */
343 if (!wwin->flags.shaded)
344 return;
346 time0 = time(NULL);
348 wwin->flags.shaded = 0;
349 wwin->flags.mapped = 1;
350 XMapWindow(dpy, wwin->client_win);
352 wSoundPlay(WSOUND_UNSHADE);
354 #ifdef ANIMATIONS
355 if (!wPreferences.no_animations && !wwin->flags.skip_next_animation) {
356 /* do the shading animation */
357 h = wwin->frame->top_width + wwin->frame->bottom_width;
358 y = wwin->frame->top_width - wwin->client.height;
359 s = abs(y)/SHADE_STEPS;
360 if (s<1) s=1;
361 w = wwin->frame->core->width;
362 XMoveWindow(dpy, wwin->client_win, 0, y);
363 if (s>0) {
364 while (h < wwin->client.height + wwin->frame->top_width
365 + wwin->frame->bottom_width) {
366 XResizeWindow(dpy, wwin->frame->core->window, w, h);
367 XMoveWindow(dpy, wwin->client_win, 0, y);
368 XFlush(dpy);
369 if (SHADE_DELAY > 0) {
370 wusleep(SHADE_DELAY*2000L/3);
371 } else {
372 wusleep(10);
374 h+=s;
375 y+=s;
377 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
378 break;
381 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
383 #endif /* ANIMATIONS */
385 wwin->flags.skip_next_animation = 0;
386 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
387 wwin->frame->top_width + wwin->client.height
388 + wwin->frame->bottom_width);
390 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
391 wWindowSynthConfigureNotify(wwin);
394 wClientSetState(wwin, NormalState, None);
396 /* if the window is focused, set the focus again as it was disabled during
397 * shading */
398 if (wwin->flags.focused)
399 wSetFocusTo(wwin->screen_ptr, wwin);
401 WMPostNotificationName(WMNChangedState, wwin, "shade");
405 void
406 wMaximizeWindow(WWindow *wwin, int directions)
408 int new_width, new_height, new_x, new_y;
409 WArea usableArea = wwin->screen_ptr->totalUsableArea;
410 WArea totalArea;
413 if (WFLAGP(wwin, no_resizable))
414 return;
416 totalArea.x1 = 0;
417 totalArea.y1 = 0;
418 totalArea.x2 = wwin->screen_ptr->scr_width;
419 totalArea.y2 = wwin->screen_ptr->scr_height;
421 #ifdef XINERAMA
422 if (wwin->screen_ptr->xine_count > 0
423 && !(directions & MAX_IGNORE_XINERAMA)) {
424 WScreen *scr = wwin->screen_ptr;
425 WMRect rect;
427 rect = wGetRectForHead(scr, wGetHeadForWindow(wwin));
428 totalArea.x1 = rect.pos.x;
429 totalArea.y1 = rect.pos.y;
430 totalArea.x2 = totalArea.x1 + rect.size.width;
431 totalArea.y2 = totalArea.y1 + rect.size.height;
433 usableArea.x1 = WMAX(totalArea.x1, usableArea.x1);
434 usableArea.y1 = WMAX(totalArea.y1, usableArea.y1);
435 usableArea.x2 = WMIN(totalArea.x2, usableArea.x2);
436 usableArea.y2 = WMIN(totalArea.y2, usableArea.y2);
438 #endif /* XINERAMA */
440 if (WFLAGP(wwin, full_maximize)) {
441 usableArea = totalArea;
444 if (wwin->flags.shaded) {
445 wwin->flags.skip_next_animation = 1;
446 wUnshadeWindow(wwin);
448 wwin->flags.maximized = directions;
449 wwin->old_geometry.width = wwin->client.width;
450 wwin->old_geometry.height = wwin->client.height;
451 wwin->old_geometry.x = wwin->frame_x;
452 wwin->old_geometry.y = wwin->frame_y;
454 #ifdef KWM_HINTS
455 wKWMUpdateClientGeometryRestore(wwin);
456 #endif
458 if (directions & MAX_HORIZONTAL) {
460 new_width = (usableArea.x2-usableArea.x1)-FRAME_BORDER_WIDTH*2;
461 new_x = usableArea.x1;
463 } else {
465 new_x = wwin->frame_x;
466 new_width = wwin->frame->core->width;
470 if (directions & MAX_VERTICAL) {
472 new_height = (usableArea.y2-usableArea.y1)-FRAME_BORDER_WIDTH*2;
473 new_y = usableArea.y1;
474 if (WFLAGP(wwin, full_maximize)) {
475 new_y -= wwin->frame->top_width;
476 new_height += wwin->frame->bottom_width - 1;
478 } else {
479 new_y = wwin->frame_y;
480 new_height = wwin->frame->core->height;
483 if (!WFLAGP(wwin, full_maximize)) {
484 new_height -= wwin->frame->top_width+wwin->frame->bottom_width;
487 wWindowConstrainSize(wwin, &new_width, &new_height);
489 wWindowCropSize(wwin, usableArea.x2-usableArea.x1,
490 usableArea.y2-usableArea.y1,
491 &new_width, &new_height);
493 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
496 WMPostNotificationName(WMNChangedState, wwin, "maximize");
498 wSoundPlay(WSOUND_MAXIMIZE);
502 void
503 wUnmaximizeWindow(WWindow *wwin)
505 int restore_x, restore_y;
507 if (!wwin->flags.maximized)
508 return;
510 if (wwin->flags.shaded) {
511 wwin->flags.skip_next_animation = 1;
512 wUnshadeWindow(wwin);
514 restore_x = (wwin->flags.maximized & MAX_HORIZONTAL) ?
515 wwin->old_geometry.x : wwin->frame_x;
516 restore_y = (wwin->flags.maximized & MAX_VERTICAL) ?
517 wwin->old_geometry.y : wwin->frame_y;
518 wwin->flags.maximized = 0;
519 wWindowConfigure(wwin, restore_x, restore_y,
520 wwin->old_geometry.width, wwin->old_geometry.height);
522 WMPostNotificationName(WMNChangedState, wwin, "maximize");
524 wSoundPlay(WSOUND_UNMAXIMIZE);
527 #ifdef ANIMATIONS
528 static void
529 animateResizeFlip(WScreen *scr, int x, int y, int w, int h,
530 int fx, int fy, int fw, int fh, int steps)
532 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
533 float cx, cy, cw, ch;
534 float xstep, ystep, wstep, hstep;
535 XPoint points[5];
536 float dx, dch, midy;
537 float angle, final_angle, delta;
539 xstep = (float)(fx-x)/steps;
540 ystep = (float)(fy-y)/steps;
541 wstep = (float)(fw-w)/steps;
542 hstep = (float)(fh-h)/steps;
544 cx = (float)x;
545 cy = (float)y;
546 cw = (float)w;
547 ch = (float)h;
549 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_F;
550 delta = (float)(final_angle/FRAMES);
551 for (angle=0;; angle+=delta) {
552 if (angle > final_angle)
553 angle = final_angle;
555 dx = (cw/10) - ((cw/5) * sin(angle));
556 dch = (ch/2) * cos(angle);
557 midy = cy + (ch/2);
559 points[0].x = cx + dx; points[0].y = midy - dch;
560 points[1].x = cx + cw - dx; points[1].y = points[0].y;
561 points[2].x = cx + cw + dx; points[2].y = midy + dch;
562 points[3].x = cx - dx; points[3].y = points[2].y;
563 points[4].x = points[0].x; points[4].y = points[0].y;
565 XGrabServer(dpy);
566 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
567 XFlush(dpy);
568 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
569 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
570 #else
571 wusleep(10);
572 #endif
574 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
575 XUngrabServer(dpy);
576 cx+=xstep;
577 cy+=ystep;
578 cw+=wstep;
579 ch+=hstep;
580 if (angle >= final_angle)
581 break;
584 XFlush(dpy);
586 #undef FRAMES
589 static void
590 animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
591 int fx, int fy, int fw, int fh, int steps)
593 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
594 float cx, cy, cw, ch;
595 float xstep, ystep, wstep, hstep;
596 XPoint points[5];
597 float angle, final_angle, a, d, delta;
599 x += w/2;
600 y += h/2;
601 fx += fw/2;
602 fy += fh/2;
604 xstep = (float)(fx-x)/steps;
605 ystep = (float)(fy-y)/steps;
606 wstep = (float)(fw-w)/steps;
607 hstep = (float)(fh-h)/steps;
609 cx = (float)x;
610 cy = (float)y;
611 cw = (float)w;
612 ch = (float)h;
614 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
615 delta = (float)(final_angle/FRAMES);
616 for (angle=0;; angle+=delta) {
617 if (angle > final_angle)
618 angle = final_angle;
620 a = atan(ch/cw);
621 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
623 points[0].x = cx+cos(angle-a)*d;
624 points[0].y = cy+sin(angle-a)*d;
625 points[1].x = cx+cos(angle+a)*d;
626 points[1].y = cy+sin(angle+a)*d;
627 points[2].x = cx+cos(angle-a+WM_PI)*d;
628 points[2].y = cy+sin(angle-a+WM_PI)*d;
629 points[3].x = cx+cos(angle+a+WM_PI)*d;
630 points[3].y = cy+sin(angle+a+WM_PI)*d;
631 points[4].x = cx+cos(angle-a)*d;
632 points[4].y = cy+sin(angle-a)*d;
633 XGrabServer(dpy);
634 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
635 XFlush(dpy);
636 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
637 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
638 #else
639 wusleep(10);
640 #endif
642 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
643 XUngrabServer(dpy);
644 cx+=xstep;
645 cy+=ystep;
646 cw+=wstep;
647 ch+=hstep;
648 if (angle >= final_angle)
649 break;
652 XFlush(dpy);
654 #undef FRAMES
657 static void
658 animateResizeZoom(WScreen *scr, int x, int y, int w, int h,
659 int fx, int fy, int fw, int fh, int steps)
661 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
662 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
663 float xstep, ystep, wstep, hstep;
664 int i, j;
666 xstep = (float)(fx-x)/steps;
667 ystep = (float)(fy-y)/steps;
668 wstep = (float)(fw-w)/steps;
669 hstep = (float)(fh-h)/steps;
671 for (j=0; j<FRAMES; j++) {
672 cx[j] = (float)x;
673 cy[j] = (float)y;
674 cw[j] = (float)w;
675 ch[j] = (float)h;
677 XGrabServer(dpy);
678 for (i=0; i<steps; i++) {
679 for (j=0; j<FRAMES; j++) {
680 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
681 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
683 XFlush(dpy);
684 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
685 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
686 #else
687 wusleep(10);
688 #endif
689 for (j=0; j<FRAMES; j++) {
690 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
691 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
692 if (j<FRAMES-1) {
693 cx[j]=cx[j+1];
694 cy[j]=cy[j+1];
695 cw[j]=cw[j+1];
696 ch[j]=ch[j+1];
697 } else {
698 cx[j]+=xstep;
699 cy[j]+=ystep;
700 cw[j]+=wstep;
701 ch[j]+=hstep;
706 for (j=0; j<FRAMES; j++) {
707 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
708 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
710 XFlush(dpy);
711 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
712 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
713 #else
714 wusleep(10);
715 #endif
716 for (j=0; j<FRAMES; j++) {
717 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
718 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
721 XUngrabServer(dpy);
723 #undef FRAMES
726 void
727 animateResize(WScreen *scr, int x, int y, int w, int h,
728 int fx, int fy, int fw, int fh, int hiding)
730 int style = wPreferences.iconification_style; /* Catch the value */
731 int steps, k;
733 if (style == WIS_NONE)
734 return;
736 if (style == WIS_RANDOM) {
737 style = rand()%3;
740 k = (hiding ? 2 : 3);
741 switch(style) {
742 case WIS_TWIST:
743 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
744 if (steps>0)
745 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
746 break;
747 case WIS_FLIP:
748 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
749 if (steps>0)
750 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
751 break;
752 case WIS_ZOOM:
753 default:
754 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
755 if (steps>0)
756 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
757 break;
760 #endif /* ANIMATIONS */
763 static void
764 flushExpose()
766 XEvent tmpev;
768 while (XCheckTypedEvent(dpy, Expose, &tmpev))
769 WMHandleEvent(&tmpev);
770 XSync(dpy, 0);
773 static void
774 unmapTransientsFor(WWindow *wwin)
776 WWindow *tmp;
779 tmp = wwin->screen_ptr->focused_window;
780 while (tmp) {
781 /* unmap the transients for this transient */
782 if (tmp!=wwin && tmp->transient_for == wwin->client_win
783 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
784 || tmp->flags.shaded)) {
785 unmapTransientsFor(tmp);
786 tmp->flags.miniaturized = 1;
787 if (!tmp->flags.shaded) {
788 wWindowUnmap(tmp);
789 } else {
790 XUnmapWindow(dpy, tmp->frame->core->window);
793 if (!tmp->flags.shaded)
795 wClientSetState(tmp, IconicState, None);
797 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
799 tmp = tmp->prev;
804 static void
805 mapTransientsFor(WWindow *wwin)
807 WWindow *tmp;
809 tmp = wwin->screen_ptr->focused_window;
810 while (tmp) {
811 /* recursively map the transients for this transient */
812 if (tmp!=wwin && tmp->transient_for == wwin->client_win
813 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
814 && tmp->icon==NULL) {
815 mapTransientsFor(tmp);
816 tmp->flags.miniaturized = 0;
817 if (!tmp->flags.shaded) {
818 wWindowMap(tmp);
819 } else {
820 XMapWindow(dpy, tmp->frame->core->window);
822 tmp->flags.semi_focused = 0;
824 if (!tmp->flags.shaded)
826 wClientSetState(tmp, NormalState, None);
828 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
830 tmp = tmp->prev;
834 #if 0
835 static void
836 setupIconGrabs(WIcon *icon)
838 /* setup passive grabs on the icon */
839 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
840 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
841 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
842 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
843 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
844 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
845 XSync(dpy, 0);
847 #endif
849 static WWindow*
850 recursiveTransientFor(WWindow *wwin)
852 int i;
854 if (!wwin)
855 return None;
857 /* hackish way to detect transient_for cycle */
858 i = wwin->screen_ptr->window_count+1;
860 while (wwin && wwin->transient_for != None && i>0) {
861 wwin = wWindowFor(wwin->transient_for);
862 i--;
864 if (i==0 && wwin) {
865 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
866 wwin->frame->title);
867 return NULL;
870 return wwin;
873 #if 0
874 static void
875 removeIconGrabs(WIcon *icon)
877 /* remove passive grabs on the icon */
878 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
879 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
880 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
881 XSync(dpy, 0);
883 #endif
886 void
887 wIconifyWindow(WWindow *wwin)
889 XWindowAttributes attribs;
890 int present;
893 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
894 /* the window doesn't exist anymore */
895 return;
898 if (wwin->flags.miniaturized) {
899 return;
903 if (wwin->transient_for!=None) {
904 WWindow *owner = wWindowFor(wwin->transient_for);
906 if (owner && owner->flags.miniaturized)
907 return;
910 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
912 /* if the window is in another workspace, simplify process */
913 if (present) {
914 /* icon creation may take a while */
915 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
916 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
917 GrabModeAsync, None, None, CurrentTime);
920 if (!wPreferences.disable_miniwindows) {
921 if (!wwin->flags.icon_moved) {
922 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y);
924 wwin->icon = wIconCreate(wwin);
926 wwin->icon->mapped = 1;
929 wwin->flags.miniaturized = 1;
930 wwin->flags.mapped = 0;
932 /* unmap transients */
934 unmapTransientsFor(wwin);
936 if (present) {
937 wSoundPlay(WSOUND_ICONIFY);
939 XUngrabPointer(dpy, CurrentTime);
940 wWindowUnmap(wwin);
941 /* let all Expose events arrive so that we can repaint
942 * something before the animation starts (and the server is grabbed) */
943 XSync(dpy, 0);
945 if (wPreferences.disable_miniwindows)
946 wClientSetState(wwin, IconicState, None);
947 else
948 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
950 flushExpose();
951 #ifdef ANIMATIONS
952 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
953 && !wPreferences.no_animations) {
954 int ix, iy, iw, ih;
956 if (!wPreferences.disable_miniwindows) {
957 ix = wwin->icon_x;
958 iy = wwin->icon_y;
959 iw = wwin->icon->core->width;
960 ih = wwin->icon->core->height;
961 } else {
962 #ifdef KWM_HINTS
963 WArea area;
965 if (wKWMGetIconGeometry(wwin, &area)) {
966 ix = area.x1;
967 iy = area.y1;
968 iw = area.x2 - ix;
969 ih = area.y2 - iy;
970 } else
971 #endif /* KWM_HINTS */
973 ix = 0;
974 iy = 0;
975 iw = wwin->screen_ptr->scr_width;
976 ih = wwin->screen_ptr->scr_height;
979 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
980 wwin->frame->core->width, wwin->frame->core->height,
981 ix, iy, iw, ih, False);
983 #endif
986 wwin->flags.skip_next_animation = 0;
988 if (!wPreferences.disable_miniwindows) {
990 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
991 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
993 XMapWindow(dpy, wwin->icon->core->window);
995 AddToStackList(wwin->icon->core);
997 wLowerFrame(wwin->icon->core);
1000 if (present) {
1001 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1004 * It doesn't seem to be working and causes button event hangup
1005 * when deiconifying a transient window.
1006 setupIconGrabs(wwin->icon);
1008 if ((wwin->flags.focused
1009 || (owner && wwin->client_win == owner->client_win))
1010 && wPreferences.focus_mode==WKF_CLICK) {
1011 WWindow *tmp;
1013 tmp = wwin->prev;
1014 while (tmp) {
1015 if (!WFLAGP(tmp, no_focusable)
1016 && !(tmp->flags.hidden||tmp->flags.miniaturized)
1017 && (wwin->frame->workspace == tmp->frame->workspace))
1018 break;
1019 tmp = tmp->prev;
1021 wSetFocusTo(wwin->screen_ptr, tmp);
1022 } else if (wPreferences.focus_mode!=WKF_CLICK) {
1023 wSetFocusTo(wwin->screen_ptr, NULL);
1026 #ifdef ANIMATIONS
1027 if (!wwin->screen_ptr->flags.startup) {
1028 Window clientwin = wwin->client_win;
1030 XSync(dpy, 0);
1031 processEvents(XPending(dpy));
1033 /* the window can disappear while doing the processEvents() */
1034 if (!wWindowFor(clientwin))
1035 return;
1037 #endif
1041 if (wwin->flags.selected && !wPreferences.disable_miniwindows)
1042 wIconSelect(wwin->icon);
1044 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1050 void
1051 wDeiconifyWindow(WWindow *wwin)
1053 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1055 if (!wwin->flags.miniaturized)
1056 return;
1058 if (wwin->transient_for != None
1059 && wwin->transient_for != wwin->screen_ptr->root_win) {
1060 WWindow *owner = recursiveTransientFor(wwin);
1062 if (owner && owner->flags.miniaturized) {
1063 wDeiconifyWindow(owner);
1064 wSetFocusTo(wwin->screen_ptr, wwin);
1065 wRaiseFrame(wwin->frame->core);
1066 return;
1070 wwin->flags.miniaturized = 0;
1071 if (!wwin->flags.shaded)
1072 wwin->flags.mapped = 1;
1074 if (!wPreferences.disable_miniwindows) {
1075 if (wwin->icon->selected)
1076 wIconSelect(wwin->icon);
1078 XUnmapWindow(dpy, wwin->icon->core->window);
1081 wSoundPlay(WSOUND_DEICONIFY);
1083 /* if the window is in another workspace, do it silently */
1084 #ifdef ANIMATIONS
1085 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1086 && !wwin->flags.skip_next_animation) {
1087 int ix, iy, iw, ih;
1089 if (!wPreferences.disable_miniwindows) {
1090 ix = wwin->icon_x;
1091 iy = wwin->icon_y;
1092 iw = wwin->icon->core->width;
1093 ih = wwin->icon->core->height;
1094 } else {
1095 #ifdef KWM_HINTS
1096 WArea area;
1098 if (wKWMGetIconGeometry(wwin, &area)) {
1099 ix = area.x1;
1100 iy = area.y1;
1101 iw = area.x2 - ix;
1102 ih = area.y2 - iy;
1103 } else
1104 #endif /* KWM_HINTS */
1106 ix = 0;
1107 iy = 0;
1108 iw = wwin->screen_ptr->scr_width;
1109 ih = wwin->screen_ptr->scr_height;
1112 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1113 wwin->frame_x, wwin->frame_y,
1114 wwin->frame->core->width, wwin->frame->core->height,
1115 False);
1117 #endif /* ANIMATIONS */
1118 wwin->flags.skip_next_animation = 0;
1119 XGrabServer(dpy);
1120 if (!wwin->flags.shaded) {
1121 XMapWindow(dpy, wwin->client_win);
1123 XMapWindow(dpy, wwin->frame->core->window);
1124 wRaiseFrame(wwin->frame->core);
1125 if (!wwin->flags.shaded) {
1126 wClientSetState(wwin, NormalState, None);
1128 mapTransientsFor(wwin);
1130 if (!wPreferences.disable_miniwindows) {
1131 RemoveFromStackList(wwin->icon->core);
1132 /* removeIconGrabs(wwin->icon);*/
1133 wIconDestroy(wwin->icon);
1134 wwin->icon = NULL;
1136 XUngrabServer(dpy);
1138 if (wPreferences.focus_mode==WKF_CLICK)
1139 wSetFocusTo(wwin->screen_ptr, wwin);
1141 #ifdef ANIMATIONS
1142 if (!wwin->screen_ptr->flags.startup) {
1143 Window clientwin = wwin->client_win;
1145 XSync(dpy, 0);
1146 processEvents(XPending(dpy));
1148 if (!wWindowFor(clientwin))
1149 return;
1151 #endif
1153 if (wPreferences.auto_arrange_icons) {
1154 wArrangeIcons(wwin->screen_ptr, True);
1157 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1159 /* In case we were shaded and iconified, also unshade */
1160 wUnshadeWindow(wwin);
1165 static void
1166 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1168 if (wwin->flags.miniaturized) {
1169 if (wwin->icon) {
1170 XUnmapWindow(dpy, wwin->icon->core->window);
1171 wwin->icon->mapped = 0;
1173 wwin->flags.hidden = 1;
1175 WMPostNotificationName(WMNChangedState, wwin, "hide");
1176 return;
1179 if (wwin->flags.inspector_open) {
1180 wHideInspectorForWindow(wwin);
1183 wwin->flags.hidden = 1;
1184 wWindowUnmap(wwin);
1186 wClientSetState(wwin, IconicState, icon->icon_win);
1187 flushExpose();
1188 wSoundPlay(WSOUND_HIDE);
1189 #ifdef ANIMATIONS
1190 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1191 !wwin->flags.skip_next_animation && animate) {
1192 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1193 wwin->frame->core->width, wwin->frame->core->height,
1194 icon_x, icon_y, icon->core->width, icon->core->height,
1195 True);
1197 #endif
1198 wwin->flags.skip_next_animation = 0;
1200 WMPostNotificationName(WMNChangedState, wwin, "hide");
1205 void
1206 wHideOtherApplications(WWindow *awin)
1208 WWindow *wwin;
1209 WApplication *tapp;
1211 if (!awin)
1212 return;
1213 wwin = awin->screen_ptr->focused_window;
1216 while (wwin) {
1217 if (wwin!=awin
1218 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1219 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1220 && !wwin->flags.internal_window
1221 && wGetWindowOfInspectorForWindow(wwin) != awin
1222 && !WFLAGP(wwin, no_hide_others)) {
1224 if (wwin->main_window==None || WFLAGP(wwin, no_appicon)) {
1225 if (!WFLAGP(wwin, no_miniaturizable)) {
1226 wwin->flags.skip_next_animation = 1;
1227 wIconifyWindow(wwin);
1229 } else if (wwin->main_window!=None
1230 && awin->main_window != wwin->main_window) {
1231 tapp = wApplicationOf(wwin->main_window);
1232 if (tapp) {
1233 tapp->flags.skip_next_animation = 1;
1234 wHideApplication(tapp);
1235 } else {
1236 if (!WFLAGP(wwin, no_miniaturizable)) {
1237 wwin->flags.skip_next_animation = 1;
1238 wIconifyWindow(wwin);
1243 wwin = wwin->prev;
1246 wSetFocusTo(awin->screen_ptr, awin);
1252 void
1253 wHideApplication(WApplication *wapp)
1255 WScreen *scr;
1256 WWindow *wlist;
1257 int hadfocus;
1259 if (!wapp) {
1260 wwarning("trying to hide a non grouped window");
1261 return;
1263 if (!wapp->main_window_desc) {
1264 wwarning("group leader not found for window group");
1265 return;
1267 scr = wapp->main_window_desc->screen_ptr;
1268 hadfocus = 0;
1269 wlist = scr->focused_window;
1270 if (!wlist)
1271 return;
1273 if (wlist->main_window == wapp->main_window)
1274 wapp->last_focused = wlist;
1275 else
1276 wapp->last_focused = NULL;
1277 while (wlist) {
1278 if (wlist->main_window == wapp->main_window) {
1279 if (wlist->flags.focused) {
1280 hadfocus = 1;
1282 if (wapp->app_icon)
1283 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1284 wapp->app_icon->y_pos, wlist,
1285 !wapp->flags.skip_next_animation);
1287 wlist = wlist->prev;
1290 wapp->flags.skip_next_animation = 0;
1292 if (hadfocus) {
1293 if (wPreferences.focus_mode==WKF_CLICK) {
1294 wlist = scr->focused_window;
1295 while (wlist) {
1296 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1297 && (wlist->flags.mapped || wlist->flags.shaded))
1298 break;
1299 wlist = wlist->prev;
1301 wSetFocusTo(scr, wlist);
1302 } else {
1303 wSetFocusTo(scr, NULL);
1307 wapp->flags.hidden = 1;
1309 if(wPreferences.auto_arrange_icons) {
1310 wArrangeIcons(scr, True);
1312 #ifdef HIDDENDOT
1313 if (wapp->app_icon)
1314 wAppIconPaint(wapp->app_icon);
1315 #endif
1321 static void
1322 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1323 int bringToCurrentWS)
1325 if (bringToCurrentWS)
1326 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1328 wwin->flags.hidden=0;
1329 wwin->flags.mapped=1;
1331 wSoundPlay(WSOUND_UNHIDE);
1332 #ifdef ANIMATIONS
1333 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1334 && animate) {
1335 animateResize(wwin->screen_ptr, icon_x, icon_y,
1336 icon->core->width, icon->core->height,
1337 wwin->frame_x, wwin->frame_y,
1338 wwin->frame->core->width, wwin->frame->core->height,
1339 True);
1341 #endif
1342 wwin->flags.skip_next_animation = 0;
1343 XMapWindow(dpy, wwin->client_win);
1344 XMapWindow(dpy, wwin->frame->core->window);
1345 wClientSetState(wwin, NormalState, None);
1346 wRaiseFrame(wwin->frame->core);
1347 if (wwin->flags.inspector_open) {
1348 wUnhideInspectorForWindow(wwin);
1351 WMPostNotificationName(WMNChangedState, wwin, "hide");
1355 void
1356 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1358 WScreen *scr;
1359 WWindow *wlist, *next;
1360 WWindow *focused=NULL;
1362 if (!wapp) {
1363 return;
1365 scr = wapp->main_window_desc->screen_ptr;
1366 wlist = scr->focused_window;
1367 if (!wlist) return;
1368 /* goto beginning of list */
1369 while (wlist->prev)
1370 wlist = wlist->prev;
1372 while (wlist) {
1373 next = wlist->next;
1375 if (wlist->main_window == wapp->main_window) {
1376 if (wlist->flags.focused)
1377 focused = wlist;
1378 else if (!focused || !focused->flags.focused)
1379 focused = wlist;
1381 if (wlist->flags.miniaturized && wlist->icon) {
1382 if (bringToCurrentWS || wPreferences.sticky_icons
1383 || wlist->frame->workspace == scr->current_workspace) {
1384 if (!wlist->icon->mapped) {
1385 XMapWindow(dpy, wlist->icon->core->window);
1386 wlist->icon->mapped = 1;
1388 wlist->flags.hidden = 0;
1390 WMPostNotificationName(WMNChangedState, wlist, "hide");
1392 if (wlist->frame->workspace != scr->current_workspace)
1393 wWindowChangeWorkspace(wlist, scr->current_workspace);
1395 if (miniwindows) {
1396 wDeiconifyWindow(wlist);
1398 } else if (wlist->flags.hidden) {
1399 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1400 wapp->app_icon->y_pos, wlist,
1401 !wapp->flags.skip_next_animation,
1402 bringToCurrentWS);
1403 } else {
1404 if (bringToCurrentWS
1405 && wlist->frame->workspace != scr->current_workspace) {
1406 wWindowChangeWorkspace(wlist, scr->current_workspace);
1408 wRaiseFrame(wlist->frame->core);
1411 wlist = next;
1414 wapp->flags.skip_next_animation = 0;
1415 wapp->flags.hidden = 0;
1417 if (focused)
1418 wSetFocusTo(scr, focused);
1419 else if (wapp->last_focused && wapp->last_focused->flags.mapped)
1420 wSetFocusTo(scr, wapp->last_focused);
1421 wapp->last_focused = NULL;
1422 if (wPreferences.auto_arrange_icons) {
1423 wArrangeIcons(scr, True);
1425 #ifdef HIDDENDOT
1426 wAppIconPaint(wapp->app_icon);
1427 #endif
1432 void
1433 wShowAllWindows(WScreen *scr)
1435 WWindow *wwin, *old_foc;
1436 WApplication *wapp;
1438 old_foc = wwin = scr->focused_window;
1439 while (wwin) {
1440 if (!wwin->flags.internal_window &&
1441 (scr->current_workspace == wwin->frame->workspace
1442 || IS_OMNIPRESENT(wwin))) {
1443 if (wwin->flags.miniaturized) {
1444 wwin->flags.skip_next_animation = 1;
1445 wDeiconifyWindow(wwin);
1446 } else if (wwin->flags.hidden) {
1447 wapp = wApplicationOf(wwin->main_window);
1448 if (wapp) {
1449 wUnhideApplication(wapp, False, False);
1450 } else {
1451 wwin->flags.skip_next_animation = 1;
1452 wDeiconifyWindow(wwin);
1456 wwin = wwin->prev;
1458 wSetFocusTo(scr, old_foc);
1459 /*wRaiseFrame(old_foc->frame->core);*/
1463 void
1464 wRefreshDesktop(WScreen *scr)
1466 Window win;
1467 XSetWindowAttributes attr;
1469 attr.backing_store = NotUseful;
1470 attr.save_under = False;
1471 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1472 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1473 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1474 &attr);
1475 XMapRaised(dpy, win);
1476 XDestroyWindow(dpy, win);
1477 XFlush(dpy);
1481 void
1482 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1484 WWindow *wwin;
1485 WAppIcon *aicon;
1486 int pf; /* primary axis */
1487 int sf; /* secondary axis */
1488 int fullW;
1489 int fullH;
1490 int pi, si;
1491 int sx1, sx2, sy1, sy2; /* screen boundary */
1492 int sw, sh;
1493 int xo, yo;
1494 int xs, ys;
1495 int isize = wPreferences.icon_size;
1498 * Find out screen boundaries.
1500 sx1 = 0;
1501 sy1 = 0;
1502 sx2 = scr->scr_width;
1503 sy2 = scr->scr_height;
1504 if (scr->dock) {
1505 if (scr->dock->on_right_side)
1506 sx2 -= isize + DOCK_EXTRA_SPACE;
1507 else
1508 sx1 += isize + DOCK_EXTRA_SPACE;
1511 sw = isize * (scr->scr_width/isize);
1512 sh = isize * (scr->scr_height/isize);
1513 fullW = (sx2-sx1)/isize;
1514 fullH = (sy2-sy1)/isize;
1516 /* icon yard boundaries */
1517 if (wPreferences.icon_yard & IY_VERT) {
1518 pf = fullH;
1519 sf = fullW;
1520 } else {
1521 pf = fullW;
1522 sf = fullH;
1524 if (wPreferences.icon_yard & IY_RIGHT) {
1525 xo = sx2 - isize;
1526 xs = -1;
1527 } else {
1528 xo = sx1;
1529 xs = 1;
1531 if (wPreferences.icon_yard & IY_TOP) {
1532 yo = sy1;
1533 ys = 1;
1534 } else {
1535 yo = sy2 - isize;
1536 ys = -1;
1539 /* arrange icons putting the most recently focused window
1540 * as the last icon */
1541 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1542 : xo + xs*(pi*isize))
1543 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1544 : yo + ys*(si*isize))
1546 /* arrange application icons */
1547 aicon = scr->app_icon_list;
1548 /* reverse them to avoid unnecessarily sliding of icons */
1549 while (aicon && aicon->next)
1550 aicon = aicon->next;
1552 pi = 0;
1553 si = 0;
1554 while (aicon) {
1555 if (!aicon->docked) {
1556 if (aicon->x_pos != X || aicon->y_pos != Y) {
1557 #ifdef ANIMATIONS
1558 if (!wPreferences.no_animations) {
1559 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1560 X, Y);
1562 #endif /* ANIMATIONS */
1564 wAppIconMove(aicon, X, Y);
1565 pi++;
1567 /* we reversed the order so we use prev */
1568 aicon = aicon->prev;
1569 if (pi >= pf) {
1570 pi=0;
1571 si++;
1575 /* arrange miniwindows */
1577 wwin = scr->focused_window;
1578 /* reverse them to avoid unnecessarily shuffling */
1579 while (wwin && wwin->prev)
1580 wwin = wwin->prev;
1582 while (wwin) {
1583 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1584 (wwin->frame->workspace==scr->current_workspace ||
1585 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1587 if (arrangeAll || !wwin->flags.icon_moved) {
1588 if (wwin->icon_x != X || wwin->icon_y != Y) {
1589 #ifdef ANIMATIONS
1590 if (wPreferences.no_animations) {
1591 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1592 } else {
1593 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1594 wwin->icon_y, X, Y);
1596 #else
1597 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1598 #endif /* ANIMATIONS */
1600 wwin->icon_x = X;
1601 wwin->icon_y = Y;
1602 pi++;
1605 if (arrangeAll) {
1606 wwin->flags.icon_moved = 0;
1608 /* we reversed the order, so we use next */
1609 wwin = wwin->next;
1610 if (pi >= pf) {
1611 pi=0;
1612 si++;
1618 void
1619 wSelectWindow(WWindow *wwin, Bool flag)
1621 WScreen *scr = wwin->screen_ptr;
1623 if (flag) {
1624 wwin->flags.selected = 1;
1625 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1627 if (WFLAGP(wwin, no_border)) {
1628 XSetWindowBorderWidth(dpy, wwin->frame->core->window,
1629 FRAME_BORDER_WIDTH);
1632 if (!scr->selected_windows)
1633 scr->selected_windows = WMCreateArray(4);
1634 WMAddToArray(scr->selected_windows, wwin);
1635 } else {
1636 wwin->flags.selected = 0;
1637 XSetWindowBorder(dpy, wwin->frame->core->window,
1638 scr->frame_border_pixel);
1640 if (WFLAGP(wwin, no_border)) {
1641 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1644 if (scr->selected_windows) {
1645 WMRemoveFromArray(scr->selected_windows, wwin);
1651 void
1652 wMakeWindowVisible(WWindow *wwin)
1654 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1655 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1657 if (wwin->flags.shaded) {
1658 wUnshadeWindow(wwin);
1660 if (wwin->flags.hidden) {
1661 WApplication *app;
1663 app = wApplicationOf(wwin->main_window);
1664 if (app)
1665 wUnhideApplication(app, False, False);
1666 } else if (wwin->flags.miniaturized) {
1667 wDeiconifyWindow(wwin);
1668 } else {
1669 if (!WFLAGP(wwin, no_focusable))
1670 wSetFocusTo(wwin->screen_ptr, wwin);
1671 wRaiseFrame(wwin->frame->core);