more fixes for missing linking flags in some cases
[wmaker-crm.git] / src / actions.c
blob9298bd20d210dca058a7e3414a09b37abef3ad16
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_x, new_y;
369 unsigned int new_width, new_height;
370 int changed_h, changed_v, shrink_h, shrink_v;
371 WArea usableArea, totalArea;
373 if (!IS_RESIZABLE(wwin))
374 return;
376 totalArea.x1 = 0;
377 totalArea.y1 = 0;
378 totalArea.x2 = wwin->screen_ptr->scr_width;
379 totalArea.y2 = wwin->screen_ptr->scr_height;
380 usableArea = totalArea;
382 if (!(directions & MAX_IGNORE_XINERAMA)) {
383 WScreen *scr = wwin->screen_ptr;
384 int head;
386 if (directions & MAX_KEYBOARD)
387 head = wGetHeadForWindow(wwin);
388 else
389 head = wGetHeadForPointerLocation(scr);
391 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
394 if (WFLAGP(wwin, full_maximize)) {
395 usableArea = totalArea;
398 if (wwin->flags.shaded) {
399 wwin->flags.skip_next_animation = 1;
400 wUnshadeWindow(wwin);
402 /* Only save directions, not kbd or xinerama hints */
403 directions &= (MAX_HORIZONTAL|MAX_VERTICAL);
405 changed_h = ((wwin->flags.maximized ^ directions) & MAX_HORIZONTAL);
406 changed_v = ((wwin->flags.maximized ^ directions) & MAX_VERTICAL);
407 shrink_h = (changed_h && (directions & MAX_HORIZONTAL)==0);
408 shrink_v = (changed_v && (directions & MAX_VERTICAL)==0);
410 if (wwin->flags.maximized) {
411 /* if already maximized in some direction, we only update the
412 * appropriate old x, old y coordinates. This is necessary to
413 * allow succesive maximizations in different directions without
414 * the need to first do an un-maximize (to avoid flicker).
416 if (!(wwin->flags.maximized & MAX_HORIZONTAL)) {
417 wwin->old_geometry.x = wwin->frame_x;
419 if (!(wwin->flags.maximized & MAX_VERTICAL)) {
420 wwin->old_geometry.y = wwin->frame_y;
422 } else {
423 wwin->old_geometry.width = wwin->client.width;
424 wwin->old_geometry.height = wwin->client.height;
425 wwin->old_geometry.x = wwin->frame_x;
426 wwin->old_geometry.y = wwin->frame_y;
428 wwin->flags.maximized = directions;
430 if (directions & MAX_HORIZONTAL) {
431 new_width = (usableArea.x2-usableArea.x1)-FRAME_BORDER_WIDTH*2;
432 new_x = usableArea.x1;
433 } else if (shrink_h) {
434 new_x = wwin->old_geometry.x;
435 new_width = wwin->old_geometry.width;
436 } else {
437 new_x = wwin->frame_x;
438 new_width = wwin->frame->core->width;
441 if (directions & MAX_VERTICAL) {
442 new_height = (usableArea.y2-usableArea.y1)-FRAME_BORDER_WIDTH*2;
443 new_y = usableArea.y1;
444 if (WFLAGP(wwin, full_maximize)) {
445 new_y -= wwin->frame->top_width;
446 new_height += wwin->frame->bottom_width - 1;
448 } else if (shrink_v) {
449 new_y = wwin->old_geometry.y;
450 new_height = wwin->old_geometry.height;
451 } else {
452 new_y = wwin->frame_y;
453 new_height = wwin->frame->core->height;
456 if (!WFLAGP(wwin, full_maximize)) {
457 new_height -= wwin->frame->top_width+wwin->frame->bottom_width;
460 wWindowConstrainSize(wwin, &new_width, &new_height);
462 wWindowCropSize(wwin, usableArea.x2-usableArea.x1,
463 usableArea.y2-usableArea.y1,
464 &new_width, &new_height);
466 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
469 WMPostNotificationName(WMNChangedState, wwin, "maximize");
471 wSoundPlay(WSOUND_MAXIMIZE);
475 void
476 wUnmaximizeWindow(WWindow *wwin)
478 int x, y, w, h;
480 if (!wwin->flags.maximized)
481 return;
483 if (wwin->flags.shaded) {
484 wwin->flags.skip_next_animation = 1;
485 wUnshadeWindow(wwin);
487 x = ((wwin->flags.maximized & MAX_HORIZONTAL) && wwin->old_geometry.x) ?
488 wwin->old_geometry.x : wwin->frame_x;
489 y = ((wwin->flags.maximized & MAX_VERTICAL) && wwin->old_geometry.y) ?
490 wwin->old_geometry.y : wwin->frame_y;
491 w = wwin->old_geometry.width ?
492 wwin->old_geometry.width : wwin->client.width;
493 h = wwin->old_geometry.height ?
494 wwin->old_geometry.height : wwin->client.height;
496 wwin->flags.maximized = 0;
497 wWindowConfigure(wwin, x, y, w, h);
499 WMPostNotificationName(WMNChangedState, wwin, "maximize");
501 wSoundPlay(WSOUND_UNMAXIMIZE);
505 void
506 wFullscreenWindow(WWindow *wwin)
508 int head;
509 WMRect rect;
511 if (wwin->flags.fullscreen)
512 return;
514 wwin->flags.fullscreen = True;
516 wWindowConfigureBorders(wwin);
518 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
520 wwin->bfs_geometry.x = wwin->frame_x;
521 wwin->bfs_geometry.y = wwin->frame_y;
522 wwin->bfs_geometry.width = wwin->frame->core->width;
523 wwin->bfs_geometry.height = wwin->frame->core->height;
525 head = wGetHeadForWindow(wwin);
526 rect = wGetRectForHead(wwin->screen_ptr, head);
527 wWindowConfigure(wwin, rect.pos.x, rect.pos.y,
528 rect.size.width, rect.size.height);
530 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
534 void
535 wUnfullscreenWindow(WWindow *wwin)
537 if (!wwin->flags.fullscreen)
538 return;
540 wwin->flags.fullscreen = False;
542 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
543 if (WFLAGP(wwin, sunken)) {
544 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
545 } else if (WFLAGP(wwin, floating)) {
546 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
547 } else {
548 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
552 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
553 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
555 wWindowConfigureBorders(wwin);
557 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
558 wFrameWindowPaint(wwin->frame);
561 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
565 #ifdef ANIMATIONS
566 static void
567 animateResizeFlip(WScreen *scr, int x, int y, int w, int h,
568 int fx, int fy, int fw, int fh, int steps)
570 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
571 float cx, cy, cw, ch;
572 float xstep, ystep, wstep, hstep;
573 XPoint points[5];
574 float dx, dch, midy;
575 float angle, final_angle, delta;
577 xstep = (float)(fx-x)/steps;
578 ystep = (float)(fy-y)/steps;
579 wstep = (float)(fw-w)/steps;
580 hstep = (float)(fh-h)/steps;
582 cx = (float)x;
583 cy = (float)y;
584 cw = (float)w;
585 ch = (float)h;
587 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_F;
588 delta = (float)(final_angle/FRAMES);
589 for (angle=0;; angle+=delta) {
590 if (angle > final_angle)
591 angle = final_angle;
593 dx = (cw/10) - ((cw/5) * sin(angle));
594 dch = (ch/2) * cos(angle);
595 midy = cy + (ch/2);
597 points[0].x = cx + dx; points[0].y = midy - dch;
598 points[1].x = cx + cw - dx; points[1].y = points[0].y;
599 points[2].x = cx + cw + dx; points[2].y = midy + dch;
600 points[3].x = cx - dx; points[3].y = points[2].y;
601 points[4].x = points[0].x; points[4].y = points[0].y;
603 XGrabServer(dpy);
604 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
605 XFlush(dpy);
606 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
607 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
608 #else
609 wusleep(10);
610 #endif
612 XDrawLines(dpy,scr->root_win,scr->frame_gc,points, 5, CoordModeOrigin);
613 XUngrabServer(dpy);
614 cx+=xstep;
615 cy+=ystep;
616 cw+=wstep;
617 ch+=hstep;
618 if (angle >= final_angle)
619 break;
622 XFlush(dpy);
624 #undef FRAMES
627 static void
628 animateResizeTwist(WScreen *scr, int x, int y, int w, int h,
629 int fx, int fy, int fw, int fh, int steps)
631 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
632 float cx, cy, cw, ch;
633 float xstep, ystep, wstep, hstep;
634 XPoint points[5];
635 float angle, final_angle, a, d, delta;
637 x += w/2;
638 y += h/2;
639 fx += fw/2;
640 fy += fh/2;
642 xstep = (float)(fx-x)/steps;
643 ystep = (float)(fy-y)/steps;
644 wstep = (float)(fw-w)/steps;
645 hstep = (float)(fh-h)/steps;
647 cx = (float)x;
648 cy = (float)y;
649 cw = (float)w;
650 ch = (float)h;
652 final_angle = 2*WM_PI*MINIATURIZE_ANIMATION_TWIST_T;
653 delta = (float)(final_angle/FRAMES);
654 for (angle=0;; angle+=delta) {
655 if (angle > final_angle)
656 angle = final_angle;
658 a = atan(ch/cw);
659 d = sqrt((cw/2)*(cw/2)+(ch/2)*(ch/2));
661 points[0].x = cx+cos(angle-a)*d;
662 points[0].y = cy+sin(angle-a)*d;
663 points[1].x = cx+cos(angle+a)*d;
664 points[1].y = cy+sin(angle+a)*d;
665 points[2].x = cx+cos(angle-a+WM_PI)*d;
666 points[2].y = cy+sin(angle-a+WM_PI)*d;
667 points[3].x = cx+cos(angle+a+WM_PI)*d;
668 points[3].y = cy+sin(angle+a+WM_PI)*d;
669 points[4].x = cx+cos(angle-a)*d;
670 points[4].y = cy+sin(angle-a)*d;
671 XGrabServer(dpy);
672 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
673 XFlush(dpy);
674 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
675 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
676 #else
677 wusleep(10);
678 #endif
680 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
681 XUngrabServer(dpy);
682 cx+=xstep;
683 cy+=ystep;
684 cw+=wstep;
685 ch+=hstep;
686 if (angle >= final_angle)
687 break;
690 XFlush(dpy);
692 #undef FRAMES
695 static void
696 animateResizeZoom(WScreen *scr, int x, int y, int w, int h,
697 int fx, int fy, int fw, int fh, int steps)
699 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
700 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
701 float xstep, ystep, wstep, hstep;
702 int i, j;
704 xstep = (float)(fx-x)/steps;
705 ystep = (float)(fy-y)/steps;
706 wstep = (float)(fw-w)/steps;
707 hstep = (float)(fh-h)/steps;
709 for (j=0; j<FRAMES; j++) {
710 cx[j] = (float)x;
711 cy[j] = (float)y;
712 cw[j] = (float)w;
713 ch[j] = (float)h;
715 XGrabServer(dpy);
716 for (i=0; i<steps; i++) {
717 for (j=0; j<FRAMES; j++) {
718 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
719 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
721 XFlush(dpy);
722 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
723 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
724 #else
725 wusleep(10);
726 #endif
727 for (j=0; j<FRAMES; j++) {
728 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
729 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
730 if (j<FRAMES-1) {
731 cx[j]=cx[j+1];
732 cy[j]=cy[j+1];
733 cw[j]=cw[j+1];
734 ch[j]=ch[j+1];
735 } else {
736 cx[j]+=xstep;
737 cy[j]+=ystep;
738 cw[j]+=wstep;
739 ch[j]+=hstep;
744 for (j=0; j<FRAMES; j++) {
745 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
746 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
748 XFlush(dpy);
749 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
750 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
751 #else
752 wusleep(10);
753 #endif
754 for (j=0; j<FRAMES; j++) {
755 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
756 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
759 XUngrabServer(dpy);
761 #undef FRAMES
764 void
765 animateResize(WScreen *scr, int x, int y, int w, int h,
766 int fx, int fy, int fw, int fh, int hiding)
768 int style = wPreferences.iconification_style; /* Catch the value */
769 int steps, k;
771 if (style == WIS_NONE)
772 return;
774 if (style == WIS_RANDOM) {
775 style = rand()%3;
778 k = (hiding ? 2 : 3);
780 switch(style) {
781 case WIS_TWIST:
782 steps = (MINIATURIZE_ANIMATION_STEPS_T * k)/3;
783 if (steps>0)
784 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
785 break;
786 case WIS_FLIP:
787 steps = (MINIATURIZE_ANIMATION_STEPS_F * k)/3;
788 if (steps>0)
789 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
790 break;
791 case WIS_ZOOM:
792 default:
793 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k)/3;
794 if (steps>0)
795 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
796 break;
799 #endif /* ANIMATIONS */
802 static void
803 flushExpose()
805 XEvent tmpev;
807 while (XCheckTypedEvent(dpy, Expose, &tmpev))
808 WMHandleEvent(&tmpev);
809 XSync(dpy, 0);
812 static void
813 unmapTransientsFor(WWindow *wwin)
815 WWindow *tmp;
818 tmp = wwin->screen_ptr->focused_window;
819 while (tmp) {
820 /* unmap the transients for this transient */
821 if (tmp!=wwin && tmp->transient_for == wwin->client_win
822 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup
823 || tmp->flags.shaded)) {
824 unmapTransientsFor(tmp);
825 tmp->flags.miniaturized = 1;
826 if (!tmp->flags.shaded) {
827 wWindowUnmap(tmp);
828 } else {
829 XUnmapWindow(dpy, tmp->frame->core->window);
832 if (!tmp->flags.shaded)
834 wClientSetState(tmp, IconicState, None);
836 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
838 tmp = tmp->prev;
843 static void
844 mapTransientsFor(WWindow *wwin)
846 WWindow *tmp;
848 tmp = wwin->screen_ptr->focused_window;
849 while (tmp) {
850 /* recursively map the transients for this transient */
851 if (tmp!=wwin && tmp->transient_for == wwin->client_win
852 && /*!tmp->flags.mapped*/ tmp->flags.miniaturized
853 && tmp->icon==NULL) {
854 mapTransientsFor(tmp);
855 tmp->flags.miniaturized = 0;
856 if (!tmp->flags.shaded) {
857 wWindowMap(tmp);
858 } else {
859 XMapWindow(dpy, tmp->frame->core->window);
861 tmp->flags.semi_focused = 0;
863 if (!tmp->flags.shaded)
865 wClientSetState(tmp, NormalState, None);
867 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
869 tmp = tmp->prev;
873 #if 0
874 static void
875 setupIconGrabs(WIcon *icon)
877 /* setup passive grabs on the icon */
878 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
879 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
880 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
881 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
882 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
883 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
884 XSync(dpy, 0);
886 #endif
888 static WWindow*
889 recursiveTransientFor(WWindow *wwin)
891 int i;
893 if (!wwin)
894 return None;
896 /* hackish way to detect transient_for cycle */
897 i = wwin->screen_ptr->window_count+1;
899 while (wwin && wwin->transient_for != None && i>0) {
900 wwin = wWindowFor(wwin->transient_for);
901 i--;
903 if (i==0 && wwin) {
904 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.",
905 wwin->frame->title);
906 return NULL;
909 return wwin;
912 #if 0
913 static void
914 removeIconGrabs(WIcon *icon)
916 /* remove passive grabs on the icon */
917 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
918 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
919 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
920 XSync(dpy, 0);
922 #endif
925 void
926 wIconifyWindow(WWindow *wwin)
928 XWindowAttributes attribs;
929 int present;
932 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
933 /* the window doesn't exist anymore */
934 return;
937 if (wwin->flags.miniaturized) {
938 return;
941 if (wwin->transient_for!=None &&
942 wwin->transient_for!=wwin->screen_ptr->root_win) {
943 WWindow *owner = wWindowFor(wwin->transient_for);
945 if (owner && owner->flags.miniaturized)
946 return;
949 present = wwin->frame->workspace==wwin->screen_ptr->current_workspace;
951 /* if the window is in another workspace, simplify process */
952 if (present) {
953 /* icon creation may take a while */
954 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
955 ButtonMotionMask|ButtonReleaseMask, GrabModeAsync,
956 GrabModeAsync, None, None, CurrentTime);
959 if (!wPreferences.disable_miniwindows
960 #ifdef NETWM_HINTS
961 && !wwin->flags.net_handle_icon
962 #endif
964 if (!wwin->flags.icon_moved) {
965 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
967 wwin->icon = wIconCreate(wwin);
969 wwin->icon->mapped = 1;
972 wwin->flags.miniaturized = 1;
973 wwin->flags.mapped = 0;
975 /* unmap transients */
977 unmapTransientsFor(wwin);
979 if (present) {
980 wSoundPlay(WSOUND_ICONIFY);
982 XUngrabPointer(dpy, CurrentTime);
983 wWindowUnmap(wwin);
984 /* let all Expose events arrive so that we can repaint
985 * something before the animation starts (and the server is grabbed) */
986 XSync(dpy, 0);
988 if (wPreferences.disable_miniwindows
989 #ifdef NETWM_HINTS
990 || wwin->flags.net_handle_icon
991 #endif
993 wClientSetState(wwin, IconicState, None);
994 else
995 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
997 flushExpose();
998 #ifdef ANIMATIONS
999 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
1000 && !wPreferences.no_animations) {
1001 int ix, iy, iw, ih;
1003 if (!wPreferences.disable_miniwindows
1004 #ifdef NETWM_HINTS
1005 && !wwin->flags.net_handle_icon
1006 #endif
1008 ix = wwin->icon_x;
1009 iy = wwin->icon_y;
1010 iw = wwin->icon->core->width;
1011 ih = wwin->icon->core->height;
1012 } else {
1013 #ifdef NETWM_HINTS
1014 if (wwin->flags.net_handle_icon) {
1015 ix = wwin->icon_x;
1016 iy = wwin->icon_y;
1017 iw = wwin->icon_w;
1018 ih = wwin->icon_h;
1019 } else
1020 #endif
1022 ix = 0;
1023 iy = 0;
1024 iw = wwin->screen_ptr->scr_width;
1025 ih = wwin->screen_ptr->scr_height;
1028 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1029 wwin->frame->core->width, wwin->frame->core->height,
1030 ix, iy, iw, ih, False);
1032 #endif
1035 wwin->flags.skip_next_animation = 0;
1037 if (!wPreferences.disable_miniwindows
1038 #ifdef NETWM_HINTS
1039 && !wwin->flags.net_handle_icon
1040 #endif
1043 if (wwin->screen_ptr->current_workspace==wwin->frame->workspace ||
1044 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1046 XMapWindow(dpy, wwin->icon->core->window);
1048 AddToStackList(wwin->icon->core);
1050 wLowerFrame(wwin->icon->core);
1053 if (present) {
1054 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1057 * It doesn't seem to be working and causes button event hangup
1058 * when deiconifying a transient window.
1059 setupIconGrabs(wwin->icon);
1061 if ((wwin->flags.focused
1062 || (owner && wwin->client_win == owner->client_win))
1063 && wPreferences.focus_mode==WKF_CLICK) {
1064 WWindow *tmp;
1066 tmp = wwin->prev;
1067 while (tmp) {
1068 if (!WFLAGP(tmp, no_focusable)
1069 && !(tmp->flags.hidden||tmp->flags.miniaturized)
1070 && (wwin->frame->workspace == tmp->frame->workspace))
1071 break;
1072 tmp = tmp->prev;
1074 wSetFocusTo(wwin->screen_ptr, tmp);
1075 } else if (wPreferences.focus_mode!=WKF_CLICK) {
1076 wSetFocusTo(wwin->screen_ptr, NULL);
1079 #ifdef ANIMATIONS
1080 if (!wwin->screen_ptr->flags.startup) {
1081 /* Catch up with events not processed while animation was running */
1082 Window clientwin = wwin->client_win;
1084 ProcessPendingEvents();
1086 /* the window can disappear while ProcessPendingEvents() runs */
1087 if (!wWindowFor(clientwin)) {
1088 return;
1091 #endif
1094 /* maybe we want to do this regardless of net_handle_icon
1095 * it seems to me we might break behaviour this way.
1097 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1098 #ifdef NETWM_HINTS
1099 && !wwin->flags.net_handle_icon
1100 #endif
1102 wIconSelect(wwin->icon);
1104 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1110 void
1111 wDeiconifyWindow(WWindow *wwin)
1113 #ifdef NETWM_HINTS
1114 /* we're hiding for show_desktop */
1115 int netwm_hidden = wwin->flags.net_show_desktop &&
1116 wwin->frame->workspace!=wwin->screen_ptr->current_workspace;
1117 #else
1118 int netwm_hidden = False;
1119 #endif
1121 if (!netwm_hidden)
1122 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1124 if (!wwin->flags.miniaturized)
1125 return;
1127 if (wwin->transient_for != None
1128 && wwin->transient_for != wwin->screen_ptr->root_win) {
1129 WWindow *owner = recursiveTransientFor(wwin);
1131 if (owner && owner->flags.miniaturized) {
1132 wDeiconifyWindow(owner);
1133 wSetFocusTo(wwin->screen_ptr, wwin);
1134 wRaiseFrame(wwin->frame->core);
1135 return;
1139 wwin->flags.miniaturized = 0;
1141 if (!netwm_hidden && !wwin->flags.shaded) {
1142 wwin->flags.mapped = 1;
1145 if (!netwm_hidden || wPreferences.sticky_icons) {
1146 /* maybe we want to do this regardless of net_handle_icon
1147 * it seems to me we might break behaviour this way.
1149 if (!wPreferences.disable_miniwindows
1150 #ifdef NETWM_HINTS
1151 && !wwin->flags.net_handle_icon
1152 #endif
1153 && wwin->icon != NULL) {
1154 if (wwin->icon->selected)
1155 wIconSelect(wwin->icon);
1157 XUnmapWindow(dpy, wwin->icon->core->window);
1161 if (!netwm_hidden)
1162 wSoundPlay(WSOUND_DEICONIFY);
1164 /* if the window is in another workspace, do it silently */
1165 if (!netwm_hidden) {
1166 #ifdef ANIMATIONS
1167 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1168 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1169 int ix, iy, iw, ih;
1171 if (!wPreferences.disable_miniwindows
1172 #ifdef NETWM_HINTS
1173 && !wwin->flags.net_handle_icon
1174 #endif
1176 ix = wwin->icon_x;
1177 iy = wwin->icon_y;
1178 iw = wwin->icon->core->width;
1179 ih = wwin->icon->core->height;
1180 } else {
1181 #ifdef NETWM_HINTS
1182 if (wwin->flags.net_handle_icon) {
1183 ix = wwin->icon_x;
1184 iy = wwin->icon_y;
1185 iw = wwin->icon_w;
1186 ih = wwin->icon_h;
1187 } else
1188 #endif
1190 ix = 0;
1191 iy = 0;
1192 iw = wwin->screen_ptr->scr_width;
1193 ih = wwin->screen_ptr->scr_height;
1196 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1197 wwin->frame_x, wwin->frame_y,
1198 wwin->frame->core->width, wwin->frame->core->height,
1199 False);
1201 #endif /* ANIMATIONS */
1202 wwin->flags.skip_next_animation = 0;
1203 XGrabServer(dpy);
1204 if (!wwin->flags.shaded) {
1205 XMapWindow(dpy, wwin->client_win);
1207 XMapWindow(dpy, wwin->frame->core->window);
1208 wRaiseFrame(wwin->frame->core);
1209 if (!wwin->flags.shaded) {
1210 wClientSetState(wwin, NormalState, None);
1212 mapTransientsFor(wwin);
1215 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1216 #ifdef NETWM_HINTS
1217 && !wwin->flags.net_handle_icon
1218 #endif
1220 RemoveFromStackList(wwin->icon->core);
1221 /* removeIconGrabs(wwin->icon);*/
1222 wIconDestroy(wwin->icon);
1223 wwin->icon = NULL;
1226 if (!netwm_hidden) {
1227 XUngrabServer(dpy);
1229 wSetFocusTo(wwin->screen_ptr, wwin);
1231 #ifdef ANIMATIONS
1232 if (!wwin->screen_ptr->flags.startup) {
1233 /* Catch up with events not processed while animation was running */
1234 Window clientwin = wwin->client_win;
1236 ProcessPendingEvents();
1238 /* the window can disappear while ProcessPendingEvents() runs */
1239 if (!wWindowFor(clientwin)) {
1240 return;
1243 #endif
1246 if (wPreferences.auto_arrange_icons) {
1247 wArrangeIcons(wwin->screen_ptr, True);
1250 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1252 /* In case we were shaded and iconified, also unshade */
1253 if (!netwm_hidden)
1254 wUnshadeWindow(wwin);
1259 static void
1260 hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1262 if (wwin->flags.miniaturized) {
1263 if (wwin->icon) {
1264 XUnmapWindow(dpy, wwin->icon->core->window);
1265 wwin->icon->mapped = 0;
1267 wwin->flags.hidden = 1;
1269 WMPostNotificationName(WMNChangedState, wwin, "hide");
1270 return;
1273 if (wwin->flags.inspector_open) {
1274 wHideInspectorForWindow(wwin);
1277 wwin->flags.hidden = 1;
1278 wWindowUnmap(wwin);
1280 wClientSetState(wwin, IconicState, icon->icon_win);
1281 flushExpose();
1282 wSoundPlay(WSOUND_HIDE);
1283 #ifdef ANIMATIONS
1284 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1285 !wwin->flags.skip_next_animation && animate) {
1286 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1287 wwin->frame->core->width, wwin->frame->core->height,
1288 icon_x, icon_y, icon->core->width, icon->core->height,
1289 True);
1291 #endif
1292 wwin->flags.skip_next_animation = 0;
1294 WMPostNotificationName(WMNChangedState, wwin, "hide");
1299 void
1300 wHideOtherApplications(WWindow *awin)
1302 WWindow *wwin;
1303 WApplication *tapp;
1305 if (!awin)
1306 return;
1307 wwin = awin->screen_ptr->focused_window;
1310 while (wwin) {
1311 if (wwin!=awin
1312 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1313 && !(wwin->flags.miniaturized||wwin->flags.hidden)
1314 && !wwin->flags.internal_window
1315 && wGetWindowOfInspectorForWindow(wwin) != awin
1316 && !WFLAGP(wwin, no_hide_others)) {
1318 if (wwin->main_window==None || WFLAGP(wwin, no_appicon)) {
1319 if (!WFLAGP(wwin, no_miniaturizable)) {
1320 wwin->flags.skip_next_animation = 1;
1321 wIconifyWindow(wwin);
1323 } else if (wwin->main_window!=None
1324 && awin->main_window != wwin->main_window) {
1325 tapp = wApplicationOf(wwin->main_window);
1326 if (tapp) {
1327 tapp->flags.skip_next_animation = 1;
1328 wHideApplication(tapp);
1329 } else {
1330 if (!WFLAGP(wwin, no_miniaturizable)) {
1331 wwin->flags.skip_next_animation = 1;
1332 wIconifyWindow(wwin);
1337 wwin = wwin->prev;
1340 wSetFocusTo(awin->screen_ptr, awin);
1346 void
1347 wHideApplication(WApplication *wapp)
1349 WScreen *scr;
1350 WWindow *wlist;
1351 int hadfocus;
1352 int animate;
1354 if (!wapp) {
1355 wwarning("trying to hide a non grouped window");
1356 return;
1358 if (!wapp->main_window_desc) {
1359 wwarning("group leader not found for window group");
1360 return;
1362 scr = wapp->main_window_desc->screen_ptr;
1363 hadfocus = 0;
1364 wlist = scr->focused_window;
1365 if (!wlist)
1366 return;
1368 if (wlist->main_window == wapp->main_window)
1369 wapp->last_focused = wlist;
1370 else
1371 wapp->last_focused = NULL;
1373 animate = !wapp->flags.skip_next_animation;
1375 while (wlist) {
1376 if (wlist->main_window == wapp->main_window) {
1377 if (wlist->flags.focused) {
1378 hadfocus = 1;
1380 if (wapp->app_icon) {
1381 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1382 wapp->app_icon->y_pos, wlist, animate);
1383 animate = False;
1386 wlist = wlist->prev;
1389 wapp->flags.skip_next_animation = 0;
1391 if (hadfocus) {
1392 if (wPreferences.focus_mode==WKF_CLICK) {
1393 wlist = scr->focused_window;
1394 while (wlist) {
1395 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1396 && (wlist->flags.mapped || wlist->flags.shaded))
1397 break;
1398 wlist = wlist->prev;
1400 wSetFocusTo(scr, wlist);
1401 } else {
1402 wSetFocusTo(scr, NULL);
1406 wapp->flags.hidden = 1;
1408 if(wPreferences.auto_arrange_icons) {
1409 wArrangeIcons(scr, True);
1411 #ifdef HIDDENDOT
1412 if (wapp->app_icon)
1413 wAppIconPaint(wapp->app_icon);
1414 #endif
1420 static void
1421 unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate,
1422 int bringToCurrentWS)
1424 if (bringToCurrentWS)
1425 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1427 wwin->flags.hidden=0;
1429 wSoundPlay(WSOUND_UNHIDE);
1430 #ifdef ANIMATIONS
1431 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1432 && animate) {
1433 animateResize(wwin->screen_ptr, icon_x, icon_y,
1434 icon->core->width, icon->core->height,
1435 wwin->frame_x, wwin->frame_y,
1436 wwin->frame->core->width, wwin->frame->core->height,
1437 True);
1439 #endif
1440 wwin->flags.skip_next_animation = 0;
1441 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1442 XMapWindow(dpy, wwin->client_win);
1443 XMapWindow(dpy, wwin->frame->core->window);
1444 wClientSetState(wwin, NormalState, None);
1445 wwin->flags.mapped=1;
1446 wRaiseFrame(wwin->frame->core);
1448 if (wwin->flags.inspector_open) {
1449 wUnhideInspectorForWindow(wwin);
1452 WMPostNotificationName(WMNChangedState, wwin, "hide");
1456 void
1457 wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1459 WScreen *scr;
1460 WWindow *wlist, *next;
1461 WWindow *focused=NULL;
1462 int animate;
1464 if (!wapp)
1465 return;
1467 scr = wapp->main_window_desc->screen_ptr;
1468 wlist = scr->focused_window;
1469 if (!wlist)
1470 return;
1472 /* goto beginning of list */
1473 while (wlist->prev)
1474 wlist = wlist->prev;
1476 animate = !wapp->flags.skip_next_animation;
1478 while (wlist) {
1479 next = wlist->next;
1481 if (wlist->main_window == wapp->main_window) {
1482 if (wlist->flags.focused)
1483 focused = wlist;
1484 else if (!focused || !focused->flags.focused)
1485 focused = wlist;
1487 if (wlist->flags.miniaturized) {
1488 if (bringToCurrentWS || wPreferences.sticky_icons ||
1489 wlist->frame->workspace == scr->current_workspace) {
1490 if (wlist->icon && !wlist->icon->mapped) {
1491 int x, y;
1493 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1494 if (wlist->icon_x!=x || wlist->icon_y!=y) {
1495 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1497 wlist->icon_x = x;
1498 wlist->icon_y = y;
1499 XMapWindow(dpy, wlist->icon->core->window);
1500 wlist->icon->mapped = 1;
1502 wRaiseFrame(wlist->icon->core);
1504 if (bringToCurrentWS)
1505 wWindowChangeWorkspace(wlist, scr->current_workspace);
1506 wlist->flags.hidden = 0;
1507 if (miniwindows &&
1508 wlist->frame->workspace == scr->current_workspace) {
1509 wDeiconifyWindow(wlist);
1511 WMPostNotificationName(WMNChangedState, wlist, "hide");
1512 } else if (wlist->flags.shaded) {
1513 if (bringToCurrentWS)
1514 wWindowChangeWorkspace(wlist, scr->current_workspace);
1515 wlist->flags.hidden = 0;
1516 if (wlist->frame->workspace == scr->current_workspace) {
1517 XMapWindow(dpy, wlist->frame->core->window);
1518 if (miniwindows) {
1519 wUnshadeWindow(wlist);
1520 wRaiseFrame(wlist->frame->core);
1523 WMPostNotificationName(WMNChangedState, wlist, "hide");
1524 } else if (wlist->flags.hidden) {
1525 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1526 wapp->app_icon->y_pos, wlist, animate,
1527 bringToCurrentWS);
1528 animate = False;
1529 } else {
1530 if (bringToCurrentWS
1531 && wlist->frame->workspace != scr->current_workspace) {
1532 wWindowChangeWorkspace(wlist, scr->current_workspace);
1534 wRaiseFrame(wlist->frame->core);
1537 wlist = next;
1540 wapp->flags.skip_next_animation = 0;
1541 wapp->flags.hidden = 0;
1543 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1544 wRaiseFrame(wapp->last_focused->frame->core);
1545 wSetFocusTo(scr, wapp->last_focused);
1546 } else if (focused) {
1547 wSetFocusTo(scr, focused);
1549 wapp->last_focused = NULL;
1550 if (wPreferences.auto_arrange_icons) {
1551 wArrangeIcons(scr, True);
1553 #ifdef HIDDENDOT
1554 wAppIconPaint(wapp->app_icon);
1555 #endif
1559 void
1560 wShowAllWindows(WScreen *scr)
1562 WWindow *wwin, *old_foc;
1563 WApplication *wapp;
1565 old_foc = wwin = scr->focused_window;
1566 while (wwin) {
1567 if (!wwin->flags.internal_window &&
1568 (scr->current_workspace == wwin->frame->workspace
1569 || IS_OMNIPRESENT(wwin))) {
1570 if (wwin->flags.miniaturized) {
1571 wwin->flags.skip_next_animation = 1;
1572 wDeiconifyWindow(wwin);
1573 } else if (wwin->flags.hidden) {
1574 wapp = wApplicationOf(wwin->main_window);
1575 if (wapp) {
1576 wUnhideApplication(wapp, False, False);
1577 } else {
1578 wwin->flags.skip_next_animation = 1;
1579 wDeiconifyWindow(wwin);
1583 wwin = wwin->prev;
1585 wSetFocusTo(scr, old_foc);
1586 /*wRaiseFrame(old_foc->frame->core);*/
1590 void
1591 wRefreshDesktop(WScreen *scr)
1593 Window win;
1594 XSetWindowAttributes attr;
1596 attr.backing_store = NotUseful;
1597 attr.save_under = False;
1598 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1599 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1600 (Visual *)CopyFromParent, CWBackingStore|CWSaveUnder,
1601 &attr);
1602 XMapRaised(dpy, win);
1603 XDestroyWindow(dpy, win);
1604 XFlush(dpy);
1608 void
1609 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1611 WWindow *wwin;
1612 WAppIcon *aicon;
1614 int head;
1615 const int heads = wXineramaHeads(scr);
1617 struct HeadVars {
1618 int pf; /* primary axis */
1619 int sf; /* secondary axis */
1620 int fullW;
1621 int fullH;
1622 int pi, si;
1623 int sx1, sx2, sy1, sy2; /* screen boundary */
1624 int sw, sh;
1625 int xo, yo;
1626 int xs, ys;
1627 } *vars;
1629 int isize = wPreferences.icon_size;
1631 vars = (struct HeadVars*)wmalloc(sizeof(struct HeadVars)*heads);
1633 for (head = 0; head < heads; ++head) {
1634 #if 0
1635 WMRect rect = wGetRectForHead(scr, head);
1636 #else
1637 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1638 WMRect rect = wmkrect(area.x1, area.y1, area.x2-area.x1, area.y2-area.y1);
1639 #endif
1641 vars[head].pi = vars[head].si = 0;
1642 vars[head].sx1 = rect.pos.x;
1643 vars[head].sy1 = rect.pos.y;
1644 vars[head].sw = rect.size.width;
1645 vars[head].sh = rect.size.height;
1646 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1647 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1649 #if 0
1650 if (scr->dock) {
1651 if (scr->dock->on_right_side)
1652 vars[head].sx2 -= isize + DOCK_EXTRA_SPACE;
1653 else
1654 vars[head].sx1 += isize + DOCK_EXTRA_SPACE;
1656 #endif
1658 vars[head].sw = isize * (vars[head].sw/isize);
1659 vars[head].sh = isize * (vars[head].sh/isize);
1660 vars[head].fullW = (vars[head].sx2-vars[head].sx1)/isize;
1661 vars[head].fullH = (vars[head].sy2-vars[head].sy1)/isize;
1663 /* icon yard boundaries */
1664 if (wPreferences.icon_yard & IY_VERT) {
1665 vars[head].pf = vars[head].fullH;
1666 vars[head].sf = vars[head].fullW;
1667 } else {
1668 vars[head].pf = vars[head].fullW;
1669 vars[head].sf = vars[head].fullH;
1671 if (wPreferences.icon_yard & IY_RIGHT) {
1672 vars[head].xo = vars[head].sx2 - isize;
1673 vars[head].xs = -1;
1674 } else {
1675 vars[head].xo = vars[head].sx1;
1676 vars[head].xs = 1;
1678 if (wPreferences.icon_yard & IY_TOP) {
1679 vars[head].yo = vars[head].sy1;
1680 vars[head].ys = 1;
1681 } else {
1682 vars[head].yo = vars[head].sy2 - isize;
1683 vars[head].ys = -1;
1687 #define X ((wPreferences.icon_yard & IY_VERT) \
1688 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1689 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1691 #define Y ((wPreferences.icon_yard & IY_VERT) \
1692 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1693 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1696 /* arrange application icons */
1697 aicon = scr->app_icon_list;
1698 /* reverse them to avoid unnecessarily sliding of icons */
1699 while (aicon && aicon->next)
1700 aicon = aicon->next;
1702 while (aicon) {
1703 if (!aicon->docked) {
1704 /* CHECK: can icon be NULL here ? */
1705 /* The intention here is to place the AppIcon on the head that
1706 * contains most of the applications _main_ window. */
1707 head = wGetHeadForWindow(aicon->icon->owner);
1709 if (aicon->x_pos != X || aicon->y_pos != Y) {
1710 #ifdef ANIMATIONS
1711 if (!wPreferences.no_animations) {
1712 SlideWindow(aicon->icon->core->window,
1713 aicon->x_pos, aicon->y_pos, X, Y);
1715 #endif /* ANIMATIONS */
1717 wAppIconMove(aicon, X, Y);
1718 vars[head].pi++;
1719 if (vars[head].pi >= vars[head].pf) {
1720 vars[head].pi = 0;
1721 vars[head].si++;
1724 aicon = aicon->prev;
1727 /* arrange miniwindows */
1728 wwin = scr->focused_window;
1729 /* reverse them to avoid unnecessarily shuffling */
1730 while (wwin && wwin->prev)
1731 wwin = wwin->prev;
1733 while (wwin) {
1734 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1735 (wwin->frame->workspace==scr->current_workspace ||
1736 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1738 head = wGetHeadForWindow(wwin);
1740 if (arrangeAll || !wwin->flags.icon_moved) {
1741 if (wwin->icon_x != X || wwin->icon_y != Y) {
1742 #ifdef ANIMATIONS
1743 if (wPreferences.no_animations) {
1744 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1745 } else {
1746 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1747 wwin->icon_y, X, Y);
1749 #else
1750 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1751 #endif /* ANIMATIONS */
1753 wwin->icon_x = X;
1754 wwin->icon_y = Y;
1756 vars[head].pi++;
1757 if (vars[head].pi >= vars[head].pf) {
1758 vars[head].pi = 0;
1759 vars[head].si++;
1763 if (arrangeAll) {
1764 wwin->flags.icon_moved = 0;
1766 /* we reversed the order, so we use next */
1767 wwin = wwin->next;
1770 wfree(vars);
1773 #if 0
1774 void
1775 wArrangeIcons(WScreen *scr, Bool arrangeAll)
1777 WWindow *wwin;
1778 WAppIcon *aicon;
1779 int pf; /* primary axis */
1780 int sf; /* secondary axis */
1781 int fullW;
1782 int fullH;
1783 int pi, si;
1784 int sx1, sx2, sy1, sy2; /* screen boundary */
1785 int sw, sh;
1786 int xo, yo;
1787 int xs, ys;
1788 int isize = wPreferences.icon_size;
1791 * Find out screen boundaries.
1795 * Allows each head to have miniwindows
1797 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1799 sx1 = rect.pos.x;
1800 sy1 = rect.pos.y;
1801 sw = rect.size.width;
1802 sh = rect.size.height;
1803 sx2 = sx1 + sw;
1804 sy2 = sy1 + sh;
1805 if (scr->dock) {
1806 if (scr->dock->on_right_side)
1807 sx2 -= isize + DOCK_EXTRA_SPACE;
1808 else
1809 sx1 += isize + DOCK_EXTRA_SPACE;
1812 #if 0
1813 sw = isize * (scr->scr_width/isize);
1814 sh = isize * (scr->scr_height/isize);
1815 #else
1816 sw = isize * (sw/isize);
1817 sh = isize * (sh/isize);
1818 #endif
1819 fullW = (sx2-sx1)/isize;
1820 fullH = (sy2-sy1)/isize;
1822 /* icon yard boundaries */
1823 if (wPreferences.icon_yard & IY_VERT) {
1824 pf = fullH;
1825 sf = fullW;
1826 } else {
1827 pf = fullW;
1828 sf = fullH;
1830 if (wPreferences.icon_yard & IY_RIGHT) {
1831 xo = sx2 - isize;
1832 xs = -1;
1833 } else {
1834 xo = sx1;
1835 xs = 1;
1837 if (wPreferences.icon_yard & IY_TOP) {
1838 yo = sy1;
1839 ys = 1;
1840 } else {
1841 yo = sy2 - isize;
1842 ys = -1;
1845 /* arrange icons putting the most recently focused window
1846 * as the last icon */
1847 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1848 : xo + xs*(pi*isize))
1849 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1850 : yo + ys*(si*isize))
1852 /* arrange application icons */
1853 aicon = scr->app_icon_list;
1854 /* reverse them to avoid unnecessarily sliding of icons */
1855 while (aicon && aicon->next)
1856 aicon = aicon->next;
1858 pi = 0;
1859 si = 0;
1860 while (aicon) {
1861 if (!aicon->docked) {
1862 if (aicon->x_pos != X || aicon->y_pos != Y) {
1863 #ifdef ANIMATIONS
1864 if (!wPreferences.no_animations) {
1865 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos,
1866 X, Y);
1868 #endif /* ANIMATIONS */
1870 wAppIconMove(aicon, X, Y);
1871 pi++;
1873 /* we reversed the order so we use prev */
1874 aicon = aicon->prev;
1875 if (pi >= pf) {
1876 pi=0;
1877 si++;
1881 /* arrange miniwindows */
1883 wwin = scr->focused_window;
1884 /* reverse them to avoid unnecessarily shuffling */
1885 while (wwin && wwin->prev)
1886 wwin = wwin->prev;
1888 while (wwin) {
1889 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1890 (wwin->frame->workspace==scr->current_workspace ||
1891 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1893 if (arrangeAll || !wwin->flags.icon_moved) {
1894 if (wwin->icon_x != X || wwin->icon_y != Y) {
1895 #ifdef ANIMATIONS
1896 if (wPreferences.no_animations) {
1897 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1898 } else {
1899 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1900 wwin->icon_y, X, Y);
1902 #else
1903 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1904 #endif /* ANIMATIONS */
1906 wwin->icon_x = X;
1907 wwin->icon_y = Y;
1908 pi++;
1911 if (arrangeAll) {
1912 wwin->flags.icon_moved = 0;
1914 /* we reversed the order, so we use next */
1915 wwin = wwin->next;
1916 if (pi >= pf) {
1917 pi=0;
1918 si++;
1922 #endif
1924 void
1925 wSelectWindow(WWindow *wwin, Bool flag)
1927 WScreen *scr = wwin->screen_ptr;
1929 if (flag) {
1930 wwin->flags.selected = 1;
1931 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1933 if (!HAS_BORDER(wwin)) {
1934 XSetWindowBorderWidth(dpy, wwin->frame->core->window,
1935 FRAME_BORDER_WIDTH);
1938 if (!scr->selected_windows)
1939 scr->selected_windows = WMCreateArray(4);
1940 WMAddToArray(scr->selected_windows, wwin);
1941 } else {
1942 wwin->flags.selected = 0;
1943 XSetWindowBorder(dpy, wwin->frame->core->window,
1944 scr->frame_border_pixel);
1946 if (!HAS_BORDER(wwin)) {
1947 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1950 if (scr->selected_windows) {
1951 WMRemoveFromArray(scr->selected_windows, wwin);
1957 void
1958 wMakeWindowVisible(WWindow *wwin)
1960 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1961 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1963 if (wwin->flags.shaded) {
1964 wUnshadeWindow(wwin);
1966 if (wwin->flags.hidden) {
1967 WApplication *app;
1969 app = wApplicationOf(wwin->main_window);
1970 if (app) {
1971 /* trick to get focus to this window */
1972 app->last_focused = wwin;
1973 wUnhideApplication(app, False, False);
1976 if (wwin->flags.miniaturized) {
1977 wDeiconifyWindow(wwin);
1978 } else {
1979 if (!WFLAGP(wwin, no_focusable))
1980 wSetFocusTo(wwin->screen_ptr, wwin);
1981 wRaiseFrame(wwin->frame->core);