- Fixed crashing bug in menu.c
[wmaker-crm.git] / src / actions.c
blobf32b32548debed04443f296bae63227c98d2f697
1 /* action.c- misc. window commands (miniaturize, hide etc.)
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 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) {
465 new_width = (usableArea.x2-usableArea.x1)-FRAME_BORDER_WIDTH*2;
466 new_x = usableArea.x1;
467 } else {
468 new_x = wwin->frame_x;
469 new_width = wwin->frame->core->width;
472 if (directions & MAX_VERTICAL) {
473 new_height = (usableArea.y2-usableArea.y1)-FRAME_BORDER_WIDTH*2;
474 new_y = usableArea.y1;
475 if (WFLAGP(wwin, full_maximize)) {
476 new_y -= wwin->frame->top_width;
477 new_height += wwin->frame->bottom_width - 1;
479 } else {
480 new_y = wwin->frame_y;
481 new_height = wwin->frame->core->height;
484 if (!WFLAGP(wwin, full_maximize)) {
485 new_height -= wwin->frame->top_width+wwin->frame->bottom_width;
488 wWindowConstrainSize(wwin, &new_width, &new_height);
490 wWindowCropSize(wwin, usableArea.x2-usableArea.x1,
491 usableArea.y2-usableArea.y1,
492 &new_width, &new_height);
494 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
497 WMPostNotificationName(WMNChangedState, wwin, "maximize");
499 wSoundPlay(WSOUND_MAXIMIZE);
503 void
504 wUnmaximizeWindow(WWindow *wwin)
506 int restore_x, restore_y;
508 if (!wwin->flags.maximized)
509 return;
511 if (wwin->flags.shaded) {
512 wwin->flags.skip_next_animation = 1;
513 wUnshadeWindow(wwin);
515 restore_x = (wwin->flags.maximized & MAX_HORIZONTAL) ?
516 wwin->old_geometry.x : wwin->frame_x;
517 restore_y = (wwin->flags.maximized & MAX_VERTICAL) ?
518 wwin->old_geometry.y : wwin->frame_y;
519 wwin->flags.maximized = 0;
520 wWindowConfigure(wwin, restore_x, restore_y,
521 wwin->old_geometry.width, wwin->old_geometry.height);
523 WMPostNotificationName(WMNChangedState, wwin, "maximize");
525 wSoundPlay(WSOUND_UNMAXIMIZE);
528 #ifdef ANIMATIONS
529 static void
530 animateResizeFlip(WScreen *scr, int x, int y, int w, int h,
531 int fx, int fy, int fw, int fh, int steps)
533 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
534 float cx, cy, cw, ch;
535 float xstep, ystep, wstep, hstep;
536 XPoint points[5];
537 float dx, dch, midy;
538 float angle, final_angle, delta;
540 xstep = (float)(fx-x)/steps;
541 ystep = (float)(fy-y)/steps;
542 wstep = (float)(fw-w)/steps;
543 hstep = (float)(fh-h)/steps;
545 cx = (float)x;
546 cy = (float)y;
547 cw = (float)w;
548 ch = (float)h;
550 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_F;
551 delta = (float)(final_angle/FRAMES);
552 for (angle=0;; angle+=delta) {
553 if (angle > final_angle)
554 angle = final_angle;
556 dx = (cw/10) - ((cw/5) * sin(angle));
557 dch = (ch/2) * cos(angle);
558 midy = cy + (ch/2);
560 points[0].x = cx + dx; points[0].y = midy - dch;
561 points[1].x = cx + cw - dx; points[1].y = points[0].y;
562 points[2].x = cx + cw + dx; points[2].y = midy + dch;
563 points[3].x = cx - dx; points[3].y = points[2].y;
564 points[4].x = points[0].x; points[4].y = points[0].y;
566 XGrabServer(dpy);
567 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
568 XFlush(dpy);
569 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
570 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
571 #else
572 wusleep(10);
573 #endif
575 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
576 XUngrabServer(dpy);
577 cx+=xstep;
578 cy+=ystep;
579 cw+=wstep;
580 ch+=hstep;
581 if (angle >= final_angle)
582 break;
585 XFlush(dpy);
587 #undef FRAMES
590 static void
591 animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
592 int fx, int fy, int fw, int fh, int steps)
594 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
595 float cx, cy, cw, ch;
596 float xstep, ystep, wstep, hstep;
597 XPoint points[5];
598 float angle, final_angle, a, d, delta;
600 x += w/2;
601 y += h/2;
602 fx += fw/2;
603 fy += fh/2;
605 xstep = (float)(fx-x)/steps;
606 ystep = (float)(fy-y)/steps;
607 wstep = (float)(fw-w)/steps;
608 hstep = (float)(fh-h)/steps;
610 cx = (float)x;
611 cy = (float)y;
612 cw = (float)w;
613 ch = (float)h;
615 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
616 delta = (float)(final_angle/FRAMES);
617 for (angle=0;; angle+=delta) {
618 if (angle > final_angle)
619 angle = final_angle;
621 a = atan(ch/cw);
622 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
624 points[0].x = cx+cos(angle-a)*d;
625 points[0].y = cy+sin(angle-a)*d;
626 points[1].x = cx+cos(angle+a)*d;
627 points[1].y = cy+sin(angle+a)*d;
628 points[2].x = cx+cos(angle-a+WM_PI)*d;
629 points[2].y = cy+sin(angle-a+WM_PI)*d;
630 points[3].x = cx+cos(angle+a+WM_PI)*d;
631 points[3].y = cy+sin(angle+a+WM_PI)*d;
632 points[4].x = cx+cos(angle-a)*d;
633 points[4].y = cy+sin(angle-a)*d;
634 XGrabServer(dpy);
635 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
636 XFlush(dpy);
637 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
638 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
639 #else
640 wusleep(10);
641 #endif
643 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
644 XUngrabServer(dpy);
645 cx+=xstep;
646 cy+=ystep;
647 cw+=wstep;
648 ch+=hstep;
649 if (angle >= final_angle)
650 break;
653 XFlush(dpy);
655 #undef FRAMES
658 static void
659 animateResizeZoom(WScreen *scr, int x, int y, int w, int h,
660 int fx, int fy, int fw, int fh, int steps)
662 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
663 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
664 float xstep, ystep, wstep, hstep;
665 int i, j;
667 xstep = (float)(fx-x)/steps;
668 ystep = (float)(fy-y)/steps;
669 wstep = (float)(fw-w)/steps;
670 hstep = (float)(fh-h)/steps;
672 for (j=0; j<FRAMES; j++) {
673 cx[j] = (float)x;
674 cy[j] = (float)y;
675 cw[j] = (float)w;
676 ch[j] = (float)h;
678 XGrabServer(dpy);
679 for (i=0; i<steps; i++) {
680 for (j=0; j<FRAMES; j++) {
681 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
682 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
684 XFlush(dpy);
685 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
686 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
687 #else
688 wusleep(10);
689 #endif
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]);
693 if (j<FRAMES-1) {
694 cx[j]=cx[j+1];
695 cy[j]=cy[j+1];
696 cw[j]=cw[j+1];
697 ch[j]=ch[j+1];
698 } else {
699 cx[j]+=xstep;
700 cy[j]+=ystep;
701 cw[j]+=wstep;
702 ch[j]+=hstep;
707 for (j=0; j<FRAMES; j++) {
708 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
709 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
711 XFlush(dpy);
712 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
713 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
714 #else
715 wusleep(10);
716 #endif
717 for (j=0; j<FRAMES; j++) {
718 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
719 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
722 XUngrabServer(dpy);
724 #undef FRAMES
727 void
728 animateResize(WScreen *scr, int x, int y, int w, int h,
729 int fx, int fy, int fw, int fh, int hiding)
731 int style = wPreferences.iconification_style; /* Catch the value */
732 int steps, k;
734 if (style == WIS_NONE)
735 return;
737 if (style == WIS_RANDOM) {
738 style = rand()%3;
741 k = (hiding ? 2 : 3);
742 switch(style) {
743 case WIS_TWIST:
744 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
745 if (steps>0)
746 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
747 break;
748 case WIS_FLIP:
749 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
750 if (steps>0)
751 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
752 break;
753 case WIS_ZOOM:
754 default:
755 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
756 if (steps>0)
757 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
758 break;
761 #endif /* ANIMATIONS */
764 static void
765 flushExpose()
767 XEvent tmpev;
769 while (XCheckTypedEvent(dpy, Expose, &tmpev))
770 WMHandleEvent(&tmpev);
771 XSync(dpy, 0);
774 static void
775 unmapTransientsFor(WWindow *wwin)
777 WWindow *tmp;
780 tmp = wwin->screen_ptr->focused_window;
781 while (tmp) {
782 /* unmap the transients for this transient */
783 if (tmp!=wwin && tmp->transient_for == wwin->client_win
784 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
785 || tmp->flags.shaded)) {
786 unmapTransientsFor(tmp);
787 tmp->flags.miniaturized = 1;
788 if (!tmp->flags.shaded) {
789 wWindowUnmap(tmp);
790 } else {
791 XUnmapWindow(dpy, tmp->frame->core->window);
794 if (!tmp->flags.shaded)
796 wClientSetState(tmp, IconicState, None);
798 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
800 tmp = tmp->prev;
805 static void
806 mapTransientsFor(WWindow *wwin)
808 WWindow *tmp;
810 tmp = wwin->screen_ptr->focused_window;
811 while (tmp) {
812 /* recursively map the transients for this transient */
813 if (tmp!=wwin && tmp->transient_for == wwin->client_win
814 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
815 && tmp->icon==NULL) {
816 mapTransientsFor(tmp);
817 tmp->flags.miniaturized = 0;
818 if (!tmp->flags.shaded) {
819 wWindowMap(tmp);
820 } else {
821 XMapWindow(dpy, tmp->frame->core->window);
823 tmp->flags.semi_focused = 0;
825 if (!tmp->flags.shaded)
827 wClientSetState(tmp, NormalState, None);
829 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
831 tmp = tmp->prev;
835 #if 0
836 static void
837 setupIconGrabs(WIcon *icon)
839 /* setup passive grabs on the icon */
840 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
841 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
842 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
843 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
844 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
845 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
846 XSync(dpy, 0);
848 #endif
850 static WWindow*
851 recursiveTransientFor(WWindow *wwin)
853 int i;
855 if (!wwin)
856 return None;
858 /* hackish way to detect transient_for cycle */
859 i = wwin->screen_ptr->window_count+1;
861 while (wwin && wwin->transient_for != None && i>0) {
862 wwin = wWindowFor(wwin->transient_for);
863 i--;
865 if (i==0 && wwin) {
866 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
867 wwin->frame->title);
868 return NULL;
871 return wwin;
874 #if 0
875 static void
876 removeIconGrabs(WIcon *icon)
878 /* remove passive grabs on the icon */
879 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
880 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
881 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
882 XSync(dpy, 0);
884 #endif
887 void
888 wIconifyWindow(WWindow *wwin)
890 XWindowAttributes attribs;
891 int present;
894 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
895 /* the window doesn't exist anymore */
896 return;
899 if (wwin->flags.miniaturized) {
900 return;
903 if (wwin->transient_for!=None &&
904 wwin->transient_for!=wwin->screen_ptr->root_win) {
905 WWindow *owner = wWindowFor(wwin->transient_for);
907 if (owner && owner->flags.miniaturized)
908 return;
911 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
913 /* if the window is in another workspace, simplify process */
914 if (present) {
915 /* icon creation may take a while */
916 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
917 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
918 GrabModeAsync, None, None, CurrentTime);
921 if (!wPreferences.disable_miniwindows) {
922 if (!wwin->flags.icon_moved) {
923 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y);
925 wwin->icon = wIconCreate(wwin);
927 wwin->icon->mapped = 1;
930 wwin->flags.miniaturized = 1;
931 wwin->flags.mapped = 0;
933 /* unmap transients */
935 unmapTransientsFor(wwin);
937 if (present) {
938 wSoundPlay(WSOUND_ICONIFY);
940 XUngrabPointer(dpy, CurrentTime);
941 wWindowUnmap(wwin);
942 /* let all Expose events arrive so that we can repaint
943 * something before the animation starts (and the server is grabbed) */
944 XSync(dpy, 0);
946 if (wPreferences.disable_miniwindows)
947 wClientSetState(wwin, IconicState, None);
948 else
949 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
951 flushExpose();
952 #ifdef ANIMATIONS
953 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
954 && !wPreferences.no_animations) {
955 int ix, iy, iw, ih;
957 if (!wPreferences.disable_miniwindows) {
958 ix = wwin->icon_x;
959 iy = wwin->icon_y;
960 iw = wwin->icon->core->width;
961 ih = wwin->icon->core->height;
962 } else {
963 #ifdef KWM_HINTS
964 WArea area;
966 if (wKWMGetIconGeometry(wwin, &area)) {
967 ix = area.x1;
968 iy = area.y1;
969 iw = area.x2 - ix;
970 ih = area.y2 - iy;
971 } else
972 #endif /* KWM_HINTS */
974 ix = 0;
975 iy = 0;
976 iw = wwin->screen_ptr->scr_width;
977 ih = wwin->screen_ptr->scr_height;
980 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
981 wwin->frame->core->width, wwin->frame->core->height,
982 ix, iy, iw, ih, False);
984 #endif
987 wwin->flags.skip_next_animation = 0;
989 if (!wPreferences.disable_miniwindows) {
991 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
992 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
994 XMapWindow(dpy, wwin->icon->core->window);
996 AddToStackList(wwin->icon->core);
998 wLowerFrame(wwin->icon->core);
1001 if (present) {
1002 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1005 * It doesn't seem to be working and causes button event hangup
1006 * when deiconifying a transient window.
1007 setupIconGrabs(wwin->icon);
1009 if ((wwin->flags.focused
1010 || (owner && wwin->client_win == owner->client_win))
1011 && wPreferences.focus_mode==WKF_CLICK) {
1012 WWindow *tmp;
1014 tmp = wwin->prev;
1015 while (tmp) {
1016 if (!WFLAGP(tmp, no_focusable)
1017 && !(tmp->flags.hidden||tmp->flags.miniaturized)
1018 && (wwin->frame->workspace == tmp->frame->workspace))
1019 break;
1020 tmp = tmp->prev;
1022 wSetFocusTo(wwin->screen_ptr, tmp);
1023 } else if (wPreferences.focus_mode!=WKF_CLICK) {
1024 wSetFocusTo(wwin->screen_ptr, NULL);
1027 #ifdef ANIMATIONS
1028 if (!wwin->screen_ptr->flags.startup) {
1029 Window clientwin = wwin->client_win;
1031 XSync(dpy, 0);
1032 processEvents(XPending(dpy));
1034 /* the window can disappear while doing the processEvents() */
1035 if (!wWindowFor(clientwin))
1036 return;
1038 #endif
1042 if (wwin->flags.selected && !wPreferences.disable_miniwindows)
1043 wIconSelect(wwin->icon);
1045 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1051 void
1052 wDeiconifyWindow(WWindow *wwin)
1054 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1056 if (!wwin->flags.miniaturized)
1057 return;
1059 if (wwin->transient_for != None
1060 && wwin->transient_for != wwin->screen_ptr->root_win) {
1061 WWindow *owner = recursiveTransientFor(wwin);
1063 if (owner && owner->flags.miniaturized) {
1064 wDeiconifyWindow(owner);
1065 wSetFocusTo(wwin->screen_ptr, wwin);
1066 wRaiseFrame(wwin->frame->core);
1067 return;
1071 wwin->flags.miniaturized = 0;
1072 if (!wwin->flags.shaded)
1073 wwin->flags.mapped = 1;
1075 if (!wPreferences.disable_miniwindows && wwin->icon != NULL) {
1076 if (wwin->icon->selected)
1077 wIconSelect(wwin->icon);
1079 XUnmapWindow(dpy, wwin->icon->core->window);
1082 wSoundPlay(WSOUND_DEICONIFY);
1084 /* if the window is in another workspace, do it silently */
1085 #ifdef ANIMATIONS
1086 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1087 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1088 int ix, iy, iw, ih;
1090 if (!wPreferences.disable_miniwindows) {
1091 ix = wwin->icon_x;
1092 iy = wwin->icon_y;
1093 iw = wwin->icon->core->width;
1094 ih = wwin->icon->core->height;
1095 } else {
1096 #ifdef KWM_HINTS
1097 WArea area;
1099 if (wKWMGetIconGeometry(wwin, &area)) {
1100 ix = area.x1;
1101 iy = area.y1;
1102 iw = area.x2 - ix;
1103 ih = area.y2 - iy;
1104 } else
1105 #endif /* KWM_HINTS */
1107 ix = 0;
1108 iy = 0;
1109 iw = wwin->screen_ptr->scr_width;
1110 ih = wwin->screen_ptr->scr_height;
1113 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1114 wwin->frame_x, wwin->frame_y,
1115 wwin->frame->core->width, wwin->frame->core->height,
1116 False);
1118 #endif /* ANIMATIONS */
1119 wwin->flags.skip_next_animation = 0;
1120 XGrabServer(dpy);
1121 if (!wwin->flags.shaded) {
1122 XMapWindow(dpy, wwin->client_win);
1124 XMapWindow(dpy, wwin->frame->core->window);
1125 wRaiseFrame(wwin->frame->core);
1126 if (!wwin->flags.shaded) {
1127 wClientSetState(wwin, NormalState, None);
1129 mapTransientsFor(wwin);
1131 if (!wPreferences.disable_miniwindows && wwin->icon != NULL) {
1132 RemoveFromStackList(wwin->icon->core);
1133 /* removeIconGrabs(wwin->icon);*/
1134 wIconDestroy(wwin->icon);
1135 wwin->icon = NULL;
1137 XUngrabServer(dpy);
1139 if (wPreferences.focus_mode==WKF_CLICK)
1140 wSetFocusTo(wwin->screen_ptr, wwin);
1142 #ifdef ANIMATIONS
1143 if (!wwin->screen_ptr->flags.startup) {
1144 Window clientwin = wwin->client_win;
1146 XSync(dpy, 0);
1147 processEvents(XPending(dpy));
1149 if (!wWindowFor(clientwin))
1150 return;
1152 #endif
1154 if (wPreferences.auto_arrange_icons) {
1155 wArrangeIcons(wwin->screen_ptr, True);
1158 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1160 /* In case we were shaded and iconified, also unshade */
1161 wUnshadeWindow(wwin);
1166 static void
1167 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1169 if (wwin->flags.miniaturized) {
1170 if (wwin->icon) {
1171 XUnmapWindow(dpy, wwin->icon->core->window);
1172 wwin->icon->mapped = 0;
1174 wwin->flags.hidden = 1;
1176 WMPostNotificationName(WMNChangedState, wwin, "hide");
1177 return;
1180 if (wwin->flags.inspector_open) {
1181 wHideInspectorForWindow(wwin);
1184 wwin->flags.hidden = 1;
1185 wWindowUnmap(wwin);
1187 wClientSetState(wwin, IconicState, icon->icon_win);
1188 flushExpose();
1189 wSoundPlay(WSOUND_HIDE);
1190 #ifdef ANIMATIONS
1191 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1192 !wwin->flags.skip_next_animation && animate) {
1193 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1194 wwin->frame->core->width, wwin->frame->core->height,
1195 icon_x, icon_y, icon->core->width, icon->core->height,
1196 True);
1198 #endif
1199 wwin->flags.skip_next_animation = 0;
1201 WMPostNotificationName(WMNChangedState, wwin, "hide");
1206 void
1207 wHideOtherApplications(WWindow *awin)
1209 WWindow *wwin;
1210 WApplication *tapp;
1212 if (!awin)
1213 return;
1214 wwin = awin->screen_ptr->focused_window;
1217 while (wwin) {
1218 if (wwin!=awin
1219 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1220 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1221 && !wwin->flags.internal_window
1222 && wGetWindowOfInspectorForWindow(wwin) != awin
1223 && !WFLAGP(wwin, no_hide_others)) {
1225 if (wwin->main_window==None || WFLAGP(wwin, no_appicon)) {
1226 if (!WFLAGP(wwin, no_miniaturizable)) {
1227 wwin->flags.skip_next_animation = 1;
1228 wIconifyWindow(wwin);
1230 } else if (wwin->main_window!=None
1231 && awin->main_window != wwin->main_window) {
1232 tapp = wApplicationOf(wwin->main_window);
1233 if (tapp) {
1234 tapp->flags.skip_next_animation = 1;
1235 wHideApplication(tapp);
1236 } else {
1237 if (!WFLAGP(wwin, no_miniaturizable)) {
1238 wwin->flags.skip_next_animation = 1;
1239 wIconifyWindow(wwin);
1244 wwin = wwin->prev;
1247 wSetFocusTo(awin->screen_ptr, awin);
1253 void
1254 wHideApplication(WApplication *wapp)
1256 WScreen *scr;
1257 WWindow *wlist;
1258 int hadfocus;
1260 if (!wapp) {
1261 wwarning("trying to hide a non grouped window");
1262 return;
1264 if (!wapp->main_window_desc) {
1265 wwarning("group leader not found for window group");
1266 return;
1268 scr = wapp->main_window_desc->screen_ptr;
1269 hadfocus = 0;
1270 wlist = scr->focused_window;
1271 if (!wlist)
1272 return;
1274 if (wlist->main_window == wapp->main_window)
1275 wapp->last_focused = wlist;
1276 else
1277 wapp->last_focused = NULL;
1278 while (wlist) {
1279 if (wlist->main_window == wapp->main_window) {
1280 if (wlist->flags.focused) {
1281 hadfocus = 1;
1283 if (wapp->app_icon)
1284 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1285 wapp->app_icon->y_pos, wlist,
1286 !wapp->flags.skip_next_animation);
1288 wlist = wlist->prev;
1291 wapp->flags.skip_next_animation = 0;
1293 if (hadfocus) {
1294 if (wPreferences.focus_mode==WKF_CLICK) {
1295 wlist = scr->focused_window;
1296 while (wlist) {
1297 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1298 && (wlist->flags.mapped || wlist->flags.shaded))
1299 break;
1300 wlist = wlist->prev;
1302 wSetFocusTo(scr, wlist);
1303 } else {
1304 wSetFocusTo(scr, NULL);
1308 wapp->flags.hidden = 1;
1310 if(wPreferences.auto_arrange_icons) {
1311 wArrangeIcons(scr, True);
1313 #ifdef HIDDENDOT
1314 if (wapp->app_icon)
1315 wAppIconPaint(wapp->app_icon);
1316 #endif
1322 static void
1323 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1324 int bringToCurrentWS)
1326 if (bringToCurrentWS)
1327 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1329 wwin->flags.hidden=0;
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 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1344 XMapWindow(dpy, wwin->client_win);
1345 XMapWindow(dpy, wwin->frame->core->window);
1346 wClientSetState(wwin, NormalState, None);
1347 wwin->flags.mapped=1;
1348 wRaiseFrame(wwin->frame->core);
1350 if (wwin->flags.inspector_open) {
1351 wUnhideInspectorForWindow(wwin);
1354 WMPostNotificationName(WMNChangedState, wwin, "hide");
1358 void
1359 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1361 WScreen *scr;
1362 WWindow *wlist, *next;
1363 WWindow *focused=NULL;
1365 if (!wapp) {
1366 return;
1368 scr = wapp->main_window_desc->screen_ptr;
1369 wlist = scr->focused_window;
1370 if (!wlist) return;
1371 /* goto beginning of list */
1372 while (wlist->prev)
1373 wlist = wlist->prev;
1375 while (wlist) {
1376 next = wlist->next;
1378 if (wlist->main_window == wapp->main_window) {
1379 if (wlist->flags.focused)
1380 focused = wlist;
1381 else if (!focused || !focused->flags.focused)
1382 focused = wlist;
1384 if (wlist->flags.miniaturized && wlist->icon) {
1385 if (bringToCurrentWS || wPreferences.sticky_icons
1386 || wlist->frame->workspace == scr->current_workspace) {
1387 if (!wlist->icon->mapped) {
1388 XMapWindow(dpy, wlist->icon->core->window);
1389 wlist->icon->mapped = 1;
1391 wlist->flags.hidden = 0;
1393 WMPostNotificationName(WMNChangedState, wlist, "hide");
1395 if (wlist->frame->workspace != scr->current_workspace)
1396 wWindowChangeWorkspace(wlist, scr->current_workspace);
1398 if (miniwindows) {
1399 wDeiconifyWindow(wlist);
1401 } else if (wlist->flags.hidden) {
1402 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1403 wapp->app_icon->y_pos, wlist,
1404 !wapp->flags.skip_next_animation,
1405 bringToCurrentWS);
1406 } else {
1407 if (bringToCurrentWS
1408 && wlist->frame->workspace != scr->current_workspace) {
1409 wWindowChangeWorkspace(wlist, scr->current_workspace);
1411 wRaiseFrame(wlist->frame->core);
1414 wlist = next;
1417 wapp->flags.skip_next_animation = 0;
1418 wapp->flags.hidden = 0;
1420 if (focused)
1421 wSetFocusTo(scr, focused);
1422 else if (wapp->last_focused && wapp->last_focused->flags.mapped)
1423 wSetFocusTo(scr, wapp->last_focused);
1424 wapp->last_focused = NULL;
1425 if (wPreferences.auto_arrange_icons) {
1426 wArrangeIcons(scr, True);
1428 #ifdef HIDDENDOT
1429 wAppIconPaint(wapp->app_icon);
1430 #endif
1435 void
1436 wShowAllWindows(WScreen *scr)
1438 WWindow *wwin, *old_foc;
1439 WApplication *wapp;
1441 old_foc = wwin = scr->focused_window;
1442 while (wwin) {
1443 if (!wwin->flags.internal_window &&
1444 (scr->current_workspace == wwin->frame->workspace
1445 || IS_OMNIPRESENT(wwin))) {
1446 if (wwin->flags.miniaturized) {
1447 wwin->flags.skip_next_animation = 1;
1448 wDeiconifyWindow(wwin);
1449 } else if (wwin->flags.hidden) {
1450 wapp = wApplicationOf(wwin->main_window);
1451 if (wapp) {
1452 wUnhideApplication(wapp, False, False);
1453 } else {
1454 wwin->flags.skip_next_animation = 1;
1455 wDeiconifyWindow(wwin);
1459 wwin = wwin->prev;
1461 wSetFocusTo(scr, old_foc);
1462 /*wRaiseFrame(old_foc->frame->core);*/
1466 void
1467 wRefreshDesktop(WScreen *scr)
1469 Window win;
1470 XSetWindowAttributes attr;
1472 attr.backing_store = NotUseful;
1473 attr.save_under = False;
1474 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1475 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1476 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1477 &attr);
1478 XMapRaised(dpy, win);
1479 XDestroyWindow(dpy, win);
1480 XFlush(dpy);
1484 void
1485 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1487 WWindow *wwin;
1488 WAppIcon *aicon;
1489 int pf; /* primary axis */
1490 int sf; /* secondary axis */
1491 int fullW;
1492 int fullH;
1493 int pi, si;
1494 int sx1, sx2, sy1, sy2; /* screen boundary */
1495 int sw, sh;
1496 int xo, yo;
1497 int xs, ys;
1498 int isize = wPreferences.icon_size;
1501 * Find out screen boundaries.
1505 * Allows each head to have miniwindows
1507 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1509 sx1 = rect.pos.x;
1510 sy1 = rect.pos.y;
1511 sw = rect.size.width;
1512 sh = rect.size.height;
1513 sx2 = sx1 + sw;
1514 sy2 = sy1 + sh;
1515 if (scr->dock) {
1516 if (scr->dock->on_right_side)
1517 sx2 -= isize + DOCK_EXTRA_SPACE;
1518 else
1519 sx1 += isize + DOCK_EXTRA_SPACE;
1522 #if 0
1523 sw = isize * (scr->scr_width/isize);
1524 sh = isize * (scr->scr_height/isize);
1525 #else
1526 sw = isize * (sw/isize);
1527 sh = isize * (sh/isize);
1528 #endif
1529 fullW = (sx2-sx1)/isize;
1530 fullW = (sx2-sx1)/isize;
1531 fullH = (sy2-sy1)/isize;
1533 /* icon yard boundaries */
1534 if (wPreferences.icon_yard & IY_VERT) {
1535 pf = fullH;
1536 sf = fullW;
1537 } else {
1538 pf = fullW;
1539 sf = fullH;
1541 if (wPreferences.icon_yard & IY_RIGHT) {
1542 xo = sx2 - isize;
1543 xs = -1;
1544 } else {
1545 xo = sx1;
1546 xs = 1;
1548 if (wPreferences.icon_yard & IY_TOP) {
1549 yo = sy1;
1550 ys = 1;
1551 } else {
1552 yo = sy2 - isize;
1553 ys = -1;
1556 /* arrange icons putting the most recently focused window
1557 * as the last icon */
1558 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1559 : xo + xs*(pi*isize))
1560 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1561 : yo + ys*(si*isize))
1563 /* arrange application icons */
1564 aicon = scr->app_icon_list;
1565 /* reverse them to avoid unnecessarily sliding of icons */
1566 while (aicon && aicon->next)
1567 aicon = aicon->next;
1569 pi = 0;
1570 si = 0;
1571 while (aicon) {
1572 if (!aicon->docked) {
1573 if (aicon->x_pos != X || aicon->y_pos != Y) {
1574 #ifdef ANIMATIONS
1575 if (!wPreferences.no_animations) {
1576 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1577 X, Y);
1579 #endif /* ANIMATIONS */
1581 wAppIconMove(aicon, X, Y);
1582 pi++;
1584 /* we reversed the order so we use prev */
1585 aicon = aicon->prev;
1586 if (pi >= pf) {
1587 pi=0;
1588 si++;
1592 /* arrange miniwindows */
1594 wwin = scr->focused_window;
1595 /* reverse them to avoid unnecessarily shuffling */
1596 while (wwin && wwin->prev)
1597 wwin = wwin->prev;
1599 while (wwin) {
1600 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1601 (wwin->frame->workspace==scr->current_workspace ||
1602 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1604 if (arrangeAll || !wwin->flags.icon_moved) {
1605 if (wwin->icon_x != X || wwin->icon_y != Y) {
1606 #ifdef ANIMATIONS
1607 if (wPreferences.no_animations) {
1608 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1609 } else {
1610 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1611 wwin->icon_y, X, Y);
1613 #else
1614 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1615 #endif /* ANIMATIONS */
1617 wwin->icon_x = X;
1618 wwin->icon_y = Y;
1619 pi++;
1622 if (arrangeAll) {
1623 wwin->flags.icon_moved = 0;
1625 /* we reversed the order, so we use next */
1626 wwin = wwin->next;
1627 if (pi >= pf) {
1628 pi=0;
1629 si++;
1635 void
1636 wSelectWindow(WWindow *wwin, Bool flag)
1638 WScreen *scr = wwin->screen_ptr;
1640 if (flag) {
1641 wwin->flags.selected = 1;
1642 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1644 if (WFLAGP(wwin, no_border)) {
1645 XSetWindowBorderWidth(dpy, wwin->frame->core->window,
1646 FRAME_BORDER_WIDTH);
1649 if (!scr->selected_windows)
1650 scr->selected_windows = WMCreateArray(4);
1651 WMAddToArray(scr->selected_windows, wwin);
1652 } else {
1653 wwin->flags.selected = 0;
1654 XSetWindowBorder(dpy, wwin->frame->core->window,
1655 scr->frame_border_pixel);
1657 if (WFLAGP(wwin, no_border)) {
1658 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1661 if (scr->selected_windows) {
1662 WMRemoveFromArray(scr->selected_windows, wwin);
1668 void
1669 wMakeWindowVisible(WWindow *wwin)
1671 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1672 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1674 if (wwin->flags.shaded) {
1675 wUnshadeWindow(wwin);
1677 if (wwin->flags.hidden) {
1678 WApplication *app;
1680 app = wApplicationOf(wwin->main_window);
1681 if (app)
1682 wUnhideApplication(app, False, False);
1683 } else if (wwin->flags.miniaturized) {
1684 wDeiconifyWindow(wwin);
1685 } else {
1686 if (!WFLAGP(wwin, no_focusable))
1687 wSetFocusTo(wwin->screen_ptr, wwin);
1688 wRaiseFrame(wwin->frame->core);