Fixed memory leak in wHideAll.
[wmaker-crm.git] / src / actions.c
blobe7305703c3e77118371fca411aed6926d062f1b1
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "wconfig.h"
25 #include <X11/Xlib.h>
26 #include <X11/Xutil.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <unistd.h>
30 #include <math.h>
31 #include <time.h>
33 #include "WindowMaker.h"
34 #include "framewin.h"
35 #include "window.h"
36 #include "client.h"
37 #include "icon.h"
38 #include "funcs.h"
39 #include "application.h"
40 #include "actions.h"
41 #include "stacking.h"
42 #include "appicon.h"
43 #include "dock.h"
44 #include "appmenu.h"
45 #include "winspector.h"
46 #include "workspace.h"
47 #include "xinerama.h"
49 /****** Global Variables ******/
51 int ignore_wks_change = 0;
52 extern Time LastTimestamp;
53 extern Time LastFocusChange;
54 extern WPreferences wPreferences;
55 extern Atom _XA_WM_TAKE_FOCUS;
56 extern void ProcessPendingEvents();
57 extern int calcIntersectionLength(int p1, int l1, int p2, int l2);
59 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
60 unsigned int *new_width, unsigned int *new_height);
61 static void save_old_geometry(WWindow *wwin);
63 /******* Local Variables *******/
64 static struct {
65 int steps;
66 int delay;
67 } shadePars[5] = {
69 SHADE_STEPS_UF, SHADE_DELAY_UF}, {
70 SHADE_STEPS_F, SHADE_DELAY_F}, {
71 SHADE_STEPS_M, SHADE_DELAY_M}, {
72 SHADE_STEPS_S, SHADE_DELAY_S}, {
73 SHADE_STEPS_US, SHADE_DELAY_US}};
75 #define UNSHADE 0
76 #define SHADE 1
77 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
78 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
80 static int compareTimes(Time t1, Time t2)
82 Time diff;
83 if (t1 == t2)
84 return 0;
85 diff = t1 - t2;
86 return (diff < 60000) ? 1 : -1;
89 #ifdef ANIMATIONS
90 static void shade_animate(WWindow *wwin, Bool what);
91 #else
92 static void shade_animate(WWindow *wwin, Bool what) { }
93 #endif
96 *----------------------------------------------------------------------
97 * wSetFocusTo--
98 * Changes the window focus to the one passed as argument.
99 * If the window to focus is not already focused, it will be brought
100 * to the head of the list of windows. Previously focused window is
101 * unfocused.
103 * Side effects:
104 * Window list may be reordered and the window focus is changed.
106 *----------------------------------------------------------------------
108 void wSetFocusTo(WScreen *scr, WWindow *wwin)
110 static WScreen *old_scr = NULL;
112 WWindow *old_focused;
113 WWindow *focused = scr->focused_window;
114 Time timestamp = LastTimestamp;
115 WApplication *oapp = NULL, *napp = NULL;
116 int wasfocused;
118 if (scr->flags.ignore_focus_events || compareTimes(LastFocusChange, timestamp) > 0)
119 return;
121 if (!old_scr)
122 old_scr = scr;
124 old_focused = old_scr->focused_window;
126 LastFocusChange = timestamp;
128 if (old_focused)
129 oapp = wApplicationOf(old_focused->main_window);
131 if (wwin == NULL) {
132 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
133 if (old_focused)
134 wWindowUnfocus(old_focused);
136 if (oapp) {
137 wAppMenuUnmap(oapp->menu);
138 wApplicationDeactivate(oapp);
141 WMPostNotificationName(WMNChangedFocus, NULL, (void *)True);
142 return;
145 if (old_scr != scr && old_focused)
146 wWindowUnfocus(old_focused);
148 wasfocused = wwin->flags.focused;
149 napp = wApplicationOf(wwin->main_window);
151 /* remember last workspace where the app has been */
152 if (napp)
153 napp->last_workspace = wwin->frame->workspace;
155 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
156 /* install colormap if colormap mode is lock mode */
157 if (wPreferences.colormap_mode == WCM_CLICK)
158 wColormapInstallForWindow(scr, wwin);
160 /* set input focus */
161 switch (wwin->focus_mode) {
162 case WFM_NO_INPUT:
163 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
164 break;
165 case WFM_PASSIVE:
166 case WFM_LOCALLY_ACTIVE:
167 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
168 break;
169 case WFM_GLOBALLY_ACTIVE:
170 break;
173 XFlush(dpy);
174 if (wwin->protocols.TAKE_FOCUS)
175 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
177 XSync(dpy, False);
178 } else {
179 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
182 if (WFLAGP(wwin, no_focusable))
183 return;
185 /* if this is not the focused window focus it */
186 if (focused != wwin) {
187 /* change the focus window list order */
188 if (wwin->prev)
189 wwin->prev->next = wwin->next;
191 if (wwin->next)
192 wwin->next->prev = wwin->prev;
194 wwin->prev = focused;
195 focused->next = wwin;
196 wwin->next = NULL;
197 scr->focused_window = wwin;
199 if (oapp && oapp != napp) {
200 wAppMenuUnmap(oapp->menu);
201 wApplicationDeactivate(oapp);
205 wWindowFocus(wwin, focused);
207 if (napp && !wasfocused) {
208 #ifdef USER_MENU
209 wUserMenuRefreshInstances(napp->menu, wwin);
210 #endif /* USER_MENU */
212 if (wwin->flags.mapped)
213 wAppMenuMap(napp->menu, wwin);
215 if (napp)
216 wApplicationActivate(napp);
218 XFlush(dpy);
219 old_scr = scr;
222 void wShadeWindow(WWindow *wwin)
225 if (wwin->flags.shaded)
226 return;
228 XLowerWindow(dpy, wwin->client_win);
229 shade_animate(wwin, SHADE);
231 wwin->flags.skip_next_animation = 0;
232 wwin->flags.shaded = 1;
233 wwin->flags.mapped = 0;
234 /* prevent window withdrawal when getting UnmapNotify */
235 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
236 XUnmapWindow(dpy, wwin->client_win);
237 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
239 /* for the client it's just like iconification */
240 wFrameWindowResize(wwin->frame, wwin->frame->core->width, wwin->frame->top_width - 1);
242 wwin->client.y = wwin->frame_y - wwin->client.height + wwin->frame->top_width;
243 wWindowSynthConfigureNotify(wwin);
246 wClientSetState(wwin, IconicState, None);
249 WMPostNotificationName(WMNChangedState, wwin, "shade");
251 #ifdef ANIMATIONS
252 if (!wwin->screen_ptr->flags.startup) {
253 /* Catch up with events not processed while animation was running */
254 ProcessPendingEvents();
256 #endif
259 void wUnshadeWindow(WWindow *wwin)
262 if (!wwin->flags.shaded)
263 return;
265 wwin->flags.shaded = 0;
266 wwin->flags.mapped = 1;
267 XMapWindow(dpy, wwin->client_win);
269 shade_animate(wwin, UNSHADE);
271 wwin->flags.skip_next_animation = 0;
272 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
273 wwin->frame->top_width + wwin->client.height + wwin->frame->bottom_width);
275 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
276 wWindowSynthConfigureNotify(wwin);
278 /* if the window is focused, set the focus again as it was disabled during
279 * shading */
280 if (wwin->flags.focused)
281 wSetFocusTo(wwin->screen_ptr, wwin);
283 WMPostNotificationName(WMNChangedState, wwin, "shade");
286 /* Set the old coordinates using the current values */
287 static void save_old_geometry(WWindow *wwin)
289 wwin->old_geometry.width = wwin->client.width;
290 wwin->old_geometry.height = wwin->client.height;
291 wwin->old_geometry.x = wwin->frame_x;
292 wwin->old_geometry.y = wwin->frame_y;
295 void wMaximizeWindow(WWindow *wwin, int directions)
297 int new_x, new_y;
298 unsigned int new_width, new_height, half_scr_width;
299 WArea usableArea, totalArea;
300 Bool has_border = 1;
301 int adj_size;
303 if (!IS_RESIZABLE(wwin))
304 return;
306 if (!HAS_BORDER(wwin))
307 has_border = 0;
309 /* the size to adjust the geometry */
310 adj_size = FRAME_BORDER_WIDTH * 2 * has_border;
312 /* save old coordinates before we change the current values */
313 save_old_geometry(wwin);
315 totalArea.x1 = 0;
316 totalArea.y1 = 0;
317 totalArea.x2 = wwin->screen_ptr->scr_width;
318 totalArea.y2 = wwin->screen_ptr->scr_height;
319 usableArea = totalArea;
321 if (!(directions & MAX_IGNORE_XINERAMA)) {
322 WScreen *scr = wwin->screen_ptr;
323 int head;
325 if (directions & MAX_KEYBOARD)
326 head = wGetHeadForWindow(wwin);
327 else
328 head = wGetHeadForPointerLocation(scr);
330 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
333 /* Only save directions, not kbd or xinerama hints */
334 directions &= (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_MAXIMUS);
336 if (WFLAGP(wwin, full_maximize)) {
337 usableArea = totalArea;
339 half_scr_width = (usableArea.x2 - usableArea.x1)/2;
341 if (wwin->flags.shaded) {
342 wwin->flags.skip_next_animation = 1;
343 wUnshadeWindow(wwin);
346 if (directions & MAX_HORIZONTAL) {
347 new_width = usableArea.x2 - usableArea.x1 - adj_size;
348 new_x = usableArea.x1;
349 } else if (directions & MAX_LEFTHALF) {
350 new_width = half_scr_width - adj_size;
351 new_x = usableArea.x1;
352 } else if (directions & MAX_RIGHTHALF) {
353 new_width = half_scr_width - adj_size;
354 new_x = usableArea.x1 + half_scr_width;
355 } else {
356 new_x = wwin->frame_x;
357 new_width = wwin->frame->core->width;
360 if (directions & MAX_VERTICAL) {
361 new_height = usableArea.y2 - usableArea.y1 - adj_size;
362 new_y = usableArea.y1;
363 if (WFLAGP(wwin, full_maximize)) {
364 new_y -= wwin->frame->top_width;
365 new_height += wwin->frame->bottom_width - 1;
367 } else {
368 new_y = wwin->frame_y;
369 new_height = wwin->frame->core->height;
372 if (!WFLAGP(wwin, full_maximize)) {
373 new_height -= wwin->frame->top_width + wwin->frame->bottom_width;
376 if (directions & MAX_MAXIMUS) {
377 find_Maximus_geometry(wwin, usableArea, &new_x, &new_y, &new_width, &new_height);
378 new_width -= adj_size;
379 new_height -= adj_size;
380 if (WFLAGP(wwin, full_maximize) && new_y == 0) {
381 new_y -= wwin->frame->top_width;
382 new_height += wwin->frame->top_width - 1;
386 wWindowConstrainSize(wwin, &new_width, &new_height);
388 wWindowCropSize(wwin, usableArea.x2 - usableArea.x1,
389 usableArea.y2 - usableArea.y1, &new_width, &new_height);
391 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
392 wWindowSynthConfigureNotify(wwin);
394 WMPostNotificationName(WMNChangedState, wwin, "maximize");
396 /* set maximization state */
397 wwin->flags.maximized = directions;
400 /* the window boundary coordinates */
401 typedef struct {
402 int left;
403 int right;
404 int bottom;
405 int top;
406 int width;
407 int height;
408 } win_coords;
410 static void set_window_coords(WWindow *wwin, win_coords *obs)
412 obs->left = wwin->frame_x;
413 obs->top = wwin->frame_y;
414 obs->width = wwin->frame->core->width;
415 obs->height = wwin->frame->core->height;
416 obs->bottom = obs->top + obs->height;
417 obs->right = obs->left + obs->width;
421 * Maximus: tiled maximization (maximize without overlapping other windows)
423 * The original window 'orig' will be maximized to new coordinates 'new'.
424 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
426 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
427 unsigned int *new_width, unsigned int *new_height)
429 WWindow *tmp;
430 short int tbar_height_0 = 0, rbar_height_0 = 0, bd_width_0 = 0;
431 short int adjust_height;
432 int x_intsect, y_intsect;
433 /* the obstructing, original and new windows */
434 win_coords obs, orig, new;
436 /* set the original coordinate positions of the window to be Maximumized */
437 set_window_coords(wwin, &orig);
439 /* Try to fully maximize first, then readjust later */
440 new.left = usableArea.x1;
441 new.right = usableArea.x2;
442 new.top = usableArea.y1;
443 new.bottom = usableArea.y2;
445 if (HAS_TITLEBAR(wwin))
446 tbar_height_0 = TITLEBAR_HEIGHT;
447 if (HAS_RESIZEBAR(wwin))
448 rbar_height_0 = RESIZEBAR_HEIGHT;
449 if (HAS_BORDER(wwin))
450 bd_width_0 = FRAME_BORDER_WIDTH;
452 /* the length to be subtracted if the window has titlebar, etc */
453 adjust_height = tbar_height_0 + 2 * bd_width_0 + rbar_height_0;
455 tmp = wwin;
456 /* The focused window is always the last in the list */
457 while (tmp->prev) {
458 /* ignore windows in other workspaces etc */
459 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
460 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
461 tmp = tmp->prev;
462 continue;
464 tmp = tmp->prev;
466 /* Set the coordinates of obstructing window */
467 set_window_coords(tmp, &obs);
469 /* Try to maximize in the y direction first */
470 x_intsect = calcIntersectionLength(orig.left, orig.width, obs.left, obs.width);
471 if (x_intsect != 0) {
472 /* TODO: Consider the case when coords are equal */
473 if (obs.bottom < orig.top && obs.bottom > new.top) {
474 /* w_0 is below the bottom of w_j */
475 new.top = obs.bottom + 1;
477 if (orig.bottom < obs.top && obs.top < new.bottom) {
478 /* The bottom of w_0 is above the top of w_j */
479 new.bottom = obs.top - 1;
484 tmp = wwin;
485 while (tmp->prev) {
486 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
487 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
488 tmp = tmp->prev;
489 continue;
491 tmp = tmp->prev;
493 set_window_coords(tmp, &obs);
496 * Use the new.top and new.height instead of original values
497 * as they may have different intersections with the obstructing windows
499 new.height = new.bottom - new.top - adjust_height;
500 y_intsect = calcIntersectionLength(new.top, new.height, obs.top, obs.height);
501 if (y_intsect != 0) {
502 if (obs.right < orig.left && obs.right > new.left) {
503 /* w_0 is completely to the right of w_j */
504 new.left = obs.right + 1;
506 if (orig.right < obs.left && obs.left < new.right) {
507 /* w_0 is completely to the left of w_j */
508 new.right = obs.left - 1;
513 *new_x = new.left;
514 *new_y = new.top;
515 /* xcalc needs -7 here, but other apps don't */
516 *new_height = new.bottom - new.top - adjust_height - 1;;
517 *new_width = new.right - new.left;
520 void wUnmaximizeWindow(WWindow *wwin)
522 int x, y, w, h;
523 WMRect old_geom_rect;
524 int old_head;
525 Bool same_head;
527 if (!wwin->flags.maximized)
528 return;
530 if (wwin->flags.shaded) {
531 wwin->flags.skip_next_animation = 1;
532 wUnshadeWindow(wwin);
534 /* Use old coordinates if they are set, current values otherwise */
535 old_geom_rect = wmkrect(wwin->old_geometry.x, wwin->old_geometry.y, wwin->old_geometry.width, wwin->old_geometry.height);
536 old_head = wGetHeadForRect(wwin->screen_ptr, old_geom_rect);
537 same_head = (wGetHeadForWindow(wwin) == old_head);
538 x = (wwin->old_geometry.x && same_head) ? wwin->old_geometry.x : wwin->frame_x;
539 y = (wwin->old_geometry.y && same_head) ? wwin->old_geometry.y : wwin->frame_y;
540 w = wwin->old_geometry.width ? wwin->old_geometry.width : wwin->client.width;
541 h = wwin->old_geometry.height ? wwin->old_geometry.height : wwin->client.height;
543 wwin->flags.maximized = 0;
544 wWindowConfigure(wwin, x, y, w, h);
545 wWindowSynthConfigureNotify(wwin);
547 WMPostNotificationName(WMNChangedState, wwin, "maximize");
550 void wFullscreenWindow(WWindow *wwin)
552 int head;
553 WMRect rect;
555 if (wwin->flags.fullscreen)
556 return;
558 wwin->flags.fullscreen = True;
560 wWindowConfigureBorders(wwin);
562 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
564 wwin->bfs_geometry.x = wwin->frame_x;
565 wwin->bfs_geometry.y = wwin->frame_y;
566 wwin->bfs_geometry.width = wwin->frame->core->width;
567 wwin->bfs_geometry.height = wwin->frame->core->height;
569 head = wGetHeadForWindow(wwin);
570 rect = wGetRectForHead(wwin->screen_ptr, head);
571 wWindowConfigure(wwin, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
573 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
576 void wUnfullscreenWindow(WWindow *wwin)
578 if (!wwin->flags.fullscreen)
579 return;
581 wwin->flags.fullscreen = False;
583 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
584 if (WFLAGP(wwin, sunken)) {
585 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
586 } else if (WFLAGP(wwin, floating)) {
587 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
588 } else {
589 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
593 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
594 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
596 wWindowConfigureBorders(wwin);
598 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
599 wFrameWindowPaint(wwin->frame);
602 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
605 #ifdef ANIMATIONS
606 static void animateResizeFlip(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
608 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
609 float cx, cy, cw, ch;
610 float xstep, ystep, wstep, hstep;
611 XPoint points[5];
612 float dx, dch, midy;
613 float angle, final_angle, delta;
615 xstep = (float)(fx - x) / steps;
616 ystep = (float)(fy - y) / steps;
617 wstep = (float)(fw - w) / steps;
618 hstep = (float)(fh - h) / steps;
620 cx = (float)x;
621 cy = (float)y;
622 cw = (float)w;
623 ch = (float)h;
625 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_F;
626 delta = (float)(final_angle / FRAMES);
627 for (angle = 0;; angle += delta) {
628 if (angle > final_angle)
629 angle = final_angle;
631 dx = (cw / 10) - ((cw / 5) * sin(angle));
632 dch = (ch / 2) * cos(angle);
633 midy = cy + (ch / 2);
635 points[0].x = cx + dx;
636 points[0].y = midy - dch;
637 points[1].x = cx + cw - dx;
638 points[1].y = points[0].y;
639 points[2].x = cx + cw + dx;
640 points[2].y = midy + dch;
641 points[3].x = cx - dx;
642 points[3].y = points[2].y;
643 points[4].x = points[0].x;
644 points[4].y = points[0].y;
646 XGrabServer(dpy);
647 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
648 XFlush(dpy);
649 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
651 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
652 XUngrabServer(dpy);
653 cx += xstep;
654 cy += ystep;
655 cw += wstep;
656 ch += hstep;
657 if (angle >= final_angle)
658 break;
661 XFlush(dpy);
664 #undef FRAMES
666 static void
667 animateResizeTwist(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
669 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
670 float cx, cy, cw, ch;
671 float xstep, ystep, wstep, hstep;
672 XPoint points[5];
673 float angle, final_angle, a, d, delta;
675 x += w / 2;
676 y += h / 2;
677 fx += fw / 2;
678 fy += fh / 2;
680 xstep = (float)(fx - x) / steps;
681 ystep = (float)(fy - y) / steps;
682 wstep = (float)(fw - w) / steps;
683 hstep = (float)(fh - h) / steps;
685 cx = (float)x;
686 cy = (float)y;
687 cw = (float)w;
688 ch = (float)h;
690 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_T;
691 delta = (float)(final_angle / FRAMES);
692 for (angle = 0;; angle += delta) {
693 if (angle > final_angle)
694 angle = final_angle;
696 a = atan(ch / cw);
697 d = sqrt((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
699 points[0].x = cx + cos(angle - a) * d;
700 points[0].y = cy + sin(angle - a) * d;
701 points[1].x = cx + cos(angle + a) * d;
702 points[1].y = cy + sin(angle + a) * d;
703 points[2].x = cx + cos(angle - a + WM_PI) * d;
704 points[2].y = cy + sin(angle - a + WM_PI) * d;
705 points[3].x = cx + cos(angle + a + WM_PI) * d;
706 points[3].y = cy + sin(angle + a + WM_PI) * d;
707 points[4].x = cx + cos(angle - a) * d;
708 points[4].y = cy + sin(angle - a) * d;
709 XGrabServer(dpy);
710 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
711 XFlush(dpy);
712 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
714 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
715 XUngrabServer(dpy);
716 cx += xstep;
717 cy += ystep;
718 cw += wstep;
719 ch += hstep;
720 if (angle >= final_angle)
721 break;
724 XFlush(dpy);
727 #undef FRAMES
729 static void animateResizeZoom(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
731 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
732 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
733 float xstep, ystep, wstep, hstep;
734 int i, j;
736 xstep = (float)(fx - x) / steps;
737 ystep = (float)(fy - y) / steps;
738 wstep = (float)(fw - w) / steps;
739 hstep = (float)(fh - h) / steps;
741 for (j = 0; j < FRAMES; j++) {
742 cx[j] = (float)x;
743 cy[j] = (float)y;
744 cw[j] = (float)w;
745 ch[j] = (float)h;
747 XGrabServer(dpy);
748 for (i = 0; i < steps; i++) {
749 for (j = 0; j < FRAMES; j++) {
750 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
751 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
753 XFlush(dpy);
754 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
756 for (j = 0; j < FRAMES; j++) {
757 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
758 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
759 if (j < FRAMES - 1) {
760 cx[j] = cx[j + 1];
761 cy[j] = cy[j + 1];
762 cw[j] = cw[j + 1];
763 ch[j] = ch[j + 1];
764 } else {
765 cx[j] += xstep;
766 cy[j] += ystep;
767 cw[j] += wstep;
768 ch[j] += hstep;
773 for (j = 0; j < FRAMES; j++) {
774 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
776 XFlush(dpy);
777 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
779 for (j = 0; j < FRAMES; j++) {
780 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
783 XUngrabServer(dpy);
786 #undef FRAMES
788 void animateResize(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh)
790 int style = wPreferences.iconification_style; /* Catch the value */
791 int steps;
793 if (style == WIS_NONE)
794 return;
796 if (style == WIS_RANDOM) {
797 style = rand() % 3;
800 switch (style) {
801 case WIS_TWIST:
802 steps = MINIATURIZE_ANIMATION_STEPS_T;
803 if (steps > 0)
804 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
805 break;
806 case WIS_FLIP:
807 steps = MINIATURIZE_ANIMATION_STEPS_F;
808 if (steps > 0)
809 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
810 break;
811 case WIS_ZOOM:
812 default:
813 steps = MINIATURIZE_ANIMATION_STEPS_Z;
814 if (steps > 0)
815 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
816 break;
819 #endif /* ANIMATIONS */
821 static void flushExpose(void)
823 XEvent tmpev;
825 while (XCheckTypedEvent(dpy, Expose, &tmpev))
826 WMHandleEvent(&tmpev);
827 XSync(dpy, 0);
830 static void unmapTransientsFor(WWindow *wwin)
832 WWindow *tmp;
834 tmp = wwin->screen_ptr->focused_window;
835 while (tmp) {
836 /* unmap the transients for this transient */
837 if (tmp != wwin && tmp->transient_for == wwin->client_win
838 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup || tmp->flags.shaded)) {
839 unmapTransientsFor(tmp);
840 tmp->flags.miniaturized = 1;
841 if (!tmp->flags.shaded) {
842 wWindowUnmap(tmp);
843 } else {
844 XUnmapWindow(dpy, tmp->frame->core->window);
847 if (!tmp->flags.shaded)
849 wClientSetState(tmp, IconicState, None);
851 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
853 tmp = tmp->prev;
857 static void mapTransientsFor(WWindow *wwin)
859 WWindow *tmp;
861 tmp = wwin->screen_ptr->focused_window;
862 while (tmp) {
863 /* recursively map the transients for this transient */
864 if (tmp != wwin && tmp->transient_for == wwin->client_win && /*!tmp->flags.mapped */ tmp->flags.miniaturized
865 && tmp->icon == NULL) {
866 mapTransientsFor(tmp);
867 tmp->flags.miniaturized = 0;
868 if (!tmp->flags.shaded) {
869 wWindowMap(tmp);
870 } else {
871 XMapWindow(dpy, tmp->frame->core->window);
873 tmp->flags.semi_focused = 0;
875 if (!tmp->flags.shaded)
877 wClientSetState(tmp, NormalState, None);
879 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
881 tmp = tmp->prev;
885 static WWindow *recursiveTransientFor(WWindow * wwin)
887 int i;
889 if (!wwin)
890 return None;
892 /* hackish way to detect transient_for cycle */
893 i = wwin->screen_ptr->window_count + 1;
895 while (wwin && wwin->transient_for != None && i > 0) {
896 wwin = wWindowFor(wwin->transient_for);
897 i--;
899 if (i == 0 && wwin) {
900 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin->frame->title);
901 return NULL;
904 return wwin;
907 void wIconifyWindow(WWindow * wwin)
909 XWindowAttributes attribs;
910 int present;
912 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs))
913 return; /* the window doesn't exist anymore */
915 if (wwin->flags.miniaturized)
916 return; /* already miniaturized */
918 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
919 WWindow *owner = wWindowFor(wwin->transient_for);
921 if (owner && owner->flags.miniaturized)
922 return;
925 present = wwin->frame->workspace == wwin->screen_ptr->current_workspace;
927 /* if the window is in another workspace, simplify process */
928 if (present) {
929 /* icon creation may take a while */
930 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
931 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
932 GrabModeAsync, None, None, CurrentTime);
935 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
936 if (!wwin->flags.icon_moved)
937 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
939 wwin->icon = wIconCreate(wwin);
940 wwin->icon->mapped = 1;
943 wwin->flags.miniaturized = 1;
944 wwin->flags.mapped = 0;
946 /* unmap transients */
947 unmapTransientsFor(wwin);
949 if (present) {
950 XUngrabPointer(dpy, CurrentTime);
951 wWindowUnmap(wwin);
952 /* let all Expose events arrive so that we can repaint
953 * something before the animation starts (and the server is grabbed) */
954 XSync(dpy, 0);
956 if (wPreferences.disable_miniwindows || wwin->flags.net_handle_icon)
957 wClientSetState(wwin, IconicState, None);
958 else
959 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
961 flushExpose();
962 #ifdef ANIMATIONS
963 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
964 && !wPreferences.no_animations) {
965 int ix, iy, iw, ih;
967 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
968 ix = wwin->icon_x;
969 iy = wwin->icon_y;
970 iw = wwin->icon->core->width;
971 ih = wwin->icon->core->height;
972 } else {
973 if (wwin->flags.net_handle_icon) {
974 ix = wwin->icon_x;
975 iy = wwin->icon_y;
976 iw = wwin->icon_w;
977 ih = wwin->icon_h;
978 } else {
979 ix = 0;
980 iy = 0;
981 iw = wwin->screen_ptr->scr_width;
982 ih = wwin->screen_ptr->scr_height;
985 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
986 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih);
988 #endif
991 wwin->flags.skip_next_animation = 0;
993 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
994 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace ||
995 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
996 XMapWindow(dpy, wwin->icon->core->window);
998 AddToStackList(wwin->icon->core);
999 wLowerFrame(wwin->icon->core);
1002 if (present) {
1003 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1006 * It doesn't seem to be working and causes button event hangup
1007 * when deiconifying a transient window.
1008 setupIconGrabs(wwin->icon);
1010 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
1011 && wPreferences.focus_mode == WKF_CLICK) {
1012 WWindow *tmp;
1014 tmp = wwin->prev;
1015 while (tmp) {
1016 if (!WFLAGP(tmp, no_focusable)
1017 && !(tmp->flags.hidden || tmp->flags.miniaturized)
1018 && (wwin->frame->workspace == tmp->frame->workspace))
1019 break;
1020 tmp = tmp->prev;
1022 wSetFocusTo(wwin->screen_ptr, tmp);
1023 } else if (wPreferences.focus_mode != WKF_CLICK) {
1024 wSetFocusTo(wwin->screen_ptr, NULL);
1026 #ifdef ANIMATIONS
1027 if (!wwin->screen_ptr->flags.startup) {
1028 /* Catch up with events not processed while animation was running */
1029 Window clientwin = wwin->client_win;
1031 ProcessPendingEvents();
1033 /* the window can disappear while ProcessPendingEvents() runs */
1034 if (!wWindowFor(clientwin)) {
1035 return;
1038 #endif
1041 /* maybe we want to do this regardless of net_handle_icon
1042 * it seems to me we might break behaviour this way.
1044 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1045 && !wwin->flags.net_handle_icon)
1046 wIconSelect(wwin->icon);
1048 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1050 if (wPreferences.auto_arrange_icons)
1051 wArrangeIcons(wwin->screen_ptr, True);
1054 void wDeiconifyWindow(WWindow *wwin)
1056 /* Let's avoid changing workspace while deiconifying */
1057 ignore_wks_change = 1;
1059 /* we're hiding for show_desktop */
1060 int netwm_hidden = wwin->flags.net_show_desktop &&
1061 wwin->frame->workspace != wwin->screen_ptr->current_workspace;
1063 if (!netwm_hidden)
1064 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1066 if (!wwin->flags.miniaturized)
1067 return;
1069 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1070 WWindow *owner = recursiveTransientFor(wwin);
1072 if (owner && owner->flags.miniaturized) {
1073 wDeiconifyWindow(owner);
1074 wSetFocusTo(wwin->screen_ptr, wwin);
1075 wRaiseFrame(wwin->frame->core);
1076 return;
1080 wwin->flags.miniaturized = 0;
1082 if (!netwm_hidden && !wwin->flags.shaded)
1083 wwin->flags.mapped = 1;
1085 if (!netwm_hidden || wPreferences.sticky_icons) {
1086 /* maybe we want to do this regardless of net_handle_icon
1087 * it seems to me we might break behaviour this way.
1089 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon
1090 && wwin->icon != NULL) {
1091 if (wwin->icon->selected)
1092 wIconSelect(wwin->icon);
1094 XUnmapWindow(dpy, wwin->icon->core->window);
1098 /* if the window is in another workspace, do it silently */
1099 if (!netwm_hidden) {
1100 #ifdef ANIMATIONS
1101 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1102 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1103 int ix, iy, iw, ih;
1105 if (!wPreferences.disable_miniwindows
1106 && !wwin->flags.net_handle_icon) {
1107 ix = wwin->icon_x;
1108 iy = wwin->icon_y;
1109 iw = wwin->icon->core->width;
1110 ih = wwin->icon->core->height;
1111 } else {
1112 if (wwin->flags.net_handle_icon) {
1113 ix = wwin->icon_x;
1114 iy = wwin->icon_y;
1115 iw = wwin->icon_w;
1116 ih = wwin->icon_h;
1117 } else {
1118 ix = 0;
1119 iy = 0;
1120 iw = wwin->screen_ptr->scr_width;
1121 ih = wwin->screen_ptr->scr_height;
1124 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1125 wwin->frame_x, wwin->frame_y,
1126 wwin->frame->core->width, wwin->frame->core->height);
1128 #endif /* ANIMATIONS */
1129 wwin->flags.skip_next_animation = 0;
1130 XGrabServer(dpy);
1131 if (!wwin->flags.shaded)
1132 XMapWindow(dpy, wwin->client_win);
1134 XMapWindow(dpy, wwin->frame->core->window);
1135 wRaiseFrame(wwin->frame->core);
1136 if (!wwin->flags.shaded)
1137 wClientSetState(wwin, NormalState, None);
1139 mapTransientsFor(wwin);
1142 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1143 && !wwin->flags.net_handle_icon) {
1144 RemoveFromStackList(wwin->icon->core);
1145 /* removeIconGrabs(wwin->icon); */
1146 wIconDestroy(wwin->icon);
1147 wwin->icon = NULL;
1150 if (!netwm_hidden) {
1151 XUngrabServer(dpy);
1153 wSetFocusTo(wwin->screen_ptr, wwin);
1155 #ifdef ANIMATIONS
1156 if (!wwin->screen_ptr->flags.startup) {
1157 /* Catch up with events not processed while animation was running */
1158 Window clientwin = wwin->client_win;
1160 ProcessPendingEvents();
1162 /* the window can disappear while ProcessPendingEvents() runs */
1163 if (!wWindowFor(clientwin))
1164 return;
1166 #endif
1169 if (wPreferences.auto_arrange_icons)
1170 wArrangeIcons(wwin->screen_ptr, True);
1172 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1174 /* In case we were shaded and iconified, also unshade */
1175 if (!netwm_hidden)
1176 wUnshadeWindow(wwin);
1178 ignore_wks_change = 0;
1181 static void hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1183 if (wwin->flags.miniaturized) {
1184 if (wwin->icon) {
1185 XUnmapWindow(dpy, wwin->icon->core->window);
1186 wwin->icon->mapped = 0;
1188 wwin->flags.hidden = 1;
1190 WMPostNotificationName(WMNChangedState, wwin, "hide");
1191 return;
1194 if (wwin->flags.inspector_open) {
1195 wHideInspectorForWindow(wwin);
1198 wwin->flags.hidden = 1;
1199 wWindowUnmap(wwin);
1201 wClientSetState(wwin, IconicState, icon->icon_win);
1202 flushExpose();
1204 #ifdef ANIMATIONS
1205 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1206 !wwin->flags.skip_next_animation && animate) {
1207 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1208 wwin->frame->core->width, wwin->frame->core->height,
1209 icon_x, icon_y, icon->core->width, icon->core->height);
1211 #endif
1212 wwin->flags.skip_next_animation = 0;
1214 WMPostNotificationName(WMNChangedState, wwin, "hide");
1217 void wHideAll(WScreen *scr)
1219 WWindow *wwin;
1220 WWindow **windows;
1221 WMenu *menu;
1222 unsigned int wcount = 0;
1223 int i;
1225 if (!scr)
1226 return;
1228 menu = scr->switch_menu;
1230 windows = wmalloc(sizeof(WWindow *));
1232 if (menu != NULL) {
1233 for (i = 0; i < menu->entry_no; i++) {
1234 windows[wcount] = (WWindow *) menu->entries[i]->clientdata;
1235 wcount++;
1236 windows = wrealloc(windows, sizeof(WWindow *) * (wcount + 1));
1238 } else {
1239 wwin = scr->focused_window;
1241 while (wwin) {
1242 windows[wcount] = wwin;
1243 wcount++;
1244 windows = wrealloc(windows, sizeof(WWindow *) * (wcount + 1));
1245 wwin = wwin->prev;
1250 for (i = 0; i < wcount; i++) {
1251 wwin = windows[i];
1252 if (wwin->frame->workspace == scr->current_workspace
1253 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1254 && !wwin->flags.internal_window
1255 && !WFLAGP(wwin, no_miniaturizable)
1257 wwin->flags.skip_next_animation = 1;
1258 wIconifyWindow(wwin);
1262 wfree(windows);
1265 void wHideOtherApplications(WWindow *awin)
1267 WWindow *wwin;
1268 WApplication *tapp;
1270 if (!awin)
1271 return;
1272 wwin = awin->screen_ptr->focused_window;
1274 while (wwin) {
1275 if (wwin != awin
1276 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1277 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1278 && !wwin->flags.internal_window
1279 && wGetWindowOfInspectorForWindow(wwin) != awin && !WFLAGP(wwin, no_hide_others)) {
1281 if (wwin->main_window == None || WFLAGP(wwin, no_appicon)) {
1282 if (!WFLAGP(wwin, no_miniaturizable)) {
1283 wwin->flags.skip_next_animation = 1;
1284 wIconifyWindow(wwin);
1286 } else if (wwin->main_window != None && awin->main_window != wwin->main_window) {
1287 tapp = wApplicationOf(wwin->main_window);
1288 if (tapp) {
1289 tapp->flags.skip_next_animation = 1;
1290 wHideApplication(tapp);
1291 } else {
1292 if (!WFLAGP(wwin, no_miniaturizable)) {
1293 wwin->flags.skip_next_animation = 1;
1294 wIconifyWindow(wwin);
1299 wwin = wwin->prev;
1302 wSetFocusTo(awin->screen_ptr, awin);
1306 void wHideApplication(WApplication *wapp)
1308 WScreen *scr;
1309 WWindow *wlist;
1310 int hadfocus;
1311 int animate;
1313 if (!wapp) {
1314 wwarning("trying to hide a non grouped window");
1315 return;
1317 if (!wapp->main_window_desc) {
1318 wwarning("group leader not found for window group");
1319 return;
1321 scr = wapp->main_window_desc->screen_ptr;
1322 hadfocus = 0;
1323 wlist = scr->focused_window;
1324 if (!wlist)
1325 return;
1327 if (wlist->main_window == wapp->main_window)
1328 wapp->last_focused = wlist;
1329 else
1330 wapp->last_focused = NULL;
1332 animate = !wapp->flags.skip_next_animation;
1334 while (wlist) {
1335 if (wlist->main_window == wapp->main_window) {
1336 if (wlist->flags.focused) {
1337 hadfocus = 1;
1339 if (wapp->app_icon) {
1340 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1341 wapp->app_icon->y_pos, wlist, animate);
1342 animate = False;
1345 wlist = wlist->prev;
1348 wapp->flags.skip_next_animation = 0;
1350 if (hadfocus) {
1351 if (wPreferences.focus_mode == WKF_CLICK) {
1352 wlist = scr->focused_window;
1353 while (wlist) {
1354 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1355 && (wlist->flags.mapped || wlist->flags.shaded))
1356 break;
1357 wlist = wlist->prev;
1359 wSetFocusTo(scr, wlist);
1360 } else {
1361 wSetFocusTo(scr, NULL);
1365 wapp->flags.hidden = 1;
1367 if (wPreferences.auto_arrange_icons) {
1368 wArrangeIcons(scr, True);
1370 #ifdef HIDDENDOT
1371 if (wapp->app_icon)
1372 wAppIconPaint(wapp->app_icon);
1373 #endif
1376 static void unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate, int bringToCurrentWS)
1378 if (bringToCurrentWS)
1379 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1381 wwin->flags.hidden = 0;
1383 #ifdef ANIMATIONS
1384 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1385 animateResize(wwin->screen_ptr, icon_x, icon_y,
1386 icon->core->width, icon->core->height,
1387 wwin->frame_x, wwin->frame_y,
1388 wwin->frame->core->width, wwin->frame->core->height);
1390 #endif
1391 wwin->flags.skip_next_animation = 0;
1392 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1393 XMapWindow(dpy, wwin->client_win);
1394 XMapWindow(dpy, wwin->frame->core->window);
1395 wClientSetState(wwin, NormalState, None);
1396 wwin->flags.mapped = 1;
1397 wRaiseFrame(wwin->frame->core);
1399 if (wwin->flags.inspector_open) {
1400 wUnhideInspectorForWindow(wwin);
1403 WMPostNotificationName(WMNChangedState, wwin, "hide");
1406 void wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1408 WScreen *scr;
1409 WWindow *wlist, *next;
1410 WWindow *focused = NULL;
1411 int animate;
1413 if (!wapp)
1414 return;
1416 scr = wapp->main_window_desc->screen_ptr;
1417 wlist = scr->focused_window;
1418 if (!wlist)
1419 return;
1421 /* goto beginning of list */
1422 while (wlist->prev)
1423 wlist = wlist->prev;
1425 animate = !wapp->flags.skip_next_animation;
1427 while (wlist) {
1428 next = wlist->next;
1430 if (wlist->main_window == wapp->main_window) {
1431 if (wlist->flags.focused)
1432 focused = wlist;
1433 else if (!focused || !focused->flags.focused)
1434 focused = wlist;
1436 if (wlist->flags.miniaturized) {
1437 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1438 wlist->frame->workspace == scr->current_workspace) && wlist->icon) {
1439 if (!wlist->icon->mapped) {
1440 int x, y;
1442 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1443 if (wlist->icon_x != x || wlist->icon_y != y) {
1444 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1446 wlist->icon_x = x;
1447 wlist->icon_y = y;
1448 XMapWindow(dpy, wlist->icon->core->window);
1449 wlist->icon->mapped = 1;
1451 wRaiseFrame(wlist->icon->core);
1453 if (bringToCurrentWS)
1454 wWindowChangeWorkspace(wlist, scr->current_workspace);
1455 wlist->flags.hidden = 0;
1456 if (miniwindows && wlist->frame->workspace == scr->current_workspace) {
1457 wDeiconifyWindow(wlist);
1459 WMPostNotificationName(WMNChangedState, wlist, "hide");
1460 } else if (wlist->flags.shaded) {
1461 if (bringToCurrentWS)
1462 wWindowChangeWorkspace(wlist, scr->current_workspace);
1463 wlist->flags.hidden = 0;
1464 wRaiseFrame(wlist->frame->core);
1465 if (wlist->frame->workspace == scr->current_workspace) {
1466 XMapWindow(dpy, wlist->frame->core->window);
1467 if (miniwindows) {
1468 wUnshadeWindow(wlist);
1471 WMPostNotificationName(WMNChangedState, wlist, "hide");
1472 } else if (wlist->flags.hidden) {
1473 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1474 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1475 animate = False;
1476 } else {
1477 if (bringToCurrentWS && wlist->frame->workspace != scr->current_workspace) {
1478 wWindowChangeWorkspace(wlist, scr->current_workspace);
1480 wRaiseFrame(wlist->frame->core);
1483 wlist = next;
1486 wapp->flags.skip_next_animation = 0;
1487 wapp->flags.hidden = 0;
1489 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1490 wRaiseFrame(wapp->last_focused->frame->core);
1491 wSetFocusTo(scr, wapp->last_focused);
1492 } else if (focused) {
1493 wSetFocusTo(scr, focused);
1495 wapp->last_focused = NULL;
1496 if (wPreferences.auto_arrange_icons) {
1497 wArrangeIcons(scr, True);
1499 #ifdef HIDDENDOT
1500 wAppIconPaint(wapp->app_icon);
1501 #endif
1504 void wShowAllWindows(WScreen *scr)
1506 WWindow *wwin, *old_foc;
1507 WApplication *wapp;
1509 old_foc = wwin = scr->focused_window;
1510 while (wwin) {
1511 if (!wwin->flags.internal_window &&
1512 (scr->current_workspace == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1513 if (wwin->flags.miniaturized) {
1514 wwin->flags.skip_next_animation = 1;
1515 wDeiconifyWindow(wwin);
1516 } else if (wwin->flags.hidden) {
1517 wapp = wApplicationOf(wwin->main_window);
1518 if (wapp) {
1519 wUnhideApplication(wapp, False, False);
1520 } else {
1521 wwin->flags.skip_next_animation = 1;
1522 wDeiconifyWindow(wwin);
1526 wwin = wwin->prev;
1528 wSetFocusTo(scr, old_foc);
1529 /*wRaiseFrame(old_foc->frame->core); */
1532 void wRefreshDesktop(WScreen *scr)
1534 Window win;
1535 XSetWindowAttributes attr;
1537 attr.backing_store = NotUseful;
1538 attr.save_under = False;
1539 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1540 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1541 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1542 XMapRaised(dpy, win);
1543 XDestroyWindow(dpy, win);
1544 XFlush(dpy);
1547 void wArrangeIcons(WScreen *scr, Bool arrangeAll)
1549 WWindow *wwin;
1550 WAppIcon *aicon;
1552 int head;
1553 const int heads = wXineramaHeads(scr);
1555 struct HeadVars {
1556 int pf; /* primary axis */
1557 int sf; /* secondary axis */
1558 int fullW;
1559 int fullH;
1560 int pi, si;
1561 int sx1, sx2, sy1, sy2; /* screen boundary */
1562 int sw, sh;
1563 int xo, yo;
1564 int xs, ys;
1565 } *vars;
1567 int isize = wPreferences.icon_size;
1569 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
1571 for (head = 0; head < heads; ++head) {
1572 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1573 WMRect rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
1574 vars[head].pi = vars[head].si = 0;
1575 vars[head].sx1 = rect.pos.x;
1576 vars[head].sy1 = rect.pos.y;
1577 vars[head].sw = rect.size.width;
1578 vars[head].sh = rect.size.height;
1579 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1580 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1581 vars[head].sw = isize * (vars[head].sw / isize);
1582 vars[head].sh = isize * (vars[head].sh / isize);
1583 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
1584 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
1586 /* icon yard boundaries */
1587 if (wPreferences.icon_yard & IY_VERT) {
1588 vars[head].pf = vars[head].fullH;
1589 vars[head].sf = vars[head].fullW;
1590 } else {
1591 vars[head].pf = vars[head].fullW;
1592 vars[head].sf = vars[head].fullH;
1594 if (wPreferences.icon_yard & IY_RIGHT) {
1595 vars[head].xo = vars[head].sx2 - isize;
1596 vars[head].xs = -1;
1597 } else {
1598 vars[head].xo = vars[head].sx1;
1599 vars[head].xs = 1;
1601 if (wPreferences.icon_yard & IY_TOP) {
1602 vars[head].yo = vars[head].sy1;
1603 vars[head].ys = 1;
1604 } else {
1605 vars[head].yo = vars[head].sy2 - isize;
1606 vars[head].ys = -1;
1610 #define X ((wPreferences.icon_yard & IY_VERT) \
1611 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1612 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1614 #define Y ((wPreferences.icon_yard & IY_VERT) \
1615 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1616 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1618 /* arrange application icons */
1619 aicon = scr->app_icon_list;
1620 /* reverse them to avoid unnecessarily sliding of icons */
1621 while (aicon && aicon->next)
1622 aicon = aicon->next;
1624 while (aicon) {
1625 if (!aicon->docked) {
1626 /* CHECK: can icon be NULL here ? */
1627 /* The intention here is to place the AppIcon on the head that
1628 * contains most of the applications _main_ window. */
1629 head = wGetHeadForWindow(aicon->icon->owner);
1631 if (aicon->x_pos != X || aicon->y_pos != Y) {
1632 #ifdef ANIMATIONS
1633 if (!wPreferences.no_animations) {
1634 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1636 #endif /* ANIMATIONS */
1638 wAppIconMove(aicon, X, Y);
1639 vars[head].pi++;
1640 if (vars[head].pi >= vars[head].pf) {
1641 vars[head].pi = 0;
1642 vars[head].si++;
1645 aicon = aicon->prev;
1648 /* arrange miniwindows */
1649 wwin = scr->focused_window;
1650 /* reverse them to avoid unnecessarily shuffling */
1651 while (wwin && wwin->prev)
1652 wwin = wwin->prev;
1654 while (wwin) {
1655 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1656 (wwin->frame->workspace == scr->current_workspace ||
1657 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1659 head = wGetHeadForWindow(wwin);
1661 if (arrangeAll || !wwin->flags.icon_moved) {
1662 if (wwin->icon_x != X || wwin->icon_y != Y) {
1663 #ifdef ANIMATIONS
1664 if (wPreferences.no_animations) {
1665 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1666 } else {
1667 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1668 wwin->icon_y, X, Y);
1670 #else
1671 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1672 #endif /* ANIMATIONS */
1674 wwin->icon_x = X;
1675 wwin->icon_y = Y;
1677 vars[head].pi++;
1678 if (vars[head].pi >= vars[head].pf) {
1679 vars[head].pi = 0;
1680 vars[head].si++;
1684 if (arrangeAll) {
1685 wwin->flags.icon_moved = 0;
1687 /* we reversed the order, so we use next */
1688 wwin = wwin->next;
1691 wfree(vars);
1694 void wSelectWindow(WWindow *wwin, Bool flag)
1696 WScreen *scr = wwin->screen_ptr;
1698 if (flag) {
1699 wwin->flags.selected = 1;
1700 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1702 if (!HAS_BORDER(wwin)) {
1703 XSetWindowBorderWidth(dpy, wwin->frame->core->window, FRAME_BORDER_WIDTH);
1706 if (!scr->selected_windows)
1707 scr->selected_windows = WMCreateArray(4);
1708 WMAddToArray(scr->selected_windows, wwin);
1709 } else {
1710 wwin->flags.selected = 0;
1711 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
1713 if (!HAS_BORDER(wwin)) {
1714 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1717 if (scr->selected_windows) {
1718 WMRemoveFromArray(scr->selected_windows, wwin);
1723 void wMakeWindowVisible(WWindow *wwin)
1725 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1726 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1728 if (wwin->flags.shaded) {
1729 wUnshadeWindow(wwin);
1731 if (wwin->flags.hidden) {
1732 WApplication *app;
1734 app = wApplicationOf(wwin->main_window);
1735 if (app) {
1736 /* trick to get focus to this window */
1737 app->last_focused = wwin;
1738 wUnhideApplication(app, False, False);
1741 if (wwin->flags.miniaturized) {
1742 wDeiconifyWindow(wwin);
1743 } else {
1744 if (!WFLAGP(wwin, no_focusable))
1745 wSetFocusTo(wwin->screen_ptr, wwin);
1746 wRaiseFrame(wwin->frame->core);
1751 * Do the animation while shading (called with what = SHADE)
1752 * or unshading (what = UNSHADE).
1754 #ifdef ANIMATIONS
1755 static void shade_animate(WWindow *wwin, Bool what)
1757 int y, s, w, h;
1758 time_t time0 = time(NULL);
1760 if (wwin->flags.skip_next_animation && wPreferences.no_animations)
1761 return;
1763 switch(what) {
1764 case SHADE:
1765 if (!wwin->screen_ptr->flags.startup) {
1766 /* do the shading animation */
1767 h = wwin->frame->core->height;
1768 s = h / SHADE_STEPS;
1769 if (s < 1)
1770 s = 1;
1771 w = wwin->frame->core->width;
1772 y = wwin->frame->top_width;
1773 while (h > wwin->frame->top_width + 1) {
1774 XMoveWindow(dpy, wwin->client_win, 0, y);
1775 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1776 XFlush(dpy);
1778 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1779 break;
1781 if (SHADE_DELAY > 0) {
1782 wusleep(SHADE_DELAY * 1000L);
1783 } else {
1784 wusleep(10);
1786 h -= s;
1787 y -= s;
1789 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1791 break;
1793 case UNSHADE:
1794 h = wwin->frame->top_width + wwin->frame->bottom_width;
1795 y = wwin->frame->top_width - wwin->client.height;
1796 s = abs(y) / SHADE_STEPS;
1797 if (s < 1)
1798 s = 1;
1799 w = wwin->frame->core->width;
1800 XMoveWindow(dpy, wwin->client_win, 0, y);
1801 if (s > 0) {
1802 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
1803 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1804 XMoveWindow(dpy, wwin->client_win, 0, y);
1805 XFlush(dpy);
1806 if (SHADE_DELAY > 0) {
1807 wusleep(SHADE_DELAY * 2000L / 3);
1808 } else {
1809 wusleep(10);
1811 h += s;
1812 y += s;
1814 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1815 break;
1818 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1819 break;
1822 #endif