applied patch from Ryosuke Nanba <rna@cyber.email.ne.jp>
[wmaker-crm.git] / src / actions.c
blob8f23c17563317442135f7247174f0c95aededb53
1 /* action.c- misc. window commands (miniaturize, hide etc.)
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997-2002 Alfredo K. Kojima
6 * Copyright (c) 1998-2002 Dan Pascu
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #include "wconfig.h"
27 #include <X11/Xlib.h>
28 #include <X11/Xutil.h>
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <unistd.h>
32 #include <math.h>
33 #include <time.h>
35 #include "WindowMaker.h"
36 #include "wcore.h"
37 #include "framewin.h"
38 #include "window.h"
39 #include "client.h"
40 #include "icon.h"
41 #include "funcs.h"
42 #include "application.h"
43 #include "actions.h"
44 #include "stacking.h"
45 #include "appicon.h"
46 #include "dock.h"
47 #include "appmenu.h"
48 #include "winspector.h"
49 #include "workspace.h"
50 #include "wsound.h"
51 #include "xinerama.h"
53 #ifdef GNOME_STUFF
54 # include "gnome.h"
55 #endif
56 #ifdef KWM_HINTS
57 # include "kwm.h"
58 #endif
62 /****** Global Variables ******/
63 extern Time LastTimestamp;
64 extern Time LastFocusChange;
66 extern Cursor wCursor[WCUR_LAST];
68 extern WPreferences wPreferences;
70 extern Atom _XA_WM_TAKE_FOCUS;
73 /******* Local Variables *******/
74 static struct {
75 int steps;
76 int delay;
77 } shadePars[5] = {
78 {SHADE_STEPS_UF, SHADE_DELAY_UF},
79 {SHADE_STEPS_F, SHADE_DELAY_F},
80 {SHADE_STEPS_M, SHADE_DELAY_M},
81 {SHADE_STEPS_S, SHADE_DELAY_S},
82 {SHADE_STEPS_US, SHADE_DELAY_US}};
84 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
85 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
88 static int ignoreTimestamp=0;
91 #ifdef ANIMATIONS
92 static void
93 processEvents(int event_count)
95 XEvent event;
98 * This is a hack. When animations are enabled, processing of
99 * events ocurred during a animation are delayed until it's end.
100 * Calls that consider the TimeStamp, like XSetInputFocus(), will
101 * fail because the TimeStamp is too old. Then, for example, if
102 * the user changes window focus while a miniaturize animation is
103 * in course, the window will not get focus properly after the end
104 * of the animation. This tries to workaround it by passing CurrentTime
105 * as the TimeStamp for XSetInputFocus() for all events ocurred during
106 * the animation.
108 ignoreTimestamp=1;
109 while (XPending(dpy) && event_count--) {
110 WMNextEvent(dpy, &event);
111 WMHandleEvent(&event);
113 ignoreTimestamp=0;
115 #endif /* ANIMATIONS */
120 *----------------------------------------------------------------------
121 * wSetFocusTo--
122 * Changes the window focus to the one passed as argument.
123 * If the window to focus is not already focused, it will be brought
124 * to the head of the list of windows. Previously focused window is
125 * unfocused.
127 * Side effects:
128 * Window list may be reordered and the window focus is changed.
130 *----------------------------------------------------------------------
132 void
133 wSetFocusTo(WScreen *scr, WWindow *wwin)
135 static WScreen *old_scr=NULL;
137 WWindow *old_focused;
138 WWindow *focused=scr->focused_window;
139 int timestamp=LastTimestamp;
140 WApplication *oapp=NULL, *napp=NULL;
141 int wasfocused;
143 if (!old_scr)
144 old_scr=scr;
145 old_focused=old_scr->focused_window;
147 LastFocusChange = timestamp;
150 * This is a hack, because XSetInputFocus() should have a proper
151 * timestamp instead of CurrentTime but it seems that some times
152 * clients will not receive focus properly that way.
153 if (ignoreTimestamp)
155 timestamp = CurrentTime;
157 if (old_focused)
158 oapp = wApplicationOf(old_focused->main_window);
160 if (wwin == NULL) {
161 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
162 if (old_focused) {
163 wWindowUnfocus(old_focused);
165 if (oapp) {
166 wAppMenuUnmap(oapp->menu);
167 #ifdef NEWAPPICON
168 wApplicationDeactivate(oapp);
169 #endif
172 WMPostNotificationName(WMNChangedFocus, NULL, (void*)True);
173 return;
174 } else if (old_scr != scr && old_focused) {
175 wWindowUnfocus(old_focused);
178 wasfocused = wwin->flags.focused;
179 napp = wApplicationOf(wwin->main_window);
181 /* remember last workspace where the app has been */
182 if (napp) {
183 /*napp->last_workspace = wwin->screen_ptr->current_workspace;*/
184 napp->last_workspace = wwin->frame->workspace;
187 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
188 /* install colormap if colormap mode is lock mode */
189 if (wPreferences.colormap_mode==WCM_CLICK)
190 wColormapInstallForWindow(scr, wwin);
192 /* set input focus */
193 switch (wwin->focus_mode) {
194 case WFM_NO_INPUT:
195 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
196 break;
198 case WFM_PASSIVE:
199 case WFM_LOCALLY_ACTIVE:
200 XSetInputFocus(dpy, wwin->client_win, RevertToParent, timestamp);
201 break;
203 case WFM_GLOBALLY_ACTIVE:
204 break;
206 XFlush(dpy);
207 if (wwin->protocols.TAKE_FOCUS) {
208 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
210 XSync(dpy, False);
211 } else {
212 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, timestamp);
214 if (WFLAGP(wwin, no_focusable))
215 return;
217 /* if this is not the focused window focus it */
218 if (focused!=wwin) {
219 /* change the focus window list order */
220 if (wwin->prev)
221 wwin->prev->next = wwin->next;
223 if (wwin->next)
224 wwin->next->prev = wwin->prev;
226 wwin->prev = focused;
227 focused->next = wwin;
228 wwin->next = NULL;
229 scr->focused_window = wwin;
231 if (oapp && oapp != napp) {
232 wAppMenuUnmap(oapp->menu);
233 #ifdef NEWAPPICON
234 wApplicationDeactivate(oapp);
235 #endif
239 wWindowFocus(wwin, focused);
241 if (napp && !wasfocused) {
242 #ifdef USER_MENU
243 wUserMenuRefreshInstances(napp->menu, wwin);
244 #endif /* USER_MENU */
246 if (wwin->flags.mapped)
247 wAppMenuMap(napp->menu, wwin);
248 #ifdef NEWAPPICON
249 wApplicationActivate(napp);
250 #endif
253 XFlush(dpy);
254 old_scr=scr;
258 void
259 wShadeWindow(WWindow *wwin)
261 time_t time0;
262 #ifdef ANIMATIONS
263 int y, s, w, h;
264 #endif
266 if (wwin->flags.shaded)
267 return;
269 time0 = time(NULL);
271 XLowerWindow(dpy, wwin->client_win);
273 wSoundPlay(WSOUND_SHADE);
275 #ifdef ANIMATIONS
276 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
277 && !wPreferences.no_animations) {
278 /* do the shading animation */
279 h = wwin->frame->core->height;
280 s = h/SHADE_STEPS;
281 if (s < 1) s=1;
282 w = wwin->frame->core->width;
283 y = wwin->frame->top_width;
284 while (h>wwin->frame->top_width+1) {
285 XMoveWindow(dpy, wwin->client_win, 0, y);
286 XResizeWindow(dpy, wwin->frame->core->window, w, h);
287 XFlush(dpy);
289 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
290 break;
292 if (SHADE_DELAY > 0) {
293 wusleep(SHADE_DELAY*1000L);
294 } else {
295 wusleep(10);
297 h-=s;
298 y-=s;
300 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
302 #endif /* ANIMATIONS */
304 wwin->flags.skip_next_animation = 0;
305 wwin->flags.shaded = 1;
306 wwin->flags.mapped = 0;
307 /* prevent window withdrawal when getting UnmapNotify */
308 XSelectInput(dpy, wwin->client_win,
309 wwin->event_mask & ~StructureNotifyMask);
310 XUnmapWindow(dpy, wwin->client_win);
311 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
313 /* for the client it's just like iconification */
314 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
315 wwin->frame->top_width - 1);
317 wwin->client.y = wwin->frame_y - wwin->client.height
318 + wwin->frame->top_width;
319 wWindowSynthConfigureNotify(wwin);
322 wClientSetState(wwin, IconicState, None);
325 WMPostNotificationName(WMNChangedState, wwin, "shade");
327 #ifdef ANIMATIONS
328 if (!wwin->screen_ptr->flags.startup) {
329 /* Look at processEvents() for reason of this code. */
330 XSync(dpy, 0);
331 processEvents(XPending(dpy));
333 #endif
337 void
338 wUnshadeWindow(WWindow *wwin)
340 time_t time0;
341 #ifdef ANIMATIONS
342 int y, s, w, h;
343 #endif /* ANIMATIONS */
346 if (!wwin->flags.shaded)
347 return;
349 time0 = time(NULL);
351 wwin->flags.shaded = 0;
352 wwin->flags.mapped = 1;
353 XMapWindow(dpy, wwin->client_win);
355 wSoundPlay(WSOUND_UNSHADE);
357 #ifdef ANIMATIONS
358 if (!wPreferences.no_animations && !wwin->flags.skip_next_animation) {
359 /* do the shading animation */
360 h = wwin->frame->top_width + wwin->frame->bottom_width;
361 y = wwin->frame->top_width - wwin->client.height;
362 s = abs(y)/SHADE_STEPS;
363 if (s<1) s=1;
364 w = wwin->frame->core->width;
365 XMoveWindow(dpy, wwin->client_win, 0, y);
366 if (s>0) {
367 while (h < wwin->client.height + wwin->frame->top_width
368 + wwin->frame->bottom_width) {
369 XResizeWindow(dpy, wwin->frame->core->window, w, h);
370 XMoveWindow(dpy, wwin->client_win, 0, y);
371 XFlush(dpy);
372 if (SHADE_DELAY > 0) {
373 wusleep(SHADE_DELAY*2000L/3);
374 } else {
375 wusleep(10);
377 h+=s;
378 y+=s;
380 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
381 break;
384 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
386 #endif /* ANIMATIONS */
388 wwin->flags.skip_next_animation = 0;
389 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
390 wwin->frame->top_width + wwin->client.height
391 + wwin->frame->bottom_width);
393 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
394 wWindowSynthConfigureNotify(wwin);
397 wClientSetState(wwin, NormalState, None);
399 /* if the window is focused, set the focus again as it was disabled during
400 * shading */
401 if (wwin->flags.focused)
402 wSetFocusTo(wwin->screen_ptr, wwin);
404 WMPostNotificationName(WMNChangedState, wwin, "shade");
408 void
409 wMaximizeWindow(WWindow *wwin, int directions)
411 int new_width, new_height, new_x, new_y;
412 WArea usableArea = wwin->screen_ptr->totalUsableArea;
413 WArea totalArea;
416 if (WFLAGP(wwin, no_resizable))
417 return;
419 totalArea.x1 = 0;
420 totalArea.y1 = 0;
421 totalArea.x2 = wwin->screen_ptr->scr_width;
422 totalArea.y2 = wwin->screen_ptr->scr_height;
424 #ifdef XINERAMA
425 if (wwin->screen_ptr->xine_count > 0
426 && !(directions & MAX_IGNORE_XINERAMA)) {
427 WScreen *scr = wwin->screen_ptr;
428 WMRect rect;
430 rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
431 totalArea.x1 = rect.pos.x;
432 totalArea.y1 = rect.pos.y;
433 totalArea.x2 = totalArea.x1 + rect.size.width;
434 totalArea.y2 = totalArea.y1 + rect.size.height;
436 usableArea.x1 = WMAX(totalArea.x1, usableArea.x1);
437 usableArea.y1 = WMAX(totalArea.y1, usableArea.y1);
438 usableArea.x2 = WMIN(totalArea.x2, usableArea.x2);
439 usableArea.y2 = WMIN(totalArea.y2, usableArea.y2);
441 #endif /* XINERAMA */
443 if (WFLAGP(wwin, full_maximize)) {
444 usableArea = totalArea;
447 if (wwin->flags.shaded) {
448 wwin->flags.skip_next_animation = 1;
449 wUnshadeWindow(wwin);
451 wwin->flags.maximized = directions;
452 wwin->old_geometry.width = wwin->client.width;
453 wwin->old_geometry.height = wwin->client.height;
454 wwin->old_geometry.x = wwin->frame_x;
455 wwin->old_geometry.y = wwin->frame_y;
457 #ifdef KWM_HINTS
458 wKWMUpdateClientGeometryRestore(wwin);
459 #endif
461 if (directions & MAX_HORIZONTAL) {
463 new_width = (usableArea.x2-usableArea.x1)-FRAME_BORDER_WIDTH*2;
464 new_x = usableArea.x1;
466 } else {
468 new_x = wwin->frame_x;
469 new_width = wwin->frame->core->width;
473 if (directions & MAX_VERTICAL) {
475 new_height = (usableArea.y2-usableArea.y1)-FRAME_BORDER_WIDTH*2;
476 new_y = usableArea.y1;
477 if (WFLAGP(wwin, full_maximize)) {
478 new_y -= wwin->frame->top_width;
479 new_height += wwin->frame->bottom_width - 1;
481 } else {
482 new_y = wwin->frame_y;
483 new_height = wwin->frame->core->height;
486 if (!WFLAGP(wwin, full_maximize)) {
487 new_height -= wwin->frame->top_width+wwin->frame->bottom_width;
490 wWindowConstrainSize(wwin, &new_width, &new_height);
492 wWindowCropSize(wwin, usableArea.x2-usableArea.x1,
493 usableArea.y2-usableArea.y1,
494 &new_width, &new_height);
496 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
499 WMPostNotificationName(WMNChangedState, wwin, "maximize");
501 wSoundPlay(WSOUND_MAXIMIZE);
505 void
506 wUnmaximizeWindow(WWindow *wwin)
508 int restore_x, restore_y;
510 if (!wwin->flags.maximized)
511 return;
513 if (wwin->flags.shaded) {
514 wwin->flags.skip_next_animation = 1;
515 wUnshadeWindow(wwin);
517 restore_x = (wwin->flags.maximized & MAX_HORIZONTAL) ?
518 wwin->old_geometry.x : wwin->frame_x;
519 restore_y = (wwin->flags.maximized & MAX_VERTICAL) ?
520 wwin->old_geometry.y : wwin->frame_y;
521 wwin->flags.maximized = 0;
522 wWindowConfigure(wwin, restore_x, restore_y,
523 wwin->old_geometry.width, wwin->old_geometry.height);
525 WMPostNotificationName(WMNChangedState, wwin, "maximize");
527 wSoundPlay(WSOUND_UNMAXIMIZE);
530 #ifdef ANIMATIONS
531 static void
532 animateResizeFlip(WScreen *scr, int x, int y, int w, int h,
533 int fx, int fy, int fw, int fh, int steps)
535 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
536 float cx, cy, cw, ch;
537 float xstep, ystep, wstep, hstep;
538 XPoint points[5];
539 float dx, dch, midy;
540 float angle, final_angle, delta;
542 xstep = (float)(fx-x)/steps;
543 ystep = (float)(fy-y)/steps;
544 wstep = (float)(fw-w)/steps;
545 hstep = (float)(fh-h)/steps;
547 cx = (float)x;
548 cy = (float)y;
549 cw = (float)w;
550 ch = (float)h;
552 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_F;
553 delta = (float)(final_angle/FRAMES);
554 for (angle=0;; angle+=delta) {
555 if (angle > final_angle)
556 angle = final_angle;
558 dx = (cw/10) - ((cw/5) * sin(angle));
559 dch = (ch/2) * cos(angle);
560 midy = cy + (ch/2);
562 points[0].x = cx + dx; points[0].y = midy - dch;
563 points[1].x = cx + cw - dx; points[1].y = points[0].y;
564 points[2].x = cx + cw + dx; points[2].y = midy + dch;
565 points[3].x = cx - dx; points[3].y = points[2].y;
566 points[4].x = points[0].x; points[4].y = points[0].y;
568 XGrabServer(dpy);
569 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
570 XFlush(dpy);
571 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
572 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
573 #else
574 wusleep(10);
575 #endif
577 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
578 XUngrabServer(dpy);
579 cx+=xstep;
580 cy+=ystep;
581 cw+=wstep;
582 ch+=hstep;
583 if (angle >= final_angle)
584 break;
587 XFlush(dpy);
589 #undef FRAMES
592 static void
593 animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
594 int fx, int fy, int fw, int fh, int steps)
596 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
597 float cx, cy, cw, ch;
598 float xstep, ystep, wstep, hstep;
599 XPoint points[5];
600 float angle, final_angle, a, d, delta;
602 x += w/2;
603 y += h/2;
604 fx += fw/2;
605 fy += fh/2;
607 xstep = (float)(fx-x)/steps;
608 ystep = (float)(fy-y)/steps;
609 wstep = (float)(fw-w)/steps;
610 hstep = (float)(fh-h)/steps;
612 cx = (float)x;
613 cy = (float)y;
614 cw = (float)w;
615 ch = (float)h;
617 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
618 delta = (float)(final_angle/FRAMES);
619 for (angle=0;; angle+=delta) {
620 if (angle > final_angle)
621 angle = final_angle;
623 a = atan(ch/cw);
624 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
626 points[0].x = cx+cos(angle-a)*d;
627 points[0].y = cy+sin(angle-a)*d;
628 points[1].x = cx+cos(angle+a)*d;
629 points[1].y = cy+sin(angle+a)*d;
630 points[2].x = cx+cos(angle-a+WM_PI)*d;
631 points[2].y = cy+sin(angle-a+WM_PI)*d;
632 points[3].x = cx+cos(angle+a+WM_PI)*d;
633 points[3].y = cy+sin(angle+a+WM_PI)*d;
634 points[4].x = cx+cos(angle-a)*d;
635 points[4].y = cy+sin(angle-a)*d;
636 XGrabServer(dpy);
637 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
638 XFlush(dpy);
639 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
640 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
641 #else
642 wusleep(10);
643 #endif
645 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
646 XUngrabServer(dpy);
647 cx+=xstep;
648 cy+=ystep;
649 cw+=wstep;
650 ch+=hstep;
651 if (angle >= final_angle)
652 break;
655 XFlush(dpy);
657 #undef FRAMES
660 static void
661 animateResizeZoom(WScreen *scr, int x, int y, int w, int h,
662 int fx, int fy, int fw, int fh, int steps)
664 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
665 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
666 float xstep, ystep, wstep, hstep;
667 int i, j;
669 xstep = (float)(fx-x)/steps;
670 ystep = (float)(fy-y)/steps;
671 wstep = (float)(fw-w)/steps;
672 hstep = (float)(fh-h)/steps;
674 for (j=0; j<FRAMES; j++) {
675 cx[j] = (float)x;
676 cy[j] = (float)y;
677 cw[j] = (float)w;
678 ch[j] = (float)h;
680 XGrabServer(dpy);
681 for (i=0; i<steps; i++) {
682 for (j=0; j<FRAMES; j++) {
683 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
684 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
686 XFlush(dpy);
687 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
688 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
689 #else
690 wusleep(10);
691 #endif
692 for (j=0; j<FRAMES; j++) {
693 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
694 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
695 if (j<FRAMES-1) {
696 cx[j]=cx[j+1];
697 cy[j]=cy[j+1];
698 cw[j]=cw[j+1];
699 ch[j]=ch[j+1];
700 } else {
701 cx[j]+=xstep;
702 cy[j]+=ystep;
703 cw[j]+=wstep;
704 ch[j]+=hstep;
709 for (j=0; j<FRAMES; j++) {
710 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
711 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
713 XFlush(dpy);
714 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
715 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
716 #else
717 wusleep(10);
718 #endif
719 for (j=0; j<FRAMES; j++) {
720 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
721 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
724 XUngrabServer(dpy);
726 #undef FRAMES
729 void
730 animateResize(WScreen *scr, int x, int y, int w, int h,
731 int fx, int fy, int fw, int fh, int hiding)
733 int style = wPreferences.iconification_style; /* Catch the value */
734 int steps, k;
736 if (style == WIS_NONE)
737 return;
739 if (style == WIS_RANDOM) {
740 style = rand()%3;
743 k = (hiding ? 2 : 3);
744 switch(style) {
745 case WIS_TWIST:
746 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
747 if (steps>0)
748 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
749 break;
750 case WIS_FLIP:
751 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
752 if (steps>0)
753 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
754 break;
755 case WIS_ZOOM:
756 default:
757 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
758 if (steps>0)
759 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
760 break;
763 #endif /* ANIMATIONS */
766 static void
767 flushExpose()
769 XEvent tmpev;
771 while (XCheckTypedEvent(dpy, Expose, &tmpev))
772 WMHandleEvent(&tmpev);
773 XSync(dpy, 0);
776 static void
777 unmapTransientsFor(WWindow *wwin)
779 WWindow *tmp;
782 tmp = wwin->screen_ptr->focused_window;
783 while (tmp) {
784 /* unmap the transients for this transient */
785 if (tmp!=wwin && tmp->transient_for == wwin->client_win
786 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
787 || tmp->flags.shaded)) {
788 unmapTransientsFor(tmp);
789 tmp->flags.miniaturized = 1;
790 if (!tmp->flags.shaded) {
791 wWindowUnmap(tmp);
792 } else {
793 XUnmapWindow(dpy, tmp->frame->core->window);
796 if (!tmp->flags.shaded)
798 wClientSetState(tmp, IconicState, None);
800 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
802 tmp = tmp->prev;
807 static void
808 mapTransientsFor(WWindow *wwin)
810 WWindow *tmp;
812 tmp = wwin->screen_ptr->focused_window;
813 while (tmp) {
814 /* recursively map the transients for this transient */
815 if (tmp!=wwin && tmp->transient_for == wwin->client_win
816 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
817 && tmp->icon==NULL) {
818 mapTransientsFor(tmp);
819 tmp->flags.miniaturized = 0;
820 if (!tmp->flags.shaded) {
821 wWindowMap(tmp);
822 } else {
823 XMapWindow(dpy, tmp->frame->core->window);
825 tmp->flags.semi_focused = 0;
827 if (!tmp->flags.shaded)
829 wClientSetState(tmp, NormalState, None);
831 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
833 tmp = tmp->prev;
837 #if 0
838 static void
839 setupIconGrabs(WIcon *icon)
841 /* setup passive grabs on the icon */
842 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
843 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
844 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
845 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
846 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
847 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
848 XSync(dpy, 0);
850 #endif
852 static WWindow*
853 recursiveTransientFor(WWindow *wwin)
855 int i;
857 if (!wwin)
858 return None;
860 /* hackish way to detect transient_for cycle */
861 i = wwin->screen_ptr->window_count+1;
863 while (wwin && wwin->transient_for != None && i>0) {
864 wwin = wWindowFor(wwin->transient_for);
865 i--;
867 if (i==0 && wwin) {
868 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
869 wwin->frame->title);
870 return NULL;
873 return wwin;
876 #if 0
877 static void
878 removeIconGrabs(WIcon *icon)
880 /* remove passive grabs on the icon */
881 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
882 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
883 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
884 XSync(dpy, 0);
886 #endif
889 void
890 wIconifyWindow(WWindow *wwin)
892 XWindowAttributes attribs;
893 int present;
896 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
897 /* the window doesn't exist anymore */
898 return;
901 if (wwin->flags.miniaturized) {
902 return;
905 if (wwin->transient_for!=None &&
906 wwin->transient_for!=wwin->screen_ptr->root_win) {
907 WWindow *owner = wWindowFor(wwin->transient_for);
909 if (owner && owner->flags.miniaturized)
910 return;
913 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
915 /* if the window is in another workspace, simplify process */
916 if (present) {
917 /* icon creation may take a while */
918 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
919 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
920 GrabModeAsync, None, None, CurrentTime);
923 if (!wPreferences.disable_miniwindows) {
924 if (!wwin->flags.icon_moved) {
925 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y);
927 wwin->icon = wIconCreate(wwin);
929 wwin->icon->mapped = 1;
932 wwin->flags.miniaturized = 1;
933 wwin->flags.mapped = 0;
935 /* unmap transients */
937 unmapTransientsFor(wwin);
939 if (present) {
940 wSoundPlay(WSOUND_ICONIFY);
942 XUngrabPointer(dpy, CurrentTime);
943 wWindowUnmap(wwin);
944 /* let all Expose events arrive so that we can repaint
945 * something before the animation starts (and the server is grabbed) */
946 XSync(dpy, 0);
948 if (wPreferences.disable_miniwindows)
949 wClientSetState(wwin, IconicState, None);
950 else
951 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
953 flushExpose();
954 #ifdef ANIMATIONS
955 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
956 && !wPreferences.no_animations) {
957 int ix, iy, iw, ih;
959 if (!wPreferences.disable_miniwindows) {
960 ix = wwin->icon_x;
961 iy = wwin->icon_y;
962 iw = wwin->icon->core->width;
963 ih = wwin->icon->core->height;
964 } else {
965 #ifdef KWM_HINTS
966 WArea area;
968 if (wKWMGetIconGeometry(wwin, &area)) {
969 ix = area.x1;
970 iy = area.y1;
971 iw = area.x2 - ix;
972 ih = area.y2 - iy;
973 } else
974 #endif /* KWM_HINTS */
976 ix = 0;
977 iy = 0;
978 iw = wwin->screen_ptr->scr_width;
979 ih = wwin->screen_ptr->scr_height;
982 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
983 wwin->frame->core->width, wwin->frame->core->height,
984 ix, iy, iw, ih, False);
986 #endif
989 wwin->flags.skip_next_animation = 0;
991 if (!wPreferences.disable_miniwindows) {
993 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
994 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
996 XMapWindow(dpy, wwin->icon->core->window);
998 AddToStackList(wwin->icon->core);
1000 wLowerFrame(wwin->icon->core);
1003 if (present) {
1004 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1007 * It doesn't seem to be working and causes button event hangup
1008 * when deiconifying a transient window.
1009 setupIconGrabs(wwin->icon);
1011 if ((wwin->flags.focused
1012 || (owner && wwin->client_win == owner->client_win))
1013 && wPreferences.focus_mode==WKF_CLICK) {
1014 WWindow *tmp;
1016 tmp = wwin->prev;
1017 while (tmp) {
1018 if (!WFLAGP(tmp, no_focusable)
1019 && !(tmp->flags.hidden||tmp->flags.miniaturized)
1020 && (wwin->frame->workspace == tmp->frame->workspace))
1021 break;
1022 tmp = tmp->prev;
1024 wSetFocusTo(wwin->screen_ptr, tmp);
1025 } else if (wPreferences.focus_mode!=WKF_CLICK) {
1026 wSetFocusTo(wwin->screen_ptr, NULL);
1029 #ifdef ANIMATIONS
1030 if (!wwin->screen_ptr->flags.startup) {
1031 Window clientwin = wwin->client_win;
1033 XSync(dpy, 0);
1034 processEvents(XPending(dpy));
1036 /* the window can disappear while doing the processEvents() */
1037 if (!wWindowFor(clientwin))
1038 return;
1040 #endif
1044 if (wwin->flags.selected && !wPreferences.disable_miniwindows)
1045 wIconSelect(wwin->icon);
1047 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1053 void
1054 wDeiconifyWindow(WWindow *wwin)
1056 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1058 if (!wwin->flags.miniaturized)
1059 return;
1061 if (wwin->transient_for != None
1062 && wwin->transient_for != wwin->screen_ptr->root_win) {
1063 WWindow *owner = recursiveTransientFor(wwin);
1065 if (owner && owner->flags.miniaturized) {
1066 wDeiconifyWindow(owner);
1067 wSetFocusTo(wwin->screen_ptr, wwin);
1068 wRaiseFrame(wwin->frame->core);
1069 return;
1073 wwin->flags.miniaturized = 0;
1074 if (!wwin->flags.shaded)
1075 wwin->flags.mapped = 1;
1077 if (!wPreferences.disable_miniwindows && wwin->icon != NULL) {
1078 if (wwin->icon->selected)
1079 wIconSelect(wwin->icon);
1081 XUnmapWindow(dpy, wwin->icon->core->window);
1084 wSoundPlay(WSOUND_DEICONIFY);
1086 /* if the window is in another workspace, do it silently */
1087 #ifdef ANIMATIONS
1088 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1089 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1090 int ix, iy, iw, ih;
1092 if (!wPreferences.disable_miniwindows) {
1093 ix = wwin->icon_x;
1094 iy = wwin->icon_y;
1095 iw = wwin->icon->core->width;
1096 ih = wwin->icon->core->height;
1097 } else {
1098 #ifdef KWM_HINTS
1099 WArea area;
1101 if (wKWMGetIconGeometry(wwin, &area)) {
1102 ix = area.x1;
1103 iy = area.y1;
1104 iw = area.x2 - ix;
1105 ih = area.y2 - iy;
1106 } else
1107 #endif /* KWM_HINTS */
1109 ix = 0;
1110 iy = 0;
1111 iw = wwin->screen_ptr->scr_width;
1112 ih = wwin->screen_ptr->scr_height;
1115 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1116 wwin->frame_x, wwin->frame_y,
1117 wwin->frame->core->width, wwin->frame->core->height,
1118 False);
1120 #endif /* ANIMATIONS */
1121 wwin->flags.skip_next_animation = 0;
1122 XGrabServer(dpy);
1123 if (!wwin->flags.shaded) {
1124 XMapWindow(dpy, wwin->client_win);
1126 XMapWindow(dpy, wwin->frame->core->window);
1127 wRaiseFrame(wwin->frame->core);
1128 if (!wwin->flags.shaded) {
1129 wClientSetState(wwin, NormalState, None);
1131 mapTransientsFor(wwin);
1133 if (!wPreferences.disable_miniwindows && wwin->icon != NULL) {
1134 RemoveFromStackList(wwin->icon->core);
1135 /* removeIconGrabs(wwin->icon);*/
1136 wIconDestroy(wwin->icon);
1137 wwin->icon = NULL;
1139 XUngrabServer(dpy);
1141 if (wPreferences.focus_mode==WKF_CLICK)
1142 wSetFocusTo(wwin->screen_ptr, wwin);
1144 #ifdef ANIMATIONS
1145 if (!wwin->screen_ptr->flags.startup) {
1146 Window clientwin = wwin->client_win;
1148 XSync(dpy, 0);
1149 processEvents(XPending(dpy));
1151 if (!wWindowFor(clientwin))
1152 return;
1154 #endif
1156 if (wPreferences.auto_arrange_icons) {
1157 wArrangeIcons(wwin->screen_ptr, True);
1160 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1162 /* In case we were shaded and iconified, also unshade */
1163 wUnshadeWindow(wwin);
1168 static void
1169 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1171 if (wwin->flags.miniaturized) {
1172 if (wwin->icon) {
1173 XUnmapWindow(dpy, wwin->icon->core->window);
1174 wwin->icon->mapped = 0;
1176 wwin->flags.hidden = 1;
1178 WMPostNotificationName(WMNChangedState, wwin, "hide");
1179 return;
1182 if (wwin->flags.inspector_open) {
1183 wHideInspectorForWindow(wwin);
1186 wwin->flags.hidden = 1;
1187 wWindowUnmap(wwin);
1189 wClientSetState(wwin, IconicState, icon->icon_win);
1190 flushExpose();
1191 wSoundPlay(WSOUND_HIDE);
1192 #ifdef ANIMATIONS
1193 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1194 !wwin->flags.skip_next_animation && animate) {
1195 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1196 wwin->frame->core->width, wwin->frame->core->height,
1197 icon_x, icon_y, icon->core->width, icon->core->height,
1198 True);
1200 #endif
1201 wwin->flags.skip_next_animation = 0;
1203 WMPostNotificationName(WMNChangedState, wwin, "hide");
1208 void
1209 wHideOtherApplications(WWindow *awin)
1211 WWindow *wwin;
1212 WApplication *tapp;
1214 if (!awin)
1215 return;
1216 wwin = awin->screen_ptr->focused_window;
1219 while (wwin) {
1220 if (wwin!=awin
1221 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1222 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1223 && !wwin->flags.internal_window
1224 && wGetWindowOfInspectorForWindow(wwin) != awin
1225 && !WFLAGP(wwin, no_hide_others)) {
1227 if (wwin->main_window==None || WFLAGP(wwin, no_appicon)) {
1228 if (!WFLAGP(wwin, no_miniaturizable)) {
1229 wwin->flags.skip_next_animation = 1;
1230 wIconifyWindow(wwin);
1232 } else if (wwin->main_window!=None
1233 && awin->main_window != wwin->main_window) {
1234 tapp = wApplicationOf(wwin->main_window);
1235 if (tapp) {
1236 tapp->flags.skip_next_animation = 1;
1237 wHideApplication(tapp);
1238 } else {
1239 if (!WFLAGP(wwin, no_miniaturizable)) {
1240 wwin->flags.skip_next_animation = 1;
1241 wIconifyWindow(wwin);
1246 wwin = wwin->prev;
1249 wSetFocusTo(awin->screen_ptr, awin);
1255 void
1256 wHideApplication(WApplication *wapp)
1258 WScreen *scr;
1259 WWindow *wlist;
1260 int hadfocus;
1262 if (!wapp) {
1263 wwarning("trying to hide a non grouped window");
1264 return;
1266 if (!wapp->main_window_desc) {
1267 wwarning("group leader not found for window group");
1268 return;
1270 scr = wapp->main_window_desc->screen_ptr;
1271 hadfocus = 0;
1272 wlist = scr->focused_window;
1273 if (!wlist)
1274 return;
1276 if (wlist->main_window == wapp->main_window)
1277 wapp->last_focused = wlist;
1278 else
1279 wapp->last_focused = NULL;
1280 while (wlist) {
1281 if (wlist->main_window == wapp->main_window) {
1282 if (wlist->flags.focused) {
1283 hadfocus = 1;
1285 if (wapp->app_icon)
1286 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1287 wapp->app_icon->y_pos, wlist,
1288 !wapp->flags.skip_next_animation);
1290 wlist = wlist->prev;
1293 wapp->flags.skip_next_animation = 0;
1295 if (hadfocus) {
1296 if (wPreferences.focus_mode==WKF_CLICK) {
1297 wlist = scr->focused_window;
1298 while (wlist) {
1299 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1300 && (wlist->flags.mapped || wlist->flags.shaded))
1301 break;
1302 wlist = wlist->prev;
1304 wSetFocusTo(scr, wlist);
1305 } else {
1306 wSetFocusTo(scr, NULL);
1310 wapp->flags.hidden = 1;
1312 if(wPreferences.auto_arrange_icons) {
1313 wArrangeIcons(scr, True);
1315 #ifdef HIDDENDOT
1316 if (wapp->app_icon)
1317 wAppIconPaint(wapp->app_icon);
1318 #endif
1324 static void
1325 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1326 int bringToCurrentWS)
1328 if (bringToCurrentWS)
1329 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1331 wwin->flags.hidden=0;
1333 wSoundPlay(WSOUND_UNHIDE);
1334 #ifdef ANIMATIONS
1335 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1336 && animate) {
1337 animateResize(wwin->screen_ptr, icon_x, icon_y,
1338 icon->core->width, icon->core->height,
1339 wwin->frame_x, wwin->frame_y,
1340 wwin->frame->core->width, wwin->frame->core->height,
1341 True);
1343 #endif
1344 wwin->flags.skip_next_animation = 0;
1345 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1346 XMapWindow(dpy, wwin->client_win);
1347 XMapWindow(dpy, wwin->frame->core->window);
1348 wClientSetState(wwin, NormalState, None);
1349 wwin->flags.mapped=1;
1350 wRaiseFrame(wwin->frame->core);
1352 if (wwin->flags.inspector_open) {
1353 wUnhideInspectorForWindow(wwin);
1356 WMPostNotificationName(WMNChangedState, wwin, "hide");
1360 void
1361 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1363 WScreen *scr;
1364 WWindow *wlist, *next;
1365 WWindow *focused=NULL;
1367 if (!wapp) {
1368 return;
1370 scr = wapp->main_window_desc->screen_ptr;
1371 wlist = scr->focused_window;
1372 if (!wlist) return;
1373 /* goto beginning of list */
1374 while (wlist->prev)
1375 wlist = wlist->prev;
1377 while (wlist) {
1378 next = wlist->next;
1380 if (wlist->main_window == wapp->main_window) {
1381 if (wlist->flags.focused)
1382 focused = wlist;
1383 else if (!focused || !focused->flags.focused)
1384 focused = wlist;
1386 if (wlist->flags.miniaturized && wlist->icon) {
1387 if (bringToCurrentWS || wPreferences.sticky_icons
1388 || wlist->frame->workspace == scr->current_workspace) {
1389 if (!wlist->icon->mapped) {
1390 XMapWindow(dpy, wlist->icon->core->window);
1391 wlist->icon->mapped = 1;
1393 wlist->flags.hidden = 0;
1395 WMPostNotificationName(WMNChangedState, wlist, "hide");
1397 if (wlist->frame->workspace != scr->current_workspace)
1398 wWindowChangeWorkspace(wlist, scr->current_workspace);
1400 if (miniwindows) {
1401 wDeiconifyWindow(wlist);
1403 } else if (wlist->flags.hidden) {
1404 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1405 wapp->app_icon->y_pos, wlist,
1406 !wapp->flags.skip_next_animation,
1407 bringToCurrentWS);
1408 } else {
1409 if (bringToCurrentWS
1410 && wlist->frame->workspace != scr->current_workspace) {
1411 wWindowChangeWorkspace(wlist, scr->current_workspace);
1413 wRaiseFrame(wlist->frame->core);
1416 wlist = next;
1419 wapp->flags.skip_next_animation = 0;
1420 wapp->flags.hidden = 0;
1422 if (focused)
1423 wSetFocusTo(scr, focused);
1424 else if (wapp->last_focused && wapp->last_focused->flags.mapped)
1425 wSetFocusTo(scr, wapp->last_focused);
1426 wapp->last_focused = NULL;
1427 if (wPreferences.auto_arrange_icons) {
1428 wArrangeIcons(scr, True);
1430 #ifdef HIDDENDOT
1431 wAppIconPaint(wapp->app_icon);
1432 #endif
1437 void
1438 wShowAllWindows(WScreen *scr)
1440 WWindow *wwin, *old_foc;
1441 WApplication *wapp;
1443 old_foc = wwin = scr->focused_window;
1444 while (wwin) {
1445 if (!wwin->flags.internal_window &&
1446 (scr->current_workspace == wwin->frame->workspace
1447 || IS_OMNIPRESENT(wwin))) {
1448 if (wwin->flags.miniaturized) {
1449 wwin->flags.skip_next_animation = 1;
1450 wDeiconifyWindow(wwin);
1451 } else if (wwin->flags.hidden) {
1452 wapp = wApplicationOf(wwin->main_window);
1453 if (wapp) {
1454 wUnhideApplication(wapp, False, False);
1455 } else {
1456 wwin->flags.skip_next_animation = 1;
1457 wDeiconifyWindow(wwin);
1461 wwin = wwin->prev;
1463 wSetFocusTo(scr, old_foc);
1464 /*wRaiseFrame(old_foc->frame->core);*/
1468 void
1469 wRefreshDesktop(WScreen *scr)
1471 Window win;
1472 XSetWindowAttributes attr;
1474 attr.backing_store = NotUseful;
1475 attr.save_under = False;
1476 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1477 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1478 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1479 &attr);
1480 XMapRaised(dpy, win);
1481 XDestroyWindow(dpy, win);
1482 XFlush(dpy);
1486 void
1487 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1489 WWindow *wwin;
1490 WAppIcon *aicon;
1491 int pf; /* primary axis */
1492 int sf; /* secondary axis */
1493 int fullW;
1494 int fullH;
1495 int pi, si;
1496 int sx1, sx2, sy1, sy2; /* screen boundary */
1497 int sw, sh;
1498 int xo, yo;
1499 int xs, ys;
1500 int isize = wPreferences.icon_size;
1503 * Find out screen boundaries.
1505 sx1 = 0;
1506 sy1 = 0;
1507 sx2 = scr->scr_width;
1508 sy2 = scr->scr_height;
1509 if (scr->dock) {
1510 if (scr->dock->on_right_side)
1511 sx2 -= isize + DOCK_EXTRA_SPACE;
1512 else
1513 sx1 += isize + DOCK_EXTRA_SPACE;
1516 sw = isize * (scr->scr_width/isize);
1517 sh = isize * (scr->scr_height/isize);
1518 fullW = (sx2-sx1)/isize;
1519 fullH = (sy2-sy1)/isize;
1521 /* icon yard boundaries */
1522 if (wPreferences.icon_yard & IY_VERT) {
1523 pf = fullH;
1524 sf = fullW;
1525 } else {
1526 pf = fullW;
1527 sf = fullH;
1529 if (wPreferences.icon_yard & IY_RIGHT) {
1530 xo = sx2 - isize;
1531 xs = -1;
1532 } else {
1533 xo = sx1;
1534 xs = 1;
1536 if (wPreferences.icon_yard & IY_TOP) {
1537 yo = sy1;
1538 ys = 1;
1539 } else {
1540 yo = sy2 - isize;
1541 ys = -1;
1544 /* arrange icons putting the most recently focused window
1545 * as the last icon */
1546 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1547 : xo + xs*(pi*isize))
1548 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1549 : yo + ys*(si*isize))
1551 /* arrange application icons */
1552 aicon = scr->app_icon_list;
1553 /* reverse them to avoid unnecessarily sliding of icons */
1554 while (aicon && aicon->next)
1555 aicon = aicon->next;
1557 pi = 0;
1558 si = 0;
1559 while (aicon) {
1560 if (!aicon->docked) {
1561 if (aicon->x_pos != X || aicon->y_pos != Y) {
1562 #ifdef ANIMATIONS
1563 if (!wPreferences.no_animations) {
1564 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1565 X, Y);
1567 #endif /* ANIMATIONS */
1569 wAppIconMove(aicon, X, Y);
1570 pi++;
1572 /* we reversed the order so we use prev */
1573 aicon = aicon->prev;
1574 if (pi >= pf) {
1575 pi=0;
1576 si++;
1580 /* arrange miniwindows */
1582 wwin = scr->focused_window;
1583 /* reverse them to avoid unnecessarily shuffling */
1584 while (wwin && wwin->prev)
1585 wwin = wwin->prev;
1587 while (wwin) {
1588 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1589 (wwin->frame->workspace==scr->current_workspace ||
1590 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1592 if (arrangeAll || !wwin->flags.icon_moved) {
1593 if (wwin->icon_x != X || wwin->icon_y != Y) {
1594 #ifdef ANIMATIONS
1595 if (wPreferences.no_animations) {
1596 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1597 } else {
1598 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1599 wwin->icon_y, X, Y);
1601 #else
1602 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1603 #endif /* ANIMATIONS */
1605 wwin->icon_x = X;
1606 wwin->icon_y = Y;
1607 pi++;
1610 if (arrangeAll) {
1611 wwin->flags.icon_moved = 0;
1613 /* we reversed the order, so we use next */
1614 wwin = wwin->next;
1615 if (pi >= pf) {
1616 pi=0;
1617 si++;
1623 void
1624 wSelectWindow(WWindow *wwin, Bool flag)
1626 WScreen *scr = wwin->screen_ptr;
1628 if (flag) {
1629 wwin->flags.selected = 1;
1630 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1632 if (WFLAGP(wwin, no_border)) {
1633 XSetWindowBorderWidth(dpy, wwin->frame->core->window,
1634 FRAME_BORDER_WIDTH);
1637 if (!scr->selected_windows)
1638 scr->selected_windows = WMCreateArray(4);
1639 WMAddToArray(scr->selected_windows, wwin);
1640 } else {
1641 wwin->flags.selected = 0;
1642 XSetWindowBorder(dpy, wwin->frame->core->window,
1643 scr->frame_border_pixel);
1645 if (WFLAGP(wwin, no_border)) {
1646 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1649 if (scr->selected_windows) {
1650 WMRemoveFromArray(scr->selected_windows, wwin);
1656 void
1657 wMakeWindowVisible(WWindow *wwin)
1659 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1660 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1662 if (wwin->flags.shaded) {
1663 wUnshadeWindow(wwin);
1665 if (wwin->flags.hidden) {
1666 WApplication *app;
1668 app = wApplicationOf(wwin->main_window);
1669 if (app)
1670 wUnhideApplication(app, False, False);
1671 } else if (wwin->flags.miniaturized) {
1672 wDeiconifyWindow(wwin);
1673 } else {
1674 if (!WFLAGP(wwin, no_focusable))
1675 wSetFocusTo(wwin->screen_ptr, wwin);
1676 wRaiseFrame(wwin->frame->core);