- new algorithm for placing miniwindows after unhiding the application they
[wmaker-crm.git] / src / actions.c
blob6e6e45c131f02f06cab88c5f102a87bd58043981
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 x, y, w, h;
479 if (!wwin->flags.maximized)
480 return;
482 if (wwin->flags.shaded) {
483 wwin->flags.skip_next_animation = 1;
484 wUnshadeWindow(wwin);
486 x = ((wwin->flags.maximized & MAX_HORIZONTAL) && wwin->old_geometry.x) ?
487 wwin->old_geometry.x : wwin->frame_x;
488 y = ((wwin->flags.maximized & MAX_VERTICAL) && wwin->old_geometry.y) ?
489 wwin->old_geometry.y : wwin->frame_y;
490 w = wwin->old_geometry.width ?
491 wwin->old_geometry.width : wwin->client.width;
492 h = wwin->old_geometry.height ?
493 wwin->old_geometry.height : wwin->client.height;
495 wwin->flags.maximized = 0;
496 wWindowConfigure(wwin, x, y, w, h);
498 WMPostNotificationName(WMNChangedState, wwin, "maximize");
500 wSoundPlay(WSOUND_UNMAXIMIZE);
504 void
505 wFullscreenWindow(WWindow *wwin)
507 int head;
508 WMRect rect;
510 if (wwin->flags.fullscreen)
511 return;
513 wwin->flags.fullscreen = True;
515 wWindowConfigureBorders(wwin);
517 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
519 wwin->bfs_geometry.x = wwin->frame_x;
520 wwin->bfs_geometry.y = wwin->frame_y;
521 wwin->bfs_geometry.width = wwin->frame->core->width;
522 wwin->bfs_geometry.height = wwin->frame->core->height;
524 head = wGetHeadForWindow(wwin);
525 rect = wGetRectForHead(wwin->screen_ptr, head);
526 wWindowConfigure(wwin, rect.pos.x, rect.pos.y,
527 rect.size.width, rect.size.height);
529 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
533 void
534 wUnfullscreenWindow(WWindow *wwin)
536 if (!wwin->flags.fullscreen)
537 return;
539 wwin->flags.fullscreen = False;
541 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
542 if (WFLAGP(wwin, sunken)) {
543 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
544 } else if (WFLAGP(wwin, floating)) {
545 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
546 } else {
547 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
551 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
552 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
554 wWindowConfigureBorders(wwin);
556 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
557 wFrameWindowPaint(wwin->frame);
560 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
564 #ifdef ANIMATIONS
565 static void
566 animateResizeFlip(WScreen *scr, int x, int y, int w, int h,
567 int fx, int fy, int fw, int fh, int steps)
569 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
570 float cx, cy, cw, ch;
571 float xstep, ystep, wstep, hstep;
572 XPoint points[5];
573 float dx, dch, midy;
574 float angle, final_angle, delta;
576 xstep = (float)(fx-x)/steps;
577 ystep = (float)(fy-y)/steps;
578 wstep = (float)(fw-w)/steps;
579 hstep = (float)(fh-h)/steps;
581 cx = (float)x;
582 cy = (float)y;
583 cw = (float)w;
584 ch = (float)h;
586 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_F;
587 delta = (float)(final_angle/FRAMES);
588 for (angle=0;; angle+=delta) {
589 if (angle > final_angle)
590 angle = final_angle;
592 dx = (cw/10) - ((cw/5) * sin(angle));
593 dch = (ch/2) * cos(angle);
594 midy = cy + (ch/2);
596 points[0].x = cx + dx; points[0].y = midy - dch;
597 points[1].x = cx + cw - dx; points[1].y = points[0].y;
598 points[2].x = cx + cw + dx; points[2].y = midy + dch;
599 points[3].x = cx - dx; points[3].y = points[2].y;
600 points[4].x = points[0].x; points[4].y = points[0].y;
602 XGrabServer(dpy);
603 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
604 XFlush(dpy);
605 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
606 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
607 #else
608 wusleep(10);
609 #endif
611 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
612 XUngrabServer(dpy);
613 cx+=xstep;
614 cy+=ystep;
615 cw+=wstep;
616 ch+=hstep;
617 if (angle >= final_angle)
618 break;
621 XFlush(dpy);
623 #undef FRAMES
626 static void
627 animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
628 int fx, int fy, int fw, int fh, int steps)
630 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
631 float cx, cy, cw, ch;
632 float xstep, ystep, wstep, hstep;
633 XPoint points[5];
634 float angle, final_angle, a, d, delta;
636 x += w/2;
637 y += h/2;
638 fx += fw/2;
639 fy += fh/2;
641 xstep = (float)(fx-x)/steps;
642 ystep = (float)(fy-y)/steps;
643 wstep = (float)(fw-w)/steps;
644 hstep = (float)(fh-h)/steps;
646 cx = (float)x;
647 cy = (float)y;
648 cw = (float)w;
649 ch = (float)h;
651 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
652 delta = (float)(final_angle/FRAMES);
653 for (angle=0;; angle+=delta) {
654 if (angle > final_angle)
655 angle = final_angle;
657 a = atan(ch/cw);
658 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
660 points[0].x = cx+cos(angle-a)*d;
661 points[0].y = cy+sin(angle-a)*d;
662 points[1].x = cx+cos(angle+a)*d;
663 points[1].y = cy+sin(angle+a)*d;
664 points[2].x = cx+cos(angle-a+WM_PI)*d;
665 points[2].y = cy+sin(angle-a+WM_PI)*d;
666 points[3].x = cx+cos(angle+a+WM_PI)*d;
667 points[3].y = cy+sin(angle+a+WM_PI)*d;
668 points[4].x = cx+cos(angle-a)*d;
669 points[4].y = cy+sin(angle-a)*d;
670 XGrabServer(dpy);
671 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
672 XFlush(dpy);
673 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
674 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
675 #else
676 wusleep(10);
677 #endif
679 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
680 XUngrabServer(dpy);
681 cx+=xstep;
682 cy+=ystep;
683 cw+=wstep;
684 ch+=hstep;
685 if (angle >= final_angle)
686 break;
689 XFlush(dpy);
691 #undef FRAMES
694 static void
695 animateResizeZoom(WScreen *scr, int x, int y, int w, int h,
696 int fx, int fy, int fw, int fh, int steps)
698 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
699 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
700 float xstep, ystep, wstep, hstep;
701 int i, j;
703 xstep = (float)(fx-x)/steps;
704 ystep = (float)(fy-y)/steps;
705 wstep = (float)(fw-w)/steps;
706 hstep = (float)(fh-h)/steps;
708 for (j=0; j<FRAMES; j++) {
709 cx[j] = (float)x;
710 cy[j] = (float)y;
711 cw[j] = (float)w;
712 ch[j] = (float)h;
714 XGrabServer(dpy);
715 for (i=0; i<steps; i++) {
716 for (j=0; j<FRAMES; j++) {
717 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
718 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
720 XFlush(dpy);
721 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
722 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
723 #else
724 wusleep(10);
725 #endif
726 for (j=0; j<FRAMES; j++) {
727 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
728 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
729 if (j<FRAMES-1) {
730 cx[j]=cx[j+1];
731 cy[j]=cy[j+1];
732 cw[j]=cw[j+1];
733 ch[j]=ch[j+1];
734 } else {
735 cx[j]+=xstep;
736 cy[j]+=ystep;
737 cw[j]+=wstep;
738 ch[j]+=hstep;
743 for (j=0; j<FRAMES; j++) {
744 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
745 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
747 XFlush(dpy);
748 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
749 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
750 #else
751 wusleep(10);
752 #endif
753 for (j=0; j<FRAMES; j++) {
754 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
755 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
758 XUngrabServer(dpy);
760 #undef FRAMES
763 void
764 animateResize(WScreen *scr, int x, int y, int w, int h,
765 int fx, int fy, int fw, int fh, int hiding)
767 int style = wPreferences.iconification_style; /* Catch the value */
768 int steps, k;
770 if (style == WIS_NONE)
771 return;
773 if (style == WIS_RANDOM) {
774 style = rand()%3;
777 k = (hiding ? 2 : 3);
779 switch(style) {
780 case WIS_TWIST:
781 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
782 if (steps>0)
783 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
784 break;
785 case WIS_FLIP:
786 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
787 if (steps>0)
788 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
789 break;
790 case WIS_ZOOM:
791 default:
792 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
793 if (steps>0)
794 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
795 break;
798 #endif /* ANIMATIONS */
801 static void
802 flushExpose()
804 XEvent tmpev;
806 while (XCheckTypedEvent(dpy, Expose, &tmpev))
807 WMHandleEvent(&tmpev);
808 XSync(dpy, 0);
811 static void
812 unmapTransientsFor(WWindow *wwin)
814 WWindow *tmp;
817 tmp = wwin->screen_ptr->focused_window;
818 while (tmp) {
819 /* unmap the transients for this transient */
820 if (tmp!=wwin && tmp->transient_for == wwin->client_win
821 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
822 || tmp->flags.shaded)) {
823 unmapTransientsFor(tmp);
824 tmp->flags.miniaturized = 1;
825 if (!tmp->flags.shaded) {
826 wWindowUnmap(tmp);
827 } else {
828 XUnmapWindow(dpy, tmp->frame->core->window);
831 if (!tmp->flags.shaded)
833 wClientSetState(tmp, IconicState, None);
835 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
837 tmp = tmp->prev;
842 static void
843 mapTransientsFor(WWindow *wwin)
845 WWindow *tmp;
847 tmp = wwin->screen_ptr->focused_window;
848 while (tmp) {
849 /* recursively map the transients for this transient */
850 if (tmp!=wwin && tmp->transient_for == wwin->client_win
851 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
852 && tmp->icon==NULL) {
853 mapTransientsFor(tmp);
854 tmp->flags.miniaturized = 0;
855 if (!tmp->flags.shaded) {
856 wWindowMap(tmp);
857 } else {
858 XMapWindow(dpy, tmp->frame->core->window);
860 tmp->flags.semi_focused = 0;
862 if (!tmp->flags.shaded)
864 wClientSetState(tmp, NormalState, None);
866 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
868 tmp = tmp->prev;
872 #if 0
873 static void
874 setupIconGrabs(WIcon *icon)
876 /* setup passive grabs on the icon */
877 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
878 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
879 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
880 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
881 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
882 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
883 XSync(dpy, 0);
885 #endif
887 static WWindow*
888 recursiveTransientFor(WWindow *wwin)
890 int i;
892 if (!wwin)
893 return None;
895 /* hackish way to detect transient_for cycle */
896 i = wwin->screen_ptr->window_count+1;
898 while (wwin && wwin->transient_for != None && i>0) {
899 wwin = wWindowFor(wwin->transient_for);
900 i--;
902 if (i==0 && wwin) {
903 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
904 wwin->frame->title);
905 return NULL;
908 return wwin;
911 #if 0
912 static void
913 removeIconGrabs(WIcon *icon)
915 /* remove passive grabs on the icon */
916 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
917 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
918 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
919 XSync(dpy, 0);
921 #endif
924 void
925 wIconifyWindow(WWindow *wwin)
927 XWindowAttributes attribs;
928 int present;
931 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
932 /* the window doesn't exist anymore */
933 return;
936 if (wwin->flags.miniaturized) {
937 return;
940 if (wwin->transient_for!=None &&
941 wwin->transient_for!=wwin->screen_ptr->root_win) {
942 WWindow *owner = wWindowFor(wwin->transient_for);
944 if (owner && owner->flags.miniaturized)
945 return;
948 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
950 /* if the window is in another workspace, simplify process */
951 if (present) {
952 /* icon creation may take a while */
953 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
954 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
955 GrabModeAsync, None, None, CurrentTime);
958 if (!wPreferences.disable_miniwindows
959 #ifdef NETWM_HINTS
960 && !wwin->flags.net_handle_icon
961 #endif
963 if (!wwin->flags.icon_moved) {
964 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
966 wwin->icon = wIconCreate(wwin);
968 wwin->icon->mapped = 1;
971 wwin->flags.miniaturized = 1;
972 wwin->flags.mapped = 0;
974 /* unmap transients */
976 unmapTransientsFor(wwin);
978 if (present) {
979 wSoundPlay(WSOUND_ICONIFY);
981 XUngrabPointer(dpy, CurrentTime);
982 wWindowUnmap(wwin);
983 /* let all Expose events arrive so that we can repaint
984 * something before the animation starts (and the server is grabbed) */
985 XSync(dpy, 0);
987 if (wPreferences.disable_miniwindows
988 #ifdef NETWM_HINTS
989 || wwin->flags.net_handle_icon
990 #endif
992 wClientSetState(wwin, IconicState, None);
993 else
994 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
996 flushExpose();
997 #ifdef ANIMATIONS
998 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
999 && !wPreferences.no_animations) {
1000 int ix, iy, iw, ih;
1002 if (!wPreferences.disable_miniwindows
1003 #ifdef NETWM_HINTS
1004 && !wwin->flags.net_handle_icon
1005 #endif
1007 ix = wwin->icon_x;
1008 iy = wwin->icon_y;
1009 iw = wwin->icon->core->width;
1010 ih = wwin->icon->core->height;
1011 } else {
1012 #ifdef NETWM_HINTS
1013 if (wwin->flags.net_handle_icon) {
1014 ix = wwin->icon_x;
1015 iy = wwin->icon_y;
1016 iw = wwin->icon_w;
1017 ih = wwin->icon_h;
1018 } else
1019 #endif
1021 ix = 0;
1022 iy = 0;
1023 iw = wwin->screen_ptr->scr_width;
1024 ih = wwin->screen_ptr->scr_height;
1027 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1028 wwin->frame->core->width, wwin->frame->core->height,
1029 ix, iy, iw, ih, False);
1031 #endif
1034 wwin->flags.skip_next_animation = 0;
1036 if (!wPreferences.disable_miniwindows
1037 #ifdef NETWM_HINTS
1038 && !wwin->flags.net_handle_icon
1039 #endif
1042 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
1043 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1045 XMapWindow(dpy, wwin->icon->core->window);
1047 AddToStackList(wwin->icon->core);
1049 wLowerFrame(wwin->icon->core);
1052 if (present) {
1053 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1056 * It doesn't seem to be working and causes button event hangup
1057 * when deiconifying a transient window.
1058 setupIconGrabs(wwin->icon);
1060 if ((wwin->flags.focused
1061 || (owner && wwin->client_win == owner->client_win))
1062 && wPreferences.focus_mode==WKF_CLICK) {
1063 WWindow *tmp;
1065 tmp = wwin->prev;
1066 while (tmp) {
1067 if (!WFLAGP(tmp, no_focusable)
1068 && !(tmp->flags.hidden||tmp->flags.miniaturized)
1069 && (wwin->frame->workspace == tmp->frame->workspace))
1070 break;
1071 tmp = tmp->prev;
1073 wSetFocusTo(wwin->screen_ptr, tmp);
1074 } else if (wPreferences.focus_mode!=WKF_CLICK) {
1075 wSetFocusTo(wwin->screen_ptr, NULL);
1078 #ifdef ANIMATIONS
1079 if (!wwin->screen_ptr->flags.startup) {
1080 /* Catch up with events not processed while animation was running */
1081 Window clientwin = wwin->client_win;
1083 ProcessPendingEvents();
1085 /* the window can disappear while ProcessPendingEvents() runs */
1086 if (!wWindowFor(clientwin)) {
1087 return;
1090 #endif
1093 /* maybe we want to do this regardless of net_handle_icon
1094 * it seems to me we might break behaviour this way.
1096 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1097 #ifdef NETWM_HINTS
1098 && !wwin->flags.net_handle_icon
1099 #endif
1101 wIconSelect(wwin->icon);
1103 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1109 void
1110 wDeiconifyWindow(WWindow *wwin)
1112 #ifdef NETWM_HINTS
1113 /* we're hiding for show_desktop */
1114 int netwm_hidden = wwin->flags.net_show_desktop &&
1115 wwin->frame->workspace!=wwin->screen_ptr->current_workspace;
1116 #else
1117 int netwm_hidden = False;
1118 #endif
1120 if (!netwm_hidden)
1121 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1123 if (!wwin->flags.miniaturized)
1124 return;
1126 if (wwin->transient_for != None
1127 && wwin->transient_for != wwin->screen_ptr->root_win) {
1128 WWindow *owner = recursiveTransientFor(wwin);
1130 if (owner && owner->flags.miniaturized) {
1131 wDeiconifyWindow(owner);
1132 wSetFocusTo(wwin->screen_ptr, wwin);
1133 wRaiseFrame(wwin->frame->core);
1134 return;
1138 wwin->flags.miniaturized = 0;
1140 if (!netwm_hidden && !wwin->flags.shaded) {
1141 wwin->flags.mapped = 1;
1144 if (!netwm_hidden || wPreferences.sticky_icons) {
1145 /* maybe we want to do this regardless of net_handle_icon
1146 * it seems to me we might break behaviour this way.
1148 if (!wPreferences.disable_miniwindows
1149 #ifdef NETWM_HINTS
1150 && !wwin->flags.net_handle_icon
1151 #endif
1152 && wwin->icon != NULL) {
1153 if (wwin->icon->selected)
1154 wIconSelect(wwin->icon);
1156 XUnmapWindow(dpy, wwin->icon->core->window);
1160 if (!netwm_hidden)
1161 wSoundPlay(WSOUND_DEICONIFY);
1163 /* if the window is in another workspace, do it silently */
1164 if (!netwm_hidden) {
1165 #ifdef ANIMATIONS
1166 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1167 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1168 int ix, iy, iw, ih;
1170 if (!wPreferences.disable_miniwindows
1171 #ifdef NETWM_HINTS
1172 && !wwin->flags.net_handle_icon
1173 #endif
1175 ix = wwin->icon_x;
1176 iy = wwin->icon_y;
1177 iw = wwin->icon->core->width;
1178 ih = wwin->icon->core->height;
1179 } else {
1180 #ifdef NETWM_HINTS
1181 if (wwin->flags.net_handle_icon) {
1182 ix = wwin->icon_x;
1183 iy = wwin->icon_y;
1184 iw = wwin->icon_w;
1185 ih = wwin->icon_h;
1186 } else
1187 #endif
1189 ix = 0;
1190 iy = 0;
1191 iw = wwin->screen_ptr->scr_width;
1192 ih = wwin->screen_ptr->scr_height;
1195 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1196 wwin->frame_x, wwin->frame_y,
1197 wwin->frame->core->width, wwin->frame->core->height,
1198 False);
1200 #endif /* ANIMATIONS */
1201 wwin->flags.skip_next_animation = 0;
1202 XGrabServer(dpy);
1203 if (!wwin->flags.shaded) {
1204 XMapWindow(dpy, wwin->client_win);
1206 XMapWindow(dpy, wwin->frame->core->window);
1207 wRaiseFrame(wwin->frame->core);
1208 if (!wwin->flags.shaded) {
1209 wClientSetState(wwin, NormalState, None);
1211 mapTransientsFor(wwin);
1214 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1215 #ifdef NETWM_HINTS
1216 && !wwin->flags.net_handle_icon
1217 #endif
1219 RemoveFromStackList(wwin->icon->core);
1220 /* removeIconGrabs(wwin->icon);*/
1221 wIconDestroy(wwin->icon);
1222 wwin->icon = NULL;
1225 if (!netwm_hidden) {
1226 XUngrabServer(dpy);
1228 wSetFocusTo(wwin->screen_ptr, wwin);
1230 #ifdef ANIMATIONS
1231 if (!wwin->screen_ptr->flags.startup) {
1232 /* Catch up with events not processed while animation was running */
1233 Window clientwin = wwin->client_win;
1235 ProcessPendingEvents();
1237 /* the window can disappear while ProcessPendingEvents() runs */
1238 if (!wWindowFor(clientwin)) {
1239 return;
1242 #endif
1245 if (wPreferences.auto_arrange_icons) {
1246 wArrangeIcons(wwin->screen_ptr, True);
1249 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1251 /* In case we were shaded and iconified, also unshade */
1252 if (!netwm_hidden)
1253 wUnshadeWindow(wwin);
1258 static void
1259 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1261 if (wwin->flags.miniaturized) {
1262 if (wwin->icon) {
1263 XUnmapWindow(dpy, wwin->icon->core->window);
1264 wwin->icon->mapped = 0;
1266 wwin->flags.hidden = 1;
1268 WMPostNotificationName(WMNChangedState, wwin, "hide");
1269 return;
1272 if (wwin->flags.inspector_open) {
1273 wHideInspectorForWindow(wwin);
1276 wwin->flags.hidden = 1;
1277 wWindowUnmap(wwin);
1279 wClientSetState(wwin, IconicState, icon->icon_win);
1280 flushExpose();
1281 wSoundPlay(WSOUND_HIDE);
1282 #ifdef ANIMATIONS
1283 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1284 !wwin->flags.skip_next_animation && animate) {
1285 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1286 wwin->frame->core->width, wwin->frame->core->height,
1287 icon_x, icon_y, icon->core->width, icon->core->height,
1288 True);
1290 #endif
1291 wwin->flags.skip_next_animation = 0;
1293 WMPostNotificationName(WMNChangedState, wwin, "hide");
1298 void
1299 wHideOtherApplications(WWindow *awin)
1301 WWindow *wwin;
1302 WApplication *tapp;
1304 if (!awin)
1305 return;
1306 wwin = awin->screen_ptr->focused_window;
1309 while (wwin) {
1310 if (wwin!=awin
1311 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1312 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1313 && !wwin->flags.internal_window
1314 && wGetWindowOfInspectorForWindow(wwin) != awin
1315 && !WFLAGP(wwin, no_hide_others)) {
1317 if (wwin->main_window==None || WFLAGP(wwin, no_appicon)) {
1318 if (!WFLAGP(wwin, no_miniaturizable)) {
1319 wwin->flags.skip_next_animation = 1;
1320 wIconifyWindow(wwin);
1322 } else if (wwin->main_window!=None
1323 && awin->main_window != wwin->main_window) {
1324 tapp = wApplicationOf(wwin->main_window);
1325 if (tapp) {
1326 tapp->flags.skip_next_animation = 1;
1327 wHideApplication(tapp);
1328 } else {
1329 if (!WFLAGP(wwin, no_miniaturizable)) {
1330 wwin->flags.skip_next_animation = 1;
1331 wIconifyWindow(wwin);
1336 wwin = wwin->prev;
1339 wSetFocusTo(awin->screen_ptr, awin);
1345 void
1346 wHideApplication(WApplication *wapp)
1348 WScreen *scr;
1349 WWindow *wlist;
1350 int hadfocus;
1351 int animate;
1353 if (!wapp) {
1354 wwarning("trying to hide a non grouped window");
1355 return;
1357 if (!wapp->main_window_desc) {
1358 wwarning("group leader not found for window group");
1359 return;
1361 scr = wapp->main_window_desc->screen_ptr;
1362 hadfocus = 0;
1363 wlist = scr->focused_window;
1364 if (!wlist)
1365 return;
1367 if (wlist->main_window == wapp->main_window)
1368 wapp->last_focused = wlist;
1369 else
1370 wapp->last_focused = NULL;
1372 animate = !wapp->flags.skip_next_animation;
1374 while (wlist) {
1375 if (wlist->main_window == wapp->main_window) {
1376 if (wlist->flags.focused) {
1377 hadfocus = 1;
1379 if (wapp->app_icon) {
1380 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1381 wapp->app_icon->y_pos, wlist, animate);
1382 animate = False;
1385 wlist = wlist->prev;
1388 wapp->flags.skip_next_animation = 0;
1390 if (hadfocus) {
1391 if (wPreferences.focus_mode==WKF_CLICK) {
1392 wlist = scr->focused_window;
1393 while (wlist) {
1394 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1395 && (wlist->flags.mapped || wlist->flags.shaded))
1396 break;
1397 wlist = wlist->prev;
1399 wSetFocusTo(scr, wlist);
1400 } else {
1401 wSetFocusTo(scr, NULL);
1405 wapp->flags.hidden = 1;
1407 if(wPreferences.auto_arrange_icons) {
1408 wArrangeIcons(scr, True);
1410 #ifdef HIDDENDOT
1411 if (wapp->app_icon)
1412 wAppIconPaint(wapp->app_icon);
1413 #endif
1419 static void
1420 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1421 int bringToCurrentWS)
1423 if (bringToCurrentWS)
1424 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1426 wwin->flags.hidden=0;
1428 wSoundPlay(WSOUND_UNHIDE);
1429 #ifdef ANIMATIONS
1430 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1431 && animate) {
1432 animateResize(wwin->screen_ptr, icon_x, icon_y,
1433 icon->core->width, icon->core->height,
1434 wwin->frame_x, wwin->frame_y,
1435 wwin->frame->core->width, wwin->frame->core->height,
1436 True);
1438 #endif
1439 wwin->flags.skip_next_animation = 0;
1440 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1441 XMapWindow(dpy, wwin->client_win);
1442 XMapWindow(dpy, wwin->frame->core->window);
1443 wClientSetState(wwin, NormalState, None);
1444 wwin->flags.mapped=1;
1445 wRaiseFrame(wwin->frame->core);
1447 if (wwin->flags.inspector_open) {
1448 wUnhideInspectorForWindow(wwin);
1451 WMPostNotificationName(WMNChangedState, wwin, "hide");
1455 void
1456 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1458 WScreen *scr;
1459 WWindow *wlist, *next;
1460 WWindow *focused=NULL;
1461 int animate;
1463 if (!wapp)
1464 return;
1466 scr = wapp->main_window_desc->screen_ptr;
1467 wlist = scr->focused_window;
1468 if (!wlist)
1469 return;
1471 /* goto beginning of list */
1472 while (wlist->prev)
1473 wlist = wlist->prev;
1475 animate = !wapp->flags.skip_next_animation;
1477 while (wlist) {
1478 next = wlist->next;
1480 if (wlist->main_window == wapp->main_window) {
1481 if (wlist->flags.focused)
1482 focused = wlist;
1483 else if (!focused || !focused->flags.focused)
1484 focused = wlist;
1486 if (wlist->flags.miniaturized) {
1487 if (bringToCurrentWS || wPreferences.sticky_icons ||
1488 wlist->frame->workspace == scr->current_workspace) {
1489 if (wlist->icon && !wlist->icon->mapped) {
1490 int x, y;
1492 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1493 if (wlist->icon_x!=x || wlist->icon_y!=y) {
1494 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1496 wlist->icon_x = x;
1497 wlist->icon_y = y;
1498 XMapWindow(dpy, wlist->icon->core->window);
1499 wlist->icon->mapped = 1;
1501 wRaiseFrame(wlist->icon->core);
1503 if (bringToCurrentWS)
1504 wWindowChangeWorkspace(wlist, scr->current_workspace);
1505 wlist->flags.hidden = 0;
1506 if (miniwindows &&
1507 wlist->frame->workspace == scr->current_workspace) {
1508 wDeiconifyWindow(wlist);
1510 WMPostNotificationName(WMNChangedState, wlist, "hide");
1511 } else if (wlist->flags.shaded) {
1512 if (bringToCurrentWS)
1513 wWindowChangeWorkspace(wlist, scr->current_workspace);
1514 wlist->flags.hidden = 0;
1515 if (wlist->frame->workspace == scr->current_workspace) {
1516 XMapWindow(dpy, wlist->frame->core->window);
1517 if (miniwindows) {
1518 wUnshadeWindow(wlist);
1519 wRaiseFrame(wlist->frame->core);
1522 WMPostNotificationName(WMNChangedState, wlist, "hide");
1523 } else if (wlist->flags.hidden) {
1524 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1525 wapp->app_icon->y_pos, wlist, animate,
1526 bringToCurrentWS);
1527 animate = False;
1528 } else {
1529 if (bringToCurrentWS
1530 && wlist->frame->workspace != scr->current_workspace) {
1531 wWindowChangeWorkspace(wlist, scr->current_workspace);
1533 wRaiseFrame(wlist->frame->core);
1536 wlist = next;
1539 wapp->flags.skip_next_animation = 0;
1540 wapp->flags.hidden = 0;
1542 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1543 wRaiseFrame(wapp->last_focused->frame->core);
1544 wSetFocusTo(scr, wapp->last_focused);
1545 } else if (focused) {
1546 wSetFocusTo(scr, focused);
1548 wapp->last_focused = NULL;
1549 if (wPreferences.auto_arrange_icons) {
1550 wArrangeIcons(scr, True);
1552 #ifdef HIDDENDOT
1553 wAppIconPaint(wapp->app_icon);
1554 #endif
1558 void
1559 wShowAllWindows(WScreen *scr)
1561 WWindow *wwin, *old_foc;
1562 WApplication *wapp;
1564 old_foc = wwin = scr->focused_window;
1565 while (wwin) {
1566 if (!wwin->flags.internal_window &&
1567 (scr->current_workspace == wwin->frame->workspace
1568 || IS_OMNIPRESENT(wwin))) {
1569 if (wwin->flags.miniaturized) {
1570 wwin->flags.skip_next_animation = 1;
1571 wDeiconifyWindow(wwin);
1572 } else if (wwin->flags.hidden) {
1573 wapp = wApplicationOf(wwin->main_window);
1574 if (wapp) {
1575 wUnhideApplication(wapp, False, False);
1576 } else {
1577 wwin->flags.skip_next_animation = 1;
1578 wDeiconifyWindow(wwin);
1582 wwin = wwin->prev;
1584 wSetFocusTo(scr, old_foc);
1585 /*wRaiseFrame(old_foc->frame->core);*/
1589 void
1590 wRefreshDesktop(WScreen *scr)
1592 Window win;
1593 XSetWindowAttributes attr;
1595 attr.backing_store = NotUseful;
1596 attr.save_under = False;
1597 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1598 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1599 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1600 &attr);
1601 XMapRaised(dpy, win);
1602 XDestroyWindow(dpy, win);
1603 XFlush(dpy);
1607 void
1608 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1610 WWindow *wwin;
1611 WAppIcon *aicon;
1613 int head;
1614 const int heads = wXineramaHeads(scr);
1616 struct HeadVars {
1617 int pf; /* primary axis */
1618 int sf; /* secondary axis */
1619 int fullW;
1620 int fullH;
1621 int pi, si;
1622 int sx1, sx2, sy1, sy2; /* screen boundary */
1623 int sw, sh;
1624 int xo, yo;
1625 int xs, ys;
1626 } *vars;
1628 int isize = wPreferences.icon_size;
1630 vars = (struct HeadVars*)wmalloc(sizeof(struct HeadVars)*heads);
1632 for (head = 0; head < heads; ++head) {
1633 #if 0
1634 WMRect rect = wGetRectForHead(scr, head);
1635 #else
1636 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1637 WMRect rect = wmkrect(area.x1, area.y1, area.x2-area.x1, area.y2-area.y1);
1638 #endif
1640 vars[head].pi = vars[head].si = 0;
1641 vars[head].sx1 = rect.pos.x;
1642 vars[head].sy1 = rect.pos.y;
1643 vars[head].sw = rect.size.width;
1644 vars[head].sh = rect.size.height;
1645 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1646 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1648 #if 0
1649 if (scr->dock) {
1650 if (scr->dock->on_right_side)
1651 vars[head].sx2 -= isize + DOCK_EXTRA_SPACE;
1652 else
1653 vars[head].sx1 += isize + DOCK_EXTRA_SPACE;
1655 #endif
1657 vars[head].sw = isize * (vars[head].sw/isize);
1658 vars[head].sh = isize * (vars[head].sh/isize);
1659 vars[head].fullW = (vars[head].sx2-vars[head].sx1)/isize;
1660 vars[head].fullH = (vars[head].sy2-vars[head].sy1)/isize;
1662 /* icon yard boundaries */
1663 if (wPreferences.icon_yard & IY_VERT) {
1664 vars[head].pf = vars[head].fullH;
1665 vars[head].sf = vars[head].fullW;
1666 } else {
1667 vars[head].pf = vars[head].fullW;
1668 vars[head].sf = vars[head].fullH;
1670 if (wPreferences.icon_yard & IY_RIGHT) {
1671 vars[head].xo = vars[head].sx2 - isize;
1672 vars[head].xs = -1;
1673 } else {
1674 vars[head].xo = vars[head].sx1;
1675 vars[head].xs = 1;
1677 if (wPreferences.icon_yard & IY_TOP) {
1678 vars[head].yo = vars[head].sy1;
1679 vars[head].ys = 1;
1680 } else {
1681 vars[head].yo = vars[head].sy2 - isize;
1682 vars[head].ys = -1;
1686 #define X ((wPreferences.icon_yard & IY_VERT) \
1687 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1688 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1690 #define Y ((wPreferences.icon_yard & IY_VERT) \
1691 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1692 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1695 /* arrange application icons */
1696 aicon = scr->app_icon_list;
1697 /* reverse them to avoid unnecessarily sliding of icons */
1698 while (aicon && aicon->next)
1699 aicon = aicon->next;
1701 while (aicon) {
1702 if (!aicon->docked) {
1703 /* CHECK: can icon be NULL here ? */
1704 /* The intention here is to place the AppIcon on the head that
1705 * contains most of the applications _main_ window. */
1706 head = wGetHeadForWindow(aicon->icon->owner);
1708 if (aicon->x_pos != X || aicon->y_pos != Y) {
1709 #ifdef ANIMATIONS
1710 if (!wPreferences.no_animations) {
1711 SlideWindow(aicon->icon->core->window,
1712 aicon->x_pos, aicon->y_pos, X, Y);
1714 #endif /* ANIMATIONS */
1716 wAppIconMove(aicon, X, Y);
1717 vars[head].pi++;
1718 if (vars[head].pi >= vars[head].pf) {
1719 vars[head].pi = 0;
1720 vars[head].si++;
1723 aicon = aicon->prev;
1726 /* arrange miniwindows */
1727 wwin = scr->focused_window;
1728 /* reverse them to avoid unnecessarily shuffling */
1729 while (wwin && wwin->prev)
1730 wwin = wwin->prev;
1732 while (wwin) {
1733 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1734 (wwin->frame->workspace==scr->current_workspace ||
1735 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1737 head = wGetHeadForWindow(wwin);
1739 if (arrangeAll || !wwin->flags.icon_moved) {
1740 if (wwin->icon_x != X || wwin->icon_y != Y) {
1741 #ifdef ANIMATIONS
1742 if (wPreferences.no_animations) {
1743 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1744 } else {
1745 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1746 wwin->icon_y, X, Y);
1748 #else
1749 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1750 #endif /* ANIMATIONS */
1752 wwin->icon_x = X;
1753 wwin->icon_y = Y;
1755 vars[head].pi++;
1756 if (vars[head].pi >= vars[head].pf) {
1757 vars[head].pi = 0;
1758 vars[head].si++;
1762 if (arrangeAll) {
1763 wwin->flags.icon_moved = 0;
1765 /* we reversed the order, so we use next */
1766 wwin = wwin->next;
1769 wfree(vars);
1772 #if 0
1773 void
1774 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1776 WWindow *wwin;
1777 WAppIcon *aicon;
1778 int pf; /* primary axis */
1779 int sf; /* secondary axis */
1780 int fullW;
1781 int fullH;
1782 int pi, si;
1783 int sx1, sx2, sy1, sy2; /* screen boundary */
1784 int sw, sh;
1785 int xo, yo;
1786 int xs, ys;
1787 int isize = wPreferences.icon_size;
1790 * Find out screen boundaries.
1794 * Allows each head to have miniwindows
1796 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1798 sx1 = rect.pos.x;
1799 sy1 = rect.pos.y;
1800 sw = rect.size.width;
1801 sh = rect.size.height;
1802 sx2 = sx1 + sw;
1803 sy2 = sy1 + sh;
1804 if (scr->dock) {
1805 if (scr->dock->on_right_side)
1806 sx2 -= isize + DOCK_EXTRA_SPACE;
1807 else
1808 sx1 += isize + DOCK_EXTRA_SPACE;
1811 #if 0
1812 sw = isize * (scr->scr_width/isize);
1813 sh = isize * (scr->scr_height/isize);
1814 #else
1815 sw = isize * (sw/isize);
1816 sh = isize * (sh/isize);
1817 #endif
1818 fullW = (sx2-sx1)/isize;
1819 fullH = (sy2-sy1)/isize;
1821 /* icon yard boundaries */
1822 if (wPreferences.icon_yard & IY_VERT) {
1823 pf = fullH;
1824 sf = fullW;
1825 } else {
1826 pf = fullW;
1827 sf = fullH;
1829 if (wPreferences.icon_yard & IY_RIGHT) {
1830 xo = sx2 - isize;
1831 xs = -1;
1832 } else {
1833 xo = sx1;
1834 xs = 1;
1836 if (wPreferences.icon_yard & IY_TOP) {
1837 yo = sy1;
1838 ys = 1;
1839 } else {
1840 yo = sy2 - isize;
1841 ys = -1;
1844 /* arrange icons putting the most recently focused window
1845 * as the last icon */
1846 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1847 : xo + xs*(pi*isize))
1848 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1849 : yo + ys*(si*isize))
1851 /* arrange application icons */
1852 aicon = scr->app_icon_list;
1853 /* reverse them to avoid unnecessarily sliding of icons */
1854 while (aicon && aicon->next)
1855 aicon = aicon->next;
1857 pi = 0;
1858 si = 0;
1859 while (aicon) {
1860 if (!aicon->docked) {
1861 if (aicon->x_pos != X || aicon->y_pos != Y) {
1862 #ifdef ANIMATIONS
1863 if (!wPreferences.no_animations) {
1864 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1865 X, Y);
1867 #endif /* ANIMATIONS */
1869 wAppIconMove(aicon, X, Y);
1870 pi++;
1872 /* we reversed the order so we use prev */
1873 aicon = aicon->prev;
1874 if (pi >= pf) {
1875 pi=0;
1876 si++;
1880 /* arrange miniwindows */
1882 wwin = scr->focused_window;
1883 /* reverse them to avoid unnecessarily shuffling */
1884 while (wwin && wwin->prev)
1885 wwin = wwin->prev;
1887 while (wwin) {
1888 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1889 (wwin->frame->workspace==scr->current_workspace ||
1890 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1892 if (arrangeAll || !wwin->flags.icon_moved) {
1893 if (wwin->icon_x != X || wwin->icon_y != Y) {
1894 #ifdef ANIMATIONS
1895 if (wPreferences.no_animations) {
1896 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1897 } else {
1898 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1899 wwin->icon_y, X, Y);
1901 #else
1902 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1903 #endif /* ANIMATIONS */
1905 wwin->icon_x = X;
1906 wwin->icon_y = Y;
1907 pi++;
1910 if (arrangeAll) {
1911 wwin->flags.icon_moved = 0;
1913 /* we reversed the order, so we use next */
1914 wwin = wwin->next;
1915 if (pi >= pf) {
1916 pi=0;
1917 si++;
1921 #endif
1923 void
1924 wSelectWindow(WWindow *wwin, Bool flag)
1926 WScreen *scr = wwin->screen_ptr;
1928 if (flag) {
1929 wwin->flags.selected = 1;
1930 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1932 if (!HAS_BORDER(wwin)) {
1933 XSetWindowBorderWidth(dpy, wwin->frame->core->window,
1934 FRAME_BORDER_WIDTH);
1937 if (!scr->selected_windows)
1938 scr->selected_windows = WMCreateArray(4);
1939 WMAddToArray(scr->selected_windows, wwin);
1940 } else {
1941 wwin->flags.selected = 0;
1942 XSetWindowBorder(dpy, wwin->frame->core->window,
1943 scr->frame_border_pixel);
1945 if (!HAS_BORDER(wwin)) {
1946 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1949 if (scr->selected_windows) {
1950 WMRemoveFromArray(scr->selected_windows, wwin);
1956 void
1957 wMakeWindowVisible(WWindow *wwin)
1959 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1960 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1962 if (wwin->flags.shaded) {
1963 wUnshadeWindow(wwin);
1965 if (wwin->flags.hidden) {
1966 WApplication *app;
1968 app = wApplicationOf(wwin->main_window);
1969 if (app) {
1970 /* trick to get focus to this window */
1971 app->last_focused = wwin;
1972 wUnhideApplication(app, False, False);
1975 if (wwin->flags.miniaturized) {
1976 wDeiconifyWindow(wwin);
1977 } else {
1978 if (!WFLAGP(wwin, no_focusable))
1979 wSetFocusTo(wwin->screen_ptr, wwin);
1980 wRaiseFrame(wwin->frame->core);