Improved hide/unhide animation for applications with multiple windows
[wmaker-crm.git] / src / actions.c
blob6a42247ade927b16b74d78c7b7f67693e06ce013
1 /* action.c- misc. window commands (miniaturize, hide etc.)
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
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"
54 /****** Global Variables ******/
55 extern Time LastTimestamp;
56 extern Time LastFocusChange;
58 extern Cursor wCursor[WCUR_LAST];
60 extern WPreferences wPreferences;
62 extern Atom _XA_WM_TAKE_FOCUS;
64 extern void ProcessPendingEvents();
67 /******* Local Variables *******/
68 static struct {
69 int steps;
70 int delay;
71 } shadePars[5] = {
72 {SHADE_STEPS_UF, SHADE_DELAY_UF},
73 {SHADE_STEPS_F, SHADE_DELAY_F},
74 {SHADE_STEPS_M, SHADE_DELAY_M},
75 {SHADE_STEPS_S, SHADE_DELAY_S},
76 {SHADE_STEPS_US, SHADE_DELAY_US}};
78 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
79 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
83 *----------------------------------------------------------------------
84 * wSetFocusTo--
85 * Changes the window focus to the one passed as argument.
86 * If the window to focus is not already focused, it will be brought
87 * to the head of the list of windows. Previously focused window is
88 * unfocused.
90 * Side effects:
91 * Window list may be reordered and the window focus is changed.
93 *----------------------------------------------------------------------
95 void
96 wSetFocusTo(WScreen *scr, WWindow *wwin)
98 static WScreen *old_scr=NULL;
100 WWindow *old_focused;
101 WWindow *focused=scr->focused_window;
102 int timestamp=LastTimestamp;
103 WApplication *oapp=NULL, *napp=NULL;
104 int wasfocused;
106 if (scr->flags.ignore_focus_events || LastFocusChange > timestamp)
107 return;
109 if (!old_scr)
110 old_scr=scr;
111 old_focused=old_scr->focused_window;
113 LastFocusChange = timestamp;
115 if (old_focused)
116 oapp = wApplicationOf(old_focused->main_window);
118 if (wwin == NULL) {
119 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
120 if (old_focused) {
121 wWindowUnfocus(old_focused);
123 if (oapp) {
124 wAppMenuUnmap(oapp->menu);
125 #ifdef NEWAPPICON
126 wApplicationDeactivate(oapp);
127 #endif
130 WMPostNotificationName(WMNChangedFocus, NULL, (void*)True);
131 return;
132 } else if (old_scr != scr && old_focused) {
133 wWindowUnfocus(old_focused);
136 wasfocused = wwin->flags.focused;
137 napp = wApplicationOf(wwin->main_window);
139 /* remember last workspace where the app has been */
140 if (napp) {
141 /*napp->last_workspace = wwin->screen_ptr->current_workspace;*/
142 napp->last_workspace = wwin->frame->workspace;
145 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
146 /* install colormap if colormap mode is lock mode */
147 if (wPreferences.colormap_mode==WCM_CLICK)
148 wColormapInstallForWindow(scr, wwin);
150 /* set input focus */
151 switch (wwin->focus_mode) {
152 case WFM_NO_INPUT:
153 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
154 break;
156 case WFM_PASSIVE:
157 case WFM_LOCALLY_ACTIVE:
158 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
159 break;
161 case WFM_GLOBALLY_ACTIVE:
162 break;
164 XFlush(dpy);
165 if (wwin->protocols.TAKE_FOCUS) {
166 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
168 XSync(dpy, False);
169 } else {
170 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
172 if (WFLAGP(wwin, no_focusable))
173 return;
175 /* if this is not the focused window focus it */
176 if (focused!=wwin) {
177 /* change the focus window list order */
178 if (wwin->prev)
179 wwin->prev->next = wwin->next;
181 if (wwin->next)
182 wwin->next->prev = wwin->prev;
184 wwin->prev = focused;
185 focused->next = wwin;
186 wwin->next = NULL;
187 scr->focused_window = wwin;
189 if (oapp && oapp != napp) {
190 wAppMenuUnmap(oapp->menu);
191 #ifdef NEWAPPICON
192 wApplicationDeactivate(oapp);
193 #endif
197 wWindowFocus(wwin, focused);
199 if (napp && !wasfocused) {
200 #ifdef USER_MENU
201 wUserMenuRefreshInstances(napp->menu, wwin);
202 #endif /* USER_MENU */
204 if (wwin->flags.mapped)
205 wAppMenuMap(napp->menu, wwin);
206 #ifdef NEWAPPICON
207 wApplicationActivate(napp);
208 #endif
211 XFlush(dpy);
212 old_scr=scr;
216 void
217 wShadeWindow(WWindow *wwin)
219 time_t time0;
220 #ifdef ANIMATIONS
221 int y, s, w, h;
222 #endif
224 if (wwin->flags.shaded)
225 return;
227 time0 = time(NULL);
229 XLowerWindow(dpy, wwin->client_win);
231 wSoundPlay(WSOUND_SHADE);
233 #ifdef ANIMATIONS
234 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
235 && !wPreferences.no_animations) {
236 /* do the shading animation */
237 h = wwin->frame->core->height;
238 s = h/SHADE_STEPS;
239 if (s < 1) s=1;
240 w = wwin->frame->core->width;
241 y = wwin->frame->top_width;
242 while (h>wwin->frame->top_width+1) {
243 XMoveWindow(dpy, wwin->client_win, 0, y);
244 XResizeWindow(dpy, wwin->frame->core->window, w, h);
245 XFlush(dpy);
247 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
248 break;
250 if (SHADE_DELAY > 0) {
251 wusleep(SHADE_DELAY*1000L);
252 } else {
253 wusleep(10);
255 h-=s;
256 y-=s;
258 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
260 #endif /* ANIMATIONS */
262 wwin->flags.skip_next_animation = 0;
263 wwin->flags.shaded = 1;
264 wwin->flags.mapped = 0;
265 /* prevent window withdrawal when getting UnmapNotify */
266 XSelectInput(dpy, wwin->client_win,
267 wwin->event_mask & ~StructureNotifyMask);
268 XUnmapWindow(dpy, wwin->client_win);
269 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
271 /* for the client it's just like iconification */
272 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
273 wwin->frame->top_width - 1);
275 wwin->client.y = wwin->frame_y - wwin->client.height
276 + wwin->frame->top_width;
277 wWindowSynthConfigureNotify(wwin);
280 wClientSetState(wwin, IconicState, None);
283 WMPostNotificationName(WMNChangedState, wwin, "shade");
285 #ifdef ANIMATIONS
286 if (!wwin->screen_ptr->flags.startup) {
287 /* Catch up with events not processed while animation was running */
288 ProcessPendingEvents();
290 #endif
294 void
295 wUnshadeWindow(WWindow *wwin)
297 time_t time0;
298 #ifdef ANIMATIONS
299 int y, s, w, h;
300 #endif /* ANIMATIONS */
303 if (!wwin->flags.shaded)
304 return;
306 time0 = time(NULL);
308 wwin->flags.shaded = 0;
309 wwin->flags.mapped = 1;
310 XMapWindow(dpy, wwin->client_win);
312 wSoundPlay(WSOUND_UNSHADE);
314 #ifdef ANIMATIONS
315 if (!wPreferences.no_animations && !wwin->flags.skip_next_animation) {
316 /* do the shading animation */
317 h = wwin->frame->top_width + wwin->frame->bottom_width;
318 y = wwin->frame->top_width - wwin->client.height;
319 s = abs(y)/SHADE_STEPS;
320 if (s<1) s=1;
321 w = wwin->frame->core->width;
322 XMoveWindow(dpy, wwin->client_win, 0, y);
323 if (s>0) {
324 while (h < wwin->client.height + wwin->frame->top_width
325 + wwin->frame->bottom_width) {
326 XResizeWindow(dpy, wwin->frame->core->window, w, h);
327 XMoveWindow(dpy, wwin->client_win, 0, y);
328 XFlush(dpy);
329 if (SHADE_DELAY > 0) {
330 wusleep(SHADE_DELAY*2000L/3);
331 } else {
332 wusleep(10);
334 h+=s;
335 y+=s;
337 if (time(NULL)-time0 > MAX_ANIMATION_TIME)
338 break;
341 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
343 #endif /* ANIMATIONS */
345 wwin->flags.skip_next_animation = 0;
346 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
347 wwin->frame->top_width + wwin->client.height
348 + wwin->frame->bottom_width);
350 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
351 wWindowSynthConfigureNotify(wwin);
354 wClientSetState(wwin, NormalState, None);
356 /* if the window is focused, set the focus again as it was disabled during
357 * shading */
358 if (wwin->flags.focused)
359 wSetFocusTo(wwin->screen_ptr, wwin);
361 WMPostNotificationName(WMNChangedState, wwin, "shade");
365 void
366 wMaximizeWindow(WWindow *wwin, int directions)
368 int new_width, new_height, new_x, new_y;
369 int changed_h, changed_v, shrink_h, shrink_v;
370 WArea usableArea, totalArea;
372 if (!IS_RESIZABLE(wwin))
373 return;
375 totalArea.x1 = 0;
376 totalArea.y1 = 0;
377 totalArea.x2 = wwin->screen_ptr->scr_width;
378 totalArea.y2 = wwin->screen_ptr->scr_height;
379 usableArea = totalArea;
381 if (!(directions & MAX_IGNORE_XINERAMA)) {
382 WScreen *scr = wwin->screen_ptr;
383 int head;
385 if (directions & MAX_KEYBOARD)
386 head = wGetHeadForWindow(wwin);
387 else
388 head = wGetHeadForPointerLocation(scr);
390 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
393 if (WFLAGP(wwin, full_maximize)) {
394 usableArea = totalArea;
397 if (wwin->flags.shaded) {
398 wwin->flags.skip_next_animation = 1;
399 wUnshadeWindow(wwin);
401 /* Only save directions, not kbd or xinerama hints */
402 directions &= (MAX_HORIZONTAL|MAX_VERTICAL);
404 changed_h = ((wwin->flags.maximized ^ directions) & MAX_HORIZONTAL);
405 changed_v = ((wwin->flags.maximized ^ directions) & MAX_VERTICAL);
406 shrink_h = (changed_h && (directions & MAX_HORIZONTAL)==0);
407 shrink_v = (changed_v && (directions & MAX_VERTICAL)==0);
409 if (wwin->flags.maximized) {
410 /* if already maximized in some direction, we only update the
411 * appropriate old x, old y coordinates. This is necessary to
412 * allow succesive maximizations in different directions without
413 * the need to first do an un-maximize (to avoid flicker).
415 if (!(wwin->flags.maximized & MAX_HORIZONTAL)) {
416 wwin->old_geometry.x = wwin->frame_x;
418 if (!(wwin->flags.maximized & MAX_VERTICAL)) {
419 wwin->old_geometry.y = wwin->frame_y;
421 } else {
422 wwin->old_geometry.width = wwin->client.width;
423 wwin->old_geometry.height = wwin->client.height;
424 wwin->old_geometry.x = wwin->frame_x;
425 wwin->old_geometry.y = wwin->frame_y;
427 wwin->flags.maximized = directions;
429 if (directions & MAX_HORIZONTAL) {
430 new_width = (usableArea.x2-usableArea.x1)-FRAME_BORDER_WIDTH*2;
431 new_x = usableArea.x1;
432 } else if (shrink_h) {
433 new_x = wwin->old_geometry.x;
434 new_width = wwin->old_geometry.width;
435 } else {
436 new_x = wwin->frame_x;
437 new_width = wwin->frame->core->width;
440 if (directions & MAX_VERTICAL) {
441 new_height = (usableArea.y2-usableArea.y1)-FRAME_BORDER_WIDTH*2;
442 new_y = usableArea.y1;
443 if (WFLAGP(wwin, full_maximize)) {
444 new_y -= wwin->frame->top_width;
445 new_height += wwin->frame->bottom_width - 1;
447 } else if (shrink_v) {
448 new_y = wwin->old_geometry.y;
449 new_height = wwin->old_geometry.height;
450 } else {
451 new_y = wwin->frame_y;
452 new_height = wwin->frame->core->height;
455 if (!WFLAGP(wwin, full_maximize)) {
456 new_height -= wwin->frame->top_width+wwin->frame->bottom_width;
459 wWindowConstrainSize(wwin, &new_width, &new_height);
461 wWindowCropSize(wwin, usableArea.x2-usableArea.x1,
462 usableArea.y2-usableArea.y1,
463 &new_width, &new_height);
465 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
468 WMPostNotificationName(WMNChangedState, wwin, "maximize");
470 wSoundPlay(WSOUND_MAXIMIZE);
474 void
475 wUnmaximizeWindow(WWindow *wwin)
477 int restore_x, restore_y;
479 if (!wwin->flags.maximized)
480 return;
482 if (wwin->flags.shaded) {
483 wwin->flags.skip_next_animation = 1;
484 wUnshadeWindow(wwin);
486 restore_x = (wwin->flags.maximized & MAX_HORIZONTAL) ?
487 wwin->old_geometry.x : wwin->frame_x;
488 restore_y = (wwin->flags.maximized & MAX_VERTICAL) ?
489 wwin->old_geometry.y : wwin->frame_y;
490 wwin->flags.maximized = 0;
491 wWindowConfigure(wwin, restore_x, restore_y,
492 wwin->old_geometry.width, wwin->old_geometry.height);
494 WMPostNotificationName(WMNChangedState, wwin, "maximize");
496 wSoundPlay(WSOUND_UNMAXIMIZE);
500 void
501 wFullscreenWindow(WWindow *wwin)
503 int head;
504 WMRect rect;
506 if (wwin->flags.fullscreen)
507 return;
509 wwin->flags.fullscreen = True;
511 wWindowConfigureBorders(wwin);
513 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
515 wwin->bfs_geometry.x = wwin->frame_x;
516 wwin->bfs_geometry.y = wwin->frame_y;
517 wwin->bfs_geometry.width = wwin->frame->core->width;
518 wwin->bfs_geometry.height = wwin->frame->core->height;
520 head = wGetHeadForWindow(wwin);
521 rect = wGetRectForHead(wwin->screen_ptr, head);
522 wWindowConfigure(wwin, rect.pos.x, rect.pos.y,
523 rect.size.width, rect.size.height);
525 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
529 void
530 wUnfullscreenWindow(WWindow *wwin)
532 if (!wwin->flags.fullscreen)
533 return;
535 wwin->flags.fullscreen = False;
537 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
538 if (WFLAGP(wwin, sunken)) {
539 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
540 } else if (WFLAGP(wwin, floating)) {
541 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
542 } else {
543 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
547 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
548 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
550 wWindowConfigureBorders(wwin);
552 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
553 wFrameWindowPaint(wwin->frame);
556 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
560 #ifdef ANIMATIONS
561 static void
562 animateResizeFlip(WScreen *scr, int x, int y, int w, int h,
563 int fx, int fy, int fw, int fh, int steps)
565 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
566 float cx, cy, cw, ch;
567 float xstep, ystep, wstep, hstep;
568 XPoint points[5];
569 float dx, dch, midy;
570 float angle, final_angle, delta;
572 xstep = (float)(fx-x)/steps;
573 ystep = (float)(fy-y)/steps;
574 wstep = (float)(fw-w)/steps;
575 hstep = (float)(fh-h)/steps;
577 cx = (float)x;
578 cy = (float)y;
579 cw = (float)w;
580 ch = (float)h;
582 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_F;
583 delta = (float)(final_angle/FRAMES);
584 for (angle=0;; angle+=delta) {
585 if (angle > final_angle)
586 angle = final_angle;
588 dx = (cw/10) - ((cw/5) * sin(angle));
589 dch = (ch/2) * cos(angle);
590 midy = cy + (ch/2);
592 points[0].x = cx + dx; points[0].y = midy - dch;
593 points[1].x = cx + cw - dx; points[1].y = points[0].y;
594 points[2].x = cx + cw + dx; points[2].y = midy + dch;
595 points[3].x = cx - dx; points[3].y = points[2].y;
596 points[4].x = points[0].x; points[4].y = points[0].y;
598 XGrabServer(dpy);
599 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
600 XFlush(dpy);
601 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
602 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
603 #else
604 wusleep(10);
605 #endif
607 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
608 XUngrabServer(dpy);
609 cx+=xstep;
610 cy+=ystep;
611 cw+=wstep;
612 ch+=hstep;
613 if (angle >= final_angle)
614 break;
617 XFlush(dpy);
619 #undef FRAMES
622 static void
623 animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
624 int fx, int fy, int fw, int fh, int steps)
626 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
627 float cx, cy, cw, ch;
628 float xstep, ystep, wstep, hstep;
629 XPoint points[5];
630 float angle, final_angle, a, d, delta;
632 x += w/2;
633 y += h/2;
634 fx += fw/2;
635 fy += fh/2;
637 xstep = (float)(fx-x)/steps;
638 ystep = (float)(fy-y)/steps;
639 wstep = (float)(fw-w)/steps;
640 hstep = (float)(fh-h)/steps;
642 cx = (float)x;
643 cy = (float)y;
644 cw = (float)w;
645 ch = (float)h;
647 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
648 delta = (float)(final_angle/FRAMES);
649 for (angle=0;; angle+=delta) {
650 if (angle > final_angle)
651 angle = final_angle;
653 a = atan(ch/cw);
654 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
656 points[0].x = cx+cos(angle-a)*d;
657 points[0].y = cy+sin(angle-a)*d;
658 points[1].x = cx+cos(angle+a)*d;
659 points[1].y = cy+sin(angle+a)*d;
660 points[2].x = cx+cos(angle-a+WM_PI)*d;
661 points[2].y = cy+sin(angle-a+WM_PI)*d;
662 points[3].x = cx+cos(angle+a+WM_PI)*d;
663 points[3].y = cy+sin(angle+a+WM_PI)*d;
664 points[4].x = cx+cos(angle-a)*d;
665 points[4].y = cy+sin(angle-a)*d;
666 XGrabServer(dpy);
667 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
668 XFlush(dpy);
669 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
670 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
671 #else
672 wusleep(10);
673 #endif
675 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
676 XUngrabServer(dpy);
677 cx+=xstep;
678 cy+=ystep;
679 cw+=wstep;
680 ch+=hstep;
681 if (angle >= final_angle)
682 break;
685 XFlush(dpy);
687 #undef FRAMES
690 static void
691 animateResizeZoom(WScreen *scr, int x, int y, int w, int h,
692 int fx, int fy, int fw, int fh, int steps)
694 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
695 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
696 float xstep, ystep, wstep, hstep;
697 int i, j;
699 xstep = (float)(fx-x)/steps;
700 ystep = (float)(fy-y)/steps;
701 wstep = (float)(fw-w)/steps;
702 hstep = (float)(fh-h)/steps;
704 for (j=0; j<FRAMES; j++) {
705 cx[j] = (float)x;
706 cy[j] = (float)y;
707 cw[j] = (float)w;
708 ch[j] = (float)h;
710 XGrabServer(dpy);
711 for (i=0; i<steps; i++) {
712 for (j=0; j<FRAMES; j++) {
713 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
714 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
716 XFlush(dpy);
717 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
718 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
719 #else
720 wusleep(10);
721 #endif
722 for (j=0; j<FRAMES; j++) {
723 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
724 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
725 if (j<FRAMES-1) {
726 cx[j]=cx[j+1];
727 cy[j]=cy[j+1];
728 cw[j]=cw[j+1];
729 ch[j]=ch[j+1];
730 } else {
731 cx[j]+=xstep;
732 cy[j]+=ystep;
733 cw[j]+=wstep;
734 ch[j]+=hstep;
739 for (j=0; j<FRAMES; j++) {
740 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
741 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
743 XFlush(dpy);
744 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
745 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
746 #else
747 wusleep(10);
748 #endif
749 for (j=0; j<FRAMES; j++) {
750 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
751 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
754 XUngrabServer(dpy);
756 #undef FRAMES
759 void
760 animateResize(WScreen *scr, int x, int y, int w, int h,
761 int fx, int fy, int fw, int fh, int hiding)
763 int style = wPreferences.iconification_style; /* Catch the value */
764 int steps, k;
766 if (style == WIS_NONE)
767 return;
769 if (style == WIS_RANDOM) {
770 style = rand()%3;
773 k = (hiding ? 2 : 3);
775 switch(style) {
776 case WIS_TWIST:
777 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
778 if (steps>0)
779 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
780 break;
781 case WIS_FLIP:
782 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
783 if (steps>0)
784 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
785 break;
786 case WIS_ZOOM:
787 default:
788 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
789 if (steps>0)
790 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
791 break;
794 #endif /* ANIMATIONS */
797 static void
798 flushExpose()
800 XEvent tmpev;
802 while (XCheckTypedEvent(dpy, Expose, &tmpev))
803 WMHandleEvent(&tmpev);
804 XSync(dpy, 0);
807 static void
808 unmapTransientsFor(WWindow *wwin)
810 WWindow *tmp;
813 tmp = wwin->screen_ptr->focused_window;
814 while (tmp) {
815 /* unmap the transients for this transient */
816 if (tmp!=wwin && tmp->transient_for == wwin->client_win
817 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
818 || tmp->flags.shaded)) {
819 unmapTransientsFor(tmp);
820 tmp->flags.miniaturized = 1;
821 if (!tmp->flags.shaded) {
822 wWindowUnmap(tmp);
823 } else {
824 XUnmapWindow(dpy, tmp->frame->core->window);
827 if (!tmp->flags.shaded)
829 wClientSetState(tmp, IconicState, None);
831 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
833 tmp = tmp->prev;
838 static void
839 mapTransientsFor(WWindow *wwin)
841 WWindow *tmp;
843 tmp = wwin->screen_ptr->focused_window;
844 while (tmp) {
845 /* recursively map the transients for this transient */
846 if (tmp!=wwin && tmp->transient_for == wwin->client_win
847 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
848 && tmp->icon==NULL) {
849 mapTransientsFor(tmp);
850 tmp->flags.miniaturized = 0;
851 if (!tmp->flags.shaded) {
852 wWindowMap(tmp);
853 } else {
854 XMapWindow(dpy, tmp->frame->core->window);
856 tmp->flags.semi_focused = 0;
858 if (!tmp->flags.shaded)
860 wClientSetState(tmp, NormalState, None);
862 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
864 tmp = tmp->prev;
868 #if 0
869 static void
870 setupIconGrabs(WIcon *icon)
872 /* setup passive grabs on the icon */
873 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
874 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
875 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
876 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
877 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
878 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
879 XSync(dpy, 0);
881 #endif
883 static WWindow*
884 recursiveTransientFor(WWindow *wwin)
886 int i;
888 if (!wwin)
889 return None;
891 /* hackish way to detect transient_for cycle */
892 i = wwin->screen_ptr->window_count+1;
894 while (wwin && wwin->transient_for != None && i>0) {
895 wwin = wWindowFor(wwin->transient_for);
896 i--;
898 if (i==0 && wwin) {
899 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
900 wwin->frame->title);
901 return NULL;
904 return wwin;
907 #if 0
908 static void
909 removeIconGrabs(WIcon *icon)
911 /* remove passive grabs on the icon */
912 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
913 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
914 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
915 XSync(dpy, 0);
917 #endif
920 void
921 wIconifyWindow(WWindow *wwin)
923 XWindowAttributes attribs;
924 int present;
927 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
928 /* the window doesn't exist anymore */
929 return;
932 if (wwin->flags.miniaturized) {
933 return;
936 if (wwin->transient_for!=None &&
937 wwin->transient_for!=wwin->screen_ptr->root_win) {
938 WWindow *owner = wWindowFor(wwin->transient_for);
940 if (owner && owner->flags.miniaturized)
941 return;
944 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
946 /* if the window is in another workspace, simplify process */
947 if (present) {
948 /* icon creation may take a while */
949 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
950 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
951 GrabModeAsync, None, None, CurrentTime);
954 if (!wPreferences.disable_miniwindows
955 #ifdef NETWM_HINTS
956 && !wwin->flags.net_handle_icon
957 #endif
959 if (!wwin->flags.icon_moved) {
960 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
962 wwin->icon = wIconCreate(wwin);
964 wwin->icon->mapped = 1;
967 wwin->flags.miniaturized = 1;
968 wwin->flags.mapped = 0;
970 /* unmap transients */
972 unmapTransientsFor(wwin);
974 if (present) {
975 wSoundPlay(WSOUND_ICONIFY);
977 XUngrabPointer(dpy, CurrentTime);
978 wWindowUnmap(wwin);
979 /* let all Expose events arrive so that we can repaint
980 * something before the animation starts (and the server is grabbed) */
981 XSync(dpy, 0);
983 if (wPreferences.disable_miniwindows
984 #ifdef NETWM_HINTS
985 || wwin->flags.net_handle_icon
986 #endif
988 wClientSetState(wwin, IconicState, None);
989 else
990 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
992 flushExpose();
993 #ifdef ANIMATIONS
994 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
995 && !wPreferences.no_animations) {
996 int ix, iy, iw, ih;
998 if (!wPreferences.disable_miniwindows
999 #ifdef NETWM_HINTS
1000 && !wwin->flags.net_handle_icon
1001 #endif
1003 ix = wwin->icon_x;
1004 iy = wwin->icon_y;
1005 iw = wwin->icon->core->width;
1006 ih = wwin->icon->core->height;
1007 } else {
1008 #ifdef NETWM_HINTS
1009 if (wwin->flags.net_handle_icon) {
1010 ix = wwin->icon_x;
1011 iy = wwin->icon_y;
1012 iw = wwin->icon_w;
1013 ih = wwin->icon_h;
1014 } else
1015 #endif
1017 ix = 0;
1018 iy = 0;
1019 iw = wwin->screen_ptr->scr_width;
1020 ih = wwin->screen_ptr->scr_height;
1023 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1024 wwin->frame->core->width, wwin->frame->core->height,
1025 ix, iy, iw, ih, False);
1027 #endif
1030 wwin->flags.skip_next_animation = 0;
1032 if (!wPreferences.disable_miniwindows
1033 #ifdef NETWM_HINTS
1034 && !wwin->flags.net_handle_icon
1035 #endif
1038 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
1039 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1041 XMapWindow(dpy, wwin->icon->core->window);
1043 AddToStackList(wwin->icon->core);
1045 wLowerFrame(wwin->icon->core);
1048 if (present) {
1049 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1052 * It doesn't seem to be working and causes button event hangup
1053 * when deiconifying a transient window.
1054 setupIconGrabs(wwin->icon);
1056 if ((wwin->flags.focused
1057 || (owner && wwin->client_win == owner->client_win))
1058 && wPreferences.focus_mode==WKF_CLICK) {
1059 WWindow *tmp;
1061 tmp = wwin->prev;
1062 while (tmp) {
1063 if (!WFLAGP(tmp, no_focusable)
1064 && !(tmp->flags.hidden||tmp->flags.miniaturized)
1065 && (wwin->frame->workspace == tmp->frame->workspace))
1066 break;
1067 tmp = tmp->prev;
1069 wSetFocusTo(wwin->screen_ptr, tmp);
1070 } else if (wPreferences.focus_mode!=WKF_CLICK) {
1071 wSetFocusTo(wwin->screen_ptr, NULL);
1074 #ifdef ANIMATIONS
1075 if (!wwin->screen_ptr->flags.startup) {
1076 /* Catch up with events not processed while animation was running */
1077 Window clientwin = wwin->client_win;
1079 ProcessPendingEvents();
1081 /* the window can disappear while ProcessPendingEvents() runs */
1082 if (!wWindowFor(clientwin)) {
1083 return;
1086 #endif
1089 /* maybe we want to do this regardless of net_handle_icon
1090 * it seems to me we might break behaviour this way.
1092 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1093 #ifdef NETWM_HINTS
1094 && !wwin->flags.net_handle_icon
1095 #endif
1097 wIconSelect(wwin->icon);
1099 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1105 void
1106 wDeiconifyWindow(WWindow *wwin)
1108 #ifdef NETWM_HINTS
1109 /* we're hiding for show_desktop */
1110 int netwm_hidden = wwin->flags.net_show_desktop &&
1111 wwin->frame->workspace!=wwin->screen_ptr->current_workspace;
1112 #else
1113 int netwm_hidden = False;
1114 #endif
1116 if (!netwm_hidden)
1117 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1119 if (!wwin->flags.miniaturized)
1120 return;
1122 if (wwin->transient_for != None
1123 && wwin->transient_for != wwin->screen_ptr->root_win) {
1124 WWindow *owner = recursiveTransientFor(wwin);
1126 if (owner && owner->flags.miniaturized) {
1127 wDeiconifyWindow(owner);
1128 wSetFocusTo(wwin->screen_ptr, wwin);
1129 wRaiseFrame(wwin->frame->core);
1130 return;
1134 wwin->flags.miniaturized = 0;
1136 if (!netwm_hidden && !wwin->flags.shaded) {
1137 wwin->flags.mapped = 1;
1140 if (!netwm_hidden || wPreferences.sticky_icons) {
1141 /* maybe we want to do this regardless of net_handle_icon
1142 * it seems to me we might break behaviour this way.
1144 if (!wPreferences.disable_miniwindows
1145 #ifdef NETWM_HINTS
1146 && !wwin->flags.net_handle_icon
1147 #endif
1148 && wwin->icon != NULL) {
1149 if (wwin->icon->selected)
1150 wIconSelect(wwin->icon);
1152 XUnmapWindow(dpy, wwin->icon->core->window);
1156 if (!netwm_hidden)
1157 wSoundPlay(WSOUND_DEICONIFY);
1159 /* if the window is in another workspace, do it silently */
1160 if (!netwm_hidden) {
1161 #ifdef ANIMATIONS
1162 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1163 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1164 int ix, iy, iw, ih;
1166 if (!wPreferences.disable_miniwindows
1167 #ifdef NETWM_HINTS
1168 && !wwin->flags.net_handle_icon
1169 #endif
1171 ix = wwin->icon_x;
1172 iy = wwin->icon_y;
1173 iw = wwin->icon->core->width;
1174 ih = wwin->icon->core->height;
1175 } else {
1176 #ifdef NETWM_HINTS
1177 if (wwin->flags.net_handle_icon) {
1178 ix = wwin->icon_x;
1179 iy = wwin->icon_y;
1180 iw = wwin->icon_w;
1181 ih = wwin->icon_h;
1182 } else
1183 #endif
1185 ix = 0;
1186 iy = 0;
1187 iw = wwin->screen_ptr->scr_width;
1188 ih = wwin->screen_ptr->scr_height;
1191 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1192 wwin->frame_x, wwin->frame_y,
1193 wwin->frame->core->width, wwin->frame->core->height,
1194 False);
1196 #endif /* ANIMATIONS */
1197 wwin->flags.skip_next_animation = 0;
1198 XGrabServer(dpy);
1199 if (!wwin->flags.shaded) {
1200 XMapWindow(dpy, wwin->client_win);
1202 XMapWindow(dpy, wwin->frame->core->window);
1203 wRaiseFrame(wwin->frame->core);
1204 if (!wwin->flags.shaded) {
1205 wClientSetState(wwin, NormalState, None);
1207 mapTransientsFor(wwin);
1210 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1211 #ifdef NETWM_HINTS
1212 && !wwin->flags.net_handle_icon
1213 #endif
1215 RemoveFromStackList(wwin->icon->core);
1216 /* removeIconGrabs(wwin->icon);*/
1217 wIconDestroy(wwin->icon);
1218 wwin->icon = NULL;
1221 if (!netwm_hidden) {
1222 XUngrabServer(dpy);
1224 wSetFocusTo(wwin->screen_ptr, wwin);
1226 #ifdef ANIMATIONS
1227 if (!wwin->screen_ptr->flags.startup) {
1228 /* Catch up with events not processed while animation was running */
1229 Window clientwin = wwin->client_win;
1231 ProcessPendingEvents();
1233 /* the window can disappear while ProcessPendingEvents() runs */
1234 if (!wWindowFor(clientwin)) {
1235 return;
1238 #endif
1241 if (wPreferences.auto_arrange_icons) {
1242 wArrangeIcons(wwin->screen_ptr, True);
1245 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1247 /* In case we were shaded and iconified, also unshade */
1248 if (!netwm_hidden)
1249 wUnshadeWindow(wwin);
1254 static void
1255 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1257 if (wwin->flags.miniaturized) {
1258 if (wwin->icon) {
1259 XUnmapWindow(dpy, wwin->icon->core->window);
1260 wwin->icon->mapped = 0;
1262 wwin->flags.hidden = 1;
1264 WMPostNotificationName(WMNChangedState, wwin, "hide");
1265 return;
1268 if (wwin->flags.inspector_open) {
1269 wHideInspectorForWindow(wwin);
1272 wwin->flags.hidden = 1;
1273 wWindowUnmap(wwin);
1275 wClientSetState(wwin, IconicState, icon->icon_win);
1276 flushExpose();
1277 wSoundPlay(WSOUND_HIDE);
1278 #ifdef ANIMATIONS
1279 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1280 !wwin->flags.skip_next_animation && animate) {
1281 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1282 wwin->frame->core->width, wwin->frame->core->height,
1283 icon_x, icon_y, icon->core->width, icon->core->height,
1284 True);
1286 #endif
1287 wwin->flags.skip_next_animation = 0;
1289 WMPostNotificationName(WMNChangedState, wwin, "hide");
1294 void
1295 wHideOtherApplications(WWindow *awin)
1297 WWindow *wwin;
1298 WApplication *tapp;
1300 if (!awin)
1301 return;
1302 wwin = awin->screen_ptr->focused_window;
1305 while (wwin) {
1306 if (wwin!=awin
1307 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1308 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1309 && !wwin->flags.internal_window
1310 && wGetWindowOfInspectorForWindow(wwin) != awin
1311 && !WFLAGP(wwin, no_hide_others)) {
1313 if (wwin->main_window==None || WFLAGP(wwin, no_appicon)) {
1314 if (!WFLAGP(wwin, no_miniaturizable)) {
1315 wwin->flags.skip_next_animation = 1;
1316 wIconifyWindow(wwin);
1318 } else if (wwin->main_window!=None
1319 && awin->main_window != wwin->main_window) {
1320 tapp = wApplicationOf(wwin->main_window);
1321 if (tapp) {
1322 tapp->flags.skip_next_animation = 1;
1323 wHideApplication(tapp);
1324 } else {
1325 if (!WFLAGP(wwin, no_miniaturizable)) {
1326 wwin->flags.skip_next_animation = 1;
1327 wIconifyWindow(wwin);
1332 wwin = wwin->prev;
1335 wSetFocusTo(awin->screen_ptr, awin);
1341 void
1342 wHideApplication(WApplication *wapp)
1344 WScreen *scr;
1345 WWindow *wlist;
1346 int hadfocus;
1347 int animate;
1349 if (!wapp) {
1350 wwarning("trying to hide a non grouped window");
1351 return;
1353 if (!wapp->main_window_desc) {
1354 wwarning("group leader not found for window group");
1355 return;
1357 scr = wapp->main_window_desc->screen_ptr;
1358 hadfocus = 0;
1359 wlist = scr->focused_window;
1360 if (!wlist)
1361 return;
1363 if (wlist->main_window == wapp->main_window)
1364 wapp->last_focused = wlist;
1365 else
1366 wapp->last_focused = NULL;
1368 animate = !wapp->flags.skip_next_animation;
1370 while (wlist) {
1371 if (wlist->main_window == wapp->main_window) {
1372 if (wlist->flags.focused) {
1373 hadfocus = 1;
1375 if (wapp->app_icon) {
1376 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1377 wapp->app_icon->y_pos, wlist, animate);
1378 animate = False;
1381 wlist = wlist->prev;
1384 wapp->flags.skip_next_animation = 0;
1386 if (hadfocus) {
1387 if (wPreferences.focus_mode==WKF_CLICK) {
1388 wlist = scr->focused_window;
1389 while (wlist) {
1390 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1391 && (wlist->flags.mapped || wlist->flags.shaded))
1392 break;
1393 wlist = wlist->prev;
1395 wSetFocusTo(scr, wlist);
1396 } else {
1397 wSetFocusTo(scr, NULL);
1401 wapp->flags.hidden = 1;
1403 if(wPreferences.auto_arrange_icons) {
1404 wArrangeIcons(scr, True);
1406 #ifdef HIDDENDOT
1407 if (wapp->app_icon)
1408 wAppIconPaint(wapp->app_icon);
1409 #endif
1415 static void
1416 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1417 int bringToCurrentWS)
1419 if (bringToCurrentWS)
1420 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1422 wwin->flags.hidden=0;
1424 wSoundPlay(WSOUND_UNHIDE);
1425 #ifdef ANIMATIONS
1426 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1427 && animate) {
1428 animateResize(wwin->screen_ptr, icon_x, icon_y,
1429 icon->core->width, icon->core->height,
1430 wwin->frame_x, wwin->frame_y,
1431 wwin->frame->core->width, wwin->frame->core->height,
1432 True);
1434 #endif
1435 wwin->flags.skip_next_animation = 0;
1436 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1437 XMapWindow(dpy, wwin->client_win);
1438 XMapWindow(dpy, wwin->frame->core->window);
1439 wClientSetState(wwin, NormalState, None);
1440 wwin->flags.mapped=1;
1441 wRaiseFrame(wwin->frame->core);
1443 if (wwin->flags.inspector_open) {
1444 wUnhideInspectorForWindow(wwin);
1447 WMPostNotificationName(WMNChangedState, wwin, "hide");
1451 void
1452 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1454 WScreen *scr;
1455 WWindow *wlist, *next;
1456 WWindow *focused=NULL;
1457 Bool shouldArrangeIcons = False;
1458 int animate;
1460 if (!wapp)
1461 return;
1463 scr = wapp->main_window_desc->screen_ptr;
1464 wlist = scr->focused_window;
1465 if (!wlist)
1466 return;
1468 /* goto beginning of list */
1469 while (wlist->prev)
1470 wlist = wlist->prev;
1472 animate = !wapp->flags.skip_next_animation;
1474 while (wlist) {
1475 next = wlist->next;
1477 if (wlist->main_window == wapp->main_window) {
1478 if (wlist->flags.focused)
1479 focused = wlist;
1480 else if (!focused || !focused->flags.focused)
1481 focused = wlist;
1483 if (wlist->flags.miniaturized) {
1484 if (bringToCurrentWS || wPreferences.sticky_icons ||
1485 wlist->frame->workspace == scr->current_workspace) {
1486 if (wlist->icon && !wlist->icon->mapped) {
1487 XMapWindow(dpy, wlist->icon->core->window);
1488 wlist->icon->mapped = 1;
1491 if (bringToCurrentWS)
1492 wWindowChangeWorkspace(wlist, scr->current_workspace);
1493 wlist->flags.hidden = 0;
1494 if (miniwindows &&
1495 wlist->frame->workspace == scr->current_workspace) {
1496 wDeiconifyWindow(wlist);
1498 shouldArrangeIcons = True;
1499 WMPostNotificationName(WMNChangedState, wlist, "hide");
1500 } else if (wlist->flags.shaded) {
1501 if (bringToCurrentWS)
1502 wWindowChangeWorkspace(wlist, scr->current_workspace);
1503 wlist->flags.hidden = 0;
1504 if (wlist->frame->workspace == scr->current_workspace) {
1505 XMapWindow(dpy, wlist->frame->core->window);
1506 if (miniwindows) {
1507 wUnshadeWindow(wlist);
1508 wRaiseFrame(wlist->frame->core);
1511 WMPostNotificationName(WMNChangedState, wlist, "hide");
1512 } else if (wlist->flags.hidden) {
1513 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1514 wapp->app_icon->y_pos, wlist, animate,
1515 bringToCurrentWS);
1516 animate = False;
1517 } else {
1518 if (bringToCurrentWS
1519 && wlist->frame->workspace != scr->current_workspace) {
1520 wWindowChangeWorkspace(wlist, scr->current_workspace);
1522 wRaiseFrame(wlist->frame->core);
1525 wlist = next;
1528 wapp->flags.skip_next_animation = 0;
1529 wapp->flags.hidden = 0;
1531 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1532 wRaiseFrame(wapp->last_focused->frame->core);
1533 wSetFocusTo(scr, wapp->last_focused);
1534 } else if (focused) {
1535 wSetFocusTo(scr, focused);
1537 wapp->last_focused = NULL;
1538 if (shouldArrangeIcons || wPreferences.auto_arrange_icons) {
1539 wArrangeIcons(scr, True);
1541 #ifdef HIDDENDOT
1542 wAppIconPaint(wapp->app_icon);
1543 #endif
1548 void
1549 wShowAllWindows(WScreen *scr)
1551 WWindow *wwin, *old_foc;
1552 WApplication *wapp;
1554 old_foc = wwin = scr->focused_window;
1555 while (wwin) {
1556 if (!wwin->flags.internal_window &&
1557 (scr->current_workspace == wwin->frame->workspace
1558 || IS_OMNIPRESENT(wwin))) {
1559 if (wwin->flags.miniaturized) {
1560 wwin->flags.skip_next_animation = 1;
1561 wDeiconifyWindow(wwin);
1562 } else if (wwin->flags.hidden) {
1563 wapp = wApplicationOf(wwin->main_window);
1564 if (wapp) {
1565 wUnhideApplication(wapp, False, False);
1566 } else {
1567 wwin->flags.skip_next_animation = 1;
1568 wDeiconifyWindow(wwin);
1572 wwin = wwin->prev;
1574 wSetFocusTo(scr, old_foc);
1575 /*wRaiseFrame(old_foc->frame->core);*/
1579 void
1580 wRefreshDesktop(WScreen *scr)
1582 Window win;
1583 XSetWindowAttributes attr;
1585 attr.backing_store = NotUseful;
1586 attr.save_under = False;
1587 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1588 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1589 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1590 &attr);
1591 XMapRaised(dpy, win);
1592 XDestroyWindow(dpy, win);
1593 XFlush(dpy);
1597 void
1598 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1600 WWindow *wwin;
1601 WAppIcon *aicon;
1603 int head;
1604 const int heads = wXineramaHeads(scr);
1606 struct HeadVars {
1607 int pf; /* primary axis */
1608 int sf; /* secondary axis */
1609 int fullW;
1610 int fullH;
1611 int pi, si;
1612 int sx1, sx2, sy1, sy2; /* screen boundary */
1613 int sw, sh;
1614 int xo, yo;
1615 int xs, ys;
1616 } *vars;
1618 int isize = wPreferences.icon_size;
1620 vars = (struct HeadVars*)wmalloc(sizeof(struct HeadVars)*heads);
1622 for (head = 0; head < heads; ++head) {
1623 #if 0
1624 WMRect rect = wGetRectForHead(scr, head);
1625 #else
1626 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1627 WMRect rect = wmkrect(area.x1, area.y1, area.x2-area.x1, area.y2-area.y1);
1628 #endif
1630 vars[head].pi = vars[head].si = 0;
1631 vars[head].sx1 = rect.pos.x;
1632 vars[head].sy1 = rect.pos.y;
1633 vars[head].sw = rect.size.width;
1634 vars[head].sh = rect.size.height;
1635 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1636 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1638 #if 0
1639 if (scr->dock) {
1640 if (scr->dock->on_right_side)
1641 vars[head].sx2 -= isize + DOCK_EXTRA_SPACE;
1642 else
1643 vars[head].sx1 += isize + DOCK_EXTRA_SPACE;
1645 #endif
1647 vars[head].sw = isize * (vars[head].sw/isize);
1648 vars[head].sh = isize * (vars[head].sh/isize);
1649 vars[head].fullW = (vars[head].sx2-vars[head].sx1)/isize;
1650 vars[head].fullH = (vars[head].sy2-vars[head].sy1)/isize;
1652 /* icon yard boundaries */
1653 if (wPreferences.icon_yard & IY_VERT) {
1654 vars[head].pf = vars[head].fullH;
1655 vars[head].sf = vars[head].fullW;
1656 } else {
1657 vars[head].pf = vars[head].fullW;
1658 vars[head].sf = vars[head].fullH;
1660 if (wPreferences.icon_yard & IY_RIGHT) {
1661 vars[head].xo = vars[head].sx2 - isize;
1662 vars[head].xs = -1;
1663 } else {
1664 vars[head].xo = vars[head].sx1;
1665 vars[head].xs = 1;
1667 if (wPreferences.icon_yard & IY_TOP) {
1668 vars[head].yo = vars[head].sy1;
1669 vars[head].ys = 1;
1670 } else {
1671 vars[head].yo = vars[head].sy2 - isize;
1672 vars[head].ys = -1;
1676 #define X ((wPreferences.icon_yard & IY_VERT) \
1677 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1678 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1680 #define Y ((wPreferences.icon_yard & IY_VERT) \
1681 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1682 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1685 /* arrange application icons */
1686 aicon = scr->app_icon_list;
1687 /* reverse them to avoid unnecessarily sliding of icons */
1688 while (aicon && aicon->next)
1689 aicon = aicon->next;
1691 while (aicon) {
1692 if (!aicon->docked) {
1693 /* CHECK: can icon be NULL here ? */
1694 /* The intention here is to place the AppIcon on the head that
1695 * contains most of the applications _main_ window. */
1696 head = wGetHeadForWindow(aicon->icon->owner);
1698 if (aicon->x_pos != X || aicon->y_pos != Y) {
1699 #ifdef ANIMATIONS
1700 if (!wPreferences.no_animations) {
1701 SlideWindow(aicon->icon->core->window,
1702 aicon->x_pos, aicon->y_pos, X, Y);
1704 #endif /* ANIMATIONS */
1706 wAppIconMove(aicon, X, Y);
1707 vars[head].pi++;
1708 if (vars[head].pi >= vars[head].pf) {
1709 vars[head].pi = 0;
1710 vars[head].si++;
1713 aicon = aicon->prev;
1716 /* arrange miniwindows */
1717 wwin = scr->focused_window;
1718 /* reverse them to avoid unnecessarily shuffling */
1719 while (wwin && wwin->prev)
1720 wwin = wwin->prev;
1722 while (wwin) {
1723 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1724 (wwin->frame->workspace==scr->current_workspace ||
1725 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1727 head = wGetHeadForWindow(wwin);
1729 if (arrangeAll || !wwin->flags.icon_moved) {
1730 if (wwin->icon_x != X || wwin->icon_y != Y) {
1731 #ifdef ANIMATIONS
1732 if (wPreferences.no_animations) {
1733 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1734 } else {
1735 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1736 wwin->icon_y, X, Y);
1738 #else
1739 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1740 #endif /* ANIMATIONS */
1742 wwin->icon_x = X;
1743 wwin->icon_y = Y;
1745 vars[head].pi++;
1746 if (vars[head].pi >= vars[head].pf) {
1747 vars[head].pi = 0;
1748 vars[head].si++;
1752 if (arrangeAll) {
1753 wwin->flags.icon_moved = 0;
1755 /* we reversed the order, so we use next */
1756 wwin = wwin->next;
1759 wfree(vars);
1762 #if 0
1763 void
1764 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1766 WWindow *wwin;
1767 WAppIcon *aicon;
1768 int pf; /* primary axis */
1769 int sf; /* secondary axis */
1770 int fullW;
1771 int fullH;
1772 int pi, si;
1773 int sx1, sx2, sy1, sy2; /* screen boundary */
1774 int sw, sh;
1775 int xo, yo;
1776 int xs, ys;
1777 int isize = wPreferences.icon_size;
1780 * Find out screen boundaries.
1784 * Allows each head to have miniwindows
1786 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1788 sx1 = rect.pos.x;
1789 sy1 = rect.pos.y;
1790 sw = rect.size.width;
1791 sh = rect.size.height;
1792 sx2 = sx1 + sw;
1793 sy2 = sy1 + sh;
1794 if (scr->dock) {
1795 if (scr->dock->on_right_side)
1796 sx2 -= isize + DOCK_EXTRA_SPACE;
1797 else
1798 sx1 += isize + DOCK_EXTRA_SPACE;
1801 #if 0
1802 sw = isize * (scr->scr_width/isize);
1803 sh = isize * (scr->scr_height/isize);
1804 #else
1805 sw = isize * (sw/isize);
1806 sh = isize * (sh/isize);
1807 #endif
1808 fullW = (sx2-sx1)/isize;
1809 fullH = (sy2-sy1)/isize;
1811 /* icon yard boundaries */
1812 if (wPreferences.icon_yard & IY_VERT) {
1813 pf = fullH;
1814 sf = fullW;
1815 } else {
1816 pf = fullW;
1817 sf = fullH;
1819 if (wPreferences.icon_yard & IY_RIGHT) {
1820 xo = sx2 - isize;
1821 xs = -1;
1822 } else {
1823 xo = sx1;
1824 xs = 1;
1826 if (wPreferences.icon_yard & IY_TOP) {
1827 yo = sy1;
1828 ys = 1;
1829 } else {
1830 yo = sy2 - isize;
1831 ys = -1;
1834 /* arrange icons putting the most recently focused window
1835 * as the last icon */
1836 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1837 : xo + xs*(pi*isize))
1838 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1839 : yo + ys*(si*isize))
1841 /* arrange application icons */
1842 aicon = scr->app_icon_list;
1843 /* reverse them to avoid unnecessarily sliding of icons */
1844 while (aicon && aicon->next)
1845 aicon = aicon->next;
1847 pi = 0;
1848 si = 0;
1849 while (aicon) {
1850 if (!aicon->docked) {
1851 if (aicon->x_pos != X || aicon->y_pos != Y) {
1852 #ifdef ANIMATIONS
1853 if (!wPreferences.no_animations) {
1854 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1855 X, Y);
1857 #endif /* ANIMATIONS */
1859 wAppIconMove(aicon, X, Y);
1860 pi++;
1862 /* we reversed the order so we use prev */
1863 aicon = aicon->prev;
1864 if (pi >= pf) {
1865 pi=0;
1866 si++;
1870 /* arrange miniwindows */
1872 wwin = scr->focused_window;
1873 /* reverse them to avoid unnecessarily shuffling */
1874 while (wwin && wwin->prev)
1875 wwin = wwin->prev;
1877 while (wwin) {
1878 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1879 (wwin->frame->workspace==scr->current_workspace ||
1880 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1882 if (arrangeAll || !wwin->flags.icon_moved) {
1883 if (wwin->icon_x != X || wwin->icon_y != Y) {
1884 #ifdef ANIMATIONS
1885 if (wPreferences.no_animations) {
1886 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1887 } else {
1888 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1889 wwin->icon_y, X, Y);
1891 #else
1892 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1893 #endif /* ANIMATIONS */
1895 wwin->icon_x = X;
1896 wwin->icon_y = Y;
1897 pi++;
1900 if (arrangeAll) {
1901 wwin->flags.icon_moved = 0;
1903 /* we reversed the order, so we use next */
1904 wwin = wwin->next;
1905 if (pi >= pf) {
1906 pi=0;
1907 si++;
1911 #endif
1913 void
1914 wSelectWindow(WWindow *wwin, Bool flag)
1916 WScreen *scr = wwin->screen_ptr;
1918 if (flag) {
1919 wwin->flags.selected = 1;
1920 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1922 if (!HAS_BORDER(wwin)) {
1923 XSetWindowBorderWidth(dpy, wwin->frame->core->window,
1924 FRAME_BORDER_WIDTH);
1927 if (!scr->selected_windows)
1928 scr->selected_windows = WMCreateArray(4);
1929 WMAddToArray(scr->selected_windows, wwin);
1930 } else {
1931 wwin->flags.selected = 0;
1932 XSetWindowBorder(dpy, wwin->frame->core->window,
1933 scr->frame_border_pixel);
1935 if (!HAS_BORDER(wwin)) {
1936 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1939 if (scr->selected_windows) {
1940 WMRemoveFromArray(scr->selected_windows, wwin);
1946 void
1947 wMakeWindowVisible(WWindow *wwin)
1949 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1950 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1952 if (wwin->flags.shaded) {
1953 wUnshadeWindow(wwin);
1955 if (wwin->flags.hidden) {
1956 WApplication *app;
1958 app = wApplicationOf(wwin->main_window);
1959 if (app) {
1960 /* trick to get focus to this window */
1961 app->last_focused = wwin;
1962 wUnhideApplication(app, False, False);
1965 if (wwin->flags.miniaturized) {
1966 wDeiconifyWindow(wwin);
1967 } else {
1968 if (!WFLAGP(wwin, no_focusable))
1969 wSetFocusTo(wwin->screen_ptr, wwin);
1970 wRaiseFrame(wwin->frame->core);