fixed bug in positioning of window list menu when opened by kbd
[wmaker-crm.git] / src / actions.c
blob81c79c7e00b13d84f762ae6497ec1bc2897b7744
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_U, SHADE_DELAY_U}};
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 = time(NULL);
259 #ifdef ANIMATIONS
260 int y, s, w, h;
261 #endif
263 if (wwin->flags.shaded)
264 return;
266 XLowerWindow(dpy, wwin->client_win);
268 wSoundPlay(WSOUND_SHADE);
270 #ifdef ANIMATIONS
271 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
272 && !wPreferences.no_animations) {
273 /* do the shading animation */
274 h = wwin->frame->core->height;
275 s = h/SHADE_STEPS;
276 if (s < 1) s=1;
277 w = wwin->frame->core->width;
278 y = wwin->frame->top_width;
279 while (h>wwin->frame->top_width+1) {
280 XMoveWindow(dpy, wwin->client_win, 0, y);
281 XResizeWindow(dpy, wwin->frame->core->window, w, h);
282 XFlush(dpy);
284 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
285 break;
287 if (SHADE_DELAY > 0)
288 wusleep(SHADE_DELAY*1000L);
289 h-=s;
290 y-=s;
292 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
294 #endif /* ANIMATIONS */
296 wwin->flags.skip_next_animation = 0;
297 wwin->flags.shaded = 1;
298 wwin->flags.mapped = 0;
299 /* prevent window withdrawal when getting UnmapNotify */
300 XSelectInput(dpy, wwin->client_win,
301 wwin->event_mask & ~StructureNotifyMask);
302 XUnmapWindow(dpy, wwin->client_win);
303 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
305 /* for the client it's just like iconification */
306 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
307 wwin->frame->top_width - 1);
309 wwin->client.y = wwin->frame_y - wwin->client.height
310 + wwin->frame->top_width;
311 wWindowSynthConfigureNotify(wwin);
314 wClientSetState(wwin, IconicState, None);
317 WMPostNotificationName(WMNChangedState, wwin, "shade");
319 #ifdef ANIMATIONS
320 if (!wwin->screen_ptr->flags.startup) {
321 /* Look at processEvents() for reason of this code. */
322 XSync(dpy, 0);
323 processEvents(XPending(dpy));
325 #endif
329 void
330 wUnshadeWindow(WWindow *wwin)
332 time_t time0 = time(NULL);
333 #ifdef ANIMATIONS
334 int y, s, w, h;
335 #endif /* ANIMATIONS */
338 if (!wwin->flags.shaded)
339 return;
341 wwin->flags.shaded = 0;
342 wwin->flags.mapped = 1;
343 XMapWindow(dpy, wwin->client_win);
345 wSoundPlay(WSOUND_UNSHADE);
347 #ifdef ANIMATIONS
348 if (!wPreferences.no_animations && !wwin->flags.skip_next_animation) {
349 /* do the shading animation */
350 h = wwin->frame->top_width + wwin->frame->bottom_width;
351 y = wwin->frame->top_width - wwin->client.height;
352 s = abs(y)/SHADE_STEPS;
353 if (s<1) s=1;
354 w = wwin->frame->core->width;
355 XMoveWindow(dpy, wwin->client_win, 0, y);
356 if (s>0) {
357 while (h < wwin->client.height + wwin->frame->top_width
358 + wwin->frame->bottom_width) {
359 XResizeWindow(dpy, wwin->frame->core->window, w, h);
360 XMoveWindow(dpy, wwin->client_win, 0, y);
361 XFlush(dpy);
362 if (SHADE_DELAY > 0)
363 wusleep(SHADE_DELAY*2000L/3);
364 h+=s;
365 y+=s;
367 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
368 break;
371 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
373 #endif /* ANIMATIONS */
375 wwin->flags.skip_next_animation = 0;
376 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
377 wwin->frame->top_width + wwin->client.height
378 + wwin->frame->bottom_width);
380 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
381 wWindowSynthConfigureNotify(wwin);
384 wClientSetState(wwin, NormalState, None);
386 /* if the window is focused, set the focus again as it was disabled during
387 * shading */
388 if (wwin->flags.focused)
389 wSetFocusTo(wwin->screen_ptr, wwin);
391 WMPostNotificationName(WMNChangedState, wwin, "shade");
395 void
396 wMaximizeWindow(WWindow *wwin, int directions)
398 int new_width, new_height, new_x, new_y;
399 WArea usableArea = wwin->screen_ptr->totalUsableArea;
400 WArea totalArea;
403 if (WFLAGP(wwin, no_resizable))
404 return;
406 totalArea.x1 = 0;
407 totalArea.y1 = 0;
408 totalArea.x2 = wwin->screen_ptr->scr_width;
409 totalArea.y2 = wwin->screen_ptr->scr_height;
411 #ifdef XINERAMA
412 if (wwin->screen_ptr->xine_count > 0
413 && !(directions & MAX_IGNORE_XINERAMA)) {
414 WScreen *scr = wwin->screen_ptr;
415 WMRect rect;
417 rect = wGetRectForHead(scr, wGetHeadForWindow(wwin));
418 totalArea.x1 = rect.pos.x;
419 totalArea.y1 = rect.pos.y;
420 totalArea.x2 = totalArea.x1 + rect.size.width;
421 totalArea.y2 = totalArea.y1 + rect.size.height;
423 usableArea.x1 = WMAX(totalArea.x1, usableArea.x1);
424 usableArea.y1 = WMAX(totalArea.y1, usableArea.y1);
425 usableArea.x2 = WMIN(totalArea.x2, usableArea.x2);
426 usableArea.y2 = WMIN(totalArea.y2, usableArea.y2);
428 #endif /* XINERAMA */
430 if (WFLAGP(wwin, full_maximize)) {
431 usableArea = totalArea;
434 if (wwin->flags.shaded) {
435 wwin->flags.skip_next_animation = 1;
436 wUnshadeWindow(wwin);
438 wwin->flags.maximized = directions;
439 wwin->old_geometry.width = wwin->client.width;
440 wwin->old_geometry.height = wwin->client.height;
441 wwin->old_geometry.x = wwin->frame_x;
442 wwin->old_geometry.y = wwin->frame_y;
444 #ifdef KWM_HINTS
445 wKWMUpdateClientGeometryRestore(wwin);
446 #endif
448 if (directions & MAX_HORIZONTAL) {
450 new_width = (usableArea.x2-usableArea.x1)-FRAME_BORDER_WIDTH*2;
451 new_x = usableArea.x1;
453 } else {
455 new_x = wwin->frame_x;
456 new_width = wwin->frame->core->width;
460 if (directions & MAX_VERTICAL) {
462 new_height = (usableArea.y2-usableArea.y1)-FRAME_BORDER_WIDTH*2;
463 new_y = usableArea.y1;
464 if (WFLAGP(wwin, full_maximize)) {
465 new_y -= wwin->frame->top_width;
466 new_height += wwin->frame->bottom_width - 1;
468 } else {
469 new_y = wwin->frame_y;
470 new_height = wwin->frame->core->height;
473 if (!WFLAGP(wwin, full_maximize)) {
474 new_height -= wwin->frame->top_width+wwin->frame->bottom_width;
477 wWindowConstrainSize(wwin, &new_width, &new_height);
479 wWindowCropSize(wwin, usableArea.x2-usableArea.x1,
480 usableArea.y2-usableArea.y1,
481 &new_width, &new_height);
483 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
486 WMPostNotificationName(WMNChangedState, wwin, "maximize");
488 wSoundPlay(WSOUND_MAXIMIZE);
492 void
493 wUnmaximizeWindow(WWindow *wwin)
495 int restore_x, restore_y;
497 if (!wwin->flags.maximized)
498 return;
500 if (wwin->flags.shaded) {
501 wwin->flags.skip_next_animation = 1;
502 wUnshadeWindow(wwin);
504 restore_x = (wwin->flags.maximized & MAX_HORIZONTAL) ?
505 wwin->old_geometry.x : wwin->frame_x;
506 restore_y = (wwin->flags.maximized & MAX_VERTICAL) ?
507 wwin->old_geometry.y : wwin->frame_y;
508 wwin->flags.maximized = 0;
509 wWindowConfigure(wwin, restore_x, restore_y,
510 wwin->old_geometry.width, wwin->old_geometry.height);
512 WMPostNotificationName(WMNChangedState, wwin, "maximize");
514 wSoundPlay(WSOUND_UNMAXIMIZE);
517 #ifdef ANIMATIONS
518 static void
519 animateResizeFlip(WScreen *scr, int x, int y, int w, int h,
520 int fx, int fy, int fw, int fh, int steps)
522 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
523 float cx, cy, cw, ch;
524 float xstep, ystep, wstep, hstep;
525 XPoint points[5];
526 float dx, dch, midy;
527 float angle, final_angle, delta;
529 xstep = (float)(fx-x)/steps;
530 ystep = (float)(fy-y)/steps;
531 wstep = (float)(fw-w)/steps;
532 hstep = (float)(fh-h)/steps;
534 cx = (float)x;
535 cy = (float)y;
536 cw = (float)w;
537 ch = (float)h;
539 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_F;
540 delta = (float)(final_angle/FRAMES);
541 for (angle=0;; angle+=delta) {
542 if (angle > final_angle)
543 angle = final_angle;
545 dx = (cw/10) - ((cw/5) * sin(angle));
546 dch = (ch/2) * cos(angle);
547 midy = cy + (ch/2);
549 points[0].x = cx + dx; points[0].y = midy - dch;
550 points[1].x = cx + cw - dx; points[1].y = points[0].y;
551 points[2].x = cx + cw + dx; points[2].y = midy + dch;
552 points[3].x = cx - dx; points[3].y = points[2].y;
553 points[4].x = points[0].x; points[4].y = points[0].y;
555 XGrabServer(dpy);
556 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
557 XFlush(dpy);
558 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
559 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
560 #endif
562 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
563 XUngrabServer(dpy);
564 cx+=xstep;
565 cy+=ystep;
566 cw+=wstep;
567 ch+=hstep;
568 if (angle >= final_angle)
569 break;
572 XFlush(dpy);
574 #undef FRAMES
577 static void
578 animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
579 int fx, int fy, int fw, int fh, int steps)
581 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
582 float cx, cy, cw, ch;
583 float xstep, ystep, wstep, hstep;
584 XPoint points[5];
585 float angle, final_angle, a, d, delta;
587 x += w/2;
588 y += h/2;
589 fx += fw/2;
590 fy += fh/2;
592 xstep = (float)(fx-x)/steps;
593 ystep = (float)(fy-y)/steps;
594 wstep = (float)(fw-w)/steps;
595 hstep = (float)(fh-h)/steps;
597 cx = (float)x;
598 cy = (float)y;
599 cw = (float)w;
600 ch = (float)h;
602 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
603 delta = (float)(final_angle/FRAMES);
604 for (angle=0;; angle+=delta) {
605 if (angle > final_angle)
606 angle = final_angle;
608 a = atan(ch/cw);
609 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
611 points[0].x = cx+cos(angle-a)*d;
612 points[0].y = cy+sin(angle-a)*d;
613 points[1].x = cx+cos(angle+a)*d;
614 points[1].y = cy+sin(angle+a)*d;
615 points[2].x = cx+cos(angle-a+WM_PI)*d;
616 points[2].y = cy+sin(angle-a+WM_PI)*d;
617 points[3].x = cx+cos(angle+a+WM_PI)*d;
618 points[3].y = cy+sin(angle+a+WM_PI)*d;
619 points[4].x = cx+cos(angle-a)*d;
620 points[4].y = cy+sin(angle-a)*d;
621 XGrabServer(dpy);
622 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
623 XFlush(dpy);
624 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
625 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
626 #endif
628 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
629 XUngrabServer(dpy);
630 cx+=xstep;
631 cy+=ystep;
632 cw+=wstep;
633 ch+=hstep;
634 if (angle >= final_angle)
635 break;
638 XFlush(dpy);
640 #undef FRAMES
643 static void
644 animateResizeZoom(WScreen *scr, int x, int y, int w, int h,
645 int fx, int fy, int fw, int fh, int steps)
647 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
648 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
649 float xstep, ystep, wstep, hstep;
650 int i, j;
652 xstep = (float)(fx-x)/steps;
653 ystep = (float)(fy-y)/steps;
654 wstep = (float)(fw-w)/steps;
655 hstep = (float)(fh-h)/steps;
657 for (j=0; j<FRAMES; j++) {
658 cx[j] = (float)x;
659 cy[j] = (float)y;
660 cw[j] = (float)w;
661 ch[j] = (float)h;
663 XGrabServer(dpy);
664 for (i=0; i<steps; i++) {
665 for (j=0; j<FRAMES; j++) {
666 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
667 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
669 XFlush(dpy);
670 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
671 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
672 #endif
673 for (j=0; j<FRAMES; j++) {
674 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
675 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
676 if (j<FRAMES-1) {
677 cx[j]=cx[j+1];
678 cy[j]=cy[j+1];
679 cw[j]=cw[j+1];
680 ch[j]=ch[j+1];
681 } else {
682 cx[j]+=xstep;
683 cy[j]+=ystep;
684 cw[j]+=wstep;
685 ch[j]+=hstep;
690 for (j=0; j<FRAMES; j++) {
691 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
692 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
694 XFlush(dpy);
695 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
696 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
697 #endif
698 for (j=0; j<FRAMES; j++) {
699 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
700 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
703 XUngrabServer(dpy);
705 #undef FRAMES
708 void
709 animateResize(WScreen *scr, int x, int y, int w, int h,
710 int fx, int fy, int fw, int fh, int hiding)
712 int style = wPreferences.iconification_style; /* Catch the value */
713 int steps, k;
715 if (style == WIS_NONE)
716 return;
718 if (style == WIS_RANDOM) {
719 style = rand()%3;
722 k = (hiding ? 2 : 3);
723 switch(style) {
724 case WIS_TWIST:
725 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
726 if (steps>0)
727 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
728 break;
729 case WIS_FLIP:
730 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
731 if (steps>0)
732 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
733 break;
734 case WIS_ZOOM:
735 default:
736 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
737 if (steps>0)
738 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
739 break;
742 #endif /* ANIMATIONS */
745 static void
746 flushExpose()
748 XEvent tmpev;
750 while (XCheckTypedEvent(dpy, Expose, &tmpev))
751 WMHandleEvent(&tmpev);
752 XSync(dpy, 0);
755 static void
756 unmapTransientsFor(WWindow *wwin)
758 WWindow *tmp;
761 tmp = wwin->screen_ptr->focused_window;
762 while (tmp) {
763 /* unmap the transients for this transient */
764 if (tmp!=wwin && tmp->transient_for == wwin->client_win
765 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
766 || tmp->flags.shaded)) {
767 unmapTransientsFor(tmp);
768 tmp->flags.miniaturized = 1;
769 if (!tmp->flags.shaded) {
770 wWindowUnmap(tmp);
771 } else {
772 XUnmapWindow(dpy, tmp->frame->core->window);
775 if (!tmp->flags.shaded)
777 wClientSetState(tmp, IconicState, None);
779 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
781 tmp = tmp->prev;
786 static void
787 mapTransientsFor(WWindow *wwin)
789 WWindow *tmp;
791 tmp = wwin->screen_ptr->focused_window;
792 while (tmp) {
793 /* recursively map the transients for this transient */
794 if (tmp!=wwin && tmp->transient_for == wwin->client_win
795 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
796 && tmp->icon==NULL) {
797 mapTransientsFor(tmp);
798 tmp->flags.miniaturized = 0;
799 if (!tmp->flags.shaded) {
800 wWindowMap(tmp);
801 } else {
802 XMapWindow(dpy, tmp->frame->core->window);
804 tmp->flags.semi_focused = 0;
806 if (!tmp->flags.shaded)
808 wClientSetState(tmp, NormalState, None);
810 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
812 tmp = tmp->prev;
816 #if 0
817 static void
818 setupIconGrabs(WIcon *icon)
820 /* setup passive grabs on the icon */
821 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
822 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
823 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
824 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
825 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
826 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
827 XSync(dpy, 0);
829 #endif
831 static WWindow*
832 recursiveTransientFor(WWindow *wwin)
834 int i;
836 if (!wwin)
837 return None;
839 /* hackish way to detect transient_for cycle */
840 i = wwin->screen_ptr->window_count+1;
842 while (wwin && wwin->transient_for != None && i>0) {
843 wwin = wWindowFor(wwin->transient_for);
844 i--;
846 if (i==0 && wwin) {
847 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
848 wwin->frame->title);
849 return NULL;
852 return wwin;
855 #if 0
856 static void
857 removeIconGrabs(WIcon *icon)
859 /* remove passive grabs on the icon */
860 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
861 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
862 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
863 XSync(dpy, 0);
865 #endif
868 void
869 wIconifyWindow(WWindow *wwin)
871 XWindowAttributes attribs;
872 int present;
875 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
876 /* the window doesn't exist anymore */
877 return;
880 if (wwin->flags.miniaturized) {
881 return;
885 if (wwin->transient_for!=None) {
886 WWindow *owner = wWindowFor(wwin->transient_for);
888 if (owner && owner->flags.miniaturized)
889 return;
892 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
894 /* if the window is in another workspace, simplify process */
895 if (present) {
896 /* icon creation may take a while */
897 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
898 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
899 GrabModeAsync, None, None, CurrentTime);
902 if (!wPreferences.disable_miniwindows) {
903 if (!wwin->flags.icon_moved) {
904 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y);
906 wwin->icon = wIconCreate(wwin);
908 wwin->icon->mapped = 1;
911 wwin->flags.miniaturized = 1;
912 wwin->flags.mapped = 0;
914 /* unmap transients */
916 unmapTransientsFor(wwin);
918 if (present) {
919 wSoundPlay(WSOUND_ICONIFY);
921 XUngrabPointer(dpy, CurrentTime);
922 wWindowUnmap(wwin);
923 /* let all Expose events arrive so that we can repaint
924 * something before the animation starts (and the server is grabbed) */
925 XSync(dpy, 0);
927 if (wPreferences.disable_miniwindows)
928 wClientSetState(wwin, IconicState, None);
929 else
930 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
932 flushExpose();
933 #ifdef ANIMATIONS
934 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
935 && !wPreferences.no_animations) {
936 int ix, iy, iw, ih;
938 if (!wPreferences.disable_miniwindows) {
939 ix = wwin->icon_x;
940 iy = wwin->icon_y;
941 iw = wwin->icon->core->width;
942 ih = wwin->icon->core->height;
943 } else {
944 #ifdef KWM_HINTS
945 WArea area;
947 if (wKWMGetIconGeometry(wwin, &area)) {
948 ix = area.x1;
949 iy = area.y1;
950 iw = area.x2 - ix;
951 ih = area.y2 - iy;
952 } else
953 #endif /* KWM_HINTS */
955 ix = 0;
956 iy = 0;
957 iw = wwin->screen_ptr->scr_width;
958 ih = wwin->screen_ptr->scr_height;
961 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
962 wwin->frame->core->width, wwin->frame->core->height,
963 ix, iy, iw, ih, False);
965 #endif
968 wwin->flags.skip_next_animation = 0;
970 if (!wPreferences.disable_miniwindows) {
972 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
973 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
975 XMapWindow(dpy, wwin->icon->core->window);
977 AddToStackList(wwin->icon->core);
979 wLowerFrame(wwin->icon->core);
982 if (present) {
983 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
986 * It doesn't seem to be working and causes button event hangup
987 * when deiconifying a transient window.
988 setupIconGrabs(wwin->icon);
990 if ((wwin->flags.focused
991 || (owner && wwin->client_win == owner->client_win))
992 && wPreferences.focus_mode==WKF_CLICK) {
993 WWindow *tmp;
995 tmp = wwin->prev;
996 while (tmp) {
997 if (!WFLAGP(tmp, no_focusable)
998 && !(tmp->flags.hidden||tmp->flags.miniaturized)
999 && (wwin->frame->workspace == tmp->frame->workspace))
1000 break;
1001 tmp = tmp->prev;
1003 wSetFocusTo(wwin->screen_ptr, tmp);
1004 } else if (wPreferences.focus_mode!=WKF_CLICK) {
1005 wSetFocusTo(wwin->screen_ptr, NULL);
1008 #ifdef ANIMATIONS
1009 if (!wwin->screen_ptr->flags.startup) {
1010 Window clientwin = wwin->client_win;
1012 XSync(dpy, 0);
1013 processEvents(XPending(dpy));
1015 /* the window can disappear while doing the processEvents() */
1016 if (!wWindowFor(clientwin))
1017 return;
1019 #endif
1023 if (wwin->flags.selected && !wPreferences.disable_miniwindows)
1024 wIconSelect(wwin->icon);
1026 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1032 void
1033 wDeiconifyWindow(WWindow *wwin)
1035 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1037 if (!wwin->flags.miniaturized)
1038 return;
1040 if (wwin->transient_for != None
1041 && wwin->transient_for != wwin->screen_ptr->root_win) {
1042 WWindow *owner = recursiveTransientFor(wwin);
1044 if (owner && owner->flags.miniaturized) {
1045 wDeiconifyWindow(owner);
1046 wSetFocusTo(wwin->screen_ptr, wwin);
1047 wRaiseFrame(wwin->frame->core);
1048 return;
1052 wwin->flags.miniaturized = 0;
1053 if (!wwin->flags.shaded)
1054 wwin->flags.mapped = 1;
1056 if (!wPreferences.disable_miniwindows) {
1057 if (wwin->icon->selected)
1058 wIconSelect(wwin->icon);
1060 XUnmapWindow(dpy, wwin->icon->core->window);
1063 wSoundPlay(WSOUND_DEICONIFY);
1065 /* if the window is in another workspace, do it silently */
1066 #ifdef ANIMATIONS
1067 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1068 && !wwin->flags.skip_next_animation) {
1069 int ix, iy, iw, ih;
1071 if (!wPreferences.disable_miniwindows) {
1072 ix = wwin->icon_x;
1073 iy = wwin->icon_y;
1074 iw = wwin->icon->core->width;
1075 ih = wwin->icon->core->height;
1076 } else {
1077 #ifdef KWM_HINTS
1078 WArea area;
1080 if (wKWMGetIconGeometry(wwin, &area)) {
1081 ix = area.x1;
1082 iy = area.y1;
1083 iw = area.x2 - ix;
1084 ih = area.y2 - iy;
1085 } else
1086 #endif /* KWM_HINTS */
1088 ix = 0;
1089 iy = 0;
1090 iw = wwin->screen_ptr->scr_width;
1091 ih = wwin->screen_ptr->scr_height;
1094 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1095 wwin->frame_x, wwin->frame_y,
1096 wwin->frame->core->width, wwin->frame->core->height,
1097 False);
1099 #endif /* ANIMATIONS */
1100 wwin->flags.skip_next_animation = 0;
1101 XGrabServer(dpy);
1102 if (!wwin->flags.shaded) {
1103 XMapWindow(dpy, wwin->client_win);
1105 XMapWindow(dpy, wwin->frame->core->window);
1106 wRaiseFrame(wwin->frame->core);
1107 if (!wwin->flags.shaded) {
1108 wClientSetState(wwin, NormalState, None);
1110 mapTransientsFor(wwin);
1112 if (!wPreferences.disable_miniwindows) {
1113 RemoveFromStackList(wwin->icon->core);
1114 /* removeIconGrabs(wwin->icon);*/
1115 wIconDestroy(wwin->icon);
1116 wwin->icon = NULL;
1118 XUngrabServer(dpy);
1120 if (wPreferences.focus_mode==WKF_CLICK)
1121 wSetFocusTo(wwin->screen_ptr, wwin);
1123 #ifdef ANIMATIONS
1124 if (!wwin->screen_ptr->flags.startup) {
1125 Window clientwin = wwin->client_win;
1127 XSync(dpy, 0);
1128 processEvents(XPending(dpy));
1130 if (!wWindowFor(clientwin))
1131 return;
1133 #endif
1135 if (wPreferences.auto_arrange_icons) {
1136 wArrangeIcons(wwin->screen_ptr, True);
1139 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1144 static void
1145 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1147 if (wwin->flags.miniaturized) {
1148 if (wwin->icon) {
1149 XUnmapWindow(dpy, wwin->icon->core->window);
1150 wwin->icon->mapped = 0;
1152 wwin->flags.hidden = 1;
1154 WMPostNotificationName(WMNChangedState, wwin, "hide");
1155 return;
1158 if (wwin->flags.inspector_open) {
1159 wHideInspectorForWindow(wwin);
1162 wwin->flags.hidden = 1;
1163 wWindowUnmap(wwin);
1165 wClientSetState(wwin, IconicState, icon->icon_win);
1166 flushExpose();
1167 wSoundPlay(WSOUND_HIDE);
1168 #ifdef ANIMATIONS
1169 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1170 !wwin->flags.skip_next_animation && animate) {
1171 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1172 wwin->frame->core->width, wwin->frame->core->height,
1173 icon_x, icon_y, icon->core->width, icon->core->height,
1174 True);
1176 #endif
1177 wwin->flags.skip_next_animation = 0;
1179 WMPostNotificationName(WMNChangedState, wwin, "hide");
1184 void
1185 wHideOtherApplications(WWindow *awin)
1187 WWindow *wwin;
1188 WApplication *tapp;
1190 if (!awin)
1191 return;
1192 wwin = awin->screen_ptr->focused_window;
1195 while (wwin) {
1196 if (wwin!=awin
1197 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1198 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1199 && !wwin->flags.internal_window
1200 && wGetWindowOfInspectorForWindow(wwin) != awin
1201 && !WFLAGP(wwin, no_hide_others)) {
1203 if (wwin->main_window==None || WFLAGP(wwin, no_appicon)) {
1204 if (!WFLAGP(wwin, no_miniaturizable)) {
1205 wwin->flags.skip_next_animation = 1;
1206 wIconifyWindow(wwin);
1208 } else if (wwin->main_window!=None
1209 && awin->main_window != wwin->main_window) {
1210 tapp = wApplicationOf(wwin->main_window);
1211 if (tapp) {
1212 tapp->flags.skip_next_animation = 1;
1213 wHideApplication(tapp);
1214 } else {
1215 if (!WFLAGP(wwin, no_miniaturizable)) {
1216 wwin->flags.skip_next_animation = 1;
1217 wIconifyWindow(wwin);
1222 wwin = wwin->prev;
1225 wSetFocusTo(awin->screen_ptr, awin);
1231 void
1232 wHideApplication(WApplication *wapp)
1234 WScreen *scr;
1235 WWindow *wlist;
1236 int hadfocus;
1238 if (!wapp) {
1239 wwarning("trying to hide a non grouped window");
1240 return;
1242 if (!wapp->main_window_desc) {
1243 wwarning("group leader not found for window group");
1244 return;
1246 scr = wapp->main_window_desc->screen_ptr;
1247 hadfocus = 0;
1248 wlist = scr->focused_window;
1249 if (!wlist)
1250 return;
1252 if (wlist->main_window == wapp->main_window)
1253 wapp->last_focused = wlist;
1254 else
1255 wapp->last_focused = NULL;
1256 while (wlist) {
1257 if (wlist->main_window == wapp->main_window) {
1258 if (wlist->flags.focused) {
1259 hadfocus = 1;
1261 if (wapp->app_icon)
1262 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1263 wapp->app_icon->y_pos, wlist,
1264 !wapp->flags.skip_next_animation);
1266 wlist = wlist->prev;
1269 wapp->flags.skip_next_animation = 0;
1271 if (hadfocus) {
1272 if (wPreferences.focus_mode==WKF_CLICK) {
1273 wlist = scr->focused_window;
1274 while (wlist) {
1275 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1276 && (wlist->flags.mapped || wlist->flags.shaded))
1277 break;
1278 wlist = wlist->prev;
1280 wSetFocusTo(scr, wlist);
1281 } else {
1282 wSetFocusTo(scr, NULL);
1286 wapp->flags.hidden = 1;
1288 if(wPreferences.auto_arrange_icons) {
1289 wArrangeIcons(scr, True);
1291 #ifdef HIDDENDOT
1292 if (wapp->app_icon)
1293 wAppIconPaint(wapp->app_icon);
1294 #endif
1300 static void
1301 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1302 int bringToCurrentWS)
1304 if (bringToCurrentWS)
1305 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1307 wwin->flags.hidden=0;
1308 wwin->flags.mapped=1;
1310 wSoundPlay(WSOUND_UNHIDE);
1311 #ifdef ANIMATIONS
1312 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1313 && animate) {
1314 animateResize(wwin->screen_ptr, icon_x, icon_y,
1315 icon->core->width, icon->core->height,
1316 wwin->frame_x, wwin->frame_y,
1317 wwin->frame->core->width, wwin->frame->core->height,
1318 True);
1320 #endif
1321 wwin->flags.skip_next_animation = 0;
1322 XMapWindow(dpy, wwin->client_win);
1323 XMapWindow(dpy, wwin->frame->core->window);
1324 wClientSetState(wwin, NormalState, None);
1325 wRaiseFrame(wwin->frame->core);
1326 if (wwin->flags.inspector_open) {
1327 wUnhideInspectorForWindow(wwin);
1330 WMPostNotificationName(WMNChangedState, wwin, "hide");
1334 void
1335 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1337 WScreen *scr;
1338 WWindow *wlist, *next;
1339 WWindow *focused=NULL;
1341 if (!wapp) {
1342 return;
1344 scr = wapp->main_window_desc->screen_ptr;
1345 wlist = scr->focused_window;
1346 if (!wlist) return;
1347 /* goto beginning of list */
1348 while (wlist->prev)
1349 wlist = wlist->prev;
1351 while (wlist) {
1352 next = wlist->next;
1354 if (wlist->main_window == wapp->main_window) {
1355 if (wlist->flags.focused)
1356 focused = wlist;
1357 else if (!focused || !focused->flags.focused)
1358 focused = wlist;
1360 if (wlist->flags.miniaturized && wlist->icon) {
1361 if (bringToCurrentWS || wPreferences.sticky_icons
1362 || wlist->frame->workspace == scr->current_workspace) {
1363 if (!wlist->icon->mapped) {
1364 XMapWindow(dpy, wlist->icon->core->window);
1365 wlist->icon->mapped = 1;
1367 wlist->flags.hidden = 0;
1369 WMPostNotificationName(WMNChangedState, wlist, "hide");
1371 if (wlist->frame->workspace != scr->current_workspace)
1372 wWindowChangeWorkspace(wlist, scr->current_workspace);
1374 if (miniwindows) {
1375 wDeiconifyWindow(wlist);
1377 } else if (wlist->flags.hidden) {
1378 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1379 wapp->app_icon->y_pos, wlist,
1380 !wapp->flags.skip_next_animation,
1381 bringToCurrentWS);
1382 } else {
1383 if (bringToCurrentWS
1384 && wlist->frame->workspace != scr->current_workspace) {
1385 wWindowChangeWorkspace(wlist, scr->current_workspace);
1387 wRaiseFrame(wlist->frame->core);
1390 wlist = next;
1393 wapp->flags.skip_next_animation = 0;
1394 wapp->flags.hidden = 0;
1396 if (focused)
1397 wSetFocusTo(scr, focused);
1398 else if (wapp->last_focused && wapp->last_focused->flags.mapped)
1399 wSetFocusTo(scr, wapp->last_focused);
1400 wapp->last_focused = NULL;
1401 if (wPreferences.auto_arrange_icons) {
1402 wArrangeIcons(scr, True);
1404 #ifdef HIDDENDOT
1405 wAppIconPaint(wapp->app_icon);
1406 #endif
1411 void
1412 wShowAllWindows(WScreen *scr)
1414 WWindow *wwin, *old_foc;
1415 WApplication *wapp;
1417 old_foc = wwin = scr->focused_window;
1418 while (wwin) {
1419 if (!wwin->flags.internal_window &&
1420 (scr->current_workspace == wwin->frame->workspace
1421 || IS_OMNIPRESENT(wwin))) {
1422 if (wwin->flags.miniaturized) {
1423 wwin->flags.skip_next_animation = 1;
1424 wDeiconifyWindow(wwin);
1425 } else if (wwin->flags.hidden) {
1426 wapp = wApplicationOf(wwin->main_window);
1427 if (wapp) {
1428 wUnhideApplication(wapp, False, False);
1429 } else {
1430 wwin->flags.skip_next_animation = 1;
1431 wDeiconifyWindow(wwin);
1435 wwin = wwin->prev;
1437 wSetFocusTo(scr, old_foc);
1438 /*wRaiseFrame(old_foc->frame->core);*/
1442 void
1443 wRefreshDesktop(WScreen *scr)
1445 Window win;
1446 XSetWindowAttributes attr;
1448 attr.backing_store = NotUseful;
1449 attr.save_under = False;
1450 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1451 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1452 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1453 &attr);
1454 XMapRaised(dpy, win);
1455 XDestroyWindow(dpy, win);
1456 XFlush(dpy);
1460 void
1461 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1463 WWindow *wwin;
1464 WAppIcon *aicon;
1465 int pf; /* primary axis */
1466 int sf; /* secondary axis */
1467 int fullW;
1468 int fullH;
1469 int pi, si;
1470 int sx1, sx2, sy1, sy2; /* screen boundary */
1471 int sw, sh;
1472 int xo, yo;
1473 int xs, ys;
1474 int isize = wPreferences.icon_size;
1477 * Find out screen boundaries.
1479 sx1 = 0;
1480 sy1 = 0;
1481 sx2 = scr->scr_width;
1482 sy2 = scr->scr_height;
1483 if (scr->dock) {
1484 if (scr->dock->on_right_side)
1485 sx2 -= isize + DOCK_EXTRA_SPACE;
1486 else
1487 sx1 += isize + DOCK_EXTRA_SPACE;
1490 sw = isize * (scr->scr_width/isize);
1491 sh = isize * (scr->scr_height/isize);
1492 fullW = (sx2-sx1)/isize;
1493 fullH = (sy2-sy1)/isize;
1495 /* icon yard boundaries */
1496 if (wPreferences.icon_yard & IY_VERT) {
1497 pf = fullH;
1498 sf = fullW;
1499 } else {
1500 pf = fullW;
1501 sf = fullH;
1503 if (wPreferences.icon_yard & IY_RIGHT) {
1504 xo = sx2 - isize;
1505 xs = -1;
1506 } else {
1507 xo = sx1;
1508 xs = 1;
1510 if (wPreferences.icon_yard & IY_TOP) {
1511 yo = sy1;
1512 ys = 1;
1513 } else {
1514 yo = sy2 - isize;
1515 ys = -1;
1518 /* arrange icons putting the most recently focused window
1519 * as the last icon */
1520 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1521 : xo + xs*(pi*isize))
1522 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1523 : yo + ys*(si*isize))
1525 /* arrange application icons */
1526 aicon = scr->app_icon_list;
1527 /* reverse them to avoid unnecessarily sliding of icons */
1528 while (aicon && aicon->next)
1529 aicon = aicon->next;
1531 pi = 0;
1532 si = 0;
1533 while (aicon) {
1534 if (!aicon->docked && wAppIconIsFirstInstance(aicon)) {
1535 if (aicon->x_pos != X || aicon->y_pos != Y) {
1536 #ifdef ANIMATIONS
1537 if (!wPreferences.no_animations) {
1538 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1539 X, Y);
1541 #endif /* ANIMATIONS */
1543 wAppIconMove(aicon, X, Y);
1544 pi++;
1546 /* we reversed the order so we use prev */
1547 aicon = aicon->prev;
1548 if (pi >= pf) {
1549 pi=0;
1550 si++;
1554 /* arrange miniwindows */
1556 wwin = scr->focused_window;
1557 /* reverse them to avoid unnecessarily shuffling */
1558 while (wwin && wwin->prev)
1559 wwin = wwin->prev;
1561 while (wwin) {
1562 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1563 (wwin->frame->workspace==scr->current_workspace ||
1564 IS_OMNIPRESENT(wwin) || 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 pi++;
1584 if (arrangeAll) {
1585 wwin->flags.icon_moved = 0;
1587 /* we reversed the order, so we use next */
1588 wwin = wwin->next;
1589 if (pi >= pf) {
1590 pi=0;
1591 si++;
1597 void
1598 wSelectWindow(WWindow *wwin, Bool flag)
1600 WScreen *scr = wwin->screen_ptr;
1602 if (flag) {
1603 wwin->flags.selected = 1;
1604 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1606 if (WFLAGP(wwin, no_border)) {
1607 XSetWindowBorderWidth(dpy, wwin->frame->core->window,
1608 FRAME_BORDER_WIDTH);
1611 if (!scr->selected_windows)
1612 scr->selected_windows = WMCreateArray(4);
1613 WMAddToArray(scr->selected_windows, wwin);
1614 } else {
1615 wwin->flags.selected = 0;
1616 XSetWindowBorder(dpy, wwin->frame->core->window,
1617 scr->frame_border_pixel);
1619 if (WFLAGP(wwin, no_border)) {
1620 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1623 if (scr->selected_windows) {
1624 WMRemoveFromArray(scr->selected_windows, wwin);
1630 void
1631 wMakeWindowVisible(WWindow *wwin)
1633 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1634 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1636 if (wwin->flags.shaded) {
1637 wUnshadeWindow(wwin);
1639 if (wwin->flags.hidden) {
1640 WApplication *app;
1642 app = wApplicationOf(wwin->main_window);
1643 if (app)
1644 wUnhideApplication(app, False, False);
1645 } else if (wwin->flags.miniaturized) {
1646 wDeiconifyWindow(wwin);
1647 } else {
1648 if (!WFLAGP(wwin, no_focusable))
1649 wSetFocusTo(wwin->screen_ptr, wwin);
1650 wRaiseFrame(wwin->frame->core);