Remove MINIATURIZE_ANIMATION_DELAY_{Z,F,T} tests
[wmaker-crm.git] / src / actions.c
blob5cb0f40b7a1b2d804e1c3ba77e556b2445a13b6a
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"
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <math.h>
32 #include <time.h>
34 #include "WindowMaker.h"
35 #include "wcore.h"
36 #include "framewin.h"
37 #include "window.h"
38 #include "client.h"
39 #include "icon.h"
40 #include "funcs.h"
41 #include "application.h"
42 #include "actions.h"
43 #include "stacking.h"
44 #include "appicon.h"
45 #include "dock.h"
46 #include "appmenu.h"
47 #include "winspector.h"
48 #include "workspace.h"
49 #include "xinerama.h"
51 /****** Global Variables ******/
52 extern Time LastTimestamp;
53 extern Time LastFocusChange;
55 extern Cursor wCursor[WCUR_LAST];
57 extern WPreferences wPreferences;
59 extern Atom _XA_WM_TAKE_FOCUS;
61 extern void ProcessPendingEvents();
62 extern int calcIntersectionLength(int p1, int l1, int p2, int l2);
64 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
65 unsigned int *new_width, unsigned int *new_height);
66 static void save_old_geometry(WWindow *wwin);
68 /******* Local Variables *******/
69 static struct {
70 int steps;
71 int delay;
72 } shadePars[5] = {
74 SHADE_STEPS_UF, SHADE_DELAY_UF}, {
75 SHADE_STEPS_F, SHADE_DELAY_F}, {
76 SHADE_STEPS_M, SHADE_DELAY_M}, {
77 SHADE_STEPS_S, SHADE_DELAY_S}, {
78 SHADE_STEPS_US, SHADE_DELAY_US}};
80 #define UNSHADE 0
81 #define SHADE 1
82 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
83 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
85 static int compareTimes(Time t1, Time t2)
87 Time diff;
88 if (t1 == t2)
89 return 0;
90 diff = t1 - t2;
91 return (diff < 60000) ? 1 : -1;
95 *----------------------------------------------------------------------
96 * wSetFocusTo--
97 * Changes the window focus to the one passed as argument.
98 * If the window to focus is not already focused, it will be brought
99 * to the head of the list of windows. Previously focused window is
100 * unfocused.
102 * Side effects:
103 * Window list may be reordered and the window focus is changed.
105 *----------------------------------------------------------------------
107 void wSetFocusTo(WScreen * scr, WWindow * wwin)
109 static WScreen *old_scr = NULL;
111 WWindow *old_focused;
112 WWindow *focused = scr->focused_window;
113 Time timestamp = LastTimestamp;
114 WApplication *oapp = NULL, *napp = NULL;
115 int wasfocused;
117 if (scr->flags.ignore_focus_events || compareTimes(LastFocusChange, timestamp) > 0)
118 return;
120 if (!old_scr)
121 old_scr = scr;
122 old_focused = old_scr->focused_window;
124 LastFocusChange = timestamp;
126 if (old_focused)
127 oapp = wApplicationOf(old_focused->main_window);
129 if (wwin == NULL) {
130 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
131 if (old_focused) {
132 wWindowUnfocus(old_focused);
134 if (oapp) {
135 wAppMenuUnmap(oapp->menu);
136 #ifdef NEWAPPICON
137 wApplicationDeactivate(oapp);
138 #endif
141 WMPostNotificationName(WMNChangedFocus, NULL, (void *)True);
142 return;
143 } else if (old_scr != scr && old_focused) {
144 wWindowUnfocus(old_focused);
147 wasfocused = wwin->flags.focused;
148 napp = wApplicationOf(wwin->main_window);
150 /* remember last workspace where the app has been */
151 if (napp) {
152 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
153 napp->last_workspace = wwin->frame->workspace;
156 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
157 /* install colormap if colormap mode is lock mode */
158 if (wPreferences.colormap_mode == WCM_CLICK)
159 wColormapInstallForWindow(scr, wwin);
161 /* set input focus */
162 switch (wwin->focus_mode) {
163 case WFM_NO_INPUT:
164 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
165 break;
167 case WFM_PASSIVE:
168 case WFM_LOCALLY_ACTIVE:
169 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
170 break;
172 case WFM_GLOBALLY_ACTIVE:
173 break;
175 XFlush(dpy);
176 if (wwin->protocols.TAKE_FOCUS) {
177 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
179 XSync(dpy, False);
180 } else {
181 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
183 if (WFLAGP(wwin, no_focusable))
184 return;
186 /* if this is not the focused window focus it */
187 if (focused != wwin) {
188 /* change the focus window list order */
189 if (wwin->prev)
190 wwin->prev->next = wwin->next;
192 if (wwin->next)
193 wwin->next->prev = wwin->prev;
195 wwin->prev = focused;
196 focused->next = wwin;
197 wwin->next = NULL;
198 scr->focused_window = wwin;
200 if (oapp && oapp != napp) {
201 wAppMenuUnmap(oapp->menu);
202 #ifdef NEWAPPICON
203 wApplicationDeactivate(oapp);
204 #endif
208 wWindowFocus(wwin, focused);
210 if (napp && !wasfocused) {
211 #ifdef USER_MENU
212 wUserMenuRefreshInstances(napp->menu, wwin);
213 #endif /* USER_MENU */
215 if (wwin->flags.mapped)
216 wAppMenuMap(napp->menu, wwin);
217 #ifdef NEWAPPICON
218 wApplicationActivate(napp);
219 #endif
222 XFlush(dpy);
223 old_scr = scr;
226 void wShadeWindow(WWindow *wwin)
229 if (wwin->flags.shaded)
230 return;
232 XLowerWindow(dpy, wwin->client_win);
233 shade_animate(wwin, SHADE);
235 wwin->flags.skip_next_animation = 0;
236 wwin->flags.shaded = 1;
237 wwin->flags.mapped = 0;
238 /* prevent window withdrawal when getting UnmapNotify */
239 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
240 XUnmapWindow(dpy, wwin->client_win);
241 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
243 /* for the client it's just like iconification */
244 wFrameWindowResize(wwin->frame, wwin->frame->core->width, wwin->frame->top_width - 1);
246 wwin->client.y = wwin->frame_y - wwin->client.height + wwin->frame->top_width;
247 wWindowSynthConfigureNotify(wwin);
250 wClientSetState(wwin, IconicState, None);
253 WMPostNotificationName(WMNChangedState, wwin, "shade");
255 #ifdef ANIMATIONS
256 if (!wwin->screen_ptr->flags.startup) {
257 /* Catch up with events not processed while animation was running */
258 ProcessPendingEvents();
260 #endif
263 void wUnshadeWindow(WWindow *wwin)
266 if (!wwin->flags.shaded)
267 return;
269 wwin->flags.shaded = 0;
270 wwin->flags.mapped = 1;
271 XMapWindow(dpy, wwin->client_win);
273 shade_animate(wwin, UNSHADE);
275 wwin->flags.skip_next_animation = 0;
276 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
277 wwin->frame->top_width + wwin->client.height + wwin->frame->bottom_width);
279 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
280 wWindowSynthConfigureNotify(wwin);
283 wClientSetState(wwin, NormalState, None);
285 /* if the window is focused, set the focus again as it was disabled during
286 * shading */
287 if (wwin->flags.focused)
288 wSetFocusTo(wwin->screen_ptr, wwin);
290 WMPostNotificationName(WMNChangedState, wwin, "shade");
293 /* Set the old coordinates using the current values */
294 static void save_old_geometry(WWindow *wwin)
296 wwin->old_geometry.width = wwin->client.width;
297 wwin->old_geometry.height = wwin->client.height;
298 wwin->old_geometry.x = wwin->frame_x;
299 wwin->old_geometry.y = wwin->frame_y;
302 void wMaximizeWindow(WWindow * wwin, int directions)
304 int new_x, new_y;
305 unsigned int new_width, new_height, half_scr_width;
306 WArea usableArea, totalArea;
307 Bool has_border = 1;
308 int adj_size;
310 if (!IS_RESIZABLE(wwin))
311 return;
313 if (!HAS_BORDER(wwin))
314 has_border = 0;
316 /* the size to adjust the geometry */
317 adj_size = FRAME_BORDER_WIDTH * 2 * has_border;
319 /* save old coordinates before we change the current values */
320 save_old_geometry(wwin);
322 totalArea.x1 = 0;
323 totalArea.y1 = 0;
324 totalArea.x2 = wwin->screen_ptr->scr_width;
325 totalArea.y2 = wwin->screen_ptr->scr_height;
326 usableArea = totalArea;
328 if (!(directions & MAX_IGNORE_XINERAMA)) {
329 WScreen *scr = wwin->screen_ptr;
330 int head;
332 if (directions & MAX_KEYBOARD)
333 head = wGetHeadForWindow(wwin);
334 else
335 head = wGetHeadForPointerLocation(scr);
337 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
340 /* Only save directions, not kbd or xinerama hints */
341 directions &= (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_MAXIMUS);
343 if (WFLAGP(wwin, full_maximize)) {
344 usableArea = totalArea;
346 half_scr_width = (usableArea.x2 - usableArea.x1)/2;
348 if (wwin->flags.shaded) {
349 wwin->flags.skip_next_animation = 1;
350 wUnshadeWindow(wwin);
353 if (directions & MAX_HORIZONTAL) {
354 new_width = usableArea.x2 - usableArea.x1 - adj_size;
355 new_x = usableArea.x1;
356 } else if (directions & MAX_LEFTHALF) {
357 new_width = half_scr_width - adj_size;
358 new_x = usableArea.x1;
359 } else if (directions & MAX_RIGHTHALF) {
360 new_width = half_scr_width - adj_size;
361 new_x = usableArea.x1 + half_scr_width;
362 } else {
363 new_x = wwin->frame_x;
364 new_width = wwin->frame->core->width;
367 if (directions & MAX_VERTICAL) {
368 new_height = usableArea.y2 - usableArea.y1 - adj_size;
369 new_y = usableArea.y1;
370 if (WFLAGP(wwin, full_maximize)) {
371 new_y -= wwin->frame->top_width;
372 new_height += wwin->frame->bottom_width - 1;
374 } else {
375 new_y = wwin->frame_y;
376 new_height = wwin->frame->core->height;
379 if (!WFLAGP(wwin, full_maximize)) {
380 new_height -= wwin->frame->top_width + wwin->frame->bottom_width;
383 if (directions & MAX_MAXIMUS) {
384 find_Maximus_geometry(wwin, usableArea, &new_x, &new_y, &new_width, &new_height);
385 if (WFLAGP(wwin, full_maximize) && new_y == 0) {
386 new_y -= wwin->frame->top_width;
387 new_height += wwin->frame->top_width - 1;
391 wWindowConstrainSize(wwin, &new_width, &new_height);
393 wWindowCropSize(wwin, usableArea.x2 - usableArea.x1,
394 usableArea.y2 - usableArea.y1, &new_width, &new_height);
396 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
398 WMPostNotificationName(WMNChangedState, wwin, "maximize");
400 /* set maximization state */
401 wwin->flags.maximized = directions;
405 * Maximus: tiled maximization (maximize without overlapping other windows)
407 * The window to be maximized will be denoted by w_0 (sub-index zero)
408 * while the windows which will stop the maximization of w_0 are denoted by w_j.
410 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
411 unsigned int *new_width, unsigned int *new_height)
413 WWindow *tmp;
414 int x_0 = wwin->frame_x;
415 int y_0 = wwin->frame_y;
416 int width_0 = wwin->frame->core->width;
417 int height_0 = wwin->frame->core->height;
418 int botton_0 = y_0 + height_0;
419 int right_border_0 = x_0 + width_0;
420 int new_x_0, new_y_0, new_botton_0, new_right_border_0, new_height_0;
421 int x_j, y_j, width_j, height_j, botton_j, top_j, right_border_j;
422 int x_intsect, y_intsect;
423 short int tbar_height_0 = 0, rbar_height_0 = 0;
424 short int bd_width_0 = 0, bd_width_j = 0;
425 short int adjust_height;
427 /* Try to fully maximize first, then readjust later */
428 new_x_0 = usableArea.x1;
429 new_y_0 = usableArea.y1;
430 new_botton_0 = usableArea.y2;
431 new_right_border_0 = usableArea.x2;
433 if (HAS_TITLEBAR(wwin))
434 tbar_height_0 = TITLEBAR_HEIGHT;
435 if (HAS_RESIZEBAR(wwin))
436 rbar_height_0 = RESIZEBAR_HEIGHT;
437 if (HAS_BORDER(wwin))
438 bd_width_0 = FRAME_BORDER_WIDTH;
440 /* the lengths to be subtracted if w_0 has titlebar, etc */
441 adjust_height = tbar_height_0 + 2 * bd_width_0 + rbar_height_0;
443 tmp = wwin;
444 /* The focused window is always the last in the list */
445 while (tmp->prev) {
446 /* ignore windows in other workspaces etc */
447 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
448 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
449 tmp = tmp->prev;
450 continue;
452 tmp = tmp->prev;
454 if (HAS_BORDER(tmp))
455 bd_width_j = FRAME_BORDER_WIDTH;
456 else
457 bd_width_j = 0;
460 * Set the w_j window coordinates. It is convenient
461 * to not use "corrected" sizes for width and height,
462 * otherwise bottom_j and right_border_j would be
463 * incorrect.
465 x_j = tmp->frame_x - bd_width_j;
466 y_j = tmp->frame_y - bd_width_j;
467 width_j = tmp->frame->core->width;
468 height_j = tmp->frame->core->height;
469 botton_j = y_j + height_j + bd_width_j;
470 top_j = y_j - bd_width_j;
471 right_border_j = x_j + width_j + bd_width_j;
473 /* Try to maximize in the y direction first */
474 x_intsect = calcIntersectionLength(x_0, width_0, x_j, width_j);
475 if (x_intsect != 0) {
476 /* TODO: Consider the case when coords are equal */
477 if (botton_j < y_0 && botton_j > new_y_0) {
478 /* w_0 is below the botton of w_j */
479 new_y_0 = botton_j;
481 if (botton_0 < top_j && top_j < new_botton_0) {
482 /* The botton of w_0 is above the top of w_j */
483 new_botton_0 = top_j;
488 tmp = wwin;
489 while (tmp->prev) {
490 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
491 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
492 tmp = tmp->prev;
493 continue;
495 tmp = tmp->prev;
497 if (HAS_BORDER(tmp))
498 bd_width_j = FRAME_BORDER_WIDTH;
499 else
500 bd_width_j = 0;
502 /* set the w_j window coordinates */
503 x_j = tmp->frame_x - bd_width_j;
504 y_j = tmp->frame_y - bd_width_j;
505 width_j = tmp->frame->core->width;
506 height_j = tmp->frame->core->height;
507 botton_j = y_j + height_j + bd_width_j;
508 top_j = y_j - bd_width_j;
509 right_border_j = x_j + width_j + bd_width_j;
512 * Use the updated y coordinates from the above step to account
513 * the possibility that the new value of y_0 will have different
514 * intersections with w_j
516 new_height_0 = new_botton_0 - new_y_0 - adjust_height;
517 y_intsect = calcIntersectionLength(new_y_0, new_height_0, y_j, height_j);
518 if (y_intsect != 0) {
519 if (right_border_j < x_0 && right_border_j > new_x_0) {
520 /* w_0 is completely to the right of w_j */
521 new_x_0 = right_border_j + 1;
523 if (right_border_0 < x_j && x_j < new_right_border_0) {
524 /* w_0 is completely to the left of w_j */
525 new_right_border_0 = x_j - 1;
530 new_height_0 = new_botton_0 - new_y_0 - adjust_height;
531 *new_x = new_x_0;
532 *new_y = new_y_0;
533 *new_height = new_height_0;
534 *new_width = new_right_border_0 - new_x_0;
537 void wUnmaximizeWindow(WWindow * wwin)
539 int x, y, w, h;
540 WMRect old_geom_rect;
541 int old_head;
542 Bool same_head;
544 if (!wwin->flags.maximized)
545 return;
547 if (wwin->flags.shaded) {
548 wwin->flags.skip_next_animation = 1;
549 wUnshadeWindow(wwin);
551 /* Use old coordinates if they are set, current values otherwise */
552 old_geom_rect = wmkrect(wwin->old_geometry.x, wwin->old_geometry.y, wwin->old_geometry.width, wwin->old_geometry.height);
553 old_head = wGetHeadForRect(wwin->screen_ptr, old_geom_rect);
554 same_head = (wGetHeadForWindow(wwin) == old_head);
555 x = (wwin->old_geometry.x && same_head) ? wwin->old_geometry.x : wwin->frame_x;
556 y = (wwin->old_geometry.y && same_head) ? wwin->old_geometry.y : wwin->frame_y;
557 w = wwin->old_geometry.width ? wwin->old_geometry.width : wwin->client.width;
558 h = wwin->old_geometry.height ? wwin->old_geometry.height : wwin->client.height;
560 wwin->flags.maximized = 0;
561 wWindowConfigure(wwin, x, y, w, h);
563 WMPostNotificationName(WMNChangedState, wwin, "maximize");
566 void wFullscreenWindow(WWindow * wwin)
568 int head;
569 WMRect rect;
571 if (wwin->flags.fullscreen)
572 return;
574 wwin->flags.fullscreen = True;
576 wWindowConfigureBorders(wwin);
578 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
580 wwin->bfs_geometry.x = wwin->frame_x;
581 wwin->bfs_geometry.y = wwin->frame_y;
582 wwin->bfs_geometry.width = wwin->frame->core->width;
583 wwin->bfs_geometry.height = wwin->frame->core->height;
585 head = wGetHeadForWindow(wwin);
586 rect = wGetRectForHead(wwin->screen_ptr, head);
587 wWindowConfigure(wwin, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
589 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
592 void wUnfullscreenWindow(WWindow * wwin)
594 if (!wwin->flags.fullscreen)
595 return;
597 wwin->flags.fullscreen = False;
599 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
600 if (WFLAGP(wwin, sunken)) {
601 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
602 } else if (WFLAGP(wwin, floating)) {
603 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
604 } else {
605 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
609 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
610 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
612 wWindowConfigureBorders(wwin);
614 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
615 wFrameWindowPaint(wwin->frame);
618 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
621 #ifdef ANIMATIONS
622 static void animateResizeFlip(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
624 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
625 float cx, cy, cw, ch;
626 float xstep, ystep, wstep, hstep;
627 XPoint points[5];
628 float dx, dch, midy;
629 float angle, final_angle, delta;
631 xstep = (float)(fx - x) / steps;
632 ystep = (float)(fy - y) / steps;
633 wstep = (float)(fw - w) / steps;
634 hstep = (float)(fh - h) / steps;
636 cx = (float)x;
637 cy = (float)y;
638 cw = (float)w;
639 ch = (float)h;
641 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_F;
642 delta = (float)(final_angle / FRAMES);
643 for (angle = 0;; angle += delta) {
644 if (angle > final_angle)
645 angle = final_angle;
647 dx = (cw / 10) - ((cw / 5) * sin(angle));
648 dch = (ch / 2) * cos(angle);
649 midy = cy + (ch / 2);
651 points[0].x = cx + dx;
652 points[0].y = midy - dch;
653 points[1].x = cx + cw - dx;
654 points[1].y = points[0].y;
655 points[2].x = cx + cw + dx;
656 points[2].y = midy + dch;
657 points[3].x = cx - dx;
658 points[3].y = points[2].y;
659 points[4].x = points[0].x;
660 points[4].y = points[0].y;
662 XGrabServer(dpy);
663 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
664 XFlush(dpy);
665 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
667 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
668 XUngrabServer(dpy);
669 cx += xstep;
670 cy += ystep;
671 cw += wstep;
672 ch += hstep;
673 if (angle >= final_angle)
674 break;
677 XFlush(dpy);
680 #undef FRAMES
682 static void
683 animateResizeTwist(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
685 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
686 float cx, cy, cw, ch;
687 float xstep, ystep, wstep, hstep;
688 XPoint points[5];
689 float angle, final_angle, a, d, delta;
691 x += w / 2;
692 y += h / 2;
693 fx += fw / 2;
694 fy += fh / 2;
696 xstep = (float)(fx - x) / steps;
697 ystep = (float)(fy - y) / steps;
698 wstep = (float)(fw - w) / steps;
699 hstep = (float)(fh - h) / steps;
701 cx = (float)x;
702 cy = (float)y;
703 cw = (float)w;
704 ch = (float)h;
706 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_T;
707 delta = (float)(final_angle / FRAMES);
708 for (angle = 0;; angle += delta) {
709 if (angle > final_angle)
710 angle = final_angle;
712 a = atan(ch / cw);
713 d = sqrt((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
715 points[0].x = cx + cos(angle - a) * d;
716 points[0].y = cy + sin(angle - a) * d;
717 points[1].x = cx + cos(angle + a) * d;
718 points[1].y = cy + sin(angle + a) * d;
719 points[2].x = cx + cos(angle - a + WM_PI) * d;
720 points[2].y = cy + sin(angle - a + WM_PI) * d;
721 points[3].x = cx + cos(angle + a + WM_PI) * d;
722 points[3].y = cy + sin(angle + a + WM_PI) * d;
723 points[4].x = cx + cos(angle - a) * d;
724 points[4].y = cy + sin(angle - a) * d;
725 XGrabServer(dpy);
726 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
727 XFlush(dpy);
728 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
730 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
731 XUngrabServer(dpy);
732 cx += xstep;
733 cy += ystep;
734 cw += wstep;
735 ch += hstep;
736 if (angle >= final_angle)
737 break;
740 XFlush(dpy);
743 #undef FRAMES
745 static void animateResizeZoom(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
747 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
748 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
749 float xstep, ystep, wstep, hstep;
750 int i, j;
752 xstep = (float)(fx - x) / steps;
753 ystep = (float)(fy - y) / steps;
754 wstep = (float)(fw - w) / steps;
755 hstep = (float)(fh - h) / steps;
757 for (j = 0; j < FRAMES; j++) {
758 cx[j] = (float)x;
759 cy[j] = (float)y;
760 cw[j] = (float)w;
761 ch[j] = (float)h;
763 XGrabServer(dpy);
764 for (i = 0; i < steps; i++) {
765 for (j = 0; j < FRAMES; j++) {
766 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
767 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
769 XFlush(dpy);
770 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
772 for (j = 0; j < FRAMES; j++) {
773 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
774 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
775 if (j < FRAMES - 1) {
776 cx[j] = cx[j + 1];
777 cy[j] = cy[j + 1];
778 cw[j] = cw[j + 1];
779 ch[j] = ch[j + 1];
780 } else {
781 cx[j] += xstep;
782 cy[j] += ystep;
783 cw[j] += wstep;
784 ch[j] += hstep;
789 for (j = 0; j < FRAMES; j++) {
790 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
792 XFlush(dpy);
793 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
795 for (j = 0; j < FRAMES; j++) {
796 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
799 XUngrabServer(dpy);
802 #undef FRAMES
804 void animateResize(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh)
806 int style = wPreferences.iconification_style; /* Catch the value */
807 int steps;
809 if (style == WIS_NONE)
810 return;
812 if (style == WIS_RANDOM) {
813 style = rand() % 3;
816 switch (style) {
817 case WIS_TWIST:
818 steps = MINIATURIZE_ANIMATION_STEPS_T;
819 if (steps > 0)
820 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
821 break;
822 case WIS_FLIP:
823 steps = MINIATURIZE_ANIMATION_STEPS_F;
824 if (steps > 0)
825 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
826 break;
827 case WIS_ZOOM:
828 default:
829 steps = MINIATURIZE_ANIMATION_STEPS_Z;
830 if (steps > 0)
831 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
832 break;
835 #endif /* ANIMATIONS */
837 static void flushExpose()
839 XEvent tmpev;
841 while (XCheckTypedEvent(dpy, Expose, &tmpev))
842 WMHandleEvent(&tmpev);
843 XSync(dpy, 0);
846 static void unmapTransientsFor(WWindow * wwin)
848 WWindow *tmp;
850 tmp = wwin->screen_ptr->focused_window;
851 while (tmp) {
852 /* unmap the transients for this transient */
853 if (tmp != wwin && tmp->transient_for == wwin->client_win
854 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup || tmp->flags.shaded)) {
855 unmapTransientsFor(tmp);
856 tmp->flags.miniaturized = 1;
857 if (!tmp->flags.shaded) {
858 wWindowUnmap(tmp);
859 } else {
860 XUnmapWindow(dpy, tmp->frame->core->window);
863 if (!tmp->flags.shaded)
865 wClientSetState(tmp, IconicState, None);
867 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
869 tmp = tmp->prev;
873 static void mapTransientsFor(WWindow * wwin)
875 WWindow *tmp;
877 tmp = wwin->screen_ptr->focused_window;
878 while (tmp) {
879 /* recursively map the transients for this transient */
880 if (tmp != wwin && tmp->transient_for == wwin->client_win && /*!tmp->flags.mapped */ tmp->flags.miniaturized
881 && tmp->icon == NULL) {
882 mapTransientsFor(tmp);
883 tmp->flags.miniaturized = 0;
884 if (!tmp->flags.shaded) {
885 wWindowMap(tmp);
886 } else {
887 XMapWindow(dpy, tmp->frame->core->window);
889 tmp->flags.semi_focused = 0;
891 if (!tmp->flags.shaded)
893 wClientSetState(tmp, NormalState, None);
895 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
897 tmp = tmp->prev;
901 #if 0
902 static void setupIconGrabs(WIcon * icon)
904 /* setup passive grabs on the icon */
905 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
906 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
907 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
908 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
909 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
910 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
911 XSync(dpy, 0);
913 #endif
915 static WWindow *recursiveTransientFor(WWindow * wwin)
917 int i;
919 if (!wwin)
920 return None;
922 /* hackish way to detect transient_for cycle */
923 i = wwin->screen_ptr->window_count + 1;
925 while (wwin && wwin->transient_for != None && i > 0) {
926 wwin = wWindowFor(wwin->transient_for);
927 i--;
929 if (i == 0 && wwin) {
930 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin->frame->title);
931 return NULL;
934 return wwin;
937 #if 0
938 static void removeIconGrabs(WIcon * icon)
940 /* remove passive grabs on the icon */
941 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
942 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
943 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
944 XSync(dpy, 0);
946 #endif
948 void wIconifyWindow(WWindow * wwin)
950 XWindowAttributes attribs;
951 int present;
953 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
954 /* the window doesn't exist anymore */
955 return;
958 if (wwin->flags.miniaturized) {
959 return;
962 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
963 WWindow *owner = wWindowFor(wwin->transient_for);
965 if (owner && owner->flags.miniaturized)
966 return;
969 present = wwin->frame->workspace == wwin->screen_ptr->current_workspace;
971 /* if the window is in another workspace, simplify process */
972 if (present) {
973 /* icon creation may take a while */
974 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
975 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
976 GrabModeAsync, None, None, CurrentTime);
979 if (!wPreferences.disable_miniwindows
980 #ifdef NETWM_HINTS
981 && !wwin->flags.net_handle_icon
982 #endif
984 if (!wwin->flags.icon_moved) {
985 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
987 wwin->icon = wIconCreate(wwin);
989 wwin->icon->mapped = 1;
992 wwin->flags.miniaturized = 1;
993 wwin->flags.mapped = 0;
995 /* unmap transients */
997 unmapTransientsFor(wwin);
999 if (present) {
1000 XUngrabPointer(dpy, CurrentTime);
1001 wWindowUnmap(wwin);
1002 /* let all Expose events arrive so that we can repaint
1003 * something before the animation starts (and the server is grabbed) */
1004 XSync(dpy, 0);
1006 if (wPreferences.disable_miniwindows
1007 #ifdef NETWM_HINTS
1008 || wwin->flags.net_handle_icon
1009 #endif
1011 wClientSetState(wwin, IconicState, None);
1012 else
1013 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
1015 flushExpose();
1016 #ifdef ANIMATIONS
1017 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
1018 && !wPreferences.no_animations) {
1019 int ix, iy, iw, ih;
1021 if (!wPreferences.disable_miniwindows
1022 #ifdef NETWM_HINTS
1023 && !wwin->flags.net_handle_icon
1024 #endif
1026 ix = wwin->icon_x;
1027 iy = wwin->icon_y;
1028 iw = wwin->icon->core->width;
1029 ih = wwin->icon->core->height;
1030 } else {
1031 #ifdef NETWM_HINTS
1032 if (wwin->flags.net_handle_icon) {
1033 ix = wwin->icon_x;
1034 iy = wwin->icon_y;
1035 iw = wwin->icon_w;
1036 ih = wwin->icon_h;
1037 } else
1038 #endif
1040 ix = 0;
1041 iy = 0;
1042 iw = wwin->screen_ptr->scr_width;
1043 ih = wwin->screen_ptr->scr_height;
1046 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1047 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih);
1049 #endif
1052 wwin->flags.skip_next_animation = 0;
1054 if (!wPreferences.disable_miniwindows
1055 #ifdef NETWM_HINTS
1056 && !wwin->flags.net_handle_icon
1057 #endif
1060 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace ||
1061 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1063 XMapWindow(dpy, wwin->icon->core->window);
1065 AddToStackList(wwin->icon->core);
1067 wLowerFrame(wwin->icon->core);
1070 if (present) {
1071 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1074 * It doesn't seem to be working and causes button event hangup
1075 * when deiconifying a transient window.
1076 setupIconGrabs(wwin->icon);
1078 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
1079 && wPreferences.focus_mode == WKF_CLICK) {
1080 WWindow *tmp;
1082 tmp = wwin->prev;
1083 while (tmp) {
1084 if (!WFLAGP(tmp, no_focusable)
1085 && !(tmp->flags.hidden || tmp->flags.miniaturized)
1086 && (wwin->frame->workspace == tmp->frame->workspace))
1087 break;
1088 tmp = tmp->prev;
1090 wSetFocusTo(wwin->screen_ptr, tmp);
1091 } else if (wPreferences.focus_mode != WKF_CLICK) {
1092 wSetFocusTo(wwin->screen_ptr, NULL);
1094 #ifdef ANIMATIONS
1095 if (!wwin->screen_ptr->flags.startup) {
1096 /* Catch up with events not processed while animation was running */
1097 Window clientwin = wwin->client_win;
1099 ProcessPendingEvents();
1101 /* the window can disappear while ProcessPendingEvents() runs */
1102 if (!wWindowFor(clientwin)) {
1103 return;
1106 #endif
1109 /* maybe we want to do this regardless of net_handle_icon
1110 * it seems to me we might break behaviour this way.
1112 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1113 #ifdef NETWM_HINTS
1114 && !wwin->flags.net_handle_icon
1115 #endif
1117 wIconSelect(wwin->icon);
1119 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1121 if (wPreferences.auto_arrange_icons)
1122 wArrangeIcons(wwin->screen_ptr, True);
1125 void wDeiconifyWindow(WWindow * wwin)
1127 #ifdef NETWM_HINTS
1128 /* we're hiding for show_desktop */
1129 int netwm_hidden = wwin->flags.net_show_desktop &&
1130 wwin->frame->workspace != wwin->screen_ptr->current_workspace;
1131 #else
1132 int netwm_hidden = False;
1133 #endif
1135 if (!netwm_hidden)
1136 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1138 if (!wwin->flags.miniaturized)
1139 return;
1141 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1142 WWindow *owner = recursiveTransientFor(wwin);
1144 if (owner && owner->flags.miniaturized) {
1145 wDeiconifyWindow(owner);
1146 wSetFocusTo(wwin->screen_ptr, wwin);
1147 wRaiseFrame(wwin->frame->core);
1148 return;
1152 wwin->flags.miniaturized = 0;
1154 if (!netwm_hidden && !wwin->flags.shaded) {
1155 wwin->flags.mapped = 1;
1158 if (!netwm_hidden || wPreferences.sticky_icons) {
1159 /* maybe we want to do this regardless of net_handle_icon
1160 * it seems to me we might break behaviour this way.
1162 if (!wPreferences.disable_miniwindows
1163 #ifdef NETWM_HINTS
1164 && !wwin->flags.net_handle_icon
1165 #endif
1166 && wwin->icon != NULL) {
1167 if (wwin->icon->selected)
1168 wIconSelect(wwin->icon);
1170 XUnmapWindow(dpy, wwin->icon->core->window);
1174 /* if the window is in another workspace, do it silently */
1175 if (!netwm_hidden) {
1176 #ifdef ANIMATIONS
1177 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1178 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1179 int ix, iy, iw, ih;
1181 if (!wPreferences.disable_miniwindows
1182 #ifdef NETWM_HINTS
1183 && !wwin->flags.net_handle_icon
1184 #endif
1186 ix = wwin->icon_x;
1187 iy = wwin->icon_y;
1188 iw = wwin->icon->core->width;
1189 ih = wwin->icon->core->height;
1190 } else {
1191 #ifdef NETWM_HINTS
1192 if (wwin->flags.net_handle_icon) {
1193 ix = wwin->icon_x;
1194 iy = wwin->icon_y;
1195 iw = wwin->icon_w;
1196 ih = wwin->icon_h;
1197 } else
1198 #endif
1200 ix = 0;
1201 iy = 0;
1202 iw = wwin->screen_ptr->scr_width;
1203 ih = wwin->screen_ptr->scr_height;
1206 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1207 wwin->frame_x, wwin->frame_y,
1208 wwin->frame->core->width, wwin->frame->core->height);
1210 #endif /* ANIMATIONS */
1211 wwin->flags.skip_next_animation = 0;
1212 XGrabServer(dpy);
1213 if (!wwin->flags.shaded) {
1214 XMapWindow(dpy, wwin->client_win);
1216 XMapWindow(dpy, wwin->frame->core->window);
1217 wRaiseFrame(wwin->frame->core);
1218 if (!wwin->flags.shaded) {
1219 wClientSetState(wwin, NormalState, None);
1221 mapTransientsFor(wwin);
1224 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1225 #ifdef NETWM_HINTS
1226 && !wwin->flags.net_handle_icon
1227 #endif
1229 RemoveFromStackList(wwin->icon->core);
1230 /* removeIconGrabs(wwin->icon); */
1231 wIconDestroy(wwin->icon);
1232 wwin->icon = NULL;
1235 if (!netwm_hidden) {
1236 XUngrabServer(dpy);
1238 wSetFocusTo(wwin->screen_ptr, wwin);
1240 #ifdef ANIMATIONS
1241 if (!wwin->screen_ptr->flags.startup) {
1242 /* Catch up with events not processed while animation was running */
1243 Window clientwin = wwin->client_win;
1245 ProcessPendingEvents();
1247 /* the window can disappear while ProcessPendingEvents() runs */
1248 if (!wWindowFor(clientwin)) {
1249 return;
1252 #endif
1255 if (wPreferences.auto_arrange_icons) {
1256 wArrangeIcons(wwin->screen_ptr, True);
1259 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1261 /* In case we were shaded and iconified, also unshade */
1262 if (!netwm_hidden)
1263 wUnshadeWindow(wwin);
1266 static void hideWindow(WIcon * icon, int icon_x, int icon_y, WWindow * wwin, int animate)
1268 if (wwin->flags.miniaturized) {
1269 if (wwin->icon) {
1270 XUnmapWindow(dpy, wwin->icon->core->window);
1271 wwin->icon->mapped = 0;
1273 wwin->flags.hidden = 1;
1275 WMPostNotificationName(WMNChangedState, wwin, "hide");
1276 return;
1279 if (wwin->flags.inspector_open) {
1280 wHideInspectorForWindow(wwin);
1283 wwin->flags.hidden = 1;
1284 wWindowUnmap(wwin);
1286 wClientSetState(wwin, IconicState, icon->icon_win);
1287 flushExpose();
1289 #ifdef ANIMATIONS
1290 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1291 !wwin->flags.skip_next_animation && animate) {
1292 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1293 wwin->frame->core->width, wwin->frame->core->height,
1294 icon_x, icon_y, icon->core->width, icon->core->height);
1296 #endif
1297 wwin->flags.skip_next_animation = 0;
1299 WMPostNotificationName(WMNChangedState, wwin, "hide");
1302 void wHideOtherApplications(WWindow * awin)
1304 WWindow *wwin;
1305 WApplication *tapp;
1307 if (!awin)
1308 return;
1309 wwin = awin->screen_ptr->focused_window;
1311 while (wwin) {
1312 if (wwin != awin
1313 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1314 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1315 && !wwin->flags.internal_window
1316 && wGetWindowOfInspectorForWindow(wwin) != awin && !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 && awin->main_window != wwin->main_window) {
1324 tapp = wApplicationOf(wwin->main_window);
1325 if (tapp) {
1326 tapp->flags.skip_next_animation = 1;
1327 wHideApplication(tapp);
1328 } else {
1329 if (!WFLAGP(wwin, no_miniaturizable)) {
1330 wwin->flags.skip_next_animation = 1;
1331 wIconifyWindow(wwin);
1336 wwin = wwin->prev;
1339 wSetFocusTo(awin->screen_ptr, awin);
1343 void wHideApplication(WApplication * wapp)
1345 WScreen *scr;
1346 WWindow *wlist;
1347 int hadfocus;
1348 int animate;
1350 if (!wapp) {
1351 wwarning("trying to hide a non grouped window");
1352 return;
1354 if (!wapp->main_window_desc) {
1355 wwarning("group leader not found for window group");
1356 return;
1358 scr = wapp->main_window_desc->screen_ptr;
1359 hadfocus = 0;
1360 wlist = scr->focused_window;
1361 if (!wlist)
1362 return;
1364 if (wlist->main_window == wapp->main_window)
1365 wapp->last_focused = wlist;
1366 else
1367 wapp->last_focused = NULL;
1369 animate = !wapp->flags.skip_next_animation;
1371 while (wlist) {
1372 if (wlist->main_window == wapp->main_window) {
1373 if (wlist->flags.focused) {
1374 hadfocus = 1;
1376 if (wapp->app_icon) {
1377 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1378 wapp->app_icon->y_pos, wlist, animate);
1379 animate = False;
1382 wlist = wlist->prev;
1385 wapp->flags.skip_next_animation = 0;
1387 if (hadfocus) {
1388 if (wPreferences.focus_mode == WKF_CLICK) {
1389 wlist = scr->focused_window;
1390 while (wlist) {
1391 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1392 && (wlist->flags.mapped || wlist->flags.shaded))
1393 break;
1394 wlist = wlist->prev;
1396 wSetFocusTo(scr, wlist);
1397 } else {
1398 wSetFocusTo(scr, NULL);
1402 wapp->flags.hidden = 1;
1404 if (wPreferences.auto_arrange_icons) {
1405 wArrangeIcons(scr, True);
1407 #ifdef HIDDENDOT
1408 if (wapp->app_icon)
1409 wAppIconPaint(wapp->app_icon);
1410 #endif
1413 static void unhideWindow(WIcon * icon, int icon_x, int icon_y, WWindow * wwin, int animate, int bringToCurrentWS)
1415 if (bringToCurrentWS)
1416 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1418 wwin->flags.hidden = 0;
1420 #ifdef ANIMATIONS
1421 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1422 animateResize(wwin->screen_ptr, icon_x, icon_y,
1423 icon->core->width, icon->core->height,
1424 wwin->frame_x, wwin->frame_y,
1425 wwin->frame->core->width, wwin->frame->core->height);
1427 #endif
1428 wwin->flags.skip_next_animation = 0;
1429 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1430 XMapWindow(dpy, wwin->client_win);
1431 XMapWindow(dpy, wwin->frame->core->window);
1432 wClientSetState(wwin, NormalState, None);
1433 wwin->flags.mapped = 1;
1434 wRaiseFrame(wwin->frame->core);
1436 if (wwin->flags.inspector_open) {
1437 wUnhideInspectorForWindow(wwin);
1440 WMPostNotificationName(WMNChangedState, wwin, "hide");
1443 void wUnhideApplication(WApplication * wapp, Bool miniwindows, Bool bringToCurrentWS)
1445 WScreen *scr;
1446 WWindow *wlist, *next;
1447 WWindow *focused = NULL;
1448 int animate;
1450 if (!wapp)
1451 return;
1453 scr = wapp->main_window_desc->screen_ptr;
1454 wlist = scr->focused_window;
1455 if (!wlist)
1456 return;
1458 /* goto beginning of list */
1459 while (wlist->prev)
1460 wlist = wlist->prev;
1462 animate = !wapp->flags.skip_next_animation;
1464 while (wlist) {
1465 next = wlist->next;
1467 if (wlist->main_window == wapp->main_window) {
1468 if (wlist->flags.focused)
1469 focused = wlist;
1470 else if (!focused || !focused->flags.focused)
1471 focused = wlist;
1473 if (wlist->flags.miniaturized) {
1474 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1475 wlist->frame->workspace == scr->current_workspace) && wlist->icon) {
1476 if (!wlist->icon->mapped) {
1477 int x, y;
1479 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1480 if (wlist->icon_x != x || wlist->icon_y != y) {
1481 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1483 wlist->icon_x = x;
1484 wlist->icon_y = y;
1485 XMapWindow(dpy, wlist->icon->core->window);
1486 wlist->icon->mapped = 1;
1488 wRaiseFrame(wlist->icon->core);
1490 if (bringToCurrentWS)
1491 wWindowChangeWorkspace(wlist, scr->current_workspace);
1492 wlist->flags.hidden = 0;
1493 if (miniwindows && wlist->frame->workspace == scr->current_workspace) {
1494 wDeiconifyWindow(wlist);
1496 WMPostNotificationName(WMNChangedState, wlist, "hide");
1497 } else if (wlist->flags.shaded) {
1498 if (bringToCurrentWS)
1499 wWindowChangeWorkspace(wlist, scr->current_workspace);
1500 wlist->flags.hidden = 0;
1501 if (wlist->frame->workspace == scr->current_workspace) {
1502 XMapWindow(dpy, wlist->frame->core->window);
1503 if (miniwindows) {
1504 wUnshadeWindow(wlist);
1505 wRaiseFrame(wlist->frame->core);
1508 WMPostNotificationName(WMNChangedState, wlist, "hide");
1509 } else if (wlist->flags.hidden) {
1510 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1511 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1512 animate = False;
1513 } else {
1514 if (bringToCurrentWS && wlist->frame->workspace != scr->current_workspace) {
1515 wWindowChangeWorkspace(wlist, scr->current_workspace);
1517 wRaiseFrame(wlist->frame->core);
1520 wlist = next;
1523 wapp->flags.skip_next_animation = 0;
1524 wapp->flags.hidden = 0;
1526 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1527 wRaiseFrame(wapp->last_focused->frame->core);
1528 wSetFocusTo(scr, wapp->last_focused);
1529 } else if (focused) {
1530 wSetFocusTo(scr, focused);
1532 wapp->last_focused = NULL;
1533 if (wPreferences.auto_arrange_icons) {
1534 wArrangeIcons(scr, True);
1536 #ifdef HIDDENDOT
1537 wAppIconPaint(wapp->app_icon);
1538 #endif
1541 void wShowAllWindows(WScreen * scr)
1543 WWindow *wwin, *old_foc;
1544 WApplication *wapp;
1546 old_foc = wwin = scr->focused_window;
1547 while (wwin) {
1548 if (!wwin->flags.internal_window &&
1549 (scr->current_workspace == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1550 if (wwin->flags.miniaturized) {
1551 wwin->flags.skip_next_animation = 1;
1552 wDeiconifyWindow(wwin);
1553 } else if (wwin->flags.hidden) {
1554 wapp = wApplicationOf(wwin->main_window);
1555 if (wapp) {
1556 wUnhideApplication(wapp, False, False);
1557 } else {
1558 wwin->flags.skip_next_animation = 1;
1559 wDeiconifyWindow(wwin);
1563 wwin = wwin->prev;
1565 wSetFocusTo(scr, old_foc);
1566 /*wRaiseFrame(old_foc->frame->core); */
1569 void wRefreshDesktop(WScreen * scr)
1571 Window win;
1572 XSetWindowAttributes attr;
1574 attr.backing_store = NotUseful;
1575 attr.save_under = False;
1576 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1577 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1578 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1579 XMapRaised(dpy, win);
1580 XDestroyWindow(dpy, win);
1581 XFlush(dpy);
1584 void wArrangeIcons(WScreen * scr, Bool arrangeAll)
1586 WWindow *wwin;
1587 WAppIcon *aicon;
1589 int head;
1590 const int heads = wXineramaHeads(scr);
1592 struct HeadVars {
1593 int pf; /* primary axis */
1594 int sf; /* secondary axis */
1595 int fullW;
1596 int fullH;
1597 int pi, si;
1598 int sx1, sx2, sy1, sy2; /* screen boundary */
1599 int sw, sh;
1600 int xo, yo;
1601 int xs, ys;
1602 } *vars;
1604 int isize = wPreferences.icon_size;
1606 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
1608 for (head = 0; head < heads; ++head) {
1609 #if 0
1610 WMRect rect = wGetRectForHead(scr, head);
1611 #else
1612 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1613 WMRect rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
1614 #endif
1616 vars[head].pi = vars[head].si = 0;
1617 vars[head].sx1 = rect.pos.x;
1618 vars[head].sy1 = rect.pos.y;
1619 vars[head].sw = rect.size.width;
1620 vars[head].sh = rect.size.height;
1621 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1622 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1624 #if 0
1625 if (scr->dock) {
1626 if (scr->dock->on_right_side)
1627 vars[head].sx2 -= isize + DOCK_EXTRA_SPACE;
1628 else
1629 vars[head].sx1 += isize + DOCK_EXTRA_SPACE;
1631 #endif
1633 vars[head].sw = isize * (vars[head].sw / isize);
1634 vars[head].sh = isize * (vars[head].sh / isize);
1635 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
1636 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
1638 /* icon yard boundaries */
1639 if (wPreferences.icon_yard & IY_VERT) {
1640 vars[head].pf = vars[head].fullH;
1641 vars[head].sf = vars[head].fullW;
1642 } else {
1643 vars[head].pf = vars[head].fullW;
1644 vars[head].sf = vars[head].fullH;
1646 if (wPreferences.icon_yard & IY_RIGHT) {
1647 vars[head].xo = vars[head].sx2 - isize;
1648 vars[head].xs = -1;
1649 } else {
1650 vars[head].xo = vars[head].sx1;
1651 vars[head].xs = 1;
1653 if (wPreferences.icon_yard & IY_TOP) {
1654 vars[head].yo = vars[head].sy1;
1655 vars[head].ys = 1;
1656 } else {
1657 vars[head].yo = vars[head].sy2 - isize;
1658 vars[head].ys = -1;
1662 #define X ((wPreferences.icon_yard & IY_VERT) \
1663 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1664 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1666 #define Y ((wPreferences.icon_yard & IY_VERT) \
1667 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1668 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1670 /* arrange application icons */
1671 aicon = scr->app_icon_list;
1672 /* reverse them to avoid unnecessarily sliding of icons */
1673 while (aicon && aicon->next)
1674 aicon = aicon->next;
1676 while (aicon) {
1677 if (!aicon->docked) {
1678 /* CHECK: can icon be NULL here ? */
1679 /* The intention here is to place the AppIcon on the head that
1680 * contains most of the applications _main_ window. */
1681 head = wGetHeadForWindow(aicon->icon->owner);
1683 if (aicon->x_pos != X || aicon->y_pos != Y) {
1684 #ifdef ANIMATIONS
1685 if (!wPreferences.no_animations) {
1686 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1688 #endif /* ANIMATIONS */
1690 wAppIconMove(aicon, X, Y);
1691 vars[head].pi++;
1692 if (vars[head].pi >= vars[head].pf) {
1693 vars[head].pi = 0;
1694 vars[head].si++;
1697 aicon = aicon->prev;
1700 /* arrange miniwindows */
1701 wwin = scr->focused_window;
1702 /* reverse them to avoid unnecessarily shuffling */
1703 while (wwin && wwin->prev)
1704 wwin = wwin->prev;
1706 while (wwin) {
1707 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1708 (wwin->frame->workspace == scr->current_workspace ||
1709 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1711 head = wGetHeadForWindow(wwin);
1713 if (arrangeAll || !wwin->flags.icon_moved) {
1714 if (wwin->icon_x != X || wwin->icon_y != Y) {
1715 #ifdef ANIMATIONS
1716 if (wPreferences.no_animations) {
1717 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1718 } else {
1719 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1720 wwin->icon_y, X, Y);
1722 #else
1723 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1724 #endif /* ANIMATIONS */
1726 wwin->icon_x = X;
1727 wwin->icon_y = Y;
1729 vars[head].pi++;
1730 if (vars[head].pi >= vars[head].pf) {
1731 vars[head].pi = 0;
1732 vars[head].si++;
1736 if (arrangeAll) {
1737 wwin->flags.icon_moved = 0;
1739 /* we reversed the order, so we use next */
1740 wwin = wwin->next;
1743 wfree(vars);
1746 #if 0
1747 void wArrangeIcons(WScreen * scr, Bool arrangeAll)
1749 WWindow *wwin;
1750 WAppIcon *aicon;
1751 int pf; /* primary axis */
1752 int sf; /* secondary axis */
1753 int fullW;
1754 int fullH;
1755 int pi, si;
1756 int sx1, sx2, sy1, sy2; /* screen boundary */
1757 int sw, sh;
1758 int xo, yo;
1759 int xs, ys;
1760 int isize = wPreferences.icon_size;
1763 * Find out screen boundaries.
1767 * Allows each head to have miniwindows
1769 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1771 sx1 = rect.pos.x;
1772 sy1 = rect.pos.y;
1773 sw = rect.size.width;
1774 sh = rect.size.height;
1775 sx2 = sx1 + sw;
1776 sy2 = sy1 + sh;
1777 if (scr->dock) {
1778 if (scr->dock->on_right_side)
1779 sx2 -= isize + DOCK_EXTRA_SPACE;
1780 else
1781 sx1 += isize + DOCK_EXTRA_SPACE;
1783 #if 0
1784 sw = isize * (scr->scr_width / isize);
1785 sh = isize * (scr->scr_height / isize);
1786 #else
1787 sw = isize * (sw / isize);
1788 sh = isize * (sh / isize);
1789 #endif
1790 fullW = (sx2 - sx1) / isize;
1791 fullH = (sy2 - sy1) / isize;
1793 /* icon yard boundaries */
1794 if (wPreferences.icon_yard & IY_VERT) {
1795 pf = fullH;
1796 sf = fullW;
1797 } else {
1798 pf = fullW;
1799 sf = fullH;
1801 if (wPreferences.icon_yard & IY_RIGHT) {
1802 xo = sx2 - isize;
1803 xs = -1;
1804 } else {
1805 xo = sx1;
1806 xs = 1;
1808 if (wPreferences.icon_yard & IY_TOP) {
1809 yo = sy1;
1810 ys = 1;
1811 } else {
1812 yo = sy2 - isize;
1813 ys = -1;
1816 /* arrange icons putting the most recently focused window
1817 * as the last icon */
1818 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1819 : xo + xs*(pi*isize))
1820 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1821 : yo + ys*(si*isize))
1823 /* arrange application icons */
1824 aicon = scr->app_icon_list;
1825 /* reverse them to avoid unnecessarily sliding of icons */
1826 while (aicon && aicon->next)
1827 aicon = aicon->next;
1829 pi = 0;
1830 si = 0;
1831 while (aicon) {
1832 if (!aicon->docked) {
1833 if (aicon->x_pos != X || aicon->y_pos != Y) {
1834 #ifdef ANIMATIONS
1835 if (!wPreferences.no_animations) {
1836 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1838 #endif /* ANIMATIONS */
1840 wAppIconMove(aicon, X, Y);
1841 pi++;
1843 /* we reversed the order so we use prev */
1844 aicon = aicon->prev;
1845 if (pi >= pf) {
1846 pi = 0;
1847 si++;
1851 /* arrange miniwindows */
1853 wwin = scr->focused_window;
1854 /* reverse them to avoid unnecessarily shuffling */
1855 while (wwin && wwin->prev)
1856 wwin = wwin->prev;
1858 while (wwin) {
1859 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1860 (wwin->frame->workspace == scr->current_workspace ||
1861 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1863 if (arrangeAll || !wwin->flags.icon_moved) {
1864 if (wwin->icon_x != X || wwin->icon_y != Y) {
1865 #ifdef ANIMATIONS
1866 if (wPreferences.no_animations) {
1867 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1868 } else {
1869 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1870 wwin->icon_y, X, Y);
1872 #else
1873 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1874 #endif /* ANIMATIONS */
1876 wwin->icon_x = X;
1877 wwin->icon_y = Y;
1878 pi++;
1881 if (arrangeAll) {
1882 wwin->flags.icon_moved = 0;
1884 /* we reversed the order, so we use next */
1885 wwin = wwin->next;
1886 if (pi >= pf) {
1887 pi = 0;
1888 si++;
1892 #endif
1894 void wSelectWindow(WWindow * wwin, Bool flag)
1896 WScreen *scr = wwin->screen_ptr;
1898 if (flag) {
1899 wwin->flags.selected = 1;
1900 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1902 if (!HAS_BORDER(wwin)) {
1903 XSetWindowBorderWidth(dpy, wwin->frame->core->window, FRAME_BORDER_WIDTH);
1906 if (!scr->selected_windows)
1907 scr->selected_windows = WMCreateArray(4);
1908 WMAddToArray(scr->selected_windows, wwin);
1909 } else {
1910 wwin->flags.selected = 0;
1911 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
1913 if (!HAS_BORDER(wwin)) {
1914 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1917 if (scr->selected_windows) {
1918 WMRemoveFromArray(scr->selected_windows, wwin);
1923 void wMakeWindowVisible(WWindow * wwin)
1925 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1926 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1928 if (wwin->flags.shaded) {
1929 wUnshadeWindow(wwin);
1931 if (wwin->flags.hidden) {
1932 WApplication *app;
1934 app = wApplicationOf(wwin->main_window);
1935 if (app) {
1936 /* trick to get focus to this window */
1937 app->last_focused = wwin;
1938 wUnhideApplication(app, False, False);
1941 if (wwin->flags.miniaturized) {
1942 wDeiconifyWindow(wwin);
1943 } else {
1944 if (!WFLAGP(wwin, no_focusable))
1945 wSetFocusTo(wwin->screen_ptr, wwin);
1946 wRaiseFrame(wwin->frame->core);
1951 * Do the animation while shading (called with what = SHADE)
1952 * or unshading (what = UNSHADE).
1954 #ifdef ANIMATIONS
1955 static void shade_animate(WWindow *wwin, Bool what)
1957 int y, s, w, h;
1958 time_t time0 = time(NULL);
1960 if (wwin->flags.skip_next_animation && wPreferences.no_animations)
1961 return;
1963 switch(what) {
1964 case SHADE:
1965 if (!wwin->screen_ptr->flags.startup) {
1966 /* do the shading animation */
1967 h = wwin->frame->core->height;
1968 s = h / SHADE_STEPS;
1969 if (s < 1)
1970 s = 1;
1971 w = wwin->frame->core->width;
1972 y = wwin->frame->top_width;
1973 while (h > wwin->frame->top_width + 1) {
1974 XMoveWindow(dpy, wwin->client_win, 0, y);
1975 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1976 XFlush(dpy);
1978 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1979 break;
1981 if (SHADE_DELAY > 0) {
1982 wusleep(SHADE_DELAY * 1000L);
1983 } else {
1984 wusleep(10);
1986 h -= s;
1987 y -= s;
1989 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1991 break;
1993 case UNSHADE:
1994 h = wwin->frame->top_width + wwin->frame->bottom_width;
1995 y = wwin->frame->top_width - wwin->client.height;
1996 s = abs(y) / SHADE_STEPS;
1997 if (s < 1)
1998 s = 1;
1999 w = wwin->frame->core->width;
2000 XMoveWindow(dpy, wwin->client_win, 0, y);
2001 if (s > 0) {
2002 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
2003 XResizeWindow(dpy, wwin->frame->core->window, w, h);
2004 XMoveWindow(dpy, wwin->client_win, 0, y);
2005 XFlush(dpy);
2006 if (SHADE_DELAY > 0) {
2007 wusleep(SHADE_DELAY * 2000L / 3);
2008 } else {
2009 wusleep(10);
2011 h += s;
2012 y += s;
2014 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
2015 break;
2018 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2019 break;
2022 #else
2023 static void shade_animate(WWindow *wwin, Bool what) { return; }
2024 #endif /* ANIMATIONS */