Add ${misc:Depends} to all package dependencies.
[wmaker-crm.git] / src / actions.c
blobdea4ebb2ca3ce4e92d1d9747437b03dd70aaeb89
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 "framewin.h"
36 #include "window.h"
37 #include "client.h"
38 #include "icon.h"
39 #include "funcs.h"
40 #include "application.h"
41 #include "actions.h"
42 #include "stacking.h"
43 #include "appicon.h"
44 #include "dock.h"
45 #include "appmenu.h"
46 #include "winspector.h"
47 #include "workspace.h"
48 #include "xinerama.h"
50 /****** Global Variables ******/
52 int ignore_wks_change = 0;
53 extern Time LastTimestamp;
54 extern Time LastFocusChange;
55 extern WPreferences wPreferences;
56 extern Atom _XA_WM_TAKE_FOCUS;
57 extern void ProcessPendingEvents();
58 extern int calcIntersectionLength(int p1, int l1, int p2, int l2);
60 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
61 unsigned int *new_width, unsigned int *new_height);
62 static void save_old_geometry(WWindow *wwin);
64 /******* Local Variables *******/
65 static struct {
66 int steps;
67 int delay;
68 } shadePars[5] = {
70 SHADE_STEPS_UF, SHADE_DELAY_UF}, {
71 SHADE_STEPS_F, SHADE_DELAY_F}, {
72 SHADE_STEPS_M, SHADE_DELAY_M}, {
73 SHADE_STEPS_S, SHADE_DELAY_S}, {
74 SHADE_STEPS_US, SHADE_DELAY_US}};
76 #define UNSHADE 0
77 #define SHADE 1
78 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
79 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
81 static int compareTimes(Time t1, Time t2)
83 Time diff;
84 if (t1 == t2)
85 return 0;
86 diff = t1 - t2;
87 return (diff < 60000) ? 1 : -1;
90 #ifdef ANIMATIONS
91 static void shade_animate(WWindow *wwin, Bool what);
92 #else
93 static void shade_animate(WWindow *wwin, Bool what) { }
94 #endif
97 *----------------------------------------------------------------------
98 * wSetFocusTo--
99 * Changes the window focus to the one passed as argument.
100 * If the window to focus is not already focused, it will be brought
101 * to the head of the list of windows. Previously focused window is
102 * unfocused.
104 * Side effects:
105 * Window list may be reordered and the window focus is changed.
107 *----------------------------------------------------------------------
109 void wSetFocusTo(WScreen *scr, WWindow *wwin)
111 static WScreen *old_scr = NULL;
113 WWindow *old_focused;
114 WWindow *focused = scr->focused_window;
115 Time timestamp = LastTimestamp;
116 WApplication *oapp = NULL, *napp = NULL;
117 int wasfocused;
119 if (scr->flags.ignore_focus_events || compareTimes(LastFocusChange, timestamp) > 0)
120 return;
122 if (!old_scr)
123 old_scr = scr;
124 old_focused = old_scr->focused_window;
126 LastFocusChange = timestamp;
128 if (old_focused)
129 oapp = wApplicationOf(old_focused->main_window);
131 if (wwin == NULL) {
132 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
133 if (old_focused)
134 wWindowUnfocus(old_focused);
135 if (oapp)
136 wAppMenuUnmap(oapp->menu);
138 WMPostNotificationName(WMNChangedFocus, NULL, (void *)True);
139 return;
140 } else if (old_scr != scr && old_focused) {
141 wWindowUnfocus(old_focused);
144 wasfocused = wwin->flags.focused;
145 napp = wApplicationOf(wwin->main_window);
147 /* remember last workspace where the app has been */
148 if (napp) {
149 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
150 napp->last_workspace = wwin->frame->workspace;
153 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
154 /* install colormap if colormap mode is lock mode */
155 if (wPreferences.colormap_mode == WCM_CLICK)
156 wColormapInstallForWindow(scr, wwin);
158 /* set input focus */
159 switch (wwin->focus_mode) {
160 case WFM_NO_INPUT:
161 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
162 break;
164 case WFM_PASSIVE:
165 case WFM_LOCALLY_ACTIVE:
166 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
167 break;
169 case WFM_GLOBALLY_ACTIVE:
170 break;
172 XFlush(dpy);
173 if (wwin->protocols.TAKE_FOCUS) {
174 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
176 XSync(dpy, False);
177 } else {
178 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
180 if (WFLAGP(wwin, no_focusable))
181 return;
183 /* if this is not the focused window focus it */
184 if (focused != wwin) {
185 /* change the focus window list order */
186 if (wwin->prev)
187 wwin->prev->next = wwin->next;
189 if (wwin->next)
190 wwin->next->prev = wwin->prev;
192 wwin->prev = focused;
193 focused->next = wwin;
194 wwin->next = NULL;
195 scr->focused_window = wwin;
197 if (oapp && oapp != napp)
198 wAppMenuUnmap(oapp->menu);
201 wWindowFocus(wwin, focused);
203 if (napp && !wasfocused) {
204 #ifdef USER_MENU
205 wUserMenuRefreshInstances(napp->menu, wwin);
206 #endif /* USER_MENU */
208 if (wwin->flags.mapped)
209 wAppMenuMap(napp->menu, wwin);
212 XFlush(dpy);
213 old_scr = scr;
216 void wShadeWindow(WWindow *wwin)
219 if (wwin->flags.shaded)
220 return;
222 XLowerWindow(dpy, wwin->client_win);
223 shade_animate(wwin, SHADE);
225 wwin->flags.skip_next_animation = 0;
226 wwin->flags.shaded = 1;
227 wwin->flags.mapped = 0;
228 /* prevent window withdrawal when getting UnmapNotify */
229 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
230 XUnmapWindow(dpy, wwin->client_win);
231 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
233 /* for the client it's just like iconification */
234 wFrameWindowResize(wwin->frame, wwin->frame->core->width, wwin->frame->top_width - 1);
236 wwin->client.y = wwin->frame_y - wwin->client.height + wwin->frame->top_width;
237 wWindowSynthConfigureNotify(wwin);
240 wClientSetState(wwin, IconicState, None);
243 WMPostNotificationName(WMNChangedState, wwin, "shade");
245 #ifdef ANIMATIONS
246 if (!wwin->screen_ptr->flags.startup) {
247 /* Catch up with events not processed while animation was running */
248 ProcessPendingEvents();
250 #endif
253 void wUnshadeWindow(WWindow *wwin)
256 if (!wwin->flags.shaded)
257 return;
259 wwin->flags.shaded = 0;
260 wwin->flags.mapped = 1;
261 XMapWindow(dpy, wwin->client_win);
263 shade_animate(wwin, UNSHADE);
265 wwin->flags.skip_next_animation = 0;
266 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
267 wwin->frame->top_width + wwin->client.height + wwin->frame->bottom_width);
269 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
270 wWindowSynthConfigureNotify(wwin);
272 /* if the window is focused, set the focus again as it was disabled during
273 * shading */
274 if (wwin->flags.focused)
275 wSetFocusTo(wwin->screen_ptr, wwin);
277 WMPostNotificationName(WMNChangedState, wwin, "shade");
280 /* Set the old coordinates using the current values */
281 static void save_old_geometry(WWindow *wwin)
283 wwin->old_geometry.width = wwin->client.width;
284 wwin->old_geometry.height = wwin->client.height;
285 wwin->old_geometry.x = wwin->frame_x;
286 wwin->old_geometry.y = wwin->frame_y;
289 void wMaximizeWindow(WWindow *wwin, int directions)
291 int new_x, new_y;
292 unsigned int new_width, new_height, half_scr_width;
293 WArea usableArea, totalArea;
294 Bool has_border = 1;
295 int adj_size;
297 if (!IS_RESIZABLE(wwin))
298 return;
300 if (!HAS_BORDER(wwin))
301 has_border = 0;
303 /* the size to adjust the geometry */
304 adj_size = FRAME_BORDER_WIDTH * 2 * has_border;
306 /* save old coordinates before we change the current values */
307 save_old_geometry(wwin);
309 totalArea.x1 = 0;
310 totalArea.y1 = 0;
311 totalArea.x2 = wwin->screen_ptr->scr_width;
312 totalArea.y2 = wwin->screen_ptr->scr_height;
313 usableArea = totalArea;
315 if (!(directions & MAX_IGNORE_XINERAMA)) {
316 WScreen *scr = wwin->screen_ptr;
317 int head;
319 if (directions & MAX_KEYBOARD)
320 head = wGetHeadForWindow(wwin);
321 else
322 head = wGetHeadForPointerLocation(scr);
324 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
327 /* Only save directions, not kbd or xinerama hints */
328 directions &= (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_MAXIMUS);
330 if (WFLAGP(wwin, full_maximize)) {
331 usableArea = totalArea;
333 half_scr_width = (usableArea.x2 - usableArea.x1)/2;
335 if (wwin->flags.shaded) {
336 wwin->flags.skip_next_animation = 1;
337 wUnshadeWindow(wwin);
340 if (directions & MAX_HORIZONTAL) {
341 new_width = usableArea.x2 - usableArea.x1 - adj_size;
342 new_x = usableArea.x1;
343 } else if (directions & MAX_LEFTHALF) {
344 new_width = half_scr_width - adj_size;
345 new_x = usableArea.x1;
346 } else if (directions & MAX_RIGHTHALF) {
347 new_width = half_scr_width - adj_size;
348 new_x = usableArea.x1 + half_scr_width;
349 } else {
350 new_x = wwin->frame_x;
351 new_width = wwin->frame->core->width;
354 if (directions & MAX_VERTICAL) {
355 new_height = usableArea.y2 - usableArea.y1 - adj_size;
356 new_y = usableArea.y1;
357 if (WFLAGP(wwin, full_maximize)) {
358 new_y -= wwin->frame->top_width;
359 new_height += wwin->frame->bottom_width - 1;
361 } else {
362 new_y = wwin->frame_y;
363 new_height = wwin->frame->core->height;
366 if (!WFLAGP(wwin, full_maximize)) {
367 new_height -= wwin->frame->top_width + wwin->frame->bottom_width;
370 if (directions & MAX_MAXIMUS) {
371 find_Maximus_geometry(wwin, usableArea, &new_x, &new_y, &new_width, &new_height);
372 new_width -= adj_size;
373 new_height -= adj_size;
374 if (WFLAGP(wwin, full_maximize) && new_y == 0) {
375 new_y -= wwin->frame->top_width;
376 new_height += wwin->frame->top_width - 1;
380 wWindowConstrainSize(wwin, &new_width, &new_height);
382 wWindowCropSize(wwin, usableArea.x2 - usableArea.x1,
383 usableArea.y2 - usableArea.y1, &new_width, &new_height);
385 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
387 WMPostNotificationName(WMNChangedState, wwin, "maximize");
389 /* set maximization state */
390 wwin->flags.maximized = directions;
393 /* the window boundary coordinates */
394 typedef struct {
395 int left;
396 int right;
397 int bottom;
398 int top;
399 int width;
400 int height;
401 } win_coords;
403 static void set_window_coords(WWindow *wwin, win_coords *obs)
405 obs->left = wwin->frame_x;
406 obs->top = wwin->frame_y;
407 obs->width = wwin->frame->core->width;
408 obs->height = wwin->frame->core->height;
409 obs->bottom = obs->top + obs->height;
410 obs->right = obs->left + obs->width;
414 * Maximus: tiled maximization (maximize without overlapping other windows)
416 * The original window 'orig' will be maximized to new coordinates 'new'.
417 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
419 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
420 unsigned int *new_width, unsigned int *new_height)
422 WWindow *tmp;
423 short int tbar_height_0 = 0, rbar_height_0 = 0, bd_width_0 = 0;
424 short int adjust_height;
425 int x_intsect, y_intsect;
426 /* the obstructing, original and new windows */
427 win_coords obs, orig, new;
429 /* set the original coordinate positions of the window to be Maximumized */
430 set_window_coords(wwin, &orig);
432 /* Try to fully maximize first, then readjust later */
433 new.left = usableArea.x1;
434 new.right = usableArea.x2;
435 new.top = usableArea.y1;
436 new.bottom = usableArea.y2;
438 if (HAS_TITLEBAR(wwin))
439 tbar_height_0 = TITLEBAR_HEIGHT;
440 if (HAS_RESIZEBAR(wwin))
441 rbar_height_0 = RESIZEBAR_HEIGHT;
442 if (HAS_BORDER(wwin))
443 bd_width_0 = FRAME_BORDER_WIDTH;
445 /* the length to be subtracted if the window has titlebar, etc */
446 adjust_height = tbar_height_0 + 2 * bd_width_0 + rbar_height_0;
448 tmp = wwin;
449 /* The focused window is always the last in the list */
450 while (tmp->prev) {
451 /* ignore windows in other workspaces etc */
452 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
453 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
454 tmp = tmp->prev;
455 continue;
457 tmp = tmp->prev;
459 /* Set the coordinates of obstructing window */
460 set_window_coords(tmp, &obs);
462 /* Try to maximize in the y direction first */
463 x_intsect = calcIntersectionLength(orig.left, orig.width, obs.left, obs.width);
464 if (x_intsect != 0) {
465 /* TODO: Consider the case when coords are equal */
466 if (obs.bottom < orig.top && obs.bottom > new.top) {
467 /* w_0 is below the bottom of w_j */
468 new.top = obs.bottom + 1;
470 if (orig.bottom < obs.top && obs.top < new.bottom) {
471 /* The bottom of w_0 is above the top of w_j */
472 new.bottom = obs.top - 1;
477 tmp = wwin;
478 while (tmp->prev) {
479 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
480 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
481 tmp = tmp->prev;
482 continue;
484 tmp = tmp->prev;
486 set_window_coords(tmp, &obs);
489 * Use the new.top and new.height instead of original values
490 * as they may have different intersections with the obstructing windows
492 new.height = new.bottom - new.top - adjust_height;
493 y_intsect = calcIntersectionLength(new.top, new.height, obs.top, obs.height);
494 if (y_intsect != 0) {
495 if (obs.right < orig.left && obs.right > new.left) {
496 /* w_0 is completely to the right of w_j */
497 new.left = obs.right + 1;
499 if (orig.right < obs.left && obs.left < new.right) {
500 /* w_0 is completely to the left of w_j */
501 new.right = obs.left - 1;
506 *new_x = new.left;
507 *new_y = new.top;
508 /* xcalc needs -7 here, but other apps don't */
509 *new_height = new.bottom - new.top - adjust_height - 1;;
510 *new_width = new.right - new.left;
513 void wUnmaximizeWindow(WWindow *wwin)
515 int x, y, w, h;
516 WMRect old_geom_rect;
517 int old_head;
518 Bool same_head;
520 if (!wwin->flags.maximized)
521 return;
523 if (wwin->flags.shaded) {
524 wwin->flags.skip_next_animation = 1;
525 wUnshadeWindow(wwin);
527 /* Use old coordinates if they are set, current values otherwise */
528 old_geom_rect = wmkrect(wwin->old_geometry.x, wwin->old_geometry.y, wwin->old_geometry.width, wwin->old_geometry.height);
529 old_head = wGetHeadForRect(wwin->screen_ptr, old_geom_rect);
530 same_head = (wGetHeadForWindow(wwin) == old_head);
531 x = (wwin->old_geometry.x && same_head) ? wwin->old_geometry.x : wwin->frame_x;
532 y = (wwin->old_geometry.y && same_head) ? wwin->old_geometry.y : wwin->frame_y;
533 w = wwin->old_geometry.width ? wwin->old_geometry.width : wwin->client.width;
534 h = wwin->old_geometry.height ? wwin->old_geometry.height : wwin->client.height;
536 wwin->flags.maximized = 0;
537 wWindowConfigure(wwin, x, y, w, h);
539 WMPostNotificationName(WMNChangedState, wwin, "maximize");
542 void wFullscreenWindow(WWindow *wwin)
544 int head;
545 WMRect rect;
547 if (wwin->flags.fullscreen)
548 return;
550 wwin->flags.fullscreen = True;
552 wWindowConfigureBorders(wwin);
554 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
556 wwin->bfs_geometry.x = wwin->frame_x;
557 wwin->bfs_geometry.y = wwin->frame_y;
558 wwin->bfs_geometry.width = wwin->frame->core->width;
559 wwin->bfs_geometry.height = wwin->frame->core->height;
561 head = wGetHeadForWindow(wwin);
562 rect = wGetRectForHead(wwin->screen_ptr, head);
563 wWindowConfigure(wwin, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
565 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
568 void wUnfullscreenWindow(WWindow *wwin)
570 if (!wwin->flags.fullscreen)
571 return;
573 wwin->flags.fullscreen = False;
575 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
576 if (WFLAGP(wwin, sunken)) {
577 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
578 } else if (WFLAGP(wwin, floating)) {
579 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
580 } else {
581 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
585 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
586 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
588 wWindowConfigureBorders(wwin);
590 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
591 wFrameWindowPaint(wwin->frame);
594 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
597 #ifdef ANIMATIONS
598 static void animateResizeFlip(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
600 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
601 float cx, cy, cw, ch;
602 float xstep, ystep, wstep, hstep;
603 XPoint points[5];
604 float dx, dch, midy;
605 float angle, final_angle, delta;
607 xstep = (float)(fx - x) / steps;
608 ystep = (float)(fy - y) / steps;
609 wstep = (float)(fw - w) / steps;
610 hstep = (float)(fh - h) / steps;
612 cx = (float)x;
613 cy = (float)y;
614 cw = (float)w;
615 ch = (float)h;
617 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_F;
618 delta = (float)(final_angle / FRAMES);
619 for (angle = 0;; angle += delta) {
620 if (angle > final_angle)
621 angle = final_angle;
623 dx = (cw / 10) - ((cw / 5) * sin(angle));
624 dch = (ch / 2) * cos(angle);
625 midy = cy + (ch / 2);
627 points[0].x = cx + dx;
628 points[0].y = midy - dch;
629 points[1].x = cx + cw - dx;
630 points[1].y = points[0].y;
631 points[2].x = cx + cw + dx;
632 points[2].y = midy + dch;
633 points[3].x = cx - dx;
634 points[3].y = points[2].y;
635 points[4].x = points[0].x;
636 points[4].y = points[0].y;
638 XGrabServer(dpy);
639 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
640 XFlush(dpy);
641 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
643 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
644 XUngrabServer(dpy);
645 cx += xstep;
646 cy += ystep;
647 cw += wstep;
648 ch += hstep;
649 if (angle >= final_angle)
650 break;
653 XFlush(dpy);
656 #undef FRAMES
658 static void
659 animateResizeTwist(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
661 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
662 float cx, cy, cw, ch;
663 float xstep, ystep, wstep, hstep;
664 XPoint points[5];
665 float angle, final_angle, a, d, delta;
667 x += w / 2;
668 y += h / 2;
669 fx += fw / 2;
670 fy += fh / 2;
672 xstep = (float)(fx - x) / steps;
673 ystep = (float)(fy - y) / steps;
674 wstep = (float)(fw - w) / steps;
675 hstep = (float)(fh - h) / steps;
677 cx = (float)x;
678 cy = (float)y;
679 cw = (float)w;
680 ch = (float)h;
682 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_T;
683 delta = (float)(final_angle / FRAMES);
684 for (angle = 0;; angle += delta) {
685 if (angle > final_angle)
686 angle = final_angle;
688 a = atan(ch / cw);
689 d = sqrt((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
691 points[0].x = cx + cos(angle - a) * d;
692 points[0].y = cy + sin(angle - a) * d;
693 points[1].x = cx + cos(angle + a) * d;
694 points[1].y = cy + sin(angle + a) * d;
695 points[2].x = cx + cos(angle - a + WM_PI) * d;
696 points[2].y = cy + sin(angle - a + WM_PI) * d;
697 points[3].x = cx + cos(angle + a + WM_PI) * d;
698 points[3].y = cy + sin(angle + a + WM_PI) * d;
699 points[4].x = cx + cos(angle - a) * d;
700 points[4].y = cy + sin(angle - a) * d;
701 XGrabServer(dpy);
702 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
703 XFlush(dpy);
704 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
706 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
707 XUngrabServer(dpy);
708 cx += xstep;
709 cy += ystep;
710 cw += wstep;
711 ch += hstep;
712 if (angle >= final_angle)
713 break;
716 XFlush(dpy);
719 #undef FRAMES
721 static void animateResizeZoom(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
723 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
724 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
725 float xstep, ystep, wstep, hstep;
726 int i, j;
728 xstep = (float)(fx - x) / steps;
729 ystep = (float)(fy - y) / steps;
730 wstep = (float)(fw - w) / steps;
731 hstep = (float)(fh - h) / steps;
733 for (j = 0; j < FRAMES; j++) {
734 cx[j] = (float)x;
735 cy[j] = (float)y;
736 cw[j] = (float)w;
737 ch[j] = (float)h;
739 XGrabServer(dpy);
740 for (i = 0; i < steps; i++) {
741 for (j = 0; j < FRAMES; j++) {
742 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
743 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
745 XFlush(dpy);
746 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
748 for (j = 0; j < FRAMES; j++) {
749 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
750 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
751 if (j < FRAMES - 1) {
752 cx[j] = cx[j + 1];
753 cy[j] = cy[j + 1];
754 cw[j] = cw[j + 1];
755 ch[j] = ch[j + 1];
756 } else {
757 cx[j] += xstep;
758 cy[j] += ystep;
759 cw[j] += wstep;
760 ch[j] += hstep;
765 for (j = 0; j < FRAMES; j++) {
766 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
768 XFlush(dpy);
769 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
771 for (j = 0; j < FRAMES; j++) {
772 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
775 XUngrabServer(dpy);
778 #undef FRAMES
780 void animateResize(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh)
782 int style = wPreferences.iconification_style; /* Catch the value */
783 int steps;
785 if (style == WIS_NONE)
786 return;
788 if (style == WIS_RANDOM) {
789 style = rand() % 3;
792 switch (style) {
793 case WIS_TWIST:
794 steps = MINIATURIZE_ANIMATION_STEPS_T;
795 if (steps > 0)
796 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
797 break;
798 case WIS_FLIP:
799 steps = MINIATURIZE_ANIMATION_STEPS_F;
800 if (steps > 0)
801 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
802 break;
803 case WIS_ZOOM:
804 default:
805 steps = MINIATURIZE_ANIMATION_STEPS_Z;
806 if (steps > 0)
807 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
808 break;
811 #endif /* ANIMATIONS */
813 static void flushExpose(void)
815 XEvent tmpev;
817 while (XCheckTypedEvent(dpy, Expose, &tmpev))
818 WMHandleEvent(&tmpev);
819 XSync(dpy, 0);
822 static void unmapTransientsFor(WWindow *wwin)
824 WWindow *tmp;
826 tmp = wwin->screen_ptr->focused_window;
827 while (tmp) {
828 /* unmap the transients for this transient */
829 if (tmp != wwin && tmp->transient_for == wwin->client_win
830 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup || tmp->flags.shaded)) {
831 unmapTransientsFor(tmp);
832 tmp->flags.miniaturized = 1;
833 if (!tmp->flags.shaded) {
834 wWindowUnmap(tmp);
835 } else {
836 XUnmapWindow(dpy, tmp->frame->core->window);
839 if (!tmp->flags.shaded)
841 wClientSetState(tmp, IconicState, None);
843 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
845 tmp = tmp->prev;
849 static void mapTransientsFor(WWindow *wwin)
851 WWindow *tmp;
853 tmp = wwin->screen_ptr->focused_window;
854 while (tmp) {
855 /* recursively map the transients for this transient */
856 if (tmp != wwin && tmp->transient_for == wwin->client_win && /*!tmp->flags.mapped */ tmp->flags.miniaturized
857 && tmp->icon == NULL) {
858 mapTransientsFor(tmp);
859 tmp->flags.miniaturized = 0;
860 if (!tmp->flags.shaded) {
861 wWindowMap(tmp);
862 } else {
863 XMapWindow(dpy, tmp->frame->core->window);
865 tmp->flags.semi_focused = 0;
867 if (!tmp->flags.shaded)
869 wClientSetState(tmp, NormalState, None);
871 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
873 tmp = tmp->prev;
877 static WWindow *recursiveTransientFor(WWindow * wwin)
879 int i;
881 if (!wwin)
882 return None;
884 /* hackish way to detect transient_for cycle */
885 i = wwin->screen_ptr->window_count + 1;
887 while (wwin && wwin->transient_for != None && i > 0) {
888 wwin = wWindowFor(wwin->transient_for);
889 i--;
891 if (i == 0 && wwin) {
892 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin->frame->title);
893 return NULL;
896 return wwin;
899 void wIconifyWindow(WWindow * wwin)
901 XWindowAttributes attribs;
902 int present;
904 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
905 /* the window doesn't exist anymore */
906 return;
909 if (wwin->flags.miniaturized) {
910 return;
913 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
914 WWindow *owner = wWindowFor(wwin->transient_for);
916 if (owner && owner->flags.miniaturized)
917 return;
920 present = wwin->frame->workspace == wwin->screen_ptr->current_workspace;
922 /* if the window is in another workspace, simplify process */
923 if (present) {
924 /* icon creation may take a while */
925 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
926 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
927 GrabModeAsync, None, None, CurrentTime);
930 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
931 if (!wwin->flags.icon_moved) {
932 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
934 wwin->icon = wIconCreate(wwin);
936 wwin->icon->mapped = 1;
939 wwin->flags.miniaturized = 1;
940 wwin->flags.mapped = 0;
942 /* unmap transients */
944 unmapTransientsFor(wwin);
946 if (present) {
947 XUngrabPointer(dpy, CurrentTime);
948 wWindowUnmap(wwin);
949 /* let all Expose events arrive so that we can repaint
950 * something before the animation starts (and the server is grabbed) */
951 XSync(dpy, 0);
953 if (wPreferences.disable_miniwindows || wwin->flags.net_handle_icon)
954 wClientSetState(wwin, IconicState, None);
955 else
956 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
958 flushExpose();
959 #ifdef ANIMATIONS
960 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
961 && !wPreferences.no_animations) {
962 int ix, iy, iw, ih;
964 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
965 ix = wwin->icon_x;
966 iy = wwin->icon_y;
967 iw = wwin->icon->core->width;
968 ih = wwin->icon->core->height;
969 } else {
970 if (wwin->flags.net_handle_icon) {
971 ix = wwin->icon_x;
972 iy = wwin->icon_y;
973 iw = wwin->icon_w;
974 ih = wwin->icon_h;
975 } else {
976 ix = 0;
977 iy = 0;
978 iw = wwin->screen_ptr->scr_width;
979 ih = wwin->screen_ptr->scr_height;
982 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
983 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih);
985 #endif
988 wwin->flags.skip_next_animation = 0;
990 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
991 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace ||
992 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
994 XMapWindow(dpy, wwin->icon->core->window);
996 AddToStackList(wwin->icon->core);
998 wLowerFrame(wwin->icon->core);
1001 if (present) {
1002 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1005 * It doesn't seem to be working and causes button event hangup
1006 * when deiconifying a transient window.
1007 setupIconGrabs(wwin->icon);
1009 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
1010 && wPreferences.focus_mode == WKF_CLICK) {
1011 WWindow *tmp;
1013 tmp = wwin->prev;
1014 while (tmp) {
1015 if (!WFLAGP(tmp, no_focusable)
1016 && !(tmp->flags.hidden || tmp->flags.miniaturized)
1017 && (wwin->frame->workspace == tmp->frame->workspace))
1018 break;
1019 tmp = tmp->prev;
1021 wSetFocusTo(wwin->screen_ptr, tmp);
1022 } else if (wPreferences.focus_mode != WKF_CLICK) {
1023 wSetFocusTo(wwin->screen_ptr, NULL);
1025 #ifdef ANIMATIONS
1026 if (!wwin->screen_ptr->flags.startup) {
1027 /* Catch up with events not processed while animation was running */
1028 Window clientwin = wwin->client_win;
1030 ProcessPendingEvents();
1032 /* the window can disappear while ProcessPendingEvents() runs */
1033 if (!wWindowFor(clientwin)) {
1034 return;
1037 #endif
1040 /* maybe we want to do this regardless of net_handle_icon
1041 * it seems to me we might break behaviour this way.
1043 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1044 && !wwin->flags.net_handle_icon)
1045 wIconSelect(wwin->icon);
1047 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1049 if (wPreferences.auto_arrange_icons)
1050 wArrangeIcons(wwin->screen_ptr, True);
1053 void wDeiconifyWindow(WWindow *wwin)
1055 /* Let's avoid changing workspace while deiconifying */
1056 ignore_wks_change = 1;
1058 /* we're hiding for show_desktop */
1059 int netwm_hidden = wwin->flags.net_show_desktop &&
1060 wwin->frame->workspace != wwin->screen_ptr->current_workspace;
1062 if (!netwm_hidden)
1063 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1065 if (!wwin->flags.miniaturized)
1066 return;
1068 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1069 WWindow *owner = recursiveTransientFor(wwin);
1071 if (owner && owner->flags.miniaturized) {
1072 wDeiconifyWindow(owner);
1073 wSetFocusTo(wwin->screen_ptr, wwin);
1074 wRaiseFrame(wwin->frame->core);
1075 return;
1079 wwin->flags.miniaturized = 0;
1081 if (!netwm_hidden && !wwin->flags.shaded) {
1082 wwin->flags.mapped = 1;
1085 if (!netwm_hidden || wPreferences.sticky_icons) {
1086 /* maybe we want to do this regardless of net_handle_icon
1087 * it seems to me we might break behaviour this way.
1089 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon
1090 && wwin->icon != NULL) {
1091 if (wwin->icon->selected)
1092 wIconSelect(wwin->icon);
1094 XUnmapWindow(dpy, wwin->icon->core->window);
1098 /* if the window is in another workspace, do it silently */
1099 if (!netwm_hidden) {
1100 #ifdef ANIMATIONS
1101 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1102 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1103 int ix, iy, iw, ih;
1105 if (!wPreferences.disable_miniwindows
1106 && !wwin->flags.net_handle_icon) {
1107 ix = wwin->icon_x;
1108 iy = wwin->icon_y;
1109 iw = wwin->icon->core->width;
1110 ih = wwin->icon->core->height;
1111 } else {
1112 if (wwin->flags.net_handle_icon) {
1113 ix = wwin->icon_x;
1114 iy = wwin->icon_y;
1115 iw = wwin->icon_w;
1116 ih = wwin->icon_h;
1117 } else {
1118 ix = 0;
1119 iy = 0;
1120 iw = wwin->screen_ptr->scr_width;
1121 ih = wwin->screen_ptr->scr_height;
1124 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1125 wwin->frame_x, wwin->frame_y,
1126 wwin->frame->core->width, wwin->frame->core->height);
1128 #endif /* ANIMATIONS */
1129 wwin->flags.skip_next_animation = 0;
1130 XGrabServer(dpy);
1131 if (!wwin->flags.shaded) {
1132 XMapWindow(dpy, wwin->client_win);
1134 XMapWindow(dpy, wwin->frame->core->window);
1135 wRaiseFrame(wwin->frame->core);
1136 if (!wwin->flags.shaded) {
1137 wClientSetState(wwin, NormalState, None);
1139 mapTransientsFor(wwin);
1142 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1143 && !wwin->flags.net_handle_icon) {
1144 RemoveFromStackList(wwin->icon->core);
1145 /* removeIconGrabs(wwin->icon); */
1146 wIconDestroy(wwin->icon);
1147 wwin->icon = NULL;
1150 if (!netwm_hidden) {
1151 XUngrabServer(dpy);
1153 wSetFocusTo(wwin->screen_ptr, wwin);
1155 #ifdef ANIMATIONS
1156 if (!wwin->screen_ptr->flags.startup) {
1157 /* Catch up with events not processed while animation was running */
1158 Window clientwin = wwin->client_win;
1160 ProcessPendingEvents();
1162 /* the window can disappear while ProcessPendingEvents() runs */
1163 if (!wWindowFor(clientwin)) {
1164 return;
1167 #endif
1170 if (wPreferences.auto_arrange_icons) {
1171 wArrangeIcons(wwin->screen_ptr, True);
1174 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1176 /* In case we were shaded and iconified, also unshade */
1177 if (!netwm_hidden)
1178 wUnshadeWindow(wwin);
1180 ignore_wks_change = 0;
1183 static void hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1185 if (wwin->flags.miniaturized) {
1186 if (wwin->icon) {
1187 XUnmapWindow(dpy, wwin->icon->core->window);
1188 wwin->icon->mapped = 0;
1190 wwin->flags.hidden = 1;
1192 WMPostNotificationName(WMNChangedState, wwin, "hide");
1193 return;
1196 if (wwin->flags.inspector_open) {
1197 wHideInspectorForWindow(wwin);
1200 wwin->flags.hidden = 1;
1201 wWindowUnmap(wwin);
1203 wClientSetState(wwin, IconicState, icon->icon_win);
1204 flushExpose();
1206 #ifdef ANIMATIONS
1207 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1208 !wwin->flags.skip_next_animation && animate) {
1209 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1210 wwin->frame->core->width, wwin->frame->core->height,
1211 icon_x, icon_y, icon->core->width, icon->core->height);
1213 #endif
1214 wwin->flags.skip_next_animation = 0;
1216 WMPostNotificationName(WMNChangedState, wwin, "hide");
1219 void wHideOtherApplications(WWindow *awin)
1221 WWindow *wwin;
1222 WApplication *tapp;
1224 if (!awin)
1225 return;
1226 wwin = awin->screen_ptr->focused_window;
1228 while (wwin) {
1229 if (wwin != awin
1230 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1231 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1232 && !wwin->flags.internal_window
1233 && wGetWindowOfInspectorForWindow(wwin) != awin && !WFLAGP(wwin, no_hide_others)) {
1235 if (wwin->main_window == None || WFLAGP(wwin, no_appicon)) {
1236 if (!WFLAGP(wwin, no_miniaturizable)) {
1237 wwin->flags.skip_next_animation = 1;
1238 wIconifyWindow(wwin);
1240 } else if (wwin->main_window != None && awin->main_window != wwin->main_window) {
1241 tapp = wApplicationOf(wwin->main_window);
1242 if (tapp) {
1243 tapp->flags.skip_next_animation = 1;
1244 wHideApplication(tapp);
1245 } else {
1246 if (!WFLAGP(wwin, no_miniaturizable)) {
1247 wwin->flags.skip_next_animation = 1;
1248 wIconifyWindow(wwin);
1253 wwin = wwin->prev;
1256 wSetFocusTo(awin->screen_ptr, awin);
1260 void wHideApplication(WApplication *wapp)
1262 WScreen *scr;
1263 WWindow *wlist;
1264 int hadfocus;
1265 int animate;
1267 if (!wapp) {
1268 wwarning("trying to hide a non grouped window");
1269 return;
1271 if (!wapp->main_window_desc) {
1272 wwarning("group leader not found for window group");
1273 return;
1275 scr = wapp->main_window_desc->screen_ptr;
1276 hadfocus = 0;
1277 wlist = scr->focused_window;
1278 if (!wlist)
1279 return;
1281 if (wlist->main_window == wapp->main_window)
1282 wapp->last_focused = wlist;
1283 else
1284 wapp->last_focused = NULL;
1286 animate = !wapp->flags.skip_next_animation;
1288 while (wlist) {
1289 if (wlist->main_window == wapp->main_window) {
1290 if (wlist->flags.focused) {
1291 hadfocus = 1;
1293 if (wapp->app_icon) {
1294 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1295 wapp->app_icon->y_pos, wlist, animate);
1296 animate = False;
1299 wlist = wlist->prev;
1302 wapp->flags.skip_next_animation = 0;
1304 if (hadfocus) {
1305 if (wPreferences.focus_mode == WKF_CLICK) {
1306 wlist = scr->focused_window;
1307 while (wlist) {
1308 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1309 && (wlist->flags.mapped || wlist->flags.shaded))
1310 break;
1311 wlist = wlist->prev;
1313 wSetFocusTo(scr, wlist);
1314 } else {
1315 wSetFocusTo(scr, NULL);
1319 wapp->flags.hidden = 1;
1321 if (wPreferences.auto_arrange_icons) {
1322 wArrangeIcons(scr, True);
1324 #ifdef HIDDENDOT
1325 if (wapp->app_icon)
1326 wAppIconPaint(wapp->app_icon);
1327 #endif
1330 static void unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate, int bringToCurrentWS)
1332 if (bringToCurrentWS)
1333 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1335 wwin->flags.hidden = 0;
1337 #ifdef ANIMATIONS
1338 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1339 animateResize(wwin->screen_ptr, icon_x, icon_y,
1340 icon->core->width, icon->core->height,
1341 wwin->frame_x, wwin->frame_y,
1342 wwin->frame->core->width, wwin->frame->core->height);
1344 #endif
1345 wwin->flags.skip_next_animation = 0;
1346 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1347 XMapWindow(dpy, wwin->client_win);
1348 XMapWindow(dpy, wwin->frame->core->window);
1349 wClientSetState(wwin, NormalState, None);
1350 wwin->flags.mapped = 1;
1351 wRaiseFrame(wwin->frame->core);
1353 if (wwin->flags.inspector_open) {
1354 wUnhideInspectorForWindow(wwin);
1357 WMPostNotificationName(WMNChangedState, wwin, "hide");
1360 void wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1362 WScreen *scr;
1363 WWindow *wlist, *next;
1364 WWindow *focused = NULL;
1365 int animate;
1367 if (!wapp)
1368 return;
1370 scr = wapp->main_window_desc->screen_ptr;
1371 wlist = scr->focused_window;
1372 if (!wlist)
1373 return;
1375 /* goto beginning of list */
1376 while (wlist->prev)
1377 wlist = wlist->prev;
1379 animate = !wapp->flags.skip_next_animation;
1381 while (wlist) {
1382 next = wlist->next;
1384 if (wlist->main_window == wapp->main_window) {
1385 if (wlist->flags.focused)
1386 focused = wlist;
1387 else if (!focused || !focused->flags.focused)
1388 focused = wlist;
1390 if (wlist->flags.miniaturized) {
1391 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1392 wlist->frame->workspace == scr->current_workspace) && wlist->icon) {
1393 if (!wlist->icon->mapped) {
1394 int x, y;
1396 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1397 if (wlist->icon_x != x || wlist->icon_y != y) {
1398 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1400 wlist->icon_x = x;
1401 wlist->icon_y = y;
1402 XMapWindow(dpy, wlist->icon->core->window);
1403 wlist->icon->mapped = 1;
1405 wRaiseFrame(wlist->icon->core);
1407 if (bringToCurrentWS)
1408 wWindowChangeWorkspace(wlist, scr->current_workspace);
1409 wlist->flags.hidden = 0;
1410 if (miniwindows && wlist->frame->workspace == scr->current_workspace) {
1411 wDeiconifyWindow(wlist);
1413 WMPostNotificationName(WMNChangedState, wlist, "hide");
1414 } else if (wlist->flags.shaded) {
1415 if (bringToCurrentWS)
1416 wWindowChangeWorkspace(wlist, scr->current_workspace);
1417 wlist->flags.hidden = 0;
1418 if (wlist->frame->workspace == scr->current_workspace) {
1419 XMapWindow(dpy, wlist->frame->core->window);
1420 if (miniwindows) {
1421 wUnshadeWindow(wlist);
1422 wRaiseFrame(wlist->frame->core);
1425 WMPostNotificationName(WMNChangedState, wlist, "hide");
1426 } else if (wlist->flags.hidden) {
1427 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1428 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1429 animate = False;
1430 } else {
1431 if (bringToCurrentWS && wlist->frame->workspace != scr->current_workspace) {
1432 wWindowChangeWorkspace(wlist, scr->current_workspace);
1434 wRaiseFrame(wlist->frame->core);
1437 wlist = next;
1440 wapp->flags.skip_next_animation = 0;
1441 wapp->flags.hidden = 0;
1443 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1444 wRaiseFrame(wapp->last_focused->frame->core);
1445 wSetFocusTo(scr, wapp->last_focused);
1446 } else if (focused) {
1447 wSetFocusTo(scr, focused);
1449 wapp->last_focused = NULL;
1450 if (wPreferences.auto_arrange_icons) {
1451 wArrangeIcons(scr, True);
1453 #ifdef HIDDENDOT
1454 wAppIconPaint(wapp->app_icon);
1455 #endif
1458 void wShowAllWindows(WScreen *scr)
1460 WWindow *wwin, *old_foc;
1461 WApplication *wapp;
1463 old_foc = wwin = scr->focused_window;
1464 while (wwin) {
1465 if (!wwin->flags.internal_window &&
1466 (scr->current_workspace == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1467 if (wwin->flags.miniaturized) {
1468 wwin->flags.skip_next_animation = 1;
1469 wDeiconifyWindow(wwin);
1470 } else if (wwin->flags.hidden) {
1471 wapp = wApplicationOf(wwin->main_window);
1472 if (wapp) {
1473 wUnhideApplication(wapp, False, False);
1474 } else {
1475 wwin->flags.skip_next_animation = 1;
1476 wDeiconifyWindow(wwin);
1480 wwin = wwin->prev;
1482 wSetFocusTo(scr, old_foc);
1483 /*wRaiseFrame(old_foc->frame->core); */
1486 void wRefreshDesktop(WScreen *scr)
1488 Window win;
1489 XSetWindowAttributes attr;
1491 attr.backing_store = NotUseful;
1492 attr.save_under = False;
1493 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1494 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1495 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1496 XMapRaised(dpy, win);
1497 XDestroyWindow(dpy, win);
1498 XFlush(dpy);
1501 void wArrangeIcons(WScreen *scr, Bool arrangeAll)
1503 WWindow *wwin;
1504 WAppIcon *aicon;
1506 int head;
1507 const int heads = wXineramaHeads(scr);
1509 struct HeadVars {
1510 int pf; /* primary axis */
1511 int sf; /* secondary axis */
1512 int fullW;
1513 int fullH;
1514 int pi, si;
1515 int sx1, sx2, sy1, sy2; /* screen boundary */
1516 int sw, sh;
1517 int xo, yo;
1518 int xs, ys;
1519 } *vars;
1521 int isize = wPreferences.icon_size;
1523 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
1525 for (head = 0; head < heads; ++head) {
1526 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1527 WMRect rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
1528 vars[head].pi = vars[head].si = 0;
1529 vars[head].sx1 = rect.pos.x;
1530 vars[head].sy1 = rect.pos.y;
1531 vars[head].sw = rect.size.width;
1532 vars[head].sh = rect.size.height;
1533 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1534 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1535 vars[head].sw = isize * (vars[head].sw / isize);
1536 vars[head].sh = isize * (vars[head].sh / isize);
1537 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
1538 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
1540 /* icon yard boundaries */
1541 if (wPreferences.icon_yard & IY_VERT) {
1542 vars[head].pf = vars[head].fullH;
1543 vars[head].sf = vars[head].fullW;
1544 } else {
1545 vars[head].pf = vars[head].fullW;
1546 vars[head].sf = vars[head].fullH;
1548 if (wPreferences.icon_yard & IY_RIGHT) {
1549 vars[head].xo = vars[head].sx2 - isize;
1550 vars[head].xs = -1;
1551 } else {
1552 vars[head].xo = vars[head].sx1;
1553 vars[head].xs = 1;
1555 if (wPreferences.icon_yard & IY_TOP) {
1556 vars[head].yo = vars[head].sy1;
1557 vars[head].ys = 1;
1558 } else {
1559 vars[head].yo = vars[head].sy2 - isize;
1560 vars[head].ys = -1;
1564 #define X ((wPreferences.icon_yard & IY_VERT) \
1565 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1566 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1568 #define Y ((wPreferences.icon_yard & IY_VERT) \
1569 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1570 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1572 /* arrange application icons */
1573 aicon = scr->app_icon_list;
1574 /* reverse them to avoid unnecessarily sliding of icons */
1575 while (aicon && aicon->next)
1576 aicon = aicon->next;
1578 while (aicon) {
1579 if (!aicon->docked) {
1580 /* CHECK: can icon be NULL here ? */
1581 /* The intention here is to place the AppIcon on the head that
1582 * contains most of the applications _main_ window. */
1583 head = wGetHeadForWindow(aicon->icon->owner);
1585 if (aicon->x_pos != X || aicon->y_pos != Y) {
1586 #ifdef ANIMATIONS
1587 if (!wPreferences.no_animations) {
1588 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1590 #endif /* ANIMATIONS */
1592 wAppIconMove(aicon, X, Y);
1593 vars[head].pi++;
1594 if (vars[head].pi >= vars[head].pf) {
1595 vars[head].pi = 0;
1596 vars[head].si++;
1599 aicon = aicon->prev;
1602 /* arrange miniwindows */
1603 wwin = scr->focused_window;
1604 /* reverse them to avoid unnecessarily shuffling */
1605 while (wwin && wwin->prev)
1606 wwin = wwin->prev;
1608 while (wwin) {
1609 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1610 (wwin->frame->workspace == scr->current_workspace ||
1611 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1613 head = wGetHeadForWindow(wwin);
1615 if (arrangeAll || !wwin->flags.icon_moved) {
1616 if (wwin->icon_x != X || wwin->icon_y != Y) {
1617 #ifdef ANIMATIONS
1618 if (wPreferences.no_animations) {
1619 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1620 } else {
1621 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1622 wwin->icon_y, X, Y);
1624 #else
1625 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1626 #endif /* ANIMATIONS */
1628 wwin->icon_x = X;
1629 wwin->icon_y = Y;
1631 vars[head].pi++;
1632 if (vars[head].pi >= vars[head].pf) {
1633 vars[head].pi = 0;
1634 vars[head].si++;
1638 if (arrangeAll) {
1639 wwin->flags.icon_moved = 0;
1641 /* we reversed the order, so we use next */
1642 wwin = wwin->next;
1645 wfree(vars);
1648 void wSelectWindow(WWindow *wwin, Bool flag)
1650 WScreen *scr = wwin->screen_ptr;
1652 if (flag) {
1653 wwin->flags.selected = 1;
1654 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1656 if (!HAS_BORDER(wwin)) {
1657 XSetWindowBorderWidth(dpy, wwin->frame->core->window, FRAME_BORDER_WIDTH);
1660 if (!scr->selected_windows)
1661 scr->selected_windows = WMCreateArray(4);
1662 WMAddToArray(scr->selected_windows, wwin);
1663 } else {
1664 wwin->flags.selected = 0;
1665 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
1667 if (!HAS_BORDER(wwin)) {
1668 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1671 if (scr->selected_windows) {
1672 WMRemoveFromArray(scr->selected_windows, wwin);
1677 void wMakeWindowVisible(WWindow *wwin)
1679 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1680 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1682 if (wwin->flags.shaded) {
1683 wUnshadeWindow(wwin);
1685 if (wwin->flags.hidden) {
1686 WApplication *app;
1688 app = wApplicationOf(wwin->main_window);
1689 if (app) {
1690 /* trick to get focus to this window */
1691 app->last_focused = wwin;
1692 wUnhideApplication(app, False, False);
1695 if (wwin->flags.miniaturized) {
1696 wDeiconifyWindow(wwin);
1697 } else {
1698 if (!WFLAGP(wwin, no_focusable))
1699 wSetFocusTo(wwin->screen_ptr, wwin);
1700 wRaiseFrame(wwin->frame->core);
1705 * Do the animation while shading (called with what = SHADE)
1706 * or unshading (what = UNSHADE).
1708 #ifdef ANIMATIONS
1709 static void shade_animate(WWindow *wwin, Bool what)
1711 int y, s, w, h;
1712 time_t time0 = time(NULL);
1714 if (wwin->flags.skip_next_animation && wPreferences.no_animations)
1715 return;
1717 switch(what) {
1718 case SHADE:
1719 if (!wwin->screen_ptr->flags.startup) {
1720 /* do the shading animation */
1721 h = wwin->frame->core->height;
1722 s = h / SHADE_STEPS;
1723 if (s < 1)
1724 s = 1;
1725 w = wwin->frame->core->width;
1726 y = wwin->frame->top_width;
1727 while (h > wwin->frame->top_width + 1) {
1728 XMoveWindow(dpy, wwin->client_win, 0, y);
1729 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1730 XFlush(dpy);
1732 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1733 break;
1735 if (SHADE_DELAY > 0) {
1736 wusleep(SHADE_DELAY * 1000L);
1737 } else {
1738 wusleep(10);
1740 h -= s;
1741 y -= s;
1743 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1745 break;
1747 case UNSHADE:
1748 h = wwin->frame->top_width + wwin->frame->bottom_width;
1749 y = wwin->frame->top_width - wwin->client.height;
1750 s = abs(y) / SHADE_STEPS;
1751 if (s < 1)
1752 s = 1;
1753 w = wwin->frame->core->width;
1754 XMoveWindow(dpy, wwin->client_win, 0, y);
1755 if (s > 0) {
1756 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
1757 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1758 XMoveWindow(dpy, wwin->client_win, 0, y);
1759 XFlush(dpy);
1760 if (SHADE_DELAY > 0) {
1761 wusleep(SHADE_DELAY * 2000L / 3);
1762 } else {
1763 wusleep(10);
1765 h += s;
1766 y += s;
1768 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1769 break;
1772 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1773 break;
1776 #endif