Address some sparse warnings
[wmaker-crm.git] / src / actions.c
blob16e12675019fb70a904fb5bc02e848c4d4f9ca59
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;
56 extern Cursor wCursor[WCUR_LAST];
58 extern WPreferences wPreferences;
60 extern Atom _XA_WM_TAKE_FOCUS;
62 extern void ProcessPendingEvents();
63 extern int calcIntersectionLength(int p1, int l1, int p2, int l2);
65 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
66 unsigned int *new_width, unsigned int *new_height);
67 static void save_old_geometry(WWindow *wwin);
69 /******* Local Variables *******/
70 static struct {
71 int steps;
72 int delay;
73 } shadePars[5] = {
75 SHADE_STEPS_UF, SHADE_DELAY_UF}, {
76 SHADE_STEPS_F, SHADE_DELAY_F}, {
77 SHADE_STEPS_M, SHADE_DELAY_M}, {
78 SHADE_STEPS_S, SHADE_DELAY_S}, {
79 SHADE_STEPS_US, SHADE_DELAY_US}};
81 #define UNSHADE 0
82 #define SHADE 1
83 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
84 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
86 static int compareTimes(Time t1, Time t2)
88 Time diff;
89 if (t1 == t2)
90 return 0;
91 diff = t1 - t2;
92 return (diff < 60000) ? 1 : -1;
95 #ifdef ANIMATIONS
96 static void shade_animate(WWindow *wwin, Bool what);
97 #else
98 static void shade_animate(WWindow *wwin, Bool what) { }
99 #endif
102 *----------------------------------------------------------------------
103 * wSetFocusTo--
104 * Changes the window focus to the one passed as argument.
105 * If the window to focus is not already focused, it will be brought
106 * to the head of the list of windows. Previously focused window is
107 * unfocused.
109 * Side effects:
110 * Window list may be reordered and the window focus is changed.
112 *----------------------------------------------------------------------
114 void wSetFocusTo(WScreen *scr, WWindow *wwin)
116 static WScreen *old_scr = NULL;
118 WWindow *old_focused;
119 WWindow *focused = scr->focused_window;
120 Time timestamp = LastTimestamp;
121 WApplication *oapp = NULL, *napp = NULL;
122 int wasfocused;
124 if (scr->flags.ignore_focus_events || compareTimes(LastFocusChange, timestamp) > 0)
125 return;
127 if (!old_scr)
128 old_scr = scr;
129 old_focused = old_scr->focused_window;
131 LastFocusChange = timestamp;
133 if (old_focused)
134 oapp = wApplicationOf(old_focused->main_window);
136 if (wwin == NULL) {
137 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
138 if (old_focused)
139 wWindowUnfocus(old_focused);
140 if (oapp)
141 wAppMenuUnmap(oapp->menu);
143 WMPostNotificationName(WMNChangedFocus, NULL, (void *)True);
144 return;
145 } else if (old_scr != scr && old_focused) {
146 wWindowUnfocus(old_focused);
149 wasfocused = wwin->flags.focused;
150 napp = wApplicationOf(wwin->main_window);
152 /* remember last workspace where the app has been */
153 if (napp) {
154 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
155 napp->last_workspace = wwin->frame->workspace;
158 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
159 /* install colormap if colormap mode is lock mode */
160 if (wPreferences.colormap_mode == WCM_CLICK)
161 wColormapInstallForWindow(scr, wwin);
163 /* set input focus */
164 switch (wwin->focus_mode) {
165 case WFM_NO_INPUT:
166 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
167 break;
169 case WFM_PASSIVE:
170 case WFM_LOCALLY_ACTIVE:
171 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
172 break;
174 case WFM_GLOBALLY_ACTIVE:
175 break;
177 XFlush(dpy);
178 if (wwin->protocols.TAKE_FOCUS) {
179 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
181 XSync(dpy, False);
182 } else {
183 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
185 if (WFLAGP(wwin, no_focusable))
186 return;
188 /* if this is not the focused window focus it */
189 if (focused != wwin) {
190 /* change the focus window list order */
191 if (wwin->prev)
192 wwin->prev->next = wwin->next;
194 if (wwin->next)
195 wwin->next->prev = wwin->prev;
197 wwin->prev = focused;
198 focused->next = wwin;
199 wwin->next = NULL;
200 scr->focused_window = wwin;
202 if (oapp && oapp != napp)
203 wAppMenuUnmap(oapp->menu);
206 wWindowFocus(wwin, focused);
208 if (napp && !wasfocused) {
209 #ifdef USER_MENU
210 wUserMenuRefreshInstances(napp->menu, wwin);
211 #endif /* USER_MENU */
213 if (wwin->flags.mapped)
214 wAppMenuMap(napp->menu, wwin);
217 XFlush(dpy);
218 old_scr = scr;
221 void wShadeWindow(WWindow *wwin)
224 if (wwin->flags.shaded)
225 return;
227 XLowerWindow(dpy, wwin->client_win);
228 shade_animate(wwin, SHADE);
230 wwin->flags.skip_next_animation = 0;
231 wwin->flags.shaded = 1;
232 wwin->flags.mapped = 0;
233 /* prevent window withdrawal when getting UnmapNotify */
234 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
235 XUnmapWindow(dpy, wwin->client_win);
236 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
238 /* for the client it's just like iconification */
239 wFrameWindowResize(wwin->frame, wwin->frame->core->width, wwin->frame->top_width - 1);
241 wwin->client.y = wwin->frame_y - wwin->client.height + wwin->frame->top_width;
242 wWindowSynthConfigureNotify(wwin);
245 wClientSetState(wwin, IconicState, None);
248 WMPostNotificationName(WMNChangedState, wwin, "shade");
250 #ifdef ANIMATIONS
251 if (!wwin->screen_ptr->flags.startup) {
252 /* Catch up with events not processed while animation was running */
253 ProcessPendingEvents();
255 #endif
258 void wUnshadeWindow(WWindow *wwin)
261 if (!wwin->flags.shaded)
262 return;
264 wwin->flags.shaded = 0;
265 wwin->flags.mapped = 1;
266 XMapWindow(dpy, wwin->client_win);
268 shade_animate(wwin, UNSHADE);
270 wwin->flags.skip_next_animation = 0;
271 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
272 wwin->frame->top_width + wwin->client.height + wwin->frame->bottom_width);
274 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
275 wWindowSynthConfigureNotify(wwin);
277 /* if the window is focused, set the focus again as it was disabled during
278 * shading */
279 if (wwin->flags.focused)
280 wSetFocusTo(wwin->screen_ptr, wwin);
282 WMPostNotificationName(WMNChangedState, wwin, "shade");
285 /* Set the old coordinates using the current values */
286 static void save_old_geometry(WWindow *wwin)
288 wwin->old_geometry.width = wwin->client.width;
289 wwin->old_geometry.height = wwin->client.height;
290 wwin->old_geometry.x = wwin->frame_x;
291 wwin->old_geometry.y = wwin->frame_y;
294 void wMaximizeWindow(WWindow *wwin, int directions)
296 int new_x, new_y;
297 unsigned int new_width, new_height, half_scr_width;
298 WArea usableArea, totalArea;
299 Bool has_border = 1;
300 int adj_size;
302 if (!IS_RESIZABLE(wwin))
303 return;
305 if (!HAS_BORDER(wwin))
306 has_border = 0;
308 /* the size to adjust the geometry */
309 adj_size = FRAME_BORDER_WIDTH * 2 * has_border;
311 /* save old coordinates before we change the current values */
312 save_old_geometry(wwin);
314 totalArea.x1 = 0;
315 totalArea.y1 = 0;
316 totalArea.x2 = wwin->screen_ptr->scr_width;
317 totalArea.y2 = wwin->screen_ptr->scr_height;
318 usableArea = totalArea;
320 if (!(directions & MAX_IGNORE_XINERAMA)) {
321 WScreen *scr = wwin->screen_ptr;
322 int head;
324 if (directions & MAX_KEYBOARD)
325 head = wGetHeadForWindow(wwin);
326 else
327 head = wGetHeadForPointerLocation(scr);
329 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
332 /* Only save directions, not kbd or xinerama hints */
333 directions &= (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_MAXIMUS);
335 if (WFLAGP(wwin, full_maximize)) {
336 usableArea = totalArea;
338 half_scr_width = (usableArea.x2 - usableArea.x1)/2;
340 if (wwin->flags.shaded) {
341 wwin->flags.skip_next_animation = 1;
342 wUnshadeWindow(wwin);
345 if (directions & MAX_HORIZONTAL) {
346 new_width = usableArea.x2 - usableArea.x1 - adj_size;
347 new_x = usableArea.x1;
348 } else if (directions & MAX_LEFTHALF) {
349 new_width = half_scr_width - adj_size;
350 new_x = usableArea.x1;
351 } else if (directions & MAX_RIGHTHALF) {
352 new_width = half_scr_width - adj_size;
353 new_x = usableArea.x1 + half_scr_width;
354 } else {
355 new_x = wwin->frame_x;
356 new_width = wwin->frame->core->width;
359 if (directions & MAX_VERTICAL) {
360 new_height = usableArea.y2 - usableArea.y1 - adj_size;
361 new_y = usableArea.y1;
362 if (WFLAGP(wwin, full_maximize)) {
363 new_y -= wwin->frame->top_width;
364 new_height += wwin->frame->bottom_width - 1;
366 } else {
367 new_y = wwin->frame_y;
368 new_height = wwin->frame->core->height;
371 if (!WFLAGP(wwin, full_maximize)) {
372 new_height -= wwin->frame->top_width + wwin->frame->bottom_width;
375 if (directions & MAX_MAXIMUS) {
376 find_Maximus_geometry(wwin, usableArea, &new_x, &new_y, &new_width, &new_height);
377 new_width -= adj_size;
378 new_height -= adj_size;
379 if (WFLAGP(wwin, full_maximize) && new_y == 0) {
380 new_y -= wwin->frame->top_width;
381 new_height += wwin->frame->top_width - 1;
385 wWindowConstrainSize(wwin, &new_width, &new_height);
387 wWindowCropSize(wwin, usableArea.x2 - usableArea.x1,
388 usableArea.y2 - usableArea.y1, &new_width, &new_height);
390 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
392 WMPostNotificationName(WMNChangedState, wwin, "maximize");
394 /* set maximization state */
395 wwin->flags.maximized = directions;
398 /* the window boundary coordinates */
399 typedef struct {
400 int left;
401 int right;
402 int bottom;
403 int top;
404 int width;
405 int height;
406 } win_coords;
408 static void set_window_coords(WWindow *wwin, win_coords *obs)
410 obs->left = wwin->frame_x;
411 obs->top = wwin->frame_y;
412 obs->width = wwin->frame->core->width;
413 obs->height = wwin->frame->core->height;
414 obs->bottom = obs->top + obs->height;
415 obs->right = obs->left + obs->width;
419 * Maximus: tiled maximization (maximize without overlapping other windows)
421 * The original window 'orig' will be maximized to new coordinates 'new'.
422 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
424 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
425 unsigned int *new_width, unsigned int *new_height)
427 WWindow *tmp;
428 short int tbar_height_0 = 0, rbar_height_0 = 0, bd_width_0 = 0;
429 short int adjust_height;
430 int x_intsect, y_intsect;
431 /* the obstructing, original and new windows */
432 win_coords obs, orig, new;
434 /* set the original coordinate positions of the window to be Maximumized */
435 set_window_coords(wwin, &orig);
437 /* Try to fully maximize first, then readjust later */
438 new.left = usableArea.x1;
439 new.right = usableArea.x2;
440 new.top = usableArea.y1;
441 new.bottom = usableArea.y2;
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 length to be subtracted if the window 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 /* Set the coordinates of obstructing window */
465 set_window_coords(tmp, &obs);
467 /* Try to maximize in the y direction first */
468 x_intsect = calcIntersectionLength(orig.left, orig.width, obs.left, obs.width);
469 if (x_intsect != 0) {
470 /* TODO: Consider the case when coords are equal */
471 if (obs.bottom < orig.top && obs.bottom > new.top) {
472 /* w_0 is below the bottom of w_j */
473 new.top = obs.bottom + 1;
475 if (orig.bottom < obs.top && obs.top < new.bottom) {
476 /* The bottom of w_0 is above the top of w_j */
477 new.bottom = obs.top - 1;
482 tmp = wwin;
483 while (tmp->prev) {
484 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
485 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
486 tmp = tmp->prev;
487 continue;
489 tmp = tmp->prev;
491 set_window_coords(tmp, &obs);
494 * Use the new.top and new.height instead of original values
495 * as they may have different intersections with the obstructing windows
497 new.height = new.bottom - new.top - adjust_height;
498 y_intsect = calcIntersectionLength(new.top, new.height, obs.top, obs.height);
499 if (y_intsect != 0) {
500 if (obs.right < orig.left && obs.right > new.left) {
501 /* w_0 is completely to the right of w_j */
502 new.left = obs.right + 1;
504 if (orig.right < obs.left && obs.left < new.right) {
505 /* w_0 is completely to the left of w_j */
506 new.right = obs.left - 1;
511 *new_x = new.left;
512 *new_y = new.top;
513 /* xcalc needs -7 here, but other apps don't */
514 *new_height = new.bottom - new.top - adjust_height - 1;;
515 *new_width = new.right - new.left;
518 void wUnmaximizeWindow(WWindow *wwin)
520 int x, y, w, h;
521 WMRect old_geom_rect;
522 int old_head;
523 Bool same_head;
525 if (!wwin->flags.maximized)
526 return;
528 if (wwin->flags.shaded) {
529 wwin->flags.skip_next_animation = 1;
530 wUnshadeWindow(wwin);
532 /* Use old coordinates if they are set, current values otherwise */
533 old_geom_rect = wmkrect(wwin->old_geometry.x, wwin->old_geometry.y, wwin->old_geometry.width, wwin->old_geometry.height);
534 old_head = wGetHeadForRect(wwin->screen_ptr, old_geom_rect);
535 same_head = (wGetHeadForWindow(wwin) == old_head);
536 x = (wwin->old_geometry.x && same_head) ? wwin->old_geometry.x : wwin->frame_x;
537 y = (wwin->old_geometry.y && same_head) ? wwin->old_geometry.y : wwin->frame_y;
538 w = wwin->old_geometry.width ? wwin->old_geometry.width : wwin->client.width;
539 h = wwin->old_geometry.height ? wwin->old_geometry.height : wwin->client.height;
541 wwin->flags.maximized = 0;
542 wWindowConfigure(wwin, x, y, w, h);
544 WMPostNotificationName(WMNChangedState, wwin, "maximize");
547 void wFullscreenWindow(WWindow *wwin)
549 int head;
550 WMRect rect;
552 if (wwin->flags.fullscreen)
553 return;
555 wwin->flags.fullscreen = True;
557 wWindowConfigureBorders(wwin);
559 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
561 wwin->bfs_geometry.x = wwin->frame_x;
562 wwin->bfs_geometry.y = wwin->frame_y;
563 wwin->bfs_geometry.width = wwin->frame->core->width;
564 wwin->bfs_geometry.height = wwin->frame->core->height;
566 head = wGetHeadForWindow(wwin);
567 rect = wGetRectForHead(wwin->screen_ptr, head);
568 wWindowConfigure(wwin, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
570 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
573 void wUnfullscreenWindow(WWindow *wwin)
575 if (!wwin->flags.fullscreen)
576 return;
578 wwin->flags.fullscreen = False;
580 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
581 if (WFLAGP(wwin, sunken)) {
582 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
583 } else if (WFLAGP(wwin, floating)) {
584 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
585 } else {
586 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
590 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
591 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
593 wWindowConfigureBorders(wwin);
595 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
596 wFrameWindowPaint(wwin->frame);
599 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
602 #ifdef ANIMATIONS
603 static void animateResizeFlip(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
605 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
606 float cx, cy, cw, ch;
607 float xstep, ystep, wstep, hstep;
608 XPoint points[5];
609 float dx, dch, midy;
610 float angle, final_angle, delta;
612 xstep = (float)(fx - x) / steps;
613 ystep = (float)(fy - y) / steps;
614 wstep = (float)(fw - w) / steps;
615 hstep = (float)(fh - h) / steps;
617 cx = (float)x;
618 cy = (float)y;
619 cw = (float)w;
620 ch = (float)h;
622 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_F;
623 delta = (float)(final_angle / FRAMES);
624 for (angle = 0;; angle += delta) {
625 if (angle > final_angle)
626 angle = final_angle;
628 dx = (cw / 10) - ((cw / 5) * sin(angle));
629 dch = (ch / 2) * cos(angle);
630 midy = cy + (ch / 2);
632 points[0].x = cx + dx;
633 points[0].y = midy - dch;
634 points[1].x = cx + cw - dx;
635 points[1].y = points[0].y;
636 points[2].x = cx + cw + dx;
637 points[2].y = midy + dch;
638 points[3].x = cx - dx;
639 points[3].y = points[2].y;
640 points[4].x = points[0].x;
641 points[4].y = points[0].y;
643 XGrabServer(dpy);
644 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
645 XFlush(dpy);
646 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
648 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
649 XUngrabServer(dpy);
650 cx += xstep;
651 cy += ystep;
652 cw += wstep;
653 ch += hstep;
654 if (angle >= final_angle)
655 break;
658 XFlush(dpy);
661 #undef FRAMES
663 static void
664 animateResizeTwist(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
666 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
667 float cx, cy, cw, ch;
668 float xstep, ystep, wstep, hstep;
669 XPoint points[5];
670 float angle, final_angle, a, d, delta;
672 x += w / 2;
673 y += h / 2;
674 fx += fw / 2;
675 fy += fh / 2;
677 xstep = (float)(fx - x) / steps;
678 ystep = (float)(fy - y) / steps;
679 wstep = (float)(fw - w) / steps;
680 hstep = (float)(fh - h) / steps;
682 cx = (float)x;
683 cy = (float)y;
684 cw = (float)w;
685 ch = (float)h;
687 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_T;
688 delta = (float)(final_angle / FRAMES);
689 for (angle = 0;; angle += delta) {
690 if (angle > final_angle)
691 angle = final_angle;
693 a = atan(ch / cw);
694 d = sqrt((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
696 points[0].x = cx + cos(angle - a) * d;
697 points[0].y = cy + sin(angle - a) * d;
698 points[1].x = cx + cos(angle + a) * d;
699 points[1].y = cy + sin(angle + a) * d;
700 points[2].x = cx + cos(angle - a + WM_PI) * d;
701 points[2].y = cy + sin(angle - a + WM_PI) * d;
702 points[3].x = cx + cos(angle + a + WM_PI) * d;
703 points[3].y = cy + sin(angle + a + WM_PI) * d;
704 points[4].x = cx + cos(angle - a) * d;
705 points[4].y = cy + sin(angle - a) * d;
706 XGrabServer(dpy);
707 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
708 XFlush(dpy);
709 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
711 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
712 XUngrabServer(dpy);
713 cx += xstep;
714 cy += ystep;
715 cw += wstep;
716 ch += hstep;
717 if (angle >= final_angle)
718 break;
721 XFlush(dpy);
724 #undef FRAMES
726 static void animateResizeZoom(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
728 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
729 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
730 float xstep, ystep, wstep, hstep;
731 int i, j;
733 xstep = (float)(fx - x) / steps;
734 ystep = (float)(fy - y) / steps;
735 wstep = (float)(fw - w) / steps;
736 hstep = (float)(fh - h) / steps;
738 for (j = 0; j < FRAMES; j++) {
739 cx[j] = (float)x;
740 cy[j] = (float)y;
741 cw[j] = (float)w;
742 ch[j] = (float)h;
744 XGrabServer(dpy);
745 for (i = 0; i < steps; i++) {
746 for (j = 0; j < FRAMES; j++) {
747 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
748 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
750 XFlush(dpy);
751 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
753 for (j = 0; j < FRAMES; j++) {
754 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
755 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
756 if (j < FRAMES - 1) {
757 cx[j] = cx[j + 1];
758 cy[j] = cy[j + 1];
759 cw[j] = cw[j + 1];
760 ch[j] = ch[j + 1];
761 } else {
762 cx[j] += xstep;
763 cy[j] += ystep;
764 cw[j] += wstep;
765 ch[j] += hstep;
770 for (j = 0; j < FRAMES; j++) {
771 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
773 XFlush(dpy);
774 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
776 for (j = 0; j < FRAMES; j++) {
777 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
780 XUngrabServer(dpy);
783 #undef FRAMES
785 void animateResize(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh)
787 int style = wPreferences.iconification_style; /* Catch the value */
788 int steps;
790 if (style == WIS_NONE)
791 return;
793 if (style == WIS_RANDOM) {
794 style = rand() % 3;
797 switch (style) {
798 case WIS_TWIST:
799 steps = MINIATURIZE_ANIMATION_STEPS_T;
800 if (steps > 0)
801 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
802 break;
803 case WIS_FLIP:
804 steps = MINIATURIZE_ANIMATION_STEPS_F;
805 if (steps > 0)
806 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
807 break;
808 case WIS_ZOOM:
809 default:
810 steps = MINIATURIZE_ANIMATION_STEPS_Z;
811 if (steps > 0)
812 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
813 break;
816 #endif /* ANIMATIONS */
818 static void flushExpose(void)
820 XEvent tmpev;
822 while (XCheckTypedEvent(dpy, Expose, &tmpev))
823 WMHandleEvent(&tmpev);
824 XSync(dpy, 0);
827 static void unmapTransientsFor(WWindow *wwin)
829 WWindow *tmp;
831 tmp = wwin->screen_ptr->focused_window;
832 while (tmp) {
833 /* unmap the transients for this transient */
834 if (tmp != wwin && tmp->transient_for == wwin->client_win
835 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup || tmp->flags.shaded)) {
836 unmapTransientsFor(tmp);
837 tmp->flags.miniaturized = 1;
838 if (!tmp->flags.shaded) {
839 wWindowUnmap(tmp);
840 } else {
841 XUnmapWindow(dpy, tmp->frame->core->window);
844 if (!tmp->flags.shaded)
846 wClientSetState(tmp, IconicState, None);
848 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
850 tmp = tmp->prev;
854 static void mapTransientsFor(WWindow *wwin)
856 WWindow *tmp;
858 tmp = wwin->screen_ptr->focused_window;
859 while (tmp) {
860 /* recursively map the transients for this transient */
861 if (tmp != wwin && tmp->transient_for == wwin->client_win && /*!tmp->flags.mapped */ tmp->flags.miniaturized
862 && tmp->icon == NULL) {
863 mapTransientsFor(tmp);
864 tmp->flags.miniaturized = 0;
865 if (!tmp->flags.shaded) {
866 wWindowMap(tmp);
867 } else {
868 XMapWindow(dpy, tmp->frame->core->window);
870 tmp->flags.semi_focused = 0;
872 if (!tmp->flags.shaded)
874 wClientSetState(tmp, NormalState, None);
876 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
878 tmp = tmp->prev;
882 static WWindow *recursiveTransientFor(WWindow * wwin)
884 int i;
886 if (!wwin)
887 return None;
889 /* hackish way to detect transient_for cycle */
890 i = wwin->screen_ptr->window_count + 1;
892 while (wwin && wwin->transient_for != None && i > 0) {
893 wwin = wWindowFor(wwin->transient_for);
894 i--;
896 if (i == 0 && wwin) {
897 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin->frame->title);
898 return NULL;
901 return wwin;
904 void wIconifyWindow(WWindow * wwin)
906 XWindowAttributes attribs;
907 int present;
909 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
910 /* the window doesn't exist anymore */
911 return;
914 if (wwin->flags.miniaturized) {
915 return;
918 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
919 WWindow *owner = wWindowFor(wwin->transient_for);
921 if (owner && owner->flags.miniaturized)
922 return;
925 present = wwin->frame->workspace == wwin->screen_ptr->current_workspace;
927 /* if the window is in another workspace, simplify process */
928 if (present) {
929 /* icon creation may take a while */
930 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
931 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
932 GrabModeAsync, None, None, CurrentTime);
935 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
936 if (!wwin->flags.icon_moved) {
937 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
939 wwin->icon = wIconCreate(wwin);
941 wwin->icon->mapped = 1;
944 wwin->flags.miniaturized = 1;
945 wwin->flags.mapped = 0;
947 /* unmap transients */
949 unmapTransientsFor(wwin);
951 if (present) {
952 XUngrabPointer(dpy, CurrentTime);
953 wWindowUnmap(wwin);
954 /* let all Expose events arrive so that we can repaint
955 * something before the animation starts (and the server is grabbed) */
956 XSync(dpy, 0);
958 if (wPreferences.disable_miniwindows || wwin->flags.net_handle_icon)
959 wClientSetState(wwin, IconicState, None);
960 else
961 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
963 flushExpose();
964 #ifdef ANIMATIONS
965 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
966 && !wPreferences.no_animations) {
967 int ix, iy, iw, ih;
969 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
970 ix = wwin->icon_x;
971 iy = wwin->icon_y;
972 iw = wwin->icon->core->width;
973 ih = wwin->icon->core->height;
974 } else {
975 if (wwin->flags.net_handle_icon) {
976 ix = wwin->icon_x;
977 iy = wwin->icon_y;
978 iw = wwin->icon_w;
979 ih = wwin->icon_h;
980 } else {
981 ix = 0;
982 iy = 0;
983 iw = wwin->screen_ptr->scr_width;
984 ih = wwin->screen_ptr->scr_height;
987 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
988 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih);
990 #endif
993 wwin->flags.skip_next_animation = 0;
995 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
996 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace ||
997 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
999 XMapWindow(dpy, wwin->icon->core->window);
1001 AddToStackList(wwin->icon->core);
1003 wLowerFrame(wwin->icon->core);
1006 if (present) {
1007 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1010 * It doesn't seem to be working and causes button event hangup
1011 * when deiconifying a transient window.
1012 setupIconGrabs(wwin->icon);
1014 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
1015 && wPreferences.focus_mode == WKF_CLICK) {
1016 WWindow *tmp;
1018 tmp = wwin->prev;
1019 while (tmp) {
1020 if (!WFLAGP(tmp, no_focusable)
1021 && !(tmp->flags.hidden || tmp->flags.miniaturized)
1022 && (wwin->frame->workspace == tmp->frame->workspace))
1023 break;
1024 tmp = tmp->prev;
1026 wSetFocusTo(wwin->screen_ptr, tmp);
1027 } else if (wPreferences.focus_mode != WKF_CLICK) {
1028 wSetFocusTo(wwin->screen_ptr, NULL);
1030 #ifdef ANIMATIONS
1031 if (!wwin->screen_ptr->flags.startup) {
1032 /* Catch up with events not processed while animation was running */
1033 Window clientwin = wwin->client_win;
1035 ProcessPendingEvents();
1037 /* the window can disappear while ProcessPendingEvents() runs */
1038 if (!wWindowFor(clientwin)) {
1039 return;
1042 #endif
1045 /* maybe we want to do this regardless of net_handle_icon
1046 * it seems to me we might break behaviour this way.
1048 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1049 && !wwin->flags.net_handle_icon)
1050 wIconSelect(wwin->icon);
1052 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1054 if (wPreferences.auto_arrange_icons)
1055 wArrangeIcons(wwin->screen_ptr, True);
1058 void wDeiconifyWindow(WWindow *wwin)
1060 /* Let's avoid changing workspace while deiconifying */
1061 ignore_wks_change = 1;
1063 /* we're hiding for show_desktop */
1064 int netwm_hidden = wwin->flags.net_show_desktop &&
1065 wwin->frame->workspace != wwin->screen_ptr->current_workspace;
1067 if (!netwm_hidden)
1068 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1070 if (!wwin->flags.miniaturized)
1071 return;
1073 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1074 WWindow *owner = recursiveTransientFor(wwin);
1076 if (owner && owner->flags.miniaturized) {
1077 wDeiconifyWindow(owner);
1078 wSetFocusTo(wwin->screen_ptr, wwin);
1079 wRaiseFrame(wwin->frame->core);
1080 return;
1084 wwin->flags.miniaturized = 0;
1086 if (!netwm_hidden && !wwin->flags.shaded) {
1087 wwin->flags.mapped = 1;
1090 if (!netwm_hidden || wPreferences.sticky_icons) {
1091 /* maybe we want to do this regardless of net_handle_icon
1092 * it seems to me we might break behaviour this way.
1094 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon
1095 && wwin->icon != NULL) {
1096 if (wwin->icon->selected)
1097 wIconSelect(wwin->icon);
1099 XUnmapWindow(dpy, wwin->icon->core->window);
1103 /* if the window is in another workspace, do it silently */
1104 if (!netwm_hidden) {
1105 #ifdef ANIMATIONS
1106 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1107 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1108 int ix, iy, iw, ih;
1110 if (!wPreferences.disable_miniwindows
1111 && !wwin->flags.net_handle_icon) {
1112 ix = wwin->icon_x;
1113 iy = wwin->icon_y;
1114 iw = wwin->icon->core->width;
1115 ih = wwin->icon->core->height;
1116 } else {
1117 if (wwin->flags.net_handle_icon) {
1118 ix = wwin->icon_x;
1119 iy = wwin->icon_y;
1120 iw = wwin->icon_w;
1121 ih = wwin->icon_h;
1122 } else {
1123 ix = 0;
1124 iy = 0;
1125 iw = wwin->screen_ptr->scr_width;
1126 ih = wwin->screen_ptr->scr_height;
1129 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1130 wwin->frame_x, wwin->frame_y,
1131 wwin->frame->core->width, wwin->frame->core->height);
1133 #endif /* ANIMATIONS */
1134 wwin->flags.skip_next_animation = 0;
1135 XGrabServer(dpy);
1136 if (!wwin->flags.shaded) {
1137 XMapWindow(dpy, wwin->client_win);
1139 XMapWindow(dpy, wwin->frame->core->window);
1140 wRaiseFrame(wwin->frame->core);
1141 if (!wwin->flags.shaded) {
1142 wClientSetState(wwin, NormalState, None);
1144 mapTransientsFor(wwin);
1147 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1148 && !wwin->flags.net_handle_icon) {
1149 RemoveFromStackList(wwin->icon->core);
1150 /* removeIconGrabs(wwin->icon); */
1151 wIconDestroy(wwin->icon);
1152 wwin->icon = NULL;
1155 if (!netwm_hidden) {
1156 XUngrabServer(dpy);
1158 wSetFocusTo(wwin->screen_ptr, wwin);
1160 #ifdef ANIMATIONS
1161 if (!wwin->screen_ptr->flags.startup) {
1162 /* Catch up with events not processed while animation was running */
1163 Window clientwin = wwin->client_win;
1165 ProcessPendingEvents();
1167 /* the window can disappear while ProcessPendingEvents() runs */
1168 if (!wWindowFor(clientwin)) {
1169 return;
1172 #endif
1175 if (wPreferences.auto_arrange_icons) {
1176 wArrangeIcons(wwin->screen_ptr, True);
1179 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1181 /* In case we were shaded and iconified, also unshade */
1182 if (!netwm_hidden)
1183 wUnshadeWindow(wwin);
1185 ignore_wks_change = 0;
1188 static void hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1190 if (wwin->flags.miniaturized) {
1191 if (wwin->icon) {
1192 XUnmapWindow(dpy, wwin->icon->core->window);
1193 wwin->icon->mapped = 0;
1195 wwin->flags.hidden = 1;
1197 WMPostNotificationName(WMNChangedState, wwin, "hide");
1198 return;
1201 if (wwin->flags.inspector_open) {
1202 wHideInspectorForWindow(wwin);
1205 wwin->flags.hidden = 1;
1206 wWindowUnmap(wwin);
1208 wClientSetState(wwin, IconicState, icon->icon_win);
1209 flushExpose();
1211 #ifdef ANIMATIONS
1212 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1213 !wwin->flags.skip_next_animation && animate) {
1214 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1215 wwin->frame->core->width, wwin->frame->core->height,
1216 icon_x, icon_y, icon->core->width, icon->core->height);
1218 #endif
1219 wwin->flags.skip_next_animation = 0;
1221 WMPostNotificationName(WMNChangedState, wwin, "hide");
1224 void wHideOtherApplications(WWindow *awin)
1226 WWindow *wwin;
1227 WApplication *tapp;
1229 if (!awin)
1230 return;
1231 wwin = awin->screen_ptr->focused_window;
1233 while (wwin) {
1234 if (wwin != awin
1235 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1236 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1237 && !wwin->flags.internal_window
1238 && wGetWindowOfInspectorForWindow(wwin) != awin && !WFLAGP(wwin, no_hide_others)) {
1240 if (wwin->main_window == None || WFLAGP(wwin, no_appicon)) {
1241 if (!WFLAGP(wwin, no_miniaturizable)) {
1242 wwin->flags.skip_next_animation = 1;
1243 wIconifyWindow(wwin);
1245 } else if (wwin->main_window != None && awin->main_window != wwin->main_window) {
1246 tapp = wApplicationOf(wwin->main_window);
1247 if (tapp) {
1248 tapp->flags.skip_next_animation = 1;
1249 wHideApplication(tapp);
1250 } else {
1251 if (!WFLAGP(wwin, no_miniaturizable)) {
1252 wwin->flags.skip_next_animation = 1;
1253 wIconifyWindow(wwin);
1258 wwin = wwin->prev;
1261 wSetFocusTo(awin->screen_ptr, awin);
1265 void wHideApplication(WApplication *wapp)
1267 WScreen *scr;
1268 WWindow *wlist;
1269 int hadfocus;
1270 int animate;
1272 if (!wapp) {
1273 wwarning("trying to hide a non grouped window");
1274 return;
1276 if (!wapp->main_window_desc) {
1277 wwarning("group leader not found for window group");
1278 return;
1280 scr = wapp->main_window_desc->screen_ptr;
1281 hadfocus = 0;
1282 wlist = scr->focused_window;
1283 if (!wlist)
1284 return;
1286 if (wlist->main_window == wapp->main_window)
1287 wapp->last_focused = wlist;
1288 else
1289 wapp->last_focused = NULL;
1291 animate = !wapp->flags.skip_next_animation;
1293 while (wlist) {
1294 if (wlist->main_window == wapp->main_window) {
1295 if (wlist->flags.focused) {
1296 hadfocus = 1;
1298 if (wapp->app_icon) {
1299 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1300 wapp->app_icon->y_pos, wlist, animate);
1301 animate = False;
1304 wlist = wlist->prev;
1307 wapp->flags.skip_next_animation = 0;
1309 if (hadfocus) {
1310 if (wPreferences.focus_mode == WKF_CLICK) {
1311 wlist = scr->focused_window;
1312 while (wlist) {
1313 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1314 && (wlist->flags.mapped || wlist->flags.shaded))
1315 break;
1316 wlist = wlist->prev;
1318 wSetFocusTo(scr, wlist);
1319 } else {
1320 wSetFocusTo(scr, NULL);
1324 wapp->flags.hidden = 1;
1326 if (wPreferences.auto_arrange_icons) {
1327 wArrangeIcons(scr, True);
1329 #ifdef HIDDENDOT
1330 if (wapp->app_icon)
1331 wAppIconPaint(wapp->app_icon);
1332 #endif
1335 static void unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate, int bringToCurrentWS)
1337 if (bringToCurrentWS)
1338 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1340 wwin->flags.hidden = 0;
1342 #ifdef ANIMATIONS
1343 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1344 animateResize(wwin->screen_ptr, icon_x, icon_y,
1345 icon->core->width, icon->core->height,
1346 wwin->frame_x, wwin->frame_y,
1347 wwin->frame->core->width, wwin->frame->core->height);
1349 #endif
1350 wwin->flags.skip_next_animation = 0;
1351 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1352 XMapWindow(dpy, wwin->client_win);
1353 XMapWindow(dpy, wwin->frame->core->window);
1354 wClientSetState(wwin, NormalState, None);
1355 wwin->flags.mapped = 1;
1356 wRaiseFrame(wwin->frame->core);
1358 if (wwin->flags.inspector_open) {
1359 wUnhideInspectorForWindow(wwin);
1362 WMPostNotificationName(WMNChangedState, wwin, "hide");
1365 void wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1367 WScreen *scr;
1368 WWindow *wlist, *next;
1369 WWindow *focused = NULL;
1370 int animate;
1372 if (!wapp)
1373 return;
1375 scr = wapp->main_window_desc->screen_ptr;
1376 wlist = scr->focused_window;
1377 if (!wlist)
1378 return;
1380 /* goto beginning of list */
1381 while (wlist->prev)
1382 wlist = wlist->prev;
1384 animate = !wapp->flags.skip_next_animation;
1386 while (wlist) {
1387 next = wlist->next;
1389 if (wlist->main_window == wapp->main_window) {
1390 if (wlist->flags.focused)
1391 focused = wlist;
1392 else if (!focused || !focused->flags.focused)
1393 focused = wlist;
1395 if (wlist->flags.miniaturized) {
1396 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1397 wlist->frame->workspace == scr->current_workspace) && wlist->icon) {
1398 if (!wlist->icon->mapped) {
1399 int x, y;
1401 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1402 if (wlist->icon_x != x || wlist->icon_y != y) {
1403 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1405 wlist->icon_x = x;
1406 wlist->icon_y = y;
1407 XMapWindow(dpy, wlist->icon->core->window);
1408 wlist->icon->mapped = 1;
1410 wRaiseFrame(wlist->icon->core);
1412 if (bringToCurrentWS)
1413 wWindowChangeWorkspace(wlist, scr->current_workspace);
1414 wlist->flags.hidden = 0;
1415 if (miniwindows && wlist->frame->workspace == scr->current_workspace) {
1416 wDeiconifyWindow(wlist);
1418 WMPostNotificationName(WMNChangedState, wlist, "hide");
1419 } else if (wlist->flags.shaded) {
1420 if (bringToCurrentWS)
1421 wWindowChangeWorkspace(wlist, scr->current_workspace);
1422 wlist->flags.hidden = 0;
1423 if (wlist->frame->workspace == scr->current_workspace) {
1424 XMapWindow(dpy, wlist->frame->core->window);
1425 if (miniwindows) {
1426 wUnshadeWindow(wlist);
1427 wRaiseFrame(wlist->frame->core);
1430 WMPostNotificationName(WMNChangedState, wlist, "hide");
1431 } else if (wlist->flags.hidden) {
1432 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1433 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1434 animate = False;
1435 } else {
1436 if (bringToCurrentWS && wlist->frame->workspace != scr->current_workspace) {
1437 wWindowChangeWorkspace(wlist, scr->current_workspace);
1439 wRaiseFrame(wlist->frame->core);
1442 wlist = next;
1445 wapp->flags.skip_next_animation = 0;
1446 wapp->flags.hidden = 0;
1448 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1449 wRaiseFrame(wapp->last_focused->frame->core);
1450 wSetFocusTo(scr, wapp->last_focused);
1451 } else if (focused) {
1452 wSetFocusTo(scr, focused);
1454 wapp->last_focused = NULL;
1455 if (wPreferences.auto_arrange_icons) {
1456 wArrangeIcons(scr, True);
1458 #ifdef HIDDENDOT
1459 wAppIconPaint(wapp->app_icon);
1460 #endif
1463 void wShowAllWindows(WScreen *scr)
1465 WWindow *wwin, *old_foc;
1466 WApplication *wapp;
1468 old_foc = wwin = scr->focused_window;
1469 while (wwin) {
1470 if (!wwin->flags.internal_window &&
1471 (scr->current_workspace == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1472 if (wwin->flags.miniaturized) {
1473 wwin->flags.skip_next_animation = 1;
1474 wDeiconifyWindow(wwin);
1475 } else if (wwin->flags.hidden) {
1476 wapp = wApplicationOf(wwin->main_window);
1477 if (wapp) {
1478 wUnhideApplication(wapp, False, False);
1479 } else {
1480 wwin->flags.skip_next_animation = 1;
1481 wDeiconifyWindow(wwin);
1485 wwin = wwin->prev;
1487 wSetFocusTo(scr, old_foc);
1488 /*wRaiseFrame(old_foc->frame->core); */
1491 void wRefreshDesktop(WScreen *scr)
1493 Window win;
1494 XSetWindowAttributes attr;
1496 attr.backing_store = NotUseful;
1497 attr.save_under = False;
1498 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1499 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1500 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1501 XMapRaised(dpy, win);
1502 XDestroyWindow(dpy, win);
1503 XFlush(dpy);
1506 void wArrangeIcons(WScreen *scr, Bool arrangeAll)
1508 WWindow *wwin;
1509 WAppIcon *aicon;
1511 int head;
1512 const int heads = wXineramaHeads(scr);
1514 struct HeadVars {
1515 int pf; /* primary axis */
1516 int sf; /* secondary axis */
1517 int fullW;
1518 int fullH;
1519 int pi, si;
1520 int sx1, sx2, sy1, sy2; /* screen boundary */
1521 int sw, sh;
1522 int xo, yo;
1523 int xs, ys;
1524 } *vars;
1526 int isize = wPreferences.icon_size;
1528 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
1530 for (head = 0; head < heads; ++head) {
1531 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1532 WMRect rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
1533 vars[head].pi = vars[head].si = 0;
1534 vars[head].sx1 = rect.pos.x;
1535 vars[head].sy1 = rect.pos.y;
1536 vars[head].sw = rect.size.width;
1537 vars[head].sh = rect.size.height;
1538 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1539 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1540 vars[head].sw = isize * (vars[head].sw / isize);
1541 vars[head].sh = isize * (vars[head].sh / isize);
1542 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
1543 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
1545 /* icon yard boundaries */
1546 if (wPreferences.icon_yard & IY_VERT) {
1547 vars[head].pf = vars[head].fullH;
1548 vars[head].sf = vars[head].fullW;
1549 } else {
1550 vars[head].pf = vars[head].fullW;
1551 vars[head].sf = vars[head].fullH;
1553 if (wPreferences.icon_yard & IY_RIGHT) {
1554 vars[head].xo = vars[head].sx2 - isize;
1555 vars[head].xs = -1;
1556 } else {
1557 vars[head].xo = vars[head].sx1;
1558 vars[head].xs = 1;
1560 if (wPreferences.icon_yard & IY_TOP) {
1561 vars[head].yo = vars[head].sy1;
1562 vars[head].ys = 1;
1563 } else {
1564 vars[head].yo = vars[head].sy2 - isize;
1565 vars[head].ys = -1;
1569 #define X ((wPreferences.icon_yard & IY_VERT) \
1570 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1571 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1573 #define Y ((wPreferences.icon_yard & IY_VERT) \
1574 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1575 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1577 /* arrange application icons */
1578 aicon = scr->app_icon_list;
1579 /* reverse them to avoid unnecessarily sliding of icons */
1580 while (aicon && aicon->next)
1581 aicon = aicon->next;
1583 while (aicon) {
1584 if (!aicon->docked) {
1585 /* CHECK: can icon be NULL here ? */
1586 /* The intention here is to place the AppIcon on the head that
1587 * contains most of the applications _main_ window. */
1588 head = wGetHeadForWindow(aicon->icon->owner);
1590 if (aicon->x_pos != X || aicon->y_pos != Y) {
1591 #ifdef ANIMATIONS
1592 if (!wPreferences.no_animations) {
1593 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1595 #endif /* ANIMATIONS */
1597 wAppIconMove(aicon, X, Y);
1598 vars[head].pi++;
1599 if (vars[head].pi >= vars[head].pf) {
1600 vars[head].pi = 0;
1601 vars[head].si++;
1604 aicon = aicon->prev;
1607 /* arrange miniwindows */
1608 wwin = scr->focused_window;
1609 /* reverse them to avoid unnecessarily shuffling */
1610 while (wwin && wwin->prev)
1611 wwin = wwin->prev;
1613 while (wwin) {
1614 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1615 (wwin->frame->workspace == scr->current_workspace ||
1616 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1618 head = wGetHeadForWindow(wwin);
1620 if (arrangeAll || !wwin->flags.icon_moved) {
1621 if (wwin->icon_x != X || wwin->icon_y != Y) {
1622 #ifdef ANIMATIONS
1623 if (wPreferences.no_animations) {
1624 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1625 } else {
1626 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1627 wwin->icon_y, X, Y);
1629 #else
1630 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1631 #endif /* ANIMATIONS */
1633 wwin->icon_x = X;
1634 wwin->icon_y = Y;
1636 vars[head].pi++;
1637 if (vars[head].pi >= vars[head].pf) {
1638 vars[head].pi = 0;
1639 vars[head].si++;
1643 if (arrangeAll) {
1644 wwin->flags.icon_moved = 0;
1646 /* we reversed the order, so we use next */
1647 wwin = wwin->next;
1650 wfree(vars);
1653 void wSelectWindow(WWindow *wwin, Bool flag)
1655 WScreen *scr = wwin->screen_ptr;
1657 if (flag) {
1658 wwin->flags.selected = 1;
1659 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1661 if (!HAS_BORDER(wwin)) {
1662 XSetWindowBorderWidth(dpy, wwin->frame->core->window, FRAME_BORDER_WIDTH);
1665 if (!scr->selected_windows)
1666 scr->selected_windows = WMCreateArray(4);
1667 WMAddToArray(scr->selected_windows, wwin);
1668 } else {
1669 wwin->flags.selected = 0;
1670 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
1672 if (!HAS_BORDER(wwin)) {
1673 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1676 if (scr->selected_windows) {
1677 WMRemoveFromArray(scr->selected_windows, wwin);
1682 void wMakeWindowVisible(WWindow *wwin)
1684 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1685 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1687 if (wwin->flags.shaded) {
1688 wUnshadeWindow(wwin);
1690 if (wwin->flags.hidden) {
1691 WApplication *app;
1693 app = wApplicationOf(wwin->main_window);
1694 if (app) {
1695 /* trick to get focus to this window */
1696 app->last_focused = wwin;
1697 wUnhideApplication(app, False, False);
1700 if (wwin->flags.miniaturized) {
1701 wDeiconifyWindow(wwin);
1702 } else {
1703 if (!WFLAGP(wwin, no_focusable))
1704 wSetFocusTo(wwin->screen_ptr, wwin);
1705 wRaiseFrame(wwin->frame->core);
1710 * Do the animation while shading (called with what = SHADE)
1711 * or unshading (what = UNSHADE).
1713 #ifdef ANIMATIONS
1714 static void shade_animate(WWindow *wwin, Bool what)
1716 int y, s, w, h;
1717 time_t time0 = time(NULL);
1719 if (wwin->flags.skip_next_animation && wPreferences.no_animations)
1720 return;
1722 switch(what) {
1723 case SHADE:
1724 if (!wwin->screen_ptr->flags.startup) {
1725 /* do the shading animation */
1726 h = wwin->frame->core->height;
1727 s = h / SHADE_STEPS;
1728 if (s < 1)
1729 s = 1;
1730 w = wwin->frame->core->width;
1731 y = wwin->frame->top_width;
1732 while (h > wwin->frame->top_width + 1) {
1733 XMoveWindow(dpy, wwin->client_win, 0, y);
1734 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1735 XFlush(dpy);
1737 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1738 break;
1740 if (SHADE_DELAY > 0) {
1741 wusleep(SHADE_DELAY * 1000L);
1742 } else {
1743 wusleep(10);
1745 h -= s;
1746 y -= s;
1748 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1750 break;
1752 case UNSHADE:
1753 h = wwin->frame->top_width + wwin->frame->bottom_width;
1754 y = wwin->frame->top_width - wwin->client.height;
1755 s = abs(y) / SHADE_STEPS;
1756 if (s < 1)
1757 s = 1;
1758 w = wwin->frame->core->width;
1759 XMoveWindow(dpy, wwin->client_win, 0, y);
1760 if (s > 0) {
1761 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
1762 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1763 XMoveWindow(dpy, wwin->client_win, 0, y);
1764 XFlush(dpy);
1765 if (SHADE_DELAY > 0) {
1766 wusleep(SHADE_DELAY * 2000L / 3);
1767 } else {
1768 wusleep(10);
1770 h += s;
1771 y += s;
1773 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1774 break;
1777 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1778 break;
1781 #endif