Fix typos, remove commented out code etc
[wmaker-crm.git] / src / actions.c
blobf58d7507d4b6bf7682174c27597b304abe843b8c
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 ******/
53 int ignore_wks_change = 0;
54 extern Time LastTimestamp;
55 extern Time LastFocusChange;
57 extern Cursor wCursor[WCUR_LAST];
59 extern WPreferences wPreferences;
61 extern Atom _XA_WM_TAKE_FOCUS;
63 extern void ProcessPendingEvents();
64 extern int calcIntersectionLength(int p1, int l1, int p2, int l2);
66 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
67 unsigned int *new_width, unsigned int *new_height);
68 static void save_old_geometry(WWindow *wwin);
70 /******* Local Variables *******/
71 static struct {
72 int steps;
73 int delay;
74 } shadePars[5] = {
76 SHADE_STEPS_UF, SHADE_DELAY_UF}, {
77 SHADE_STEPS_F, SHADE_DELAY_F}, {
78 SHADE_STEPS_M, SHADE_DELAY_M}, {
79 SHADE_STEPS_S, SHADE_DELAY_S}, {
80 SHADE_STEPS_US, SHADE_DELAY_US}};
82 #define UNSHADE 0
83 #define SHADE 1
84 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
85 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
87 static int compareTimes(Time t1, Time t2)
89 Time diff;
90 if (t1 == t2)
91 return 0;
92 diff = t1 - t2;
93 return (diff < 60000) ? 1 : -1;
96 #ifdef ANIMATIONS
97 static void shade_animate(WWindow *wwin, Bool what);
98 #else
99 static void shade_animate(WWindow *wwin, Bool what) { }
100 #endif
103 *----------------------------------------------------------------------
104 * wSetFocusTo--
105 * Changes the window focus to the one passed as argument.
106 * If the window to focus is not already focused, it will be brought
107 * to the head of the list of windows. Previously focused window is
108 * unfocused.
110 * Side effects:
111 * Window list may be reordered and the window focus is changed.
113 *----------------------------------------------------------------------
115 void wSetFocusTo(WScreen *scr, WWindow *wwin)
117 static WScreen *old_scr = NULL;
119 WWindow *old_focused;
120 WWindow *focused = scr->focused_window;
121 Time timestamp = LastTimestamp;
122 WApplication *oapp = NULL, *napp = NULL;
123 int wasfocused;
125 if (scr->flags.ignore_focus_events || compareTimes(LastFocusChange, timestamp) > 0)
126 return;
128 if (!old_scr)
129 old_scr = scr;
130 old_focused = old_scr->focused_window;
132 LastFocusChange = timestamp;
134 if (old_focused)
135 oapp = wApplicationOf(old_focused->main_window);
137 if (wwin == NULL) {
138 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
139 if (old_focused)
140 wWindowUnfocus(old_focused);
141 if (oapp)
142 wAppMenuUnmap(oapp->menu);
144 WMPostNotificationName(WMNChangedFocus, NULL, (void *)True);
145 return;
146 } else if (old_scr != scr && old_focused) {
147 wWindowUnfocus(old_focused);
150 wasfocused = wwin->flags.focused;
151 napp = wApplicationOf(wwin->main_window);
153 /* remember last workspace where the app has been */
154 if (napp) {
155 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
156 napp->last_workspace = wwin->frame->workspace;
159 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
160 /* install colormap if colormap mode is lock mode */
161 if (wPreferences.colormap_mode == WCM_CLICK)
162 wColormapInstallForWindow(scr, wwin);
164 /* set input focus */
165 switch (wwin->focus_mode) {
166 case WFM_NO_INPUT:
167 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
168 break;
170 case WFM_PASSIVE:
171 case WFM_LOCALLY_ACTIVE:
172 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
173 break;
175 case WFM_GLOBALLY_ACTIVE:
176 break;
178 XFlush(dpy);
179 if (wwin->protocols.TAKE_FOCUS) {
180 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
182 XSync(dpy, False);
183 } else {
184 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
186 if (WFLAGP(wwin, no_focusable))
187 return;
189 /* if this is not the focused window focus it */
190 if (focused != wwin) {
191 /* change the focus window list order */
192 if (wwin->prev)
193 wwin->prev->next = wwin->next;
195 if (wwin->next)
196 wwin->next->prev = wwin->prev;
198 wwin->prev = focused;
199 focused->next = wwin;
200 wwin->next = NULL;
201 scr->focused_window = wwin;
203 if (oapp && oapp != napp)
204 wAppMenuUnmap(oapp->menu);
207 wWindowFocus(wwin, focused);
209 if (napp && !wasfocused) {
210 #ifdef USER_MENU
211 wUserMenuRefreshInstances(napp->menu, wwin);
212 #endif /* USER_MENU */
214 if (wwin->flags.mapped)
215 wAppMenuMap(napp->menu, wwin);
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);
393 WMPostNotificationName(WMNChangedState, wwin, "maximize");
395 /* set maximization state */
396 wwin->flags.maximized = directions;
400 * Maximus: tiled maximization (maximize without overlapping other windows)
402 * The window to be maximized will be denoted by w_0 (sub-index zero)
403 * while the windows which will stop the maximization of w_0 are denoted by w_j.
405 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
406 unsigned int *new_width, unsigned int *new_height)
408 WWindow *tmp;
409 int x_0 = wwin->frame_x;
410 int y_0 = wwin->frame_y;
411 int width_0 = wwin->frame->core->width;
412 int height_0 = wwin->frame->core->height;
413 int bottom_0 = y_0 + height_0;
414 int right_border_0 = x_0 + width_0;
415 int new_x_0, new_y_0, new_bottom_0, new_right_border_0, new_height_0;
416 int x_j, y_j, width_j, height_j, bottom_j, top_j, right_border_j;
417 int x_intsect, y_intsect;
418 short int tbar_height_0 = 0, rbar_height_0 = 0;
419 short int bd_width_0 = 0;
420 short int adjust_height;
422 /* Try to fully maximize first, then readjust later */
423 new_x_0 = usableArea.x1;
424 new_y_0 = usableArea.y1;
425 new_bottom_0 = usableArea.y2;
426 new_right_border_0 = usableArea.x2;
428 if (HAS_TITLEBAR(wwin))
429 tbar_height_0 = TITLEBAR_HEIGHT;
430 if (HAS_RESIZEBAR(wwin))
431 rbar_height_0 = RESIZEBAR_HEIGHT;
432 if (HAS_BORDER(wwin))
433 bd_width_0 = FRAME_BORDER_WIDTH;
435 /* the length to be subtracted if w_0 has titlebar, etc */
436 adjust_height = tbar_height_0 + 2 * bd_width_0 + rbar_height_0;
438 tmp = wwin;
439 /* The focused window is always the last in the list */
440 while (tmp->prev) {
441 /* ignore windows in other workspaces etc */
442 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
443 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
444 tmp = tmp->prev;
445 continue;
447 tmp = tmp->prev;
450 * Set the w_j window coordinates. It is convenient
451 * to not use "corrected" sizes for width and height,
452 * otherwise bottom_j and right_border_j would be
453 * incorrect.
455 x_j = tmp->frame_x;
456 y_j = tmp->frame_y;
457 width_j = tmp->frame->core->width;
458 height_j = tmp->frame->core->height;
459 bottom_j = y_j + height_j;
460 top_j = y_j;
461 right_border_j = x_j + width_j;
463 /* Try to maximize in the y direction first */
464 x_intsect = calcIntersectionLength(x_0, width_0, x_j, width_j);
465 if (x_intsect != 0) {
466 /* TODO: Consider the case when coords are equal */
467 if (bottom_j < y_0 && bottom_j > new_y_0) {
468 /* w_0 is below the bottom of w_j */
469 new_y_0 = bottom_j + 1;
471 if (bottom_0 < top_j && top_j < new_bottom_0) {
472 /* The bottom of w_0 is above the top of w_j */
473 new_bottom_0 = top_j - 1;
478 tmp = wwin;
479 while (tmp->prev) {
480 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
481 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
482 tmp = tmp->prev;
483 continue;
485 tmp = tmp->prev;
487 /* set the w_j window coordinates */
488 x_j = tmp->frame_x;
489 y_j = tmp->frame_y;
490 width_j = tmp->frame->core->width;
491 height_j = tmp->frame->core->height;
492 bottom_j = y_j + height_j;
493 top_j = y_j;
494 right_border_j = x_j + width_j;
497 * Use the updated y coordinates from the above step to account
498 * the possibility that the new value of y_0 will have different
499 * intersections with w_j
501 new_height_0 = new_bottom_0 - new_y_0 - adjust_height;
502 y_intsect = calcIntersectionLength(new_y_0, new_height_0, y_j, height_j);
503 if (y_intsect != 0) {
504 if (right_border_j < x_0 && right_border_j > new_x_0) {
505 /* w_0 is completely to the right of w_j */
506 new_x_0 = right_border_j + 1;
508 if (right_border_0 < x_j && x_j < new_right_border_0) {
509 /* w_0 is completely to the left of w_j */
510 new_right_border_0 = x_j - 1;
515 /* xcalc needs -7 here, but other apps don't */
516 new_height_0 = new_bottom_0 - new_y_0 - adjust_height - 1;
517 *new_x = new_x_0;
518 *new_y = new_y_0;
519 *new_height = new_height_0;
520 *new_width = new_right_border_0 - new_x_0;
523 void wUnmaximizeWindow(WWindow *wwin)
525 int x, y, w, h;
526 WMRect old_geom_rect;
527 int old_head;
528 Bool same_head;
530 if (!wwin->flags.maximized)
531 return;
533 if (wwin->flags.shaded) {
534 wwin->flags.skip_next_animation = 1;
535 wUnshadeWindow(wwin);
537 /* Use old coordinates if they are set, current values otherwise */
538 old_geom_rect = wmkrect(wwin->old_geometry.x, wwin->old_geometry.y, wwin->old_geometry.width, wwin->old_geometry.height);
539 old_head = wGetHeadForRect(wwin->screen_ptr, old_geom_rect);
540 same_head = (wGetHeadForWindow(wwin) == old_head);
541 x = (wwin->old_geometry.x && same_head) ? wwin->old_geometry.x : wwin->frame_x;
542 y = (wwin->old_geometry.y && same_head) ? wwin->old_geometry.y : wwin->frame_y;
543 w = wwin->old_geometry.width ? wwin->old_geometry.width : wwin->client.width;
544 h = wwin->old_geometry.height ? wwin->old_geometry.height : wwin->client.height;
546 wwin->flags.maximized = 0;
547 wWindowConfigure(wwin, x, y, w, h);
549 WMPostNotificationName(WMNChangedState, wwin, "maximize");
552 void wFullscreenWindow(WWindow *wwin)
554 int head;
555 WMRect rect;
557 if (wwin->flags.fullscreen)
558 return;
560 wwin->flags.fullscreen = True;
562 wWindowConfigureBorders(wwin);
564 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
566 wwin->bfs_geometry.x = wwin->frame_x;
567 wwin->bfs_geometry.y = wwin->frame_y;
568 wwin->bfs_geometry.width = wwin->frame->core->width;
569 wwin->bfs_geometry.height = wwin->frame->core->height;
571 head = wGetHeadForWindow(wwin);
572 rect = wGetRectForHead(wwin->screen_ptr, head);
573 wWindowConfigure(wwin, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
575 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
578 void wUnfullscreenWindow(WWindow *wwin)
580 if (!wwin->flags.fullscreen)
581 return;
583 wwin->flags.fullscreen = False;
585 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
586 if (WFLAGP(wwin, sunken)) {
587 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
588 } else if (WFLAGP(wwin, floating)) {
589 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
590 } else {
591 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
595 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
596 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
598 wWindowConfigureBorders(wwin);
600 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
601 wFrameWindowPaint(wwin->frame);
604 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
607 #ifdef ANIMATIONS
608 static void animateResizeFlip(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
610 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
611 float cx, cy, cw, ch;
612 float xstep, ystep, wstep, hstep;
613 XPoint points[5];
614 float dx, dch, midy;
615 float angle, final_angle, delta;
617 xstep = (float)(fx - x) / steps;
618 ystep = (float)(fy - y) / steps;
619 wstep = (float)(fw - w) / steps;
620 hstep = (float)(fh - h) / steps;
622 cx = (float)x;
623 cy = (float)y;
624 cw = (float)w;
625 ch = (float)h;
627 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_F;
628 delta = (float)(final_angle / FRAMES);
629 for (angle = 0;; angle += delta) {
630 if (angle > final_angle)
631 angle = final_angle;
633 dx = (cw / 10) - ((cw / 5) * sin(angle));
634 dch = (ch / 2) * cos(angle);
635 midy = cy + (ch / 2);
637 points[0].x = cx + dx;
638 points[0].y = midy - dch;
639 points[1].x = cx + cw - dx;
640 points[1].y = points[0].y;
641 points[2].x = cx + cw + dx;
642 points[2].y = midy + dch;
643 points[3].x = cx - dx;
644 points[3].y = points[2].y;
645 points[4].x = points[0].x;
646 points[4].y = points[0].y;
648 XGrabServer(dpy);
649 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
650 XFlush(dpy);
651 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
653 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
654 XUngrabServer(dpy);
655 cx += xstep;
656 cy += ystep;
657 cw += wstep;
658 ch += hstep;
659 if (angle >= final_angle)
660 break;
663 XFlush(dpy);
666 #undef FRAMES
668 static void
669 animateResizeTwist(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
671 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
672 float cx, cy, cw, ch;
673 float xstep, ystep, wstep, hstep;
674 XPoint points[5];
675 float angle, final_angle, a, d, delta;
677 x += w / 2;
678 y += h / 2;
679 fx += fw / 2;
680 fy += fh / 2;
682 xstep = (float)(fx - x) / steps;
683 ystep = (float)(fy - y) / steps;
684 wstep = (float)(fw - w) / steps;
685 hstep = (float)(fh - h) / steps;
687 cx = (float)x;
688 cy = (float)y;
689 cw = (float)w;
690 ch = (float)h;
692 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_T;
693 delta = (float)(final_angle / FRAMES);
694 for (angle = 0;; angle += delta) {
695 if (angle > final_angle)
696 angle = final_angle;
698 a = atan(ch / cw);
699 d = sqrt((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
701 points[0].x = cx + cos(angle - a) * d;
702 points[0].y = cy + sin(angle - a) * d;
703 points[1].x = cx + cos(angle + a) * d;
704 points[1].y = cy + sin(angle + a) * d;
705 points[2].x = cx + cos(angle - a + WM_PI) * d;
706 points[2].y = cy + sin(angle - a + WM_PI) * d;
707 points[3].x = cx + cos(angle + a + WM_PI) * d;
708 points[3].y = cy + sin(angle + a + WM_PI) * d;
709 points[4].x = cx + cos(angle - a) * d;
710 points[4].y = cy + sin(angle - a) * d;
711 XGrabServer(dpy);
712 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
713 XFlush(dpy);
714 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
716 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
717 XUngrabServer(dpy);
718 cx += xstep;
719 cy += ystep;
720 cw += wstep;
721 ch += hstep;
722 if (angle >= final_angle)
723 break;
726 XFlush(dpy);
729 #undef FRAMES
731 static void animateResizeZoom(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
733 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
734 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
735 float xstep, ystep, wstep, hstep;
736 int i, j;
738 xstep = (float)(fx - x) / steps;
739 ystep = (float)(fy - y) / steps;
740 wstep = (float)(fw - w) / steps;
741 hstep = (float)(fh - h) / steps;
743 for (j = 0; j < FRAMES; j++) {
744 cx[j] = (float)x;
745 cy[j] = (float)y;
746 cw[j] = (float)w;
747 ch[j] = (float)h;
749 XGrabServer(dpy);
750 for (i = 0; i < steps; i++) {
751 for (j = 0; j < FRAMES; j++) {
752 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
753 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
755 XFlush(dpy);
756 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
758 for (j = 0; j < FRAMES; j++) {
759 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
760 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
761 if (j < FRAMES - 1) {
762 cx[j] = cx[j + 1];
763 cy[j] = cy[j + 1];
764 cw[j] = cw[j + 1];
765 ch[j] = ch[j + 1];
766 } else {
767 cx[j] += xstep;
768 cy[j] += ystep;
769 cw[j] += wstep;
770 ch[j] += hstep;
775 for (j = 0; j < FRAMES; j++) {
776 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
778 XFlush(dpy);
779 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
781 for (j = 0; j < FRAMES; j++) {
782 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
785 XUngrabServer(dpy);
788 #undef FRAMES
790 void animateResize(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh)
792 int style = wPreferences.iconification_style; /* Catch the value */
793 int steps;
795 if (style == WIS_NONE)
796 return;
798 if (style == WIS_RANDOM) {
799 style = rand() % 3;
802 switch (style) {
803 case WIS_TWIST:
804 steps = MINIATURIZE_ANIMATION_STEPS_T;
805 if (steps > 0)
806 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
807 break;
808 case WIS_FLIP:
809 steps = MINIATURIZE_ANIMATION_STEPS_F;
810 if (steps > 0)
811 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
812 break;
813 case WIS_ZOOM:
814 default:
815 steps = MINIATURIZE_ANIMATION_STEPS_Z;
816 if (steps > 0)
817 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
818 break;
821 #endif /* ANIMATIONS */
823 static void flushExpose()
825 XEvent tmpev;
827 while (XCheckTypedEvent(dpy, Expose, &tmpev))
828 WMHandleEvent(&tmpev);
829 XSync(dpy, 0);
832 static void unmapTransientsFor(WWindow *wwin)
834 WWindow *tmp;
836 tmp = wwin->screen_ptr->focused_window;
837 while (tmp) {
838 /* unmap the transients for this transient */
839 if (tmp != wwin && tmp->transient_for == wwin->client_win
840 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup || tmp->flags.shaded)) {
841 unmapTransientsFor(tmp);
842 tmp->flags.miniaturized = 1;
843 if (!tmp->flags.shaded) {
844 wWindowUnmap(tmp);
845 } else {
846 XUnmapWindow(dpy, tmp->frame->core->window);
849 if (!tmp->flags.shaded)
851 wClientSetState(tmp, IconicState, None);
853 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
855 tmp = tmp->prev;
859 static void mapTransientsFor(WWindow *wwin)
861 WWindow *tmp;
863 tmp = wwin->screen_ptr->focused_window;
864 while (tmp) {
865 /* recursively map the transients for this transient */
866 if (tmp != wwin && tmp->transient_for == wwin->client_win && /*!tmp->flags.mapped */ tmp->flags.miniaturized
867 && tmp->icon == NULL) {
868 mapTransientsFor(tmp);
869 tmp->flags.miniaturized = 0;
870 if (!tmp->flags.shaded) {
871 wWindowMap(tmp);
872 } else {
873 XMapWindow(dpy, tmp->frame->core->window);
875 tmp->flags.semi_focused = 0;
877 if (!tmp->flags.shaded)
879 wClientSetState(tmp, NormalState, None);
881 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
883 tmp = tmp->prev;
887 static WWindow *recursiveTransientFor(WWindow * wwin)
889 int i;
891 if (!wwin)
892 return None;
894 /* hackish way to detect transient_for cycle */
895 i = wwin->screen_ptr->window_count + 1;
897 while (wwin && wwin->transient_for != None && i > 0) {
898 wwin = wWindowFor(wwin->transient_for);
899 i--;
901 if (i == 0 && wwin) {
902 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin->frame->title);
903 return NULL;
906 return wwin;
909 void wIconifyWindow(WWindow * wwin)
911 XWindowAttributes attribs;
912 int present;
914 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
915 /* the window doesn't exist anymore */
916 return;
919 if (wwin->flags.miniaturized) {
920 return;
923 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
924 WWindow *owner = wWindowFor(wwin->transient_for);
926 if (owner && owner->flags.miniaturized)
927 return;
930 present = wwin->frame->workspace == wwin->screen_ptr->current_workspace;
932 /* if the window is in another workspace, simplify process */
933 if (present) {
934 /* icon creation may take a while */
935 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
936 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
937 GrabModeAsync, None, None, CurrentTime);
940 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
941 if (!wwin->flags.icon_moved) {
942 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
944 wwin->icon = wIconCreate(wwin);
946 wwin->icon->mapped = 1;
949 wwin->flags.miniaturized = 1;
950 wwin->flags.mapped = 0;
952 /* unmap transients */
954 unmapTransientsFor(wwin);
956 if (present) {
957 XUngrabPointer(dpy, CurrentTime);
958 wWindowUnmap(wwin);
959 /* let all Expose events arrive so that we can repaint
960 * something before the animation starts (and the server is grabbed) */
961 XSync(dpy, 0);
963 if (wPreferences.disable_miniwindows || wwin->flags.net_handle_icon)
964 wClientSetState(wwin, IconicState, None);
965 else
966 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
968 flushExpose();
969 #ifdef ANIMATIONS
970 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
971 && !wPreferences.no_animations) {
972 int ix, iy, iw, ih;
974 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
975 ix = wwin->icon_x;
976 iy = wwin->icon_y;
977 iw = wwin->icon->core->width;
978 ih = wwin->icon->core->height;
979 } else {
980 if (wwin->flags.net_handle_icon) {
981 ix = wwin->icon_x;
982 iy = wwin->icon_y;
983 iw = wwin->icon_w;
984 ih = wwin->icon_h;
985 } else {
986 ix = 0;
987 iy = 0;
988 iw = wwin->screen_ptr->scr_width;
989 ih = wwin->screen_ptr->scr_height;
992 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
993 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih);
995 #endif
998 wwin->flags.skip_next_animation = 0;
1000 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1001 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace ||
1002 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1004 XMapWindow(dpy, wwin->icon->core->window);
1006 AddToStackList(wwin->icon->core);
1008 wLowerFrame(wwin->icon->core);
1011 if (present) {
1012 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1015 * It doesn't seem to be working and causes button event hangup
1016 * when deiconifying a transient window.
1017 setupIconGrabs(wwin->icon);
1019 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
1020 && wPreferences.focus_mode == WKF_CLICK) {
1021 WWindow *tmp;
1023 tmp = wwin->prev;
1024 while (tmp) {
1025 if (!WFLAGP(tmp, no_focusable)
1026 && !(tmp->flags.hidden || tmp->flags.miniaturized)
1027 && (wwin->frame->workspace == tmp->frame->workspace))
1028 break;
1029 tmp = tmp->prev;
1031 wSetFocusTo(wwin->screen_ptr, tmp);
1032 } else if (wPreferences.focus_mode != WKF_CLICK) {
1033 wSetFocusTo(wwin->screen_ptr, NULL);
1035 #ifdef ANIMATIONS
1036 if (!wwin->screen_ptr->flags.startup) {
1037 /* Catch up with events not processed while animation was running */
1038 Window clientwin = wwin->client_win;
1040 ProcessPendingEvents();
1042 /* the window can disappear while ProcessPendingEvents() runs */
1043 if (!wWindowFor(clientwin)) {
1044 return;
1047 #endif
1050 /* maybe we want to do this regardless of net_handle_icon
1051 * it seems to me we might break behaviour this way.
1053 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1054 && !wwin->flags.net_handle_icon)
1055 wIconSelect(wwin->icon);
1057 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1059 if (wPreferences.auto_arrange_icons)
1060 wArrangeIcons(wwin->screen_ptr, True);
1063 void wDeiconifyWindow(WWindow *wwin)
1065 /* Let's avoid changing workspace while deiconifying */
1066 ignore_wks_change = 1;
1068 /* we're hiding for show_desktop */
1069 int netwm_hidden = wwin->flags.net_show_desktop &&
1070 wwin->frame->workspace != wwin->screen_ptr->current_workspace;
1072 if (!netwm_hidden)
1073 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1075 if (!wwin->flags.miniaturized)
1076 return;
1078 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1079 WWindow *owner = recursiveTransientFor(wwin);
1081 if (owner && owner->flags.miniaturized) {
1082 wDeiconifyWindow(owner);
1083 wSetFocusTo(wwin->screen_ptr, wwin);
1084 wRaiseFrame(wwin->frame->core);
1085 return;
1089 wwin->flags.miniaturized = 0;
1091 if (!netwm_hidden && !wwin->flags.shaded) {
1092 wwin->flags.mapped = 1;
1095 if (!netwm_hidden || wPreferences.sticky_icons) {
1096 /* maybe we want to do this regardless of net_handle_icon
1097 * it seems to me we might break behaviour this way.
1099 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon
1100 && wwin->icon != NULL) {
1101 if (wwin->icon->selected)
1102 wIconSelect(wwin->icon);
1104 XUnmapWindow(dpy, wwin->icon->core->window);
1108 /* if the window is in another workspace, do it silently */
1109 if (!netwm_hidden) {
1110 #ifdef ANIMATIONS
1111 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1112 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1113 int ix, iy, iw, ih;
1115 if (!wPreferences.disable_miniwindows
1116 && !wwin->flags.net_handle_icon) {
1117 ix = wwin->icon_x;
1118 iy = wwin->icon_y;
1119 iw = wwin->icon->core->width;
1120 ih = wwin->icon->core->height;
1121 } else {
1122 if (wwin->flags.net_handle_icon) {
1123 ix = wwin->icon_x;
1124 iy = wwin->icon_y;
1125 iw = wwin->icon_w;
1126 ih = wwin->icon_h;
1127 } else {
1128 ix = 0;
1129 iy = 0;
1130 iw = wwin->screen_ptr->scr_width;
1131 ih = wwin->screen_ptr->scr_height;
1134 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1135 wwin->frame_x, wwin->frame_y,
1136 wwin->frame->core->width, wwin->frame->core->height);
1138 #endif /* ANIMATIONS */
1139 wwin->flags.skip_next_animation = 0;
1140 XGrabServer(dpy);
1141 if (!wwin->flags.shaded) {
1142 XMapWindow(dpy, wwin->client_win);
1144 XMapWindow(dpy, wwin->frame->core->window);
1145 wRaiseFrame(wwin->frame->core);
1146 if (!wwin->flags.shaded) {
1147 wClientSetState(wwin, NormalState, None);
1149 mapTransientsFor(wwin);
1152 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1153 && !wwin->flags.net_handle_icon) {
1154 RemoveFromStackList(wwin->icon->core);
1155 /* removeIconGrabs(wwin->icon); */
1156 wIconDestroy(wwin->icon);
1157 wwin->icon = NULL;
1160 if (!netwm_hidden) {
1161 XUngrabServer(dpy);
1163 wSetFocusTo(wwin->screen_ptr, wwin);
1165 #ifdef ANIMATIONS
1166 if (!wwin->screen_ptr->flags.startup) {
1167 /* Catch up with events not processed while animation was running */
1168 Window clientwin = wwin->client_win;
1170 ProcessPendingEvents();
1172 /* the window can disappear while ProcessPendingEvents() runs */
1173 if (!wWindowFor(clientwin)) {
1174 return;
1177 #endif
1180 if (wPreferences.auto_arrange_icons) {
1181 wArrangeIcons(wwin->screen_ptr, True);
1184 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1186 /* In case we were shaded and iconified, also unshade */
1187 if (!netwm_hidden)
1188 wUnshadeWindow(wwin);
1190 ignore_wks_change = 0;
1193 static void hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1195 if (wwin->flags.miniaturized) {
1196 if (wwin->icon) {
1197 XUnmapWindow(dpy, wwin->icon->core->window);
1198 wwin->icon->mapped = 0;
1200 wwin->flags.hidden = 1;
1202 WMPostNotificationName(WMNChangedState, wwin, "hide");
1203 return;
1206 if (wwin->flags.inspector_open) {
1207 wHideInspectorForWindow(wwin);
1210 wwin->flags.hidden = 1;
1211 wWindowUnmap(wwin);
1213 wClientSetState(wwin, IconicState, icon->icon_win);
1214 flushExpose();
1216 #ifdef ANIMATIONS
1217 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1218 !wwin->flags.skip_next_animation && animate) {
1219 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1220 wwin->frame->core->width, wwin->frame->core->height,
1221 icon_x, icon_y, icon->core->width, icon->core->height);
1223 #endif
1224 wwin->flags.skip_next_animation = 0;
1226 WMPostNotificationName(WMNChangedState, wwin, "hide");
1229 void wHideOtherApplications(WWindow *awin)
1231 WWindow *wwin;
1232 WApplication *tapp;
1234 if (!awin)
1235 return;
1236 wwin = awin->screen_ptr->focused_window;
1238 while (wwin) {
1239 if (wwin != awin
1240 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1241 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1242 && !wwin->flags.internal_window
1243 && wGetWindowOfInspectorForWindow(wwin) != awin && !WFLAGP(wwin, no_hide_others)) {
1245 if (wwin->main_window == None || WFLAGP(wwin, no_appicon)) {
1246 if (!WFLAGP(wwin, no_miniaturizable)) {
1247 wwin->flags.skip_next_animation = 1;
1248 wIconifyWindow(wwin);
1250 } else if (wwin->main_window != None && awin->main_window != wwin->main_window) {
1251 tapp = wApplicationOf(wwin->main_window);
1252 if (tapp) {
1253 tapp->flags.skip_next_animation = 1;
1254 wHideApplication(tapp);
1255 } else {
1256 if (!WFLAGP(wwin, no_miniaturizable)) {
1257 wwin->flags.skip_next_animation = 1;
1258 wIconifyWindow(wwin);
1263 wwin = wwin->prev;
1266 wSetFocusTo(awin->screen_ptr, awin);
1270 void wHideApplication(WApplication *wapp)
1272 WScreen *scr;
1273 WWindow *wlist;
1274 int hadfocus;
1275 int animate;
1277 if (!wapp) {
1278 wwarning("trying to hide a non grouped window");
1279 return;
1281 if (!wapp->main_window_desc) {
1282 wwarning("group leader not found for window group");
1283 return;
1285 scr = wapp->main_window_desc->screen_ptr;
1286 hadfocus = 0;
1287 wlist = scr->focused_window;
1288 if (!wlist)
1289 return;
1291 if (wlist->main_window == wapp->main_window)
1292 wapp->last_focused = wlist;
1293 else
1294 wapp->last_focused = NULL;
1296 animate = !wapp->flags.skip_next_animation;
1298 while (wlist) {
1299 if (wlist->main_window == wapp->main_window) {
1300 if (wlist->flags.focused) {
1301 hadfocus = 1;
1303 if (wapp->app_icon) {
1304 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1305 wapp->app_icon->y_pos, wlist, animate);
1306 animate = False;
1309 wlist = wlist->prev;
1312 wapp->flags.skip_next_animation = 0;
1314 if (hadfocus) {
1315 if (wPreferences.focus_mode == WKF_CLICK) {
1316 wlist = scr->focused_window;
1317 while (wlist) {
1318 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1319 && (wlist->flags.mapped || wlist->flags.shaded))
1320 break;
1321 wlist = wlist->prev;
1323 wSetFocusTo(scr, wlist);
1324 } else {
1325 wSetFocusTo(scr, NULL);
1329 wapp->flags.hidden = 1;
1331 if (wPreferences.auto_arrange_icons) {
1332 wArrangeIcons(scr, True);
1334 #ifdef HIDDENDOT
1335 if (wapp->app_icon)
1336 wAppIconPaint(wapp->app_icon);
1337 #endif
1340 static void unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate, int bringToCurrentWS)
1342 if (bringToCurrentWS)
1343 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1345 wwin->flags.hidden = 0;
1347 #ifdef ANIMATIONS
1348 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1349 animateResize(wwin->screen_ptr, icon_x, icon_y,
1350 icon->core->width, icon->core->height,
1351 wwin->frame_x, wwin->frame_y,
1352 wwin->frame->core->width, wwin->frame->core->height);
1354 #endif
1355 wwin->flags.skip_next_animation = 0;
1356 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1357 XMapWindow(dpy, wwin->client_win);
1358 XMapWindow(dpy, wwin->frame->core->window);
1359 wClientSetState(wwin, NormalState, None);
1360 wwin->flags.mapped = 1;
1361 wRaiseFrame(wwin->frame->core);
1363 if (wwin->flags.inspector_open) {
1364 wUnhideInspectorForWindow(wwin);
1367 WMPostNotificationName(WMNChangedState, wwin, "hide");
1370 void wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1372 WScreen *scr;
1373 WWindow *wlist, *next;
1374 WWindow *focused = NULL;
1375 int animate;
1377 if (!wapp)
1378 return;
1380 scr = wapp->main_window_desc->screen_ptr;
1381 wlist = scr->focused_window;
1382 if (!wlist)
1383 return;
1385 /* goto beginning of list */
1386 while (wlist->prev)
1387 wlist = wlist->prev;
1389 animate = !wapp->flags.skip_next_animation;
1391 while (wlist) {
1392 next = wlist->next;
1394 if (wlist->main_window == wapp->main_window) {
1395 if (wlist->flags.focused)
1396 focused = wlist;
1397 else if (!focused || !focused->flags.focused)
1398 focused = wlist;
1400 if (wlist->flags.miniaturized) {
1401 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1402 wlist->frame->workspace == scr->current_workspace) && wlist->icon) {
1403 if (!wlist->icon->mapped) {
1404 int x, y;
1406 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1407 if (wlist->icon_x != x || wlist->icon_y != y) {
1408 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1410 wlist->icon_x = x;
1411 wlist->icon_y = y;
1412 XMapWindow(dpy, wlist->icon->core->window);
1413 wlist->icon->mapped = 1;
1415 wRaiseFrame(wlist->icon->core);
1417 if (bringToCurrentWS)
1418 wWindowChangeWorkspace(wlist, scr->current_workspace);
1419 wlist->flags.hidden = 0;
1420 if (miniwindows && wlist->frame->workspace == scr->current_workspace) {
1421 wDeiconifyWindow(wlist);
1423 WMPostNotificationName(WMNChangedState, wlist, "hide");
1424 } else if (wlist->flags.shaded) {
1425 if (bringToCurrentWS)
1426 wWindowChangeWorkspace(wlist, scr->current_workspace);
1427 wlist->flags.hidden = 0;
1428 if (wlist->frame->workspace == scr->current_workspace) {
1429 XMapWindow(dpy, wlist->frame->core->window);
1430 if (miniwindows) {
1431 wUnshadeWindow(wlist);
1432 wRaiseFrame(wlist->frame->core);
1435 WMPostNotificationName(WMNChangedState, wlist, "hide");
1436 } else if (wlist->flags.hidden) {
1437 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1438 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1439 animate = False;
1440 } else {
1441 if (bringToCurrentWS && wlist->frame->workspace != scr->current_workspace) {
1442 wWindowChangeWorkspace(wlist, scr->current_workspace);
1444 wRaiseFrame(wlist->frame->core);
1447 wlist = next;
1450 wapp->flags.skip_next_animation = 0;
1451 wapp->flags.hidden = 0;
1453 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1454 wRaiseFrame(wapp->last_focused->frame->core);
1455 wSetFocusTo(scr, wapp->last_focused);
1456 } else if (focused) {
1457 wSetFocusTo(scr, focused);
1459 wapp->last_focused = NULL;
1460 if (wPreferences.auto_arrange_icons) {
1461 wArrangeIcons(scr, True);
1463 #ifdef HIDDENDOT
1464 wAppIconPaint(wapp->app_icon);
1465 #endif
1468 void wShowAllWindows(WScreen *scr)
1470 WWindow *wwin, *old_foc;
1471 WApplication *wapp;
1473 old_foc = wwin = scr->focused_window;
1474 while (wwin) {
1475 if (!wwin->flags.internal_window &&
1476 (scr->current_workspace == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1477 if (wwin->flags.miniaturized) {
1478 wwin->flags.skip_next_animation = 1;
1479 wDeiconifyWindow(wwin);
1480 } else if (wwin->flags.hidden) {
1481 wapp = wApplicationOf(wwin->main_window);
1482 if (wapp) {
1483 wUnhideApplication(wapp, False, False);
1484 } else {
1485 wwin->flags.skip_next_animation = 1;
1486 wDeiconifyWindow(wwin);
1490 wwin = wwin->prev;
1492 wSetFocusTo(scr, old_foc);
1493 /*wRaiseFrame(old_foc->frame->core); */
1496 void wRefreshDesktop(WScreen *scr)
1498 Window win;
1499 XSetWindowAttributes attr;
1501 attr.backing_store = NotUseful;
1502 attr.save_under = False;
1503 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1504 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1505 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1506 XMapRaised(dpy, win);
1507 XDestroyWindow(dpy, win);
1508 XFlush(dpy);
1511 void wArrangeIcons(WScreen *scr, Bool arrangeAll)
1513 WWindow *wwin;
1514 WAppIcon *aicon;
1516 int head;
1517 const int heads = wXineramaHeads(scr);
1519 struct HeadVars {
1520 int pf; /* primary axis */
1521 int sf; /* secondary axis */
1522 int fullW;
1523 int fullH;
1524 int pi, si;
1525 int sx1, sx2, sy1, sy2; /* screen boundary */
1526 int sw, sh;
1527 int xo, yo;
1528 int xs, ys;
1529 } *vars;
1531 int isize = wPreferences.icon_size;
1533 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
1535 for (head = 0; head < heads; ++head) {
1536 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1537 WMRect rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
1538 vars[head].pi = vars[head].si = 0;
1539 vars[head].sx1 = rect.pos.x;
1540 vars[head].sy1 = rect.pos.y;
1541 vars[head].sw = rect.size.width;
1542 vars[head].sh = rect.size.height;
1543 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1544 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1545 vars[head].sw = isize * (vars[head].sw / isize);
1546 vars[head].sh = isize * (vars[head].sh / isize);
1547 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
1548 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
1550 /* icon yard boundaries */
1551 if (wPreferences.icon_yard & IY_VERT) {
1552 vars[head].pf = vars[head].fullH;
1553 vars[head].sf = vars[head].fullW;
1554 } else {
1555 vars[head].pf = vars[head].fullW;
1556 vars[head].sf = vars[head].fullH;
1558 if (wPreferences.icon_yard & IY_RIGHT) {
1559 vars[head].xo = vars[head].sx2 - isize;
1560 vars[head].xs = -1;
1561 } else {
1562 vars[head].xo = vars[head].sx1;
1563 vars[head].xs = 1;
1565 if (wPreferences.icon_yard & IY_TOP) {
1566 vars[head].yo = vars[head].sy1;
1567 vars[head].ys = 1;
1568 } else {
1569 vars[head].yo = vars[head].sy2 - isize;
1570 vars[head].ys = -1;
1574 #define X ((wPreferences.icon_yard & IY_VERT) \
1575 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1576 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1578 #define Y ((wPreferences.icon_yard & IY_VERT) \
1579 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1580 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1582 /* arrange application icons */
1583 aicon = scr->app_icon_list;
1584 /* reverse them to avoid unnecessarily sliding of icons */
1585 while (aicon && aicon->next)
1586 aicon = aicon->next;
1588 while (aicon) {
1589 if (!aicon->docked) {
1590 /* CHECK: can icon be NULL here ? */
1591 /* The intention here is to place the AppIcon on the head that
1592 * contains most of the applications _main_ window. */
1593 head = wGetHeadForWindow(aicon->icon->owner);
1595 if (aicon->x_pos != X || aicon->y_pos != Y) {
1596 #ifdef ANIMATIONS
1597 if (!wPreferences.no_animations) {
1598 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1600 #endif /* ANIMATIONS */
1602 wAppIconMove(aicon, X, Y);
1603 vars[head].pi++;
1604 if (vars[head].pi >= vars[head].pf) {
1605 vars[head].pi = 0;
1606 vars[head].si++;
1609 aicon = aicon->prev;
1612 /* arrange miniwindows */
1613 wwin = scr->focused_window;
1614 /* reverse them to avoid unnecessarily shuffling */
1615 while (wwin && wwin->prev)
1616 wwin = wwin->prev;
1618 while (wwin) {
1619 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1620 (wwin->frame->workspace == scr->current_workspace ||
1621 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1623 head = wGetHeadForWindow(wwin);
1625 if (arrangeAll || !wwin->flags.icon_moved) {
1626 if (wwin->icon_x != X || wwin->icon_y != Y) {
1627 #ifdef ANIMATIONS
1628 if (wPreferences.no_animations) {
1629 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1630 } else {
1631 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1632 wwin->icon_y, X, Y);
1634 #else
1635 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1636 #endif /* ANIMATIONS */
1638 wwin->icon_x = X;
1639 wwin->icon_y = Y;
1641 vars[head].pi++;
1642 if (vars[head].pi >= vars[head].pf) {
1643 vars[head].pi = 0;
1644 vars[head].si++;
1648 if (arrangeAll) {
1649 wwin->flags.icon_moved = 0;
1651 /* we reversed the order, so we use next */
1652 wwin = wwin->next;
1655 wfree(vars);
1658 void wSelectWindow(WWindow *wwin, Bool flag)
1660 WScreen *scr = wwin->screen_ptr;
1662 if (flag) {
1663 wwin->flags.selected = 1;
1664 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1666 if (!HAS_BORDER(wwin)) {
1667 XSetWindowBorderWidth(dpy, wwin->frame->core->window, FRAME_BORDER_WIDTH);
1670 if (!scr->selected_windows)
1671 scr->selected_windows = WMCreateArray(4);
1672 WMAddToArray(scr->selected_windows, wwin);
1673 } else {
1674 wwin->flags.selected = 0;
1675 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
1677 if (!HAS_BORDER(wwin)) {
1678 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1681 if (scr->selected_windows) {
1682 WMRemoveFromArray(scr->selected_windows, wwin);
1687 void wMakeWindowVisible(WWindow *wwin)
1689 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1690 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1692 if (wwin->flags.shaded) {
1693 wUnshadeWindow(wwin);
1695 if (wwin->flags.hidden) {
1696 WApplication *app;
1698 app = wApplicationOf(wwin->main_window);
1699 if (app) {
1700 /* trick to get focus to this window */
1701 app->last_focused = wwin;
1702 wUnhideApplication(app, False, False);
1705 if (wwin->flags.miniaturized) {
1706 wDeiconifyWindow(wwin);
1707 } else {
1708 if (!WFLAGP(wwin, no_focusable))
1709 wSetFocusTo(wwin->screen_ptr, wwin);
1710 wRaiseFrame(wwin->frame->core);
1715 * Do the animation while shading (called with what = SHADE)
1716 * or unshading (what = UNSHADE).
1718 #ifdef ANIMATIONS
1719 static void shade_animate(WWindow *wwin, Bool what)
1721 int y, s, w, h;
1722 time_t time0 = time(NULL);
1724 if (wwin->flags.skip_next_animation && wPreferences.no_animations)
1725 return;
1727 switch(what) {
1728 case SHADE:
1729 if (!wwin->screen_ptr->flags.startup) {
1730 /* do the shading animation */
1731 h = wwin->frame->core->height;
1732 s = h / SHADE_STEPS;
1733 if (s < 1)
1734 s = 1;
1735 w = wwin->frame->core->width;
1736 y = wwin->frame->top_width;
1737 while (h > wwin->frame->top_width + 1) {
1738 XMoveWindow(dpy, wwin->client_win, 0, y);
1739 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1740 XFlush(dpy);
1742 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1743 break;
1745 if (SHADE_DELAY > 0) {
1746 wusleep(SHADE_DELAY * 1000L);
1747 } else {
1748 wusleep(10);
1750 h -= s;
1751 y -= s;
1753 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1755 break;
1757 case UNSHADE:
1758 h = wwin->frame->top_width + wwin->frame->bottom_width;
1759 y = wwin->frame->top_width - wwin->client.height;
1760 s = abs(y) / SHADE_STEPS;
1761 if (s < 1)
1762 s = 1;
1763 w = wwin->frame->core->width;
1764 XMoveWindow(dpy, wwin->client_win, 0, y);
1765 if (s > 0) {
1766 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
1767 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1768 XMoveWindow(dpy, wwin->client_win, 0, y);
1769 XFlush(dpy);
1770 if (SHADE_DELAY > 0) {
1771 wusleep(SHADE_DELAY * 2000L / 3);
1772 } else {
1773 wusleep(10);
1775 h += s;
1776 y += s;
1778 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1779 break;
1782 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1783 break;
1786 #endif