WINGs: Add copy_file() to libWUtil
[wmaker-crm.git] / src / actions.c
blobd7edf451b392406454b064ef9f95a548f8b5fb65
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "wconfig.h"
25 #include <X11/Xlib.h>
26 #include <X11/Xutil.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <unistd.h>
30 #include <math.h>
31 #include <time.h>
33 #include "WindowMaker.h"
34 #include "framewin.h"
35 #include "window.h"
36 #include "client.h"
37 #include "icon.h"
38 #include "funcs.h"
39 #include "application.h"
40 #include "actions.h"
41 #include "stacking.h"
42 #include "appicon.h"
43 #include "dock.h"
44 #include "appmenu.h"
45 #include "winspector.h"
46 #include "workspace.h"
47 #include "xinerama.h"
49 /****** Global Variables ******/
51 int ignore_wks_change = 0;
52 extern Time LastTimestamp;
53 extern Time LastFocusChange;
54 extern WPreferences wPreferences;
55 extern Atom _XA_WM_TAKE_FOCUS;
56 extern void ProcessPendingEvents();
57 extern int calcIntersectionLength(int p1, int l1, int p2, int l2);
59 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
60 unsigned int *new_width, unsigned int *new_height);
61 static void save_old_geometry(WWindow *wwin);
63 /******* Local Variables *******/
64 static struct {
65 int steps;
66 int delay;
67 } shadePars[5] = {
69 SHADE_STEPS_UF, SHADE_DELAY_UF}, {
70 SHADE_STEPS_F, SHADE_DELAY_F}, {
71 SHADE_STEPS_M, SHADE_DELAY_M}, {
72 SHADE_STEPS_S, SHADE_DELAY_S}, {
73 SHADE_STEPS_US, SHADE_DELAY_US}};
75 #define UNSHADE 0
76 #define SHADE 1
77 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
78 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
80 static int compareTimes(Time t1, Time t2)
82 Time diff;
83 if (t1 == t2)
84 return 0;
85 diff = t1 - t2;
86 return (diff < 60000) ? 1 : -1;
89 #ifdef ANIMATIONS
90 static void shade_animate(WWindow *wwin, Bool what);
91 #else
92 static void shade_animate(WWindow *wwin, Bool what) { }
93 #endif
96 *----------------------------------------------------------------------
97 * wSetFocusTo--
98 * Changes the window focus to the one passed as argument.
99 * If the window to focus is not already focused, it will be brought
100 * to the head of the list of windows. Previously focused window is
101 * unfocused.
103 * Side effects:
104 * Window list may be reordered and the window focus is changed.
106 *----------------------------------------------------------------------
108 void wSetFocusTo(WScreen *scr, WWindow *wwin)
110 static WScreen *old_scr = NULL;
112 WWindow *old_focused;
113 WWindow *focused = scr->focused_window;
114 Time timestamp = LastTimestamp;
115 WApplication *oapp = NULL, *napp = NULL;
116 int wasfocused;
118 if (scr->flags.ignore_focus_events || compareTimes(LastFocusChange, timestamp) > 0)
119 return;
121 if (!old_scr)
122 old_scr = scr;
123 old_focused = old_scr->focused_window;
125 LastFocusChange = timestamp;
127 if (old_focused)
128 oapp = wApplicationOf(old_focused->main_window);
130 if (wwin == NULL) {
131 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
132 if (old_focused)
133 wWindowUnfocus(old_focused);
134 if (oapp) {
135 wAppMenuUnmap(oapp->menu);
136 wApplicationDeactivate(oapp);
139 WMPostNotificationName(WMNChangedFocus, NULL, (void *)True);
140 return;
141 } else if (old_scr != scr && old_focused) {
142 wWindowUnfocus(old_focused);
145 wasfocused = wwin->flags.focused;
146 napp = wApplicationOf(wwin->main_window);
148 /* remember last workspace where the app has been */
149 if (napp) {
150 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
151 napp->last_workspace = wwin->frame->workspace;
154 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
155 /* install colormap if colormap mode is lock mode */
156 if (wPreferences.colormap_mode == WCM_CLICK)
157 wColormapInstallForWindow(scr, wwin);
159 /* set input focus */
160 switch (wwin->focus_mode) {
161 case WFM_NO_INPUT:
162 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
163 break;
165 case WFM_PASSIVE:
166 case WFM_LOCALLY_ACTIVE:
167 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
168 break;
170 case WFM_GLOBALLY_ACTIVE:
171 break;
173 XFlush(dpy);
174 if (wwin->protocols.TAKE_FOCUS) {
175 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
177 XSync(dpy, False);
178 } else {
179 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
181 if (WFLAGP(wwin, no_focusable))
182 return;
184 /* if this is not the focused window focus it */
185 if (focused != wwin) {
186 /* change the focus window list order */
187 if (wwin->prev)
188 wwin->prev->next = wwin->next;
190 if (wwin->next)
191 wwin->next->prev = wwin->prev;
193 wwin->prev = focused;
194 focused->next = wwin;
195 wwin->next = NULL;
196 scr->focused_window = wwin;
198 if (oapp && oapp != napp) {
199 wAppMenuUnmap(oapp->menu);
200 wApplicationDeactivate(oapp);
204 wWindowFocus(wwin, focused);
206 if (napp && !wasfocused) {
207 #ifdef USER_MENU
208 wUserMenuRefreshInstances(napp->menu, wwin);
209 #endif /* USER_MENU */
211 if (wwin->flags.mapped)
212 wAppMenuMap(napp->menu, wwin);
214 if (napp)
215 wApplicationActivate(napp);
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);
391 wWindowSynthConfigureNotify(wwin);
393 WMPostNotificationName(WMNChangedState, wwin, "maximize");
395 /* set maximization state */
396 wwin->flags.maximized = directions;
399 /* the window boundary coordinates */
400 typedef struct {
401 int left;
402 int right;
403 int bottom;
404 int top;
405 int width;
406 int height;
407 } win_coords;
409 static void set_window_coords(WWindow *wwin, win_coords *obs)
411 obs->left = wwin->frame_x;
412 obs->top = wwin->frame_y;
413 obs->width = wwin->frame->core->width;
414 obs->height = wwin->frame->core->height;
415 obs->bottom = obs->top + obs->height;
416 obs->right = obs->left + obs->width;
420 * Maximus: tiled maximization (maximize without overlapping other windows)
422 * The original window 'orig' will be maximized to new coordinates 'new'.
423 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
425 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
426 unsigned int *new_width, unsigned int *new_height)
428 WWindow *tmp;
429 short int tbar_height_0 = 0, rbar_height_0 = 0, bd_width_0 = 0;
430 short int adjust_height;
431 int x_intsect, y_intsect;
432 /* the obstructing, original and new windows */
433 win_coords obs, orig, new;
435 /* set the original coordinate positions of the window to be Maximumized */
436 set_window_coords(wwin, &orig);
438 /* Try to fully maximize first, then readjust later */
439 new.left = usableArea.x1;
440 new.right = usableArea.x2;
441 new.top = usableArea.y1;
442 new.bottom = usableArea.y2;
444 if (HAS_TITLEBAR(wwin))
445 tbar_height_0 = TITLEBAR_HEIGHT;
446 if (HAS_RESIZEBAR(wwin))
447 rbar_height_0 = RESIZEBAR_HEIGHT;
448 if (HAS_BORDER(wwin))
449 bd_width_0 = FRAME_BORDER_WIDTH;
451 /* the length to be subtracted if the window has titlebar, etc */
452 adjust_height = tbar_height_0 + 2 * bd_width_0 + rbar_height_0;
454 tmp = wwin;
455 /* The focused window is always the last in the list */
456 while (tmp->prev) {
457 /* ignore windows in other workspaces etc */
458 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
459 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
460 tmp = tmp->prev;
461 continue;
463 tmp = tmp->prev;
465 /* Set the coordinates of obstructing window */
466 set_window_coords(tmp, &obs);
468 /* Try to maximize in the y direction first */
469 x_intsect = calcIntersectionLength(orig.left, orig.width, obs.left, obs.width);
470 if (x_intsect != 0) {
471 /* TODO: Consider the case when coords are equal */
472 if (obs.bottom < orig.top && obs.bottom > new.top) {
473 /* w_0 is below the bottom of w_j */
474 new.top = obs.bottom + 1;
476 if (orig.bottom < obs.top && obs.top < new.bottom) {
477 /* The bottom of w_0 is above the top of w_j */
478 new.bottom = obs.top - 1;
483 tmp = wwin;
484 while (tmp->prev) {
485 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
486 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
487 tmp = tmp->prev;
488 continue;
490 tmp = tmp->prev;
492 set_window_coords(tmp, &obs);
495 * Use the new.top and new.height instead of original values
496 * as they may have different intersections with the obstructing windows
498 new.height = new.bottom - new.top - adjust_height;
499 y_intsect = calcIntersectionLength(new.top, new.height, obs.top, obs.height);
500 if (y_intsect != 0) {
501 if (obs.right < orig.left && obs.right > new.left) {
502 /* w_0 is completely to the right of w_j */
503 new.left = obs.right + 1;
505 if (orig.right < obs.left && obs.left < new.right) {
506 /* w_0 is completely to the left of w_j */
507 new.right = obs.left - 1;
512 *new_x = new.left;
513 *new_y = new.top;
514 /* xcalc needs -7 here, but other apps don't */
515 *new_height = new.bottom - new.top - adjust_height - 1;;
516 *new_width = new.right - new.left;
519 void wUnmaximizeWindow(WWindow *wwin)
521 int x, y, w, h;
522 WMRect old_geom_rect;
523 int old_head;
524 Bool same_head;
526 if (!wwin->flags.maximized)
527 return;
529 if (wwin->flags.shaded) {
530 wwin->flags.skip_next_animation = 1;
531 wUnshadeWindow(wwin);
533 /* Use old coordinates if they are set, current values otherwise */
534 old_geom_rect = wmkrect(wwin->old_geometry.x, wwin->old_geometry.y, wwin->old_geometry.width, wwin->old_geometry.height);
535 old_head = wGetHeadForRect(wwin->screen_ptr, old_geom_rect);
536 same_head = (wGetHeadForWindow(wwin) == old_head);
537 x = (wwin->old_geometry.x && same_head) ? wwin->old_geometry.x : wwin->frame_x;
538 y = (wwin->old_geometry.y && same_head) ? wwin->old_geometry.y : wwin->frame_y;
539 w = wwin->old_geometry.width ? wwin->old_geometry.width : wwin->client.width;
540 h = wwin->old_geometry.height ? wwin->old_geometry.height : wwin->client.height;
542 wwin->flags.maximized = 0;
543 wWindowConfigure(wwin, x, y, w, h);
544 wWindowSynthConfigureNotify(wwin);
546 WMPostNotificationName(WMNChangedState, wwin, "maximize");
549 void wFullscreenWindow(WWindow *wwin)
551 int head;
552 WMRect rect;
554 if (wwin->flags.fullscreen)
555 return;
557 wwin->flags.fullscreen = True;
559 wWindowConfigureBorders(wwin);
561 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
563 wwin->bfs_geometry.x = wwin->frame_x;
564 wwin->bfs_geometry.y = wwin->frame_y;
565 wwin->bfs_geometry.width = wwin->frame->core->width;
566 wwin->bfs_geometry.height = wwin->frame->core->height;
568 head = wGetHeadForWindow(wwin);
569 rect = wGetRectForHead(wwin->screen_ptr, head);
570 wWindowConfigure(wwin, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
572 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
575 void wUnfullscreenWindow(WWindow *wwin)
577 if (!wwin->flags.fullscreen)
578 return;
580 wwin->flags.fullscreen = False;
582 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
583 if (WFLAGP(wwin, sunken)) {
584 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
585 } else if (WFLAGP(wwin, floating)) {
586 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
587 } else {
588 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
592 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
593 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
595 wWindowConfigureBorders(wwin);
597 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
598 wFrameWindowPaint(wwin->frame);
601 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
604 #ifdef ANIMATIONS
605 static void animateResizeFlip(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
607 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
608 float cx, cy, cw, ch;
609 float xstep, ystep, wstep, hstep;
610 XPoint points[5];
611 float dx, dch, midy;
612 float angle, final_angle, delta;
614 xstep = (float)(fx - x) / steps;
615 ystep = (float)(fy - y) / steps;
616 wstep = (float)(fw - w) / steps;
617 hstep = (float)(fh - h) / steps;
619 cx = (float)x;
620 cy = (float)y;
621 cw = (float)w;
622 ch = (float)h;
624 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_F;
625 delta = (float)(final_angle / FRAMES);
626 for (angle = 0;; angle += delta) {
627 if (angle > final_angle)
628 angle = final_angle;
630 dx = (cw / 10) - ((cw / 5) * sin(angle));
631 dch = (ch / 2) * cos(angle);
632 midy = cy + (ch / 2);
634 points[0].x = cx + dx;
635 points[0].y = midy - dch;
636 points[1].x = cx + cw - dx;
637 points[1].y = points[0].y;
638 points[2].x = cx + cw + dx;
639 points[2].y = midy + dch;
640 points[3].x = cx - dx;
641 points[3].y = points[2].y;
642 points[4].x = points[0].x;
643 points[4].y = points[0].y;
645 XGrabServer(dpy);
646 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
647 XFlush(dpy);
648 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
650 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
651 XUngrabServer(dpy);
652 cx += xstep;
653 cy += ystep;
654 cw += wstep;
655 ch += hstep;
656 if (angle >= final_angle)
657 break;
660 XFlush(dpy);
663 #undef FRAMES
665 static void
666 animateResizeTwist(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
668 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
669 float cx, cy, cw, ch;
670 float xstep, ystep, wstep, hstep;
671 XPoint points[5];
672 float angle, final_angle, a, d, delta;
674 x += w / 2;
675 y += h / 2;
676 fx += fw / 2;
677 fy += fh / 2;
679 xstep = (float)(fx - x) / steps;
680 ystep = (float)(fy - y) / steps;
681 wstep = (float)(fw - w) / steps;
682 hstep = (float)(fh - h) / steps;
684 cx = (float)x;
685 cy = (float)y;
686 cw = (float)w;
687 ch = (float)h;
689 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_T;
690 delta = (float)(final_angle / FRAMES);
691 for (angle = 0;; angle += delta) {
692 if (angle > final_angle)
693 angle = final_angle;
695 a = atan(ch / cw);
696 d = sqrt((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
698 points[0].x = cx + cos(angle - a) * d;
699 points[0].y = cy + sin(angle - a) * d;
700 points[1].x = cx + cos(angle + a) * d;
701 points[1].y = cy + sin(angle + a) * d;
702 points[2].x = cx + cos(angle - a + WM_PI) * d;
703 points[2].y = cy + sin(angle - a + WM_PI) * d;
704 points[3].x = cx + cos(angle + a + WM_PI) * d;
705 points[3].y = cy + sin(angle + a + WM_PI) * d;
706 points[4].x = cx + cos(angle - a) * d;
707 points[4].y = cy + sin(angle - a) * d;
708 XGrabServer(dpy);
709 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
710 XFlush(dpy);
711 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
713 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
714 XUngrabServer(dpy);
715 cx += xstep;
716 cy += ystep;
717 cw += wstep;
718 ch += hstep;
719 if (angle >= final_angle)
720 break;
723 XFlush(dpy);
726 #undef FRAMES
728 static void animateResizeZoom(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
730 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
731 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
732 float xstep, ystep, wstep, hstep;
733 int i, j;
735 xstep = (float)(fx - x) / steps;
736 ystep = (float)(fy - y) / steps;
737 wstep = (float)(fw - w) / steps;
738 hstep = (float)(fh - h) / steps;
740 for (j = 0; j < FRAMES; j++) {
741 cx[j] = (float)x;
742 cy[j] = (float)y;
743 cw[j] = (float)w;
744 ch[j] = (float)h;
746 XGrabServer(dpy);
747 for (i = 0; i < steps; i++) {
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]);
752 XFlush(dpy);
753 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
755 for (j = 0; j < FRAMES; j++) {
756 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
757 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
758 if (j < FRAMES - 1) {
759 cx[j] = cx[j + 1];
760 cy[j] = cy[j + 1];
761 cw[j] = cw[j + 1];
762 ch[j] = ch[j + 1];
763 } else {
764 cx[j] += xstep;
765 cy[j] += ystep;
766 cw[j] += wstep;
767 ch[j] += hstep;
772 for (j = 0; j < FRAMES; j++) {
773 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
775 XFlush(dpy);
776 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
778 for (j = 0; j < FRAMES; j++) {
779 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
782 XUngrabServer(dpy);
785 #undef FRAMES
787 void animateResize(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh)
789 int style = wPreferences.iconification_style; /* Catch the value */
790 int steps;
792 if (style == WIS_NONE)
793 return;
795 if (style == WIS_RANDOM) {
796 style = rand() % 3;
799 switch (style) {
800 case WIS_TWIST:
801 steps = MINIATURIZE_ANIMATION_STEPS_T;
802 if (steps > 0)
803 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
804 break;
805 case WIS_FLIP:
806 steps = MINIATURIZE_ANIMATION_STEPS_F;
807 if (steps > 0)
808 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
809 break;
810 case WIS_ZOOM:
811 default:
812 steps = MINIATURIZE_ANIMATION_STEPS_Z;
813 if (steps > 0)
814 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
815 break;
818 #endif /* ANIMATIONS */
820 static void flushExpose(void)
822 XEvent tmpev;
824 while (XCheckTypedEvent(dpy, Expose, &tmpev))
825 WMHandleEvent(&tmpev);
826 XSync(dpy, 0);
829 static void unmapTransientsFor(WWindow *wwin)
831 WWindow *tmp;
833 tmp = wwin->screen_ptr->focused_window;
834 while (tmp) {
835 /* unmap the transients for this transient */
836 if (tmp != wwin && tmp->transient_for == wwin->client_win
837 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup || tmp->flags.shaded)) {
838 unmapTransientsFor(tmp);
839 tmp->flags.miniaturized = 1;
840 if (!tmp->flags.shaded) {
841 wWindowUnmap(tmp);
842 } else {
843 XUnmapWindow(dpy, tmp->frame->core->window);
846 if (!tmp->flags.shaded)
848 wClientSetState(tmp, IconicState, None);
850 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
852 tmp = tmp->prev;
856 static void mapTransientsFor(WWindow *wwin)
858 WWindow *tmp;
860 tmp = wwin->screen_ptr->focused_window;
861 while (tmp) {
862 /* recursively map the transients for this transient */
863 if (tmp != wwin && tmp->transient_for == wwin->client_win && /*!tmp->flags.mapped */ tmp->flags.miniaturized
864 && tmp->icon == NULL) {
865 mapTransientsFor(tmp);
866 tmp->flags.miniaturized = 0;
867 if (!tmp->flags.shaded) {
868 wWindowMap(tmp);
869 } else {
870 XMapWindow(dpy, tmp->frame->core->window);
872 tmp->flags.semi_focused = 0;
874 if (!tmp->flags.shaded)
876 wClientSetState(tmp, NormalState, None);
878 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
880 tmp = tmp->prev;
884 static WWindow *recursiveTransientFor(WWindow * wwin)
886 int i;
888 if (!wwin)
889 return None;
891 /* hackish way to detect transient_for cycle */
892 i = wwin->screen_ptr->window_count + 1;
894 while (wwin && wwin->transient_for != None && i > 0) {
895 wwin = wWindowFor(wwin->transient_for);
896 i--;
898 if (i == 0 && wwin) {
899 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin->frame->title);
900 return NULL;
903 return wwin;
906 void wIconifyWindow(WWindow * wwin)
908 XWindowAttributes attribs;
909 int present;
911 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
912 /* the window doesn't exist anymore */
913 return;
916 if (wwin->flags.miniaturized) {
917 return;
920 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
921 WWindow *owner = wWindowFor(wwin->transient_for);
923 if (owner && owner->flags.miniaturized)
924 return;
927 present = wwin->frame->workspace == wwin->screen_ptr->current_workspace;
929 /* if the window is in another workspace, simplify process */
930 if (present) {
931 /* icon creation may take a while */
932 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
933 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
934 GrabModeAsync, None, None, CurrentTime);
937 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
938 if (!wwin->flags.icon_moved) {
939 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
941 wwin->icon = wIconCreate(wwin);
943 wwin->icon->mapped = 1;
946 wwin->flags.miniaturized = 1;
947 wwin->flags.mapped = 0;
949 /* unmap transients */
951 unmapTransientsFor(wwin);
953 if (present) {
954 XUngrabPointer(dpy, CurrentTime);
955 wWindowUnmap(wwin);
956 /* let all Expose events arrive so that we can repaint
957 * something before the animation starts (and the server is grabbed) */
958 XSync(dpy, 0);
960 if (wPreferences.disable_miniwindows || wwin->flags.net_handle_icon)
961 wClientSetState(wwin, IconicState, None);
962 else
963 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
965 flushExpose();
966 #ifdef ANIMATIONS
967 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
968 && !wPreferences.no_animations) {
969 int ix, iy, iw, ih;
971 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
972 ix = wwin->icon_x;
973 iy = wwin->icon_y;
974 iw = wwin->icon->core->width;
975 ih = wwin->icon->core->height;
976 } else {
977 if (wwin->flags.net_handle_icon) {
978 ix = wwin->icon_x;
979 iy = wwin->icon_y;
980 iw = wwin->icon_w;
981 ih = wwin->icon_h;
982 } else {
983 ix = 0;
984 iy = 0;
985 iw = wwin->screen_ptr->scr_width;
986 ih = wwin->screen_ptr->scr_height;
989 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
990 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih);
992 #endif
995 wwin->flags.skip_next_animation = 0;
997 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
998 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace ||
999 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1001 XMapWindow(dpy, wwin->icon->core->window);
1003 AddToStackList(wwin->icon->core);
1005 wLowerFrame(wwin->icon->core);
1008 if (present) {
1009 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1012 * It doesn't seem to be working and causes button event hangup
1013 * when deiconifying a transient window.
1014 setupIconGrabs(wwin->icon);
1016 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
1017 && wPreferences.focus_mode == WKF_CLICK) {
1018 WWindow *tmp;
1020 tmp = wwin->prev;
1021 while (tmp) {
1022 if (!WFLAGP(tmp, no_focusable)
1023 && !(tmp->flags.hidden || tmp->flags.miniaturized)
1024 && (wwin->frame->workspace == tmp->frame->workspace))
1025 break;
1026 tmp = tmp->prev;
1028 wSetFocusTo(wwin->screen_ptr, tmp);
1029 } else if (wPreferences.focus_mode != WKF_CLICK) {
1030 wSetFocusTo(wwin->screen_ptr, NULL);
1032 #ifdef ANIMATIONS
1033 if (!wwin->screen_ptr->flags.startup) {
1034 /* Catch up with events not processed while animation was running */
1035 Window clientwin = wwin->client_win;
1037 ProcessPendingEvents();
1039 /* the window can disappear while ProcessPendingEvents() runs */
1040 if (!wWindowFor(clientwin)) {
1041 return;
1044 #endif
1047 /* maybe we want to do this regardless of net_handle_icon
1048 * it seems to me we might break behaviour this way.
1050 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1051 && !wwin->flags.net_handle_icon)
1052 wIconSelect(wwin->icon);
1054 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1056 if (wPreferences.auto_arrange_icons)
1057 wArrangeIcons(wwin->screen_ptr, True);
1060 void wDeiconifyWindow(WWindow *wwin)
1062 /* Let's avoid changing workspace while deiconifying */
1063 ignore_wks_change = 1;
1065 /* we're hiding for show_desktop */
1066 int netwm_hidden = wwin->flags.net_show_desktop &&
1067 wwin->frame->workspace != wwin->screen_ptr->current_workspace;
1069 if (!netwm_hidden)
1070 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1072 if (!wwin->flags.miniaturized)
1073 return;
1075 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1076 WWindow *owner = recursiveTransientFor(wwin);
1078 if (owner && owner->flags.miniaturized) {
1079 wDeiconifyWindow(owner);
1080 wSetFocusTo(wwin->screen_ptr, wwin);
1081 wRaiseFrame(wwin->frame->core);
1082 return;
1086 wwin->flags.miniaturized = 0;
1088 if (!netwm_hidden && !wwin->flags.shaded) {
1089 wwin->flags.mapped = 1;
1092 if (!netwm_hidden || wPreferences.sticky_icons) {
1093 /* maybe we want to do this regardless of net_handle_icon
1094 * it seems to me we might break behaviour this way.
1096 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon
1097 && wwin->icon != NULL) {
1098 if (wwin->icon->selected)
1099 wIconSelect(wwin->icon);
1101 XUnmapWindow(dpy, wwin->icon->core->window);
1105 /* if the window is in another workspace, do it silently */
1106 if (!netwm_hidden) {
1107 #ifdef ANIMATIONS
1108 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1109 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1110 int ix, iy, iw, ih;
1112 if (!wPreferences.disable_miniwindows
1113 && !wwin->flags.net_handle_icon) {
1114 ix = wwin->icon_x;
1115 iy = wwin->icon_y;
1116 iw = wwin->icon->core->width;
1117 ih = wwin->icon->core->height;
1118 } else {
1119 if (wwin->flags.net_handle_icon) {
1120 ix = wwin->icon_x;
1121 iy = wwin->icon_y;
1122 iw = wwin->icon_w;
1123 ih = wwin->icon_h;
1124 } else {
1125 ix = 0;
1126 iy = 0;
1127 iw = wwin->screen_ptr->scr_width;
1128 ih = wwin->screen_ptr->scr_height;
1131 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1132 wwin->frame_x, wwin->frame_y,
1133 wwin->frame->core->width, wwin->frame->core->height);
1135 #endif /* ANIMATIONS */
1136 wwin->flags.skip_next_animation = 0;
1137 XGrabServer(dpy);
1138 if (!wwin->flags.shaded) {
1139 XMapWindow(dpy, wwin->client_win);
1141 XMapWindow(dpy, wwin->frame->core->window);
1142 wRaiseFrame(wwin->frame->core);
1143 if (!wwin->flags.shaded) {
1144 wClientSetState(wwin, NormalState, None);
1146 mapTransientsFor(wwin);
1149 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1150 && !wwin->flags.net_handle_icon) {
1151 RemoveFromStackList(wwin->icon->core);
1152 /* removeIconGrabs(wwin->icon); */
1153 wIconDestroy(wwin->icon);
1154 wwin->icon = NULL;
1157 if (!netwm_hidden) {
1158 XUngrabServer(dpy);
1160 wSetFocusTo(wwin->screen_ptr, wwin);
1162 #ifdef ANIMATIONS
1163 if (!wwin->screen_ptr->flags.startup) {
1164 /* Catch up with events not processed while animation was running */
1165 Window clientwin = wwin->client_win;
1167 ProcessPendingEvents();
1169 /* the window can disappear while ProcessPendingEvents() runs */
1170 if (!wWindowFor(clientwin)) {
1171 return;
1174 #endif
1177 if (wPreferences.auto_arrange_icons) {
1178 wArrangeIcons(wwin->screen_ptr, True);
1181 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1183 /* In case we were shaded and iconified, also unshade */
1184 if (!netwm_hidden)
1185 wUnshadeWindow(wwin);
1187 ignore_wks_change = 0;
1190 static void hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1192 if (wwin->flags.miniaturized) {
1193 if (wwin->icon) {
1194 XUnmapWindow(dpy, wwin->icon->core->window);
1195 wwin->icon->mapped = 0;
1197 wwin->flags.hidden = 1;
1199 WMPostNotificationName(WMNChangedState, wwin, "hide");
1200 return;
1203 if (wwin->flags.inspector_open) {
1204 wHideInspectorForWindow(wwin);
1207 wwin->flags.hidden = 1;
1208 wWindowUnmap(wwin);
1210 wClientSetState(wwin, IconicState, icon->icon_win);
1211 flushExpose();
1213 #ifdef ANIMATIONS
1214 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1215 !wwin->flags.skip_next_animation && animate) {
1216 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1217 wwin->frame->core->width, wwin->frame->core->height,
1218 icon_x, icon_y, icon->core->width, icon->core->height);
1220 #endif
1221 wwin->flags.skip_next_animation = 0;
1223 WMPostNotificationName(WMNChangedState, wwin, "hide");
1226 void wHideAll(WScreen *scr)
1228 WWindow *wwin;
1229 WWindow **windows;
1230 WMenu *menu;
1231 unsigned int wcount = 0;
1232 int i;
1234 if (!scr)
1235 return;
1237 menu = scr->switch_menu;
1239 windows = malloc(sizeof(WWindow *));
1241 if (menu != NULL) {
1242 for (i = 0; i < menu->entry_no; i++) {
1243 windows[wcount] = (WWindow *) menu->entries[i]->clientdata;
1244 wcount++;
1245 windows = realloc(windows, sizeof(WWindow *) * (wcount+1));
1247 } else {
1248 wwin = scr->focused_window;
1250 while (wwin) {
1251 windows[wcount] = wwin;
1252 wcount++;
1253 windows = realloc(windows, sizeof(WWindow *) * (wcount+1));
1254 wwin = wwin->prev;
1259 for (i = 0; i < wcount; i++) {
1260 wwin = windows[i];
1261 if (wwin->frame->workspace == scr->current_workspace
1262 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1263 && !wwin->flags.internal_window
1264 && !WFLAGP(wwin, no_miniaturizable)
1266 wwin->flags.skip_next_animation = 1;
1267 wIconifyWindow(wwin);
1272 void wHideOtherApplications(WWindow *awin)
1274 WWindow *wwin;
1275 WApplication *tapp;
1277 if (!awin)
1278 return;
1279 wwin = awin->screen_ptr->focused_window;
1281 while (wwin) {
1282 if (wwin != awin
1283 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1284 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1285 && !wwin->flags.internal_window
1286 && wGetWindowOfInspectorForWindow(wwin) != awin && !WFLAGP(wwin, no_hide_others)) {
1288 if (wwin->main_window == None || WFLAGP(wwin, no_appicon)) {
1289 if (!WFLAGP(wwin, no_miniaturizable)) {
1290 wwin->flags.skip_next_animation = 1;
1291 wIconifyWindow(wwin);
1293 } else if (wwin->main_window != None && awin->main_window != wwin->main_window) {
1294 tapp = wApplicationOf(wwin->main_window);
1295 if (tapp) {
1296 tapp->flags.skip_next_animation = 1;
1297 wHideApplication(tapp);
1298 } else {
1299 if (!WFLAGP(wwin, no_miniaturizable)) {
1300 wwin->flags.skip_next_animation = 1;
1301 wIconifyWindow(wwin);
1306 wwin = wwin->prev;
1309 wSetFocusTo(awin->screen_ptr, awin);
1313 void wHideApplication(WApplication *wapp)
1315 WScreen *scr;
1316 WWindow *wlist;
1317 int hadfocus;
1318 int animate;
1320 if (!wapp) {
1321 wwarning("trying to hide a non grouped window");
1322 return;
1324 if (!wapp->main_window_desc) {
1325 wwarning("group leader not found for window group");
1326 return;
1328 scr = wapp->main_window_desc->screen_ptr;
1329 hadfocus = 0;
1330 wlist = scr->focused_window;
1331 if (!wlist)
1332 return;
1334 if (wlist->main_window == wapp->main_window)
1335 wapp->last_focused = wlist;
1336 else
1337 wapp->last_focused = NULL;
1339 animate = !wapp->flags.skip_next_animation;
1341 while (wlist) {
1342 if (wlist->main_window == wapp->main_window) {
1343 if (wlist->flags.focused) {
1344 hadfocus = 1;
1346 if (wapp->app_icon) {
1347 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1348 wapp->app_icon->y_pos, wlist, animate);
1349 animate = False;
1352 wlist = wlist->prev;
1355 wapp->flags.skip_next_animation = 0;
1357 if (hadfocus) {
1358 if (wPreferences.focus_mode == WKF_CLICK) {
1359 wlist = scr->focused_window;
1360 while (wlist) {
1361 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1362 && (wlist->flags.mapped || wlist->flags.shaded))
1363 break;
1364 wlist = wlist->prev;
1366 wSetFocusTo(scr, wlist);
1367 } else {
1368 wSetFocusTo(scr, NULL);
1372 wapp->flags.hidden = 1;
1374 if (wPreferences.auto_arrange_icons) {
1375 wArrangeIcons(scr, True);
1377 #ifdef HIDDENDOT
1378 if (wapp->app_icon)
1379 wAppIconPaint(wapp->app_icon);
1380 #endif
1383 static void unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate, int bringToCurrentWS)
1385 if (bringToCurrentWS)
1386 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1388 wwin->flags.hidden = 0;
1390 #ifdef ANIMATIONS
1391 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1392 animateResize(wwin->screen_ptr, icon_x, icon_y,
1393 icon->core->width, icon->core->height,
1394 wwin->frame_x, wwin->frame_y,
1395 wwin->frame->core->width, wwin->frame->core->height);
1397 #endif
1398 wwin->flags.skip_next_animation = 0;
1399 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1400 XMapWindow(dpy, wwin->client_win);
1401 XMapWindow(dpy, wwin->frame->core->window);
1402 wClientSetState(wwin, NormalState, None);
1403 wwin->flags.mapped = 1;
1404 wRaiseFrame(wwin->frame->core);
1406 if (wwin->flags.inspector_open) {
1407 wUnhideInspectorForWindow(wwin);
1410 WMPostNotificationName(WMNChangedState, wwin, "hide");
1413 void wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1415 WScreen *scr;
1416 WWindow *wlist, *next;
1417 WWindow *focused = NULL;
1418 int animate;
1420 if (!wapp)
1421 return;
1423 scr = wapp->main_window_desc->screen_ptr;
1424 wlist = scr->focused_window;
1425 if (!wlist)
1426 return;
1428 /* goto beginning of list */
1429 while (wlist->prev)
1430 wlist = wlist->prev;
1432 animate = !wapp->flags.skip_next_animation;
1434 while (wlist) {
1435 next = wlist->next;
1437 if (wlist->main_window == wapp->main_window) {
1438 if (wlist->flags.focused)
1439 focused = wlist;
1440 else if (!focused || !focused->flags.focused)
1441 focused = wlist;
1443 if (wlist->flags.miniaturized) {
1444 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1445 wlist->frame->workspace == scr->current_workspace) && wlist->icon) {
1446 if (!wlist->icon->mapped) {
1447 int x, y;
1449 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1450 if (wlist->icon_x != x || wlist->icon_y != y) {
1451 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1453 wlist->icon_x = x;
1454 wlist->icon_y = y;
1455 XMapWindow(dpy, wlist->icon->core->window);
1456 wlist->icon->mapped = 1;
1458 wRaiseFrame(wlist->icon->core);
1460 if (bringToCurrentWS)
1461 wWindowChangeWorkspace(wlist, scr->current_workspace);
1462 wlist->flags.hidden = 0;
1463 if (miniwindows && wlist->frame->workspace == scr->current_workspace) {
1464 wDeiconifyWindow(wlist);
1466 WMPostNotificationName(WMNChangedState, wlist, "hide");
1467 } else if (wlist->flags.shaded) {
1468 if (bringToCurrentWS)
1469 wWindowChangeWorkspace(wlist, scr->current_workspace);
1470 wlist->flags.hidden = 0;
1471 wRaiseFrame(wlist->frame->core);
1472 if (wlist->frame->workspace == scr->current_workspace) {
1473 XMapWindow(dpy, wlist->frame->core->window);
1474 if (miniwindows) {
1475 wUnshadeWindow(wlist);
1478 WMPostNotificationName(WMNChangedState, wlist, "hide");
1479 } else if (wlist->flags.hidden) {
1480 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1481 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1482 animate = False;
1483 } else {
1484 if (bringToCurrentWS && wlist->frame->workspace != scr->current_workspace) {
1485 wWindowChangeWorkspace(wlist, scr->current_workspace);
1487 wRaiseFrame(wlist->frame->core);
1490 wlist = next;
1493 wapp->flags.skip_next_animation = 0;
1494 wapp->flags.hidden = 0;
1496 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1497 wRaiseFrame(wapp->last_focused->frame->core);
1498 wSetFocusTo(scr, wapp->last_focused);
1499 } else if (focused) {
1500 wSetFocusTo(scr, focused);
1502 wapp->last_focused = NULL;
1503 if (wPreferences.auto_arrange_icons) {
1504 wArrangeIcons(scr, True);
1506 #ifdef HIDDENDOT
1507 wAppIconPaint(wapp->app_icon);
1508 #endif
1511 void wShowAllWindows(WScreen *scr)
1513 WWindow *wwin, *old_foc;
1514 WApplication *wapp;
1516 old_foc = wwin = scr->focused_window;
1517 while (wwin) {
1518 if (!wwin->flags.internal_window &&
1519 (scr->current_workspace == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1520 if (wwin->flags.miniaturized) {
1521 wwin->flags.skip_next_animation = 1;
1522 wDeiconifyWindow(wwin);
1523 } else if (wwin->flags.hidden) {
1524 wapp = wApplicationOf(wwin->main_window);
1525 if (wapp) {
1526 wUnhideApplication(wapp, False, False);
1527 } else {
1528 wwin->flags.skip_next_animation = 1;
1529 wDeiconifyWindow(wwin);
1533 wwin = wwin->prev;
1535 wSetFocusTo(scr, old_foc);
1536 /*wRaiseFrame(old_foc->frame->core); */
1539 void wRefreshDesktop(WScreen *scr)
1541 Window win;
1542 XSetWindowAttributes attr;
1544 attr.backing_store = NotUseful;
1545 attr.save_under = False;
1546 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1547 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1548 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1549 XMapRaised(dpy, win);
1550 XDestroyWindow(dpy, win);
1551 XFlush(dpy);
1554 void wArrangeIcons(WScreen *scr, Bool arrangeAll)
1556 WWindow *wwin;
1557 WAppIcon *aicon;
1559 int head;
1560 const int heads = wXineramaHeads(scr);
1562 struct HeadVars {
1563 int pf; /* primary axis */
1564 int sf; /* secondary axis */
1565 int fullW;
1566 int fullH;
1567 int pi, si;
1568 int sx1, sx2, sy1, sy2; /* screen boundary */
1569 int sw, sh;
1570 int xo, yo;
1571 int xs, ys;
1572 } *vars;
1574 int isize = wPreferences.icon_size;
1576 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
1578 for (head = 0; head < heads; ++head) {
1579 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1580 WMRect rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
1581 vars[head].pi = vars[head].si = 0;
1582 vars[head].sx1 = rect.pos.x;
1583 vars[head].sy1 = rect.pos.y;
1584 vars[head].sw = rect.size.width;
1585 vars[head].sh = rect.size.height;
1586 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1587 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1588 vars[head].sw = isize * (vars[head].sw / isize);
1589 vars[head].sh = isize * (vars[head].sh / isize);
1590 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
1591 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
1593 /* icon yard boundaries */
1594 if (wPreferences.icon_yard & IY_VERT) {
1595 vars[head].pf = vars[head].fullH;
1596 vars[head].sf = vars[head].fullW;
1597 } else {
1598 vars[head].pf = vars[head].fullW;
1599 vars[head].sf = vars[head].fullH;
1601 if (wPreferences.icon_yard & IY_RIGHT) {
1602 vars[head].xo = vars[head].sx2 - isize;
1603 vars[head].xs = -1;
1604 } else {
1605 vars[head].xo = vars[head].sx1;
1606 vars[head].xs = 1;
1608 if (wPreferences.icon_yard & IY_TOP) {
1609 vars[head].yo = vars[head].sy1;
1610 vars[head].ys = 1;
1611 } else {
1612 vars[head].yo = vars[head].sy2 - isize;
1613 vars[head].ys = -1;
1617 #define X ((wPreferences.icon_yard & IY_VERT) \
1618 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1619 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1621 #define Y ((wPreferences.icon_yard & IY_VERT) \
1622 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1623 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1625 /* arrange application icons */
1626 aicon = scr->app_icon_list;
1627 /* reverse them to avoid unnecessarily sliding of icons */
1628 while (aicon && aicon->next)
1629 aicon = aicon->next;
1631 while (aicon) {
1632 if (!aicon->docked) {
1633 /* CHECK: can icon be NULL here ? */
1634 /* The intention here is to place the AppIcon on the head that
1635 * contains most of the applications _main_ window. */
1636 head = wGetHeadForWindow(aicon->icon->owner);
1638 if (aicon->x_pos != X || aicon->y_pos != Y) {
1639 #ifdef ANIMATIONS
1640 if (!wPreferences.no_animations) {
1641 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1643 #endif /* ANIMATIONS */
1645 wAppIconMove(aicon, X, Y);
1646 vars[head].pi++;
1647 if (vars[head].pi >= vars[head].pf) {
1648 vars[head].pi = 0;
1649 vars[head].si++;
1652 aicon = aicon->prev;
1655 /* arrange miniwindows */
1656 wwin = scr->focused_window;
1657 /* reverse them to avoid unnecessarily shuffling */
1658 while (wwin && wwin->prev)
1659 wwin = wwin->prev;
1661 while (wwin) {
1662 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1663 (wwin->frame->workspace == scr->current_workspace ||
1664 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1666 head = wGetHeadForWindow(wwin);
1668 if (arrangeAll || !wwin->flags.icon_moved) {
1669 if (wwin->icon_x != X || wwin->icon_y != Y) {
1670 #ifdef ANIMATIONS
1671 if (wPreferences.no_animations) {
1672 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1673 } else {
1674 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1675 wwin->icon_y, X, Y);
1677 #else
1678 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1679 #endif /* ANIMATIONS */
1681 wwin->icon_x = X;
1682 wwin->icon_y = Y;
1684 vars[head].pi++;
1685 if (vars[head].pi >= vars[head].pf) {
1686 vars[head].pi = 0;
1687 vars[head].si++;
1691 if (arrangeAll) {
1692 wwin->flags.icon_moved = 0;
1694 /* we reversed the order, so we use next */
1695 wwin = wwin->next;
1698 wfree(vars);
1701 void wSelectWindow(WWindow *wwin, Bool flag)
1703 WScreen *scr = wwin->screen_ptr;
1705 if (flag) {
1706 wwin->flags.selected = 1;
1707 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1709 if (!HAS_BORDER(wwin)) {
1710 XSetWindowBorderWidth(dpy, wwin->frame->core->window, FRAME_BORDER_WIDTH);
1713 if (!scr->selected_windows)
1714 scr->selected_windows = WMCreateArray(4);
1715 WMAddToArray(scr->selected_windows, wwin);
1716 } else {
1717 wwin->flags.selected = 0;
1718 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
1720 if (!HAS_BORDER(wwin)) {
1721 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1724 if (scr->selected_windows) {
1725 WMRemoveFromArray(scr->selected_windows, wwin);
1730 void wMakeWindowVisible(WWindow *wwin)
1732 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1733 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1735 if (wwin->flags.shaded) {
1736 wUnshadeWindow(wwin);
1738 if (wwin->flags.hidden) {
1739 WApplication *app;
1741 app = wApplicationOf(wwin->main_window);
1742 if (app) {
1743 /* trick to get focus to this window */
1744 app->last_focused = wwin;
1745 wUnhideApplication(app, False, False);
1748 if (wwin->flags.miniaturized) {
1749 wDeiconifyWindow(wwin);
1750 } else {
1751 if (!WFLAGP(wwin, no_focusable))
1752 wSetFocusTo(wwin->screen_ptr, wwin);
1753 wRaiseFrame(wwin->frame->core);
1758 * Do the animation while shading (called with what = SHADE)
1759 * or unshading (what = UNSHADE).
1761 #ifdef ANIMATIONS
1762 static void shade_animate(WWindow *wwin, Bool what)
1764 int y, s, w, h;
1765 time_t time0 = time(NULL);
1767 if (wwin->flags.skip_next_animation && wPreferences.no_animations)
1768 return;
1770 switch(what) {
1771 case SHADE:
1772 if (!wwin->screen_ptr->flags.startup) {
1773 /* do the shading animation */
1774 h = wwin->frame->core->height;
1775 s = h / SHADE_STEPS;
1776 if (s < 1)
1777 s = 1;
1778 w = wwin->frame->core->width;
1779 y = wwin->frame->top_width;
1780 while (h > wwin->frame->top_width + 1) {
1781 XMoveWindow(dpy, wwin->client_win, 0, y);
1782 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1783 XFlush(dpy);
1785 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1786 break;
1788 if (SHADE_DELAY > 0) {
1789 wusleep(SHADE_DELAY * 1000L);
1790 } else {
1791 wusleep(10);
1793 h -= s;
1794 y -= s;
1796 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1798 break;
1800 case UNSHADE:
1801 h = wwin->frame->top_width + wwin->frame->bottom_width;
1802 y = wwin->frame->top_width - wwin->client.height;
1803 s = abs(y) / SHADE_STEPS;
1804 if (s < 1)
1805 s = 1;
1806 w = wwin->frame->core->width;
1807 XMoveWindow(dpy, wwin->client_win, 0, y);
1808 if (s > 0) {
1809 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
1810 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1811 XMoveWindow(dpy, wwin->client_win, 0, y);
1812 XFlush(dpy);
1813 if (SHADE_DELAY > 0) {
1814 wusleep(SHADE_DELAY * 2000L / 3);
1815 } else {
1816 wusleep(10);
1818 h += s;
1819 y += s;
1821 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1822 break;
1825 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1826 break;
1829 #endif