Small fix for wmaker nightly build script 2
[wmaker-crm.git] / src / actions.c
blob891c4f297a339bc1142419b029a60965bfad1785
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);
142 if (oapp) {
143 wAppMenuUnmap(oapp->menu);
144 #ifdef NEWAPPICON
145 wApplicationDeactivate(oapp);
146 #endif
149 WMPostNotificationName(WMNChangedFocus, NULL, (void *)True);
150 return;
151 } else if (old_scr != scr && old_focused) {
152 wWindowUnfocus(old_focused);
155 wasfocused = wwin->flags.focused;
156 napp = wApplicationOf(wwin->main_window);
158 /* remember last workspace where the app has been */
159 if (napp) {
160 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
161 napp->last_workspace = wwin->frame->workspace;
164 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
165 /* install colormap if colormap mode is lock mode */
166 if (wPreferences.colormap_mode == WCM_CLICK)
167 wColormapInstallForWindow(scr, wwin);
169 /* set input focus */
170 switch (wwin->focus_mode) {
171 case WFM_NO_INPUT:
172 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
173 break;
175 case WFM_PASSIVE:
176 case WFM_LOCALLY_ACTIVE:
177 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
178 break;
180 case WFM_GLOBALLY_ACTIVE:
181 break;
183 XFlush(dpy);
184 if (wwin->protocols.TAKE_FOCUS) {
185 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
187 XSync(dpy, False);
188 } else {
189 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
191 if (WFLAGP(wwin, no_focusable))
192 return;
194 /* if this is not the focused window focus it */
195 if (focused != wwin) {
196 /* change the focus window list order */
197 if (wwin->prev)
198 wwin->prev->next = wwin->next;
200 if (wwin->next)
201 wwin->next->prev = wwin->prev;
203 wwin->prev = focused;
204 focused->next = wwin;
205 wwin->next = NULL;
206 scr->focused_window = wwin;
208 if (oapp && oapp != napp) {
209 wAppMenuUnmap(oapp->menu);
210 #ifdef NEWAPPICON
211 wApplicationDeactivate(oapp);
212 #endif
216 wWindowFocus(wwin, focused);
218 if (napp && !wasfocused) {
219 #ifdef USER_MENU
220 wUserMenuRefreshInstances(napp->menu, wwin);
221 #endif /* USER_MENU */
223 if (wwin->flags.mapped)
224 wAppMenuMap(napp->menu, wwin);
225 #ifdef NEWAPPICON
226 wApplicationActivate(napp);
227 #endif
230 XFlush(dpy);
231 old_scr = scr;
234 void wShadeWindow(WWindow *wwin)
237 if (wwin->flags.shaded)
238 return;
240 XLowerWindow(dpy, wwin->client_win);
241 shade_animate(wwin, SHADE);
243 wwin->flags.skip_next_animation = 0;
244 wwin->flags.shaded = 1;
245 wwin->flags.mapped = 0;
246 /* prevent window withdrawal when getting UnmapNotify */
247 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
248 XUnmapWindow(dpy, wwin->client_win);
249 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
251 /* for the client it's just like iconification */
252 wFrameWindowResize(wwin->frame, wwin->frame->core->width, wwin->frame->top_width - 1);
254 wwin->client.y = wwin->frame_y - wwin->client.height + wwin->frame->top_width;
255 wWindowSynthConfigureNotify(wwin);
258 wClientSetState(wwin, IconicState, None);
261 WMPostNotificationName(WMNChangedState, wwin, "shade");
263 #ifdef ANIMATIONS
264 if (!wwin->screen_ptr->flags.startup) {
265 /* Catch up with events not processed while animation was running */
266 ProcessPendingEvents();
268 #endif
271 void wUnshadeWindow(WWindow *wwin)
274 if (!wwin->flags.shaded)
275 return;
277 wwin->flags.shaded = 0;
278 wwin->flags.mapped = 1;
279 XMapWindow(dpy, wwin->client_win);
281 shade_animate(wwin, UNSHADE);
283 wwin->flags.skip_next_animation = 0;
284 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
285 wwin->frame->top_width + wwin->client.height + wwin->frame->bottom_width);
287 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
288 wWindowSynthConfigureNotify(wwin);
291 wClientSetState(wwin, NormalState, None);
293 /* if the window is focused, set the focus again as it was disabled during
294 * shading */
295 if (wwin->flags.focused)
296 wSetFocusTo(wwin->screen_ptr, wwin);
298 WMPostNotificationName(WMNChangedState, wwin, "shade");
301 /* Set the old coordinates using the current values */
302 static void save_old_geometry(WWindow *wwin)
304 wwin->old_geometry.width = wwin->client.width;
305 wwin->old_geometry.height = wwin->client.height;
306 wwin->old_geometry.x = wwin->frame_x;
307 wwin->old_geometry.y = wwin->frame_y;
310 void wMaximizeWindow(WWindow * wwin, int directions)
312 int new_x, new_y;
313 unsigned int new_width, new_height, half_scr_width;
314 WArea usableArea, totalArea;
315 Bool has_border = 1;
316 int adj_size;
318 if (!IS_RESIZABLE(wwin))
319 return;
321 if (!HAS_BORDER(wwin))
322 has_border = 0;
324 /* the size to adjust the geometry */
325 adj_size = FRAME_BORDER_WIDTH * 2 * has_border;
327 /* save old coordinates before we change the current values */
328 save_old_geometry(wwin);
330 totalArea.x1 = 0;
331 totalArea.y1 = 0;
332 totalArea.x2 = wwin->screen_ptr->scr_width;
333 totalArea.y2 = wwin->screen_ptr->scr_height;
334 usableArea = totalArea;
336 if (!(directions & MAX_IGNORE_XINERAMA)) {
337 WScreen *scr = wwin->screen_ptr;
338 int head;
340 if (directions & MAX_KEYBOARD)
341 head = wGetHeadForWindow(wwin);
342 else
343 head = wGetHeadForPointerLocation(scr);
345 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
348 /* Only save directions, not kbd or xinerama hints */
349 directions &= (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_MAXIMUS);
351 if (WFLAGP(wwin, full_maximize)) {
352 usableArea = totalArea;
354 half_scr_width = (usableArea.x2 - usableArea.x1)/2;
356 if (wwin->flags.shaded) {
357 wwin->flags.skip_next_animation = 1;
358 wUnshadeWindow(wwin);
361 if (directions & MAX_HORIZONTAL) {
362 new_width = usableArea.x2 - usableArea.x1 - adj_size;
363 new_x = usableArea.x1;
364 } else if (directions & MAX_LEFTHALF) {
365 new_width = half_scr_width - adj_size;
366 new_x = usableArea.x1;
367 } else if (directions & MAX_RIGHTHALF) {
368 new_width = half_scr_width - adj_size;
369 new_x = usableArea.x1 + half_scr_width;
370 } else {
371 new_x = wwin->frame_x;
372 new_width = wwin->frame->core->width;
375 if (directions & MAX_VERTICAL) {
376 new_height = usableArea.y2 - usableArea.y1 - adj_size;
377 new_y = usableArea.y1;
378 if (WFLAGP(wwin, full_maximize)) {
379 new_y -= wwin->frame->top_width;
380 new_height += wwin->frame->bottom_width - 1;
382 } else {
383 new_y = wwin->frame_y;
384 new_height = wwin->frame->core->height;
387 if (!WFLAGP(wwin, full_maximize)) {
388 new_height -= wwin->frame->top_width + wwin->frame->bottom_width;
391 if (directions & MAX_MAXIMUS) {
392 find_Maximus_geometry(wwin, usableArea, &new_x, &new_y, &new_width, &new_height);
393 new_width -= adj_size;
394 new_height -= adj_size;
395 if (WFLAGP(wwin, full_maximize) && new_y == 0) {
396 new_y -= wwin->frame->top_width;
397 new_height += wwin->frame->top_width - 1;
401 wWindowConstrainSize(wwin, &new_width, &new_height);
403 wWindowCropSize(wwin, usableArea.x2 - usableArea.x1,
404 usableArea.y2 - usableArea.y1, &new_width, &new_height);
406 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
408 WMPostNotificationName(WMNChangedState, wwin, "maximize");
410 /* set maximization state */
411 wwin->flags.maximized = directions;
415 * Maximus: tiled maximization (maximize without overlapping other windows)
417 * The window to be maximized will be denoted by w_0 (sub-index zero)
418 * while the windows which will stop the maximization of w_0 are denoted by w_j.
420 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
421 unsigned int *new_width, unsigned int *new_height)
423 WWindow *tmp;
424 int x_0 = wwin->frame_x;
425 int y_0 = wwin->frame_y;
426 int width_0 = wwin->frame->core->width;
427 int height_0 = wwin->frame->core->height;
428 int botton_0 = y_0 + height_0;
429 int right_border_0 = x_0 + width_0;
430 int new_x_0, new_y_0, new_botton_0, new_right_border_0, new_height_0;
431 int x_j, y_j, width_j, height_j, botton_j, top_j, right_border_j;
432 int x_intsect, y_intsect;
433 short int tbar_height_0 = 0, rbar_height_0 = 0;
434 short int bd_width_0 = 0, bd_width_j = 0;
435 short int adjust_height;
437 /* Try to fully maximize first, then readjust later */
438 new_x_0 = usableArea.x1;
439 new_y_0 = usableArea.y1;
440 new_botton_0 = usableArea.y2;
441 new_right_border_0 = usableArea.x2;
443 if (HAS_TITLEBAR(wwin))
444 tbar_height_0 = TITLEBAR_HEIGHT;
445 if (HAS_RESIZEBAR(wwin))
446 rbar_height_0 = RESIZEBAR_HEIGHT;
447 if (HAS_BORDER(wwin))
448 bd_width_0 = FRAME_BORDER_WIDTH;
450 /* the lengths to be subtracted if w_0 has titlebar, etc */
451 adjust_height = tbar_height_0 + 2 * bd_width_0 + rbar_height_0;
453 tmp = wwin;
454 /* The focused window is always the last in the list */
455 while (tmp->prev) {
456 /* ignore windows in other workspaces etc */
457 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
458 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
459 tmp = tmp->prev;
460 continue;
462 tmp = tmp->prev;
464 if (HAS_BORDER(tmp))
465 bd_width_j = FRAME_BORDER_WIDTH;
466 else
467 bd_width_j = 0;
470 * Set the w_j window coordinates. It is convenient
471 * to not use "corrected" sizes for width and height,
472 * otherwise bottom_j and right_border_j would be
473 * incorrect.
475 x_j = tmp->frame_x - bd_width_j;
476 y_j = tmp->frame_y - bd_width_j;
477 width_j = tmp->frame->core->width;
478 height_j = tmp->frame->core->height;
479 botton_j = y_j + height_j + bd_width_j;
480 top_j = y_j - bd_width_j;
481 right_border_j = x_j + width_j + bd_width_j;
483 /* Try to maximize in the y direction first */
484 x_intsect = calcIntersectionLength(x_0, width_0, x_j, width_j);
485 if (x_intsect != 0) {
486 /* TODO: Consider the case when coords are equal */
487 if (botton_j < y_0 && botton_j > new_y_0) {
488 /* w_0 is below the botton of w_j */
489 new_y_0 = botton_j;
491 if (botton_0 < top_j && top_j < new_botton_0) {
492 /* The botton of w_0 is above the top of w_j */
493 new_botton_0 = top_j;
498 tmp = wwin;
499 while (tmp->prev) {
500 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
501 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
502 tmp = tmp->prev;
503 continue;
505 tmp = tmp->prev;
507 if (HAS_BORDER(tmp))
508 bd_width_j = FRAME_BORDER_WIDTH;
509 else
510 bd_width_j = 0;
512 /* set the w_j window coordinates */
513 x_j = tmp->frame_x - bd_width_j;
514 y_j = tmp->frame_y - bd_width_j;
515 width_j = tmp->frame->core->width;
516 height_j = tmp->frame->core->height;
517 botton_j = y_j + height_j + bd_width_j;
518 top_j = y_j - bd_width_j;
519 right_border_j = x_j + width_j + bd_width_j;
522 * Use the updated y coordinates from the above step to account
523 * the possibility that the new value of y_0 will have different
524 * intersections with w_j
526 new_height_0 = new_botton_0 - new_y_0 - adjust_height;
527 y_intsect = calcIntersectionLength(new_y_0, new_height_0, y_j, height_j);
528 if (y_intsect != 0) {
529 if (right_border_j < x_0 && right_border_j > new_x_0) {
530 /* w_0 is completely to the right of w_j */
531 new_x_0 = right_border_j + 1;
533 if (right_border_0 < x_j && x_j < new_right_border_0) {
534 /* w_0 is completely to the left of w_j */
535 new_right_border_0 = x_j - 1;
540 new_height_0 = new_botton_0 - new_y_0 - adjust_height;
541 *new_x = new_x_0;
542 *new_y = new_y_0;
543 *new_height = new_height_0;
544 *new_width = new_right_border_0 - new_x_0;
547 void wUnmaximizeWindow(WWindow * wwin)
549 int x, y, w, h;
550 WMRect old_geom_rect;
551 int old_head;
552 Bool same_head;
554 if (!wwin->flags.maximized)
555 return;
557 if (wwin->flags.shaded) {
558 wwin->flags.skip_next_animation = 1;
559 wUnshadeWindow(wwin);
561 /* Use old coordinates if they are set, current values otherwise */
562 old_geom_rect = wmkrect(wwin->old_geometry.x, wwin->old_geometry.y, wwin->old_geometry.width, wwin->old_geometry.height);
563 old_head = wGetHeadForRect(wwin->screen_ptr, old_geom_rect);
564 same_head = (wGetHeadForWindow(wwin) == old_head);
565 x = (wwin->old_geometry.x && same_head) ? wwin->old_geometry.x : wwin->frame_x;
566 y = (wwin->old_geometry.y && same_head) ? wwin->old_geometry.y : wwin->frame_y;
567 w = wwin->old_geometry.width ? wwin->old_geometry.width : wwin->client.width;
568 h = wwin->old_geometry.height ? wwin->old_geometry.height : wwin->client.height;
570 wwin->flags.maximized = 0;
571 wWindowConfigure(wwin, x, y, w, h);
573 WMPostNotificationName(WMNChangedState, wwin, "maximize");
576 void wFullscreenWindow(WWindow * wwin)
578 int head;
579 WMRect rect;
581 if (wwin->flags.fullscreen)
582 return;
584 wwin->flags.fullscreen = True;
586 wWindowConfigureBorders(wwin);
588 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
590 wwin->bfs_geometry.x = wwin->frame_x;
591 wwin->bfs_geometry.y = wwin->frame_y;
592 wwin->bfs_geometry.width = wwin->frame->core->width;
593 wwin->bfs_geometry.height = wwin->frame->core->height;
595 head = wGetHeadForWindow(wwin);
596 rect = wGetRectForHead(wwin->screen_ptr, head);
597 wWindowConfigure(wwin, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
599 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
602 void wUnfullscreenWindow(WWindow * wwin)
604 if (!wwin->flags.fullscreen)
605 return;
607 wwin->flags.fullscreen = False;
609 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
610 if (WFLAGP(wwin, sunken)) {
611 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
612 } else if (WFLAGP(wwin, floating)) {
613 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
614 } else {
615 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
619 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
620 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
622 wWindowConfigureBorders(wwin);
624 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
625 wFrameWindowPaint(wwin->frame);
628 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
631 #ifdef ANIMATIONS
632 static void animateResizeFlip(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
634 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
635 float cx, cy, cw, ch;
636 float xstep, ystep, wstep, hstep;
637 XPoint points[5];
638 float dx, dch, midy;
639 float angle, final_angle, delta;
641 xstep = (float)(fx - x) / steps;
642 ystep = (float)(fy - y) / steps;
643 wstep = (float)(fw - w) / steps;
644 hstep = (float)(fh - h) / steps;
646 cx = (float)x;
647 cy = (float)y;
648 cw = (float)w;
649 ch = (float)h;
651 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_F;
652 delta = (float)(final_angle / FRAMES);
653 for (angle = 0;; angle += delta) {
654 if (angle > final_angle)
655 angle = final_angle;
657 dx = (cw / 10) - ((cw / 5) * sin(angle));
658 dch = (ch / 2) * cos(angle);
659 midy = cy + (ch / 2);
661 points[0].x = cx + dx;
662 points[0].y = midy - dch;
663 points[1].x = cx + cw - dx;
664 points[1].y = points[0].y;
665 points[2].x = cx + cw + dx;
666 points[2].y = midy + dch;
667 points[3].x = cx - dx;
668 points[3].y = points[2].y;
669 points[4].x = points[0].x;
670 points[4].y = points[0].y;
672 XGrabServer(dpy);
673 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
674 XFlush(dpy);
675 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
677 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
678 XUngrabServer(dpy);
679 cx += xstep;
680 cy += ystep;
681 cw += wstep;
682 ch += hstep;
683 if (angle >= final_angle)
684 break;
687 XFlush(dpy);
690 #undef FRAMES
692 static void
693 animateResizeTwist(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
695 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
696 float cx, cy, cw, ch;
697 float xstep, ystep, wstep, hstep;
698 XPoint points[5];
699 float angle, final_angle, a, d, delta;
701 x += w / 2;
702 y += h / 2;
703 fx += fw / 2;
704 fy += fh / 2;
706 xstep = (float)(fx - x) / steps;
707 ystep = (float)(fy - y) / steps;
708 wstep = (float)(fw - w) / steps;
709 hstep = (float)(fh - h) / steps;
711 cx = (float)x;
712 cy = (float)y;
713 cw = (float)w;
714 ch = (float)h;
716 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_T;
717 delta = (float)(final_angle / FRAMES);
718 for (angle = 0;; angle += delta) {
719 if (angle > final_angle)
720 angle = final_angle;
722 a = atan(ch / cw);
723 d = sqrt((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
725 points[0].x = cx + cos(angle - a) * d;
726 points[0].y = cy + sin(angle - a) * d;
727 points[1].x = cx + cos(angle + a) * d;
728 points[1].y = cy + sin(angle + a) * d;
729 points[2].x = cx + cos(angle - a + WM_PI) * d;
730 points[2].y = cy + sin(angle - a + WM_PI) * d;
731 points[3].x = cx + cos(angle + a + WM_PI) * d;
732 points[3].y = cy + sin(angle + a + WM_PI) * d;
733 points[4].x = cx + cos(angle - a) * d;
734 points[4].y = cy + sin(angle - a) * d;
735 XGrabServer(dpy);
736 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
737 XFlush(dpy);
738 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
740 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
741 XUngrabServer(dpy);
742 cx += xstep;
743 cy += ystep;
744 cw += wstep;
745 ch += hstep;
746 if (angle >= final_angle)
747 break;
750 XFlush(dpy);
753 #undef FRAMES
755 static void animateResizeZoom(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
757 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
758 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
759 float xstep, ystep, wstep, hstep;
760 int i, j;
762 xstep = (float)(fx - x) / steps;
763 ystep = (float)(fy - y) / steps;
764 wstep = (float)(fw - w) / steps;
765 hstep = (float)(fh - h) / steps;
767 for (j = 0; j < FRAMES; j++) {
768 cx[j] = (float)x;
769 cy[j] = (float)y;
770 cw[j] = (float)w;
771 ch[j] = (float)h;
773 XGrabServer(dpy);
774 for (i = 0; i < steps; i++) {
775 for (j = 0; j < FRAMES; j++) {
776 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
777 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
779 XFlush(dpy);
780 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
782 for (j = 0; j < FRAMES; j++) {
783 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
784 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
785 if (j < FRAMES - 1) {
786 cx[j] = cx[j + 1];
787 cy[j] = cy[j + 1];
788 cw[j] = cw[j + 1];
789 ch[j] = ch[j + 1];
790 } else {
791 cx[j] += xstep;
792 cy[j] += ystep;
793 cw[j] += wstep;
794 ch[j] += hstep;
799 for (j = 0; j < FRAMES; j++) {
800 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
802 XFlush(dpy);
803 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
805 for (j = 0; j < FRAMES; j++) {
806 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
809 XUngrabServer(dpy);
812 #undef FRAMES
814 void animateResize(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh)
816 int style = wPreferences.iconification_style; /* Catch the value */
817 int steps;
819 if (style == WIS_NONE)
820 return;
822 if (style == WIS_RANDOM) {
823 style = rand() % 3;
826 switch (style) {
827 case WIS_TWIST:
828 steps = MINIATURIZE_ANIMATION_STEPS_T;
829 if (steps > 0)
830 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
831 break;
832 case WIS_FLIP:
833 steps = MINIATURIZE_ANIMATION_STEPS_F;
834 if (steps > 0)
835 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
836 break;
837 case WIS_ZOOM:
838 default:
839 steps = MINIATURIZE_ANIMATION_STEPS_Z;
840 if (steps > 0)
841 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
842 break;
845 #endif /* ANIMATIONS */
847 static void flushExpose()
849 XEvent tmpev;
851 while (XCheckTypedEvent(dpy, Expose, &tmpev))
852 WMHandleEvent(&tmpev);
853 XSync(dpy, 0);
856 static void unmapTransientsFor(WWindow * wwin)
858 WWindow *tmp;
860 tmp = wwin->screen_ptr->focused_window;
861 while (tmp) {
862 /* unmap the transients for this transient */
863 if (tmp != wwin && tmp->transient_for == wwin->client_win
864 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup || tmp->flags.shaded)) {
865 unmapTransientsFor(tmp);
866 tmp->flags.miniaturized = 1;
867 if (!tmp->flags.shaded) {
868 wWindowUnmap(tmp);
869 } else {
870 XUnmapWindow(dpy, tmp->frame->core->window);
873 if (!tmp->flags.shaded)
875 wClientSetState(tmp, IconicState, None);
877 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
879 tmp = tmp->prev;
883 static void mapTransientsFor(WWindow * wwin)
885 WWindow *tmp;
887 tmp = wwin->screen_ptr->focused_window;
888 while (tmp) {
889 /* recursively map the transients for this transient */
890 if (tmp != wwin && tmp->transient_for == wwin->client_win && /*!tmp->flags.mapped */ tmp->flags.miniaturized
891 && tmp->icon == NULL) {
892 mapTransientsFor(tmp);
893 tmp->flags.miniaturized = 0;
894 if (!tmp->flags.shaded) {
895 wWindowMap(tmp);
896 } else {
897 XMapWindow(dpy, tmp->frame->core->window);
899 tmp->flags.semi_focused = 0;
901 if (!tmp->flags.shaded)
903 wClientSetState(tmp, NormalState, None);
905 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
907 tmp = tmp->prev;
911 #if 0
912 static void setupIconGrabs(WIcon * icon)
914 /* setup passive grabs on the icon */
915 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
916 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
917 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
918 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
919 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
920 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
921 XSync(dpy, 0);
923 #endif
925 static WWindow *recursiveTransientFor(WWindow * wwin)
927 int i;
929 if (!wwin)
930 return None;
932 /* hackish way to detect transient_for cycle */
933 i = wwin->screen_ptr->window_count + 1;
935 while (wwin && wwin->transient_for != None && i > 0) {
936 wwin = wWindowFor(wwin->transient_for);
937 i--;
939 if (i == 0 && wwin) {
940 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin->frame->title);
941 return NULL;
944 return wwin;
947 #if 0
948 static void removeIconGrabs(WIcon * icon)
950 /* remove passive grabs on the icon */
951 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
952 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
953 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
954 XSync(dpy, 0);
956 #endif
958 void wIconifyWindow(WWindow * wwin)
960 XWindowAttributes attribs;
961 int present;
963 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
964 /* the window doesn't exist anymore */
965 return;
968 if (wwin->flags.miniaturized) {
969 return;
972 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
973 WWindow *owner = wWindowFor(wwin->transient_for);
975 if (owner && owner->flags.miniaturized)
976 return;
979 present = wwin->frame->workspace == wwin->screen_ptr->current_workspace;
981 /* if the window is in another workspace, simplify process */
982 if (present) {
983 /* icon creation may take a while */
984 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
985 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
986 GrabModeAsync, None, None, CurrentTime);
989 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
990 if (!wwin->flags.icon_moved) {
991 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
993 wwin->icon = wIconCreate(wwin);
995 wwin->icon->mapped = 1;
998 wwin->flags.miniaturized = 1;
999 wwin->flags.mapped = 0;
1001 /* unmap transients */
1003 unmapTransientsFor(wwin);
1005 if (present) {
1006 XUngrabPointer(dpy, CurrentTime);
1007 wWindowUnmap(wwin);
1008 /* let all Expose events arrive so that we can repaint
1009 * something before the animation starts (and the server is grabbed) */
1010 XSync(dpy, 0);
1012 if (wPreferences.disable_miniwindows || wwin->flags.net_handle_icon)
1013 wClientSetState(wwin, IconicState, None);
1014 else
1015 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
1017 flushExpose();
1018 #ifdef ANIMATIONS
1019 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
1020 && !wPreferences.no_animations) {
1021 int ix, iy, iw, ih;
1023 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1024 ix = wwin->icon_x;
1025 iy = wwin->icon_y;
1026 iw = wwin->icon->core->width;
1027 ih = wwin->icon->core->height;
1028 } else {
1029 if (wwin->flags.net_handle_icon) {
1030 ix = wwin->icon_x;
1031 iy = wwin->icon_y;
1032 iw = wwin->icon_w;
1033 ih = wwin->icon_h;
1034 } else {
1035 ix = 0;
1036 iy = 0;
1037 iw = wwin->screen_ptr->scr_width;
1038 ih = wwin->screen_ptr->scr_height;
1041 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1042 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih);
1044 #endif
1047 wwin->flags.skip_next_animation = 0;
1049 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1050 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace ||
1051 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1053 XMapWindow(dpy, wwin->icon->core->window);
1055 AddToStackList(wwin->icon->core);
1057 wLowerFrame(wwin->icon->core);
1060 if (present) {
1061 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1064 * It doesn't seem to be working and causes button event hangup
1065 * when deiconifying a transient window.
1066 setupIconGrabs(wwin->icon);
1068 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
1069 && wPreferences.focus_mode == WKF_CLICK) {
1070 WWindow *tmp;
1072 tmp = wwin->prev;
1073 while (tmp) {
1074 if (!WFLAGP(tmp, no_focusable)
1075 && !(tmp->flags.hidden || tmp->flags.miniaturized)
1076 && (wwin->frame->workspace == tmp->frame->workspace))
1077 break;
1078 tmp = tmp->prev;
1080 wSetFocusTo(wwin->screen_ptr, tmp);
1081 } else if (wPreferences.focus_mode != WKF_CLICK) {
1082 wSetFocusTo(wwin->screen_ptr, NULL);
1084 #ifdef ANIMATIONS
1085 if (!wwin->screen_ptr->flags.startup) {
1086 /* Catch up with events not processed while animation was running */
1087 Window clientwin = wwin->client_win;
1089 ProcessPendingEvents();
1091 /* the window can disappear while ProcessPendingEvents() runs */
1092 if (!wWindowFor(clientwin)) {
1093 return;
1096 #endif
1099 /* maybe we want to do this regardless of net_handle_icon
1100 * it seems to me we might break behaviour this way.
1102 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1103 && !wwin->flags.net_handle_icon)
1104 wIconSelect(wwin->icon);
1106 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1108 if (wPreferences.auto_arrange_icons)
1109 wArrangeIcons(wwin->screen_ptr, True);
1112 void wDeiconifyWindow(WWindow * wwin)
1114 /* Let's avoid changing workspace while deiconifying */
1115 ignore_wks_change = 1;
1117 /* we're hiding for show_desktop */
1118 int netwm_hidden = wwin->flags.net_show_desktop &&
1119 wwin->frame->workspace != wwin->screen_ptr->current_workspace;
1121 if (!netwm_hidden)
1122 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1124 if (!wwin->flags.miniaturized)
1125 return;
1127 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1128 WWindow *owner = recursiveTransientFor(wwin);
1130 if (owner && owner->flags.miniaturized) {
1131 wDeiconifyWindow(owner);
1132 wSetFocusTo(wwin->screen_ptr, wwin);
1133 wRaiseFrame(wwin->frame->core);
1134 return;
1138 wwin->flags.miniaturized = 0;
1140 if (!netwm_hidden && !wwin->flags.shaded) {
1141 wwin->flags.mapped = 1;
1144 if (!netwm_hidden || wPreferences.sticky_icons) {
1145 /* maybe we want to do this regardless of net_handle_icon
1146 * it seems to me we might break behaviour this way.
1148 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon
1149 && wwin->icon != NULL) {
1150 if (wwin->icon->selected)
1151 wIconSelect(wwin->icon);
1153 XUnmapWindow(dpy, wwin->icon->core->window);
1157 /* if the window is in another workspace, do it silently */
1158 if (!netwm_hidden) {
1159 #ifdef ANIMATIONS
1160 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1161 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1162 int ix, iy, iw, ih;
1164 if (!wPreferences.disable_miniwindows
1165 && !wwin->flags.net_handle_icon) {
1166 ix = wwin->icon_x;
1167 iy = wwin->icon_y;
1168 iw = wwin->icon->core->width;
1169 ih = wwin->icon->core->height;
1170 } else {
1171 if (wwin->flags.net_handle_icon) {
1172 ix = wwin->icon_x;
1173 iy = wwin->icon_y;
1174 iw = wwin->icon_w;
1175 ih = wwin->icon_h;
1176 } else {
1177 ix = 0;
1178 iy = 0;
1179 iw = wwin->screen_ptr->scr_width;
1180 ih = wwin->screen_ptr->scr_height;
1183 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1184 wwin->frame_x, wwin->frame_y,
1185 wwin->frame->core->width, wwin->frame->core->height);
1187 #endif /* ANIMATIONS */
1188 wwin->flags.skip_next_animation = 0;
1189 XGrabServer(dpy);
1190 if (!wwin->flags.shaded) {
1191 XMapWindow(dpy, wwin->client_win);
1193 XMapWindow(dpy, wwin->frame->core->window);
1194 wRaiseFrame(wwin->frame->core);
1195 if (!wwin->flags.shaded) {
1196 wClientSetState(wwin, NormalState, None);
1198 mapTransientsFor(wwin);
1201 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1202 && !wwin->flags.net_handle_icon) {
1203 RemoveFromStackList(wwin->icon->core);
1204 /* removeIconGrabs(wwin->icon); */
1205 wIconDestroy(wwin->icon);
1206 wwin->icon = NULL;
1209 if (!netwm_hidden) {
1210 XUngrabServer(dpy);
1212 wSetFocusTo(wwin->screen_ptr, wwin);
1214 #ifdef ANIMATIONS
1215 if (!wwin->screen_ptr->flags.startup) {
1216 /* Catch up with events not processed while animation was running */
1217 Window clientwin = wwin->client_win;
1219 ProcessPendingEvents();
1221 /* the window can disappear while ProcessPendingEvents() runs */
1222 if (!wWindowFor(clientwin)) {
1223 return;
1226 #endif
1229 if (wPreferences.auto_arrange_icons) {
1230 wArrangeIcons(wwin->screen_ptr, True);
1233 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1235 /* In case we were shaded and iconified, also unshade */
1236 if (!netwm_hidden)
1237 wUnshadeWindow(wwin);
1239 ignore_wks_change = 0;
1242 static void hideWindow(WIcon * icon, int icon_x, int icon_y, WWindow * wwin, int animate)
1244 if (wwin->flags.miniaturized) {
1245 if (wwin->icon) {
1246 XUnmapWindow(dpy, wwin->icon->core->window);
1247 wwin->icon->mapped = 0;
1249 wwin->flags.hidden = 1;
1251 WMPostNotificationName(WMNChangedState, wwin, "hide");
1252 return;
1255 if (wwin->flags.inspector_open) {
1256 wHideInspectorForWindow(wwin);
1259 wwin->flags.hidden = 1;
1260 wWindowUnmap(wwin);
1262 wClientSetState(wwin, IconicState, icon->icon_win);
1263 flushExpose();
1265 #ifdef ANIMATIONS
1266 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1267 !wwin->flags.skip_next_animation && animate) {
1268 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1269 wwin->frame->core->width, wwin->frame->core->height,
1270 icon_x, icon_y, icon->core->width, icon->core->height);
1272 #endif
1273 wwin->flags.skip_next_animation = 0;
1275 WMPostNotificationName(WMNChangedState, wwin, "hide");
1278 void wHideOtherApplications(WWindow * awin)
1280 WWindow *wwin;
1281 WApplication *tapp;
1283 if (!awin)
1284 return;
1285 wwin = awin->screen_ptr->focused_window;
1287 while (wwin) {
1288 if (wwin != awin
1289 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1290 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1291 && !wwin->flags.internal_window
1292 && wGetWindowOfInspectorForWindow(wwin) != awin && !WFLAGP(wwin, no_hide_others)) {
1294 if (wwin->main_window == None || WFLAGP(wwin, no_appicon)) {
1295 if (!WFLAGP(wwin, no_miniaturizable)) {
1296 wwin->flags.skip_next_animation = 1;
1297 wIconifyWindow(wwin);
1299 } else if (wwin->main_window != None && awin->main_window != wwin->main_window) {
1300 tapp = wApplicationOf(wwin->main_window);
1301 if (tapp) {
1302 tapp->flags.skip_next_animation = 1;
1303 wHideApplication(tapp);
1304 } else {
1305 if (!WFLAGP(wwin, no_miniaturizable)) {
1306 wwin->flags.skip_next_animation = 1;
1307 wIconifyWindow(wwin);
1312 wwin = wwin->prev;
1315 wSetFocusTo(awin->screen_ptr, awin);
1319 void wHideApplication(WApplication * wapp)
1321 WScreen *scr;
1322 WWindow *wlist;
1323 int hadfocus;
1324 int animate;
1326 if (!wapp) {
1327 wwarning("trying to hide a non grouped window");
1328 return;
1330 if (!wapp->main_window_desc) {
1331 wwarning("group leader not found for window group");
1332 return;
1334 scr = wapp->main_window_desc->screen_ptr;
1335 hadfocus = 0;
1336 wlist = scr->focused_window;
1337 if (!wlist)
1338 return;
1340 if (wlist->main_window == wapp->main_window)
1341 wapp->last_focused = wlist;
1342 else
1343 wapp->last_focused = NULL;
1345 animate = !wapp->flags.skip_next_animation;
1347 while (wlist) {
1348 if (wlist->main_window == wapp->main_window) {
1349 if (wlist->flags.focused) {
1350 hadfocus = 1;
1352 if (wapp->app_icon) {
1353 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1354 wapp->app_icon->y_pos, wlist, animate);
1355 animate = False;
1358 wlist = wlist->prev;
1361 wapp->flags.skip_next_animation = 0;
1363 if (hadfocus) {
1364 if (wPreferences.focus_mode == WKF_CLICK) {
1365 wlist = scr->focused_window;
1366 while (wlist) {
1367 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1368 && (wlist->flags.mapped || wlist->flags.shaded))
1369 break;
1370 wlist = wlist->prev;
1372 wSetFocusTo(scr, wlist);
1373 } else {
1374 wSetFocusTo(scr, NULL);
1378 wapp->flags.hidden = 1;
1380 if (wPreferences.auto_arrange_icons) {
1381 wArrangeIcons(scr, True);
1383 #ifdef HIDDENDOT
1384 if (wapp->app_icon)
1385 wAppIconPaint(wapp->app_icon);
1386 #endif
1389 static void unhideWindow(WIcon * icon, int icon_x, int icon_y, WWindow * wwin, int animate, int bringToCurrentWS)
1391 if (bringToCurrentWS)
1392 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1394 wwin->flags.hidden = 0;
1396 #ifdef ANIMATIONS
1397 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1398 animateResize(wwin->screen_ptr, icon_x, icon_y,
1399 icon->core->width, icon->core->height,
1400 wwin->frame_x, wwin->frame_y,
1401 wwin->frame->core->width, wwin->frame->core->height);
1403 #endif
1404 wwin->flags.skip_next_animation = 0;
1405 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1406 XMapWindow(dpy, wwin->client_win);
1407 XMapWindow(dpy, wwin->frame->core->window);
1408 wClientSetState(wwin, NormalState, None);
1409 wwin->flags.mapped = 1;
1410 wRaiseFrame(wwin->frame->core);
1412 if (wwin->flags.inspector_open) {
1413 wUnhideInspectorForWindow(wwin);
1416 WMPostNotificationName(WMNChangedState, wwin, "hide");
1419 void wUnhideApplication(WApplication * wapp, Bool miniwindows, Bool bringToCurrentWS)
1421 WScreen *scr;
1422 WWindow *wlist, *next;
1423 WWindow *focused = NULL;
1424 int animate;
1426 if (!wapp)
1427 return;
1429 scr = wapp->main_window_desc->screen_ptr;
1430 wlist = scr->focused_window;
1431 if (!wlist)
1432 return;
1434 /* goto beginning of list */
1435 while (wlist->prev)
1436 wlist = wlist->prev;
1438 animate = !wapp->flags.skip_next_animation;
1440 while (wlist) {
1441 next = wlist->next;
1443 if (wlist->main_window == wapp->main_window) {
1444 if (wlist->flags.focused)
1445 focused = wlist;
1446 else if (!focused || !focused->flags.focused)
1447 focused = wlist;
1449 if (wlist->flags.miniaturized) {
1450 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1451 wlist->frame->workspace == scr->current_workspace) && wlist->icon) {
1452 if (!wlist->icon->mapped) {
1453 int x, y;
1455 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1456 if (wlist->icon_x != x || wlist->icon_y != y) {
1457 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1459 wlist->icon_x = x;
1460 wlist->icon_y = y;
1461 XMapWindow(dpy, wlist->icon->core->window);
1462 wlist->icon->mapped = 1;
1464 wRaiseFrame(wlist->icon->core);
1466 if (bringToCurrentWS)
1467 wWindowChangeWorkspace(wlist, scr->current_workspace);
1468 wlist->flags.hidden = 0;
1469 if (miniwindows && wlist->frame->workspace == scr->current_workspace) {
1470 wDeiconifyWindow(wlist);
1472 WMPostNotificationName(WMNChangedState, wlist, "hide");
1473 } else if (wlist->flags.shaded) {
1474 if (bringToCurrentWS)
1475 wWindowChangeWorkspace(wlist, scr->current_workspace);
1476 wlist->flags.hidden = 0;
1477 if (wlist->frame->workspace == scr->current_workspace) {
1478 XMapWindow(dpy, wlist->frame->core->window);
1479 if (miniwindows) {
1480 wUnshadeWindow(wlist);
1481 wRaiseFrame(wlist->frame->core);
1484 WMPostNotificationName(WMNChangedState, wlist, "hide");
1485 } else if (wlist->flags.hidden) {
1486 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1487 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1488 animate = False;
1489 } else {
1490 if (bringToCurrentWS && wlist->frame->workspace != scr->current_workspace) {
1491 wWindowChangeWorkspace(wlist, scr->current_workspace);
1493 wRaiseFrame(wlist->frame->core);
1496 wlist = next;
1499 wapp->flags.skip_next_animation = 0;
1500 wapp->flags.hidden = 0;
1502 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1503 wRaiseFrame(wapp->last_focused->frame->core);
1504 wSetFocusTo(scr, wapp->last_focused);
1505 } else if (focused) {
1506 wSetFocusTo(scr, focused);
1508 wapp->last_focused = NULL;
1509 if (wPreferences.auto_arrange_icons) {
1510 wArrangeIcons(scr, True);
1512 #ifdef HIDDENDOT
1513 wAppIconPaint(wapp->app_icon);
1514 #endif
1517 void wShowAllWindows(WScreen * scr)
1519 WWindow *wwin, *old_foc;
1520 WApplication *wapp;
1522 old_foc = wwin = scr->focused_window;
1523 while (wwin) {
1524 if (!wwin->flags.internal_window &&
1525 (scr->current_workspace == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1526 if (wwin->flags.miniaturized) {
1527 wwin->flags.skip_next_animation = 1;
1528 wDeiconifyWindow(wwin);
1529 } else if (wwin->flags.hidden) {
1530 wapp = wApplicationOf(wwin->main_window);
1531 if (wapp) {
1532 wUnhideApplication(wapp, False, False);
1533 } else {
1534 wwin->flags.skip_next_animation = 1;
1535 wDeiconifyWindow(wwin);
1539 wwin = wwin->prev;
1541 wSetFocusTo(scr, old_foc);
1542 /*wRaiseFrame(old_foc->frame->core); */
1545 void wRefreshDesktop(WScreen * scr)
1547 Window win;
1548 XSetWindowAttributes attr;
1550 attr.backing_store = NotUseful;
1551 attr.save_under = False;
1552 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1553 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1554 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1555 XMapRaised(dpy, win);
1556 XDestroyWindow(dpy, win);
1557 XFlush(dpy);
1560 void wArrangeIcons(WScreen * scr, Bool arrangeAll)
1562 WWindow *wwin;
1563 WAppIcon *aicon;
1565 int head;
1566 const int heads = wXineramaHeads(scr);
1568 struct HeadVars {
1569 int pf; /* primary axis */
1570 int sf; /* secondary axis */
1571 int fullW;
1572 int fullH;
1573 int pi, si;
1574 int sx1, sx2, sy1, sy2; /* screen boundary */
1575 int sw, sh;
1576 int xo, yo;
1577 int xs, ys;
1578 } *vars;
1580 int isize = wPreferences.icon_size;
1582 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
1584 for (head = 0; head < heads; ++head) {
1585 #if 0
1586 WMRect rect = wGetRectForHead(scr, head);
1587 #else
1588 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1589 WMRect rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
1590 #endif
1592 vars[head].pi = vars[head].si = 0;
1593 vars[head].sx1 = rect.pos.x;
1594 vars[head].sy1 = rect.pos.y;
1595 vars[head].sw = rect.size.width;
1596 vars[head].sh = rect.size.height;
1597 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1598 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1600 #if 0
1601 if (scr->dock) {
1602 if (scr->dock->on_right_side)
1603 vars[head].sx2 -= isize + DOCK_EXTRA_SPACE;
1604 else
1605 vars[head].sx1 += isize + DOCK_EXTRA_SPACE;
1607 #endif
1609 vars[head].sw = isize * (vars[head].sw / isize);
1610 vars[head].sh = isize * (vars[head].sh / isize);
1611 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
1612 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
1614 /* icon yard boundaries */
1615 if (wPreferences.icon_yard & IY_VERT) {
1616 vars[head].pf = vars[head].fullH;
1617 vars[head].sf = vars[head].fullW;
1618 } else {
1619 vars[head].pf = vars[head].fullW;
1620 vars[head].sf = vars[head].fullH;
1622 if (wPreferences.icon_yard & IY_RIGHT) {
1623 vars[head].xo = vars[head].sx2 - isize;
1624 vars[head].xs = -1;
1625 } else {
1626 vars[head].xo = vars[head].sx1;
1627 vars[head].xs = 1;
1629 if (wPreferences.icon_yard & IY_TOP) {
1630 vars[head].yo = vars[head].sy1;
1631 vars[head].ys = 1;
1632 } else {
1633 vars[head].yo = vars[head].sy2 - isize;
1634 vars[head].ys = -1;
1638 #define X ((wPreferences.icon_yard & IY_VERT) \
1639 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1640 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1642 #define Y ((wPreferences.icon_yard & IY_VERT) \
1643 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1644 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1646 /* arrange application icons */
1647 aicon = scr->app_icon_list;
1648 /* reverse them to avoid unnecessarily sliding of icons */
1649 while (aicon && aicon->next)
1650 aicon = aicon->next;
1652 while (aicon) {
1653 if (!aicon->docked) {
1654 /* CHECK: can icon be NULL here ? */
1655 /* The intention here is to place the AppIcon on the head that
1656 * contains most of the applications _main_ window. */
1657 head = wGetHeadForWindow(aicon->icon->owner);
1659 if (aicon->x_pos != X || aicon->y_pos != Y) {
1660 #ifdef ANIMATIONS
1661 if (!wPreferences.no_animations) {
1662 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1664 #endif /* ANIMATIONS */
1666 wAppIconMove(aicon, X, Y);
1667 vars[head].pi++;
1668 if (vars[head].pi >= vars[head].pf) {
1669 vars[head].pi = 0;
1670 vars[head].si++;
1673 aicon = aicon->prev;
1676 /* arrange miniwindows */
1677 wwin = scr->focused_window;
1678 /* reverse them to avoid unnecessarily shuffling */
1679 while (wwin && wwin->prev)
1680 wwin = wwin->prev;
1682 while (wwin) {
1683 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1684 (wwin->frame->workspace == scr->current_workspace ||
1685 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1687 head = wGetHeadForWindow(wwin);
1689 if (arrangeAll || !wwin->flags.icon_moved) {
1690 if (wwin->icon_x != X || wwin->icon_y != Y) {
1691 #ifdef ANIMATIONS
1692 if (wPreferences.no_animations) {
1693 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1694 } else {
1695 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1696 wwin->icon_y, X, Y);
1698 #else
1699 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1700 #endif /* ANIMATIONS */
1702 wwin->icon_x = X;
1703 wwin->icon_y = Y;
1705 vars[head].pi++;
1706 if (vars[head].pi >= vars[head].pf) {
1707 vars[head].pi = 0;
1708 vars[head].si++;
1712 if (arrangeAll) {
1713 wwin->flags.icon_moved = 0;
1715 /* we reversed the order, so we use next */
1716 wwin = wwin->next;
1719 wfree(vars);
1722 void wSelectWindow(WWindow * wwin, Bool flag)
1724 WScreen *scr = wwin->screen_ptr;
1726 if (flag) {
1727 wwin->flags.selected = 1;
1728 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1730 if (!HAS_BORDER(wwin)) {
1731 XSetWindowBorderWidth(dpy, wwin->frame->core->window, FRAME_BORDER_WIDTH);
1734 if (!scr->selected_windows)
1735 scr->selected_windows = WMCreateArray(4);
1736 WMAddToArray(scr->selected_windows, wwin);
1737 } else {
1738 wwin->flags.selected = 0;
1739 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
1741 if (!HAS_BORDER(wwin)) {
1742 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1745 if (scr->selected_windows) {
1746 WMRemoveFromArray(scr->selected_windows, wwin);
1751 void wMakeWindowVisible(WWindow * wwin)
1753 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1754 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1756 if (wwin->flags.shaded) {
1757 wUnshadeWindow(wwin);
1759 if (wwin->flags.hidden) {
1760 WApplication *app;
1762 app = wApplicationOf(wwin->main_window);
1763 if (app) {
1764 /* trick to get focus to this window */
1765 app->last_focused = wwin;
1766 wUnhideApplication(app, False, False);
1769 if (wwin->flags.miniaturized) {
1770 wDeiconifyWindow(wwin);
1771 } else {
1772 if (!WFLAGP(wwin, no_focusable))
1773 wSetFocusTo(wwin->screen_ptr, wwin);
1774 wRaiseFrame(wwin->frame->core);
1779 * Do the animation while shading (called with what = SHADE)
1780 * or unshading (what = UNSHADE).
1782 #ifdef ANIMATIONS
1783 static void shade_animate(WWindow *wwin, Bool what)
1785 int y, s, w, h;
1786 time_t time0 = time(NULL);
1788 if (wwin->flags.skip_next_animation && wPreferences.no_animations)
1789 return;
1791 switch(what) {
1792 case SHADE:
1793 if (!wwin->screen_ptr->flags.startup) {
1794 /* do the shading animation */
1795 h = wwin->frame->core->height;
1796 s = h / SHADE_STEPS;
1797 if (s < 1)
1798 s = 1;
1799 w = wwin->frame->core->width;
1800 y = wwin->frame->top_width;
1801 while (h > wwin->frame->top_width + 1) {
1802 XMoveWindow(dpy, wwin->client_win, 0, y);
1803 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1804 XFlush(dpy);
1806 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1807 break;
1809 if (SHADE_DELAY > 0) {
1810 wusleep(SHADE_DELAY * 1000L);
1811 } else {
1812 wusleep(10);
1814 h -= s;
1815 y -= s;
1817 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1819 break;
1821 case UNSHADE:
1822 h = wwin->frame->top_width + wwin->frame->bottom_width;
1823 y = wwin->frame->top_width - wwin->client.height;
1824 s = abs(y) / SHADE_STEPS;
1825 if (s < 1)
1826 s = 1;
1827 w = wwin->frame->core->width;
1828 XMoveWindow(dpy, wwin->client_win, 0, y);
1829 if (s > 0) {
1830 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
1831 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1832 XMoveWindow(dpy, wwin->client_win, 0, y);
1833 XFlush(dpy);
1834 if (SHADE_DELAY > 0) {
1835 wusleep(SHADE_DELAY * 2000L / 3);
1836 } else {
1837 wusleep(10);
1839 h += s;
1840 y += s;
1842 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1843 break;
1846 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1847 break;
1850 #endif