Remove SPEAKER_SOUND dead code
[wmaker-crm.git] / src / actions.c
blob2aae7581d5b053bdf333e9a9648cc212b80ce9ae
1 /* action.c- misc. window commands (miniaturize, hide etc.)
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #include "wconfig.h"
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <math.h>
32 #include <time.h>
34 #include "WindowMaker.h"
35 #include "wcore.h"
36 #include "framewin.h"
37 #include "window.h"
38 #include "client.h"
39 #include "icon.h"
40 #include "funcs.h"
41 #include "application.h"
42 #include "actions.h"
43 #include "stacking.h"
44 #include "appicon.h"
45 #include "dock.h"
46 #include "appmenu.h"
47 #include "winspector.h"
48 #include "workspace.h"
49 #include "xinerama.h"
51 /****** Global Variables ******/
52 extern Time LastTimestamp;
53 extern Time LastFocusChange;
55 extern Cursor wCursor[WCUR_LAST];
57 extern WPreferences wPreferences;
59 extern Atom _XA_WM_TAKE_FOCUS;
61 extern void ProcessPendingEvents();
62 extern int calcIntersectionLength(int p1, int l1, int p2, int l2);
64 /******* Local Variables *******/
65 static struct {
66 int steps;
67 int delay;
68 } shadePars[5] = {
70 SHADE_STEPS_UF, SHADE_DELAY_UF}, {
71 SHADE_STEPS_F, SHADE_DELAY_F}, {
72 SHADE_STEPS_M, SHADE_DELAY_M}, {
73 SHADE_STEPS_S, SHADE_DELAY_S}, {
74 SHADE_STEPS_US, SHADE_DELAY_US}};
76 #define UNSHADE 0
77 #define SHADE 1
78 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
79 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
81 static int compareTimes(Time t1, Time t2)
83 Time diff;
84 if (t1 == t2)
85 return 0;
86 diff = t1 - t2;
87 return (diff < 60000) ? 1 : -1;
91 *----------------------------------------------------------------------
92 * wSetFocusTo--
93 * Changes the window focus to the one passed as argument.
94 * If the window to focus is not already focused, it will be brought
95 * to the head of the list of windows. Previously focused window is
96 * unfocused.
98 * Side effects:
99 * Window list may be reordered and the window focus is changed.
101 *----------------------------------------------------------------------
103 void wSetFocusTo(WScreen * scr, WWindow * wwin)
105 static WScreen *old_scr = NULL;
107 WWindow *old_focused;
108 WWindow *focused = scr->focused_window;
109 Time timestamp = LastTimestamp;
110 WApplication *oapp = NULL, *napp = NULL;
111 int wasfocused;
113 if (scr->flags.ignore_focus_events || compareTimes(LastFocusChange, timestamp) > 0)
114 return;
116 if (!old_scr)
117 old_scr = scr;
118 old_focused = old_scr->focused_window;
120 LastFocusChange = timestamp;
122 if (old_focused)
123 oapp = wApplicationOf(old_focused->main_window);
125 if (wwin == NULL) {
126 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
127 if (old_focused) {
128 wWindowUnfocus(old_focused);
130 if (oapp) {
131 wAppMenuUnmap(oapp->menu);
132 #ifdef NEWAPPICON
133 wApplicationDeactivate(oapp);
134 #endif
137 WMPostNotificationName(WMNChangedFocus, NULL, (void *)True);
138 return;
139 } else if (old_scr != scr && old_focused) {
140 wWindowUnfocus(old_focused);
143 wasfocused = wwin->flags.focused;
144 napp = wApplicationOf(wwin->main_window);
146 /* remember last workspace where the app has been */
147 if (napp) {
148 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
149 napp->last_workspace = wwin->frame->workspace;
152 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
153 /* install colormap if colormap mode is lock mode */
154 if (wPreferences.colormap_mode == WCM_CLICK)
155 wColormapInstallForWindow(scr, wwin);
157 /* set input focus */
158 switch (wwin->focus_mode) {
159 case WFM_NO_INPUT:
160 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
161 break;
163 case WFM_PASSIVE:
164 case WFM_LOCALLY_ACTIVE:
165 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
166 break;
168 case WFM_GLOBALLY_ACTIVE:
169 break;
171 XFlush(dpy);
172 if (wwin->protocols.TAKE_FOCUS) {
173 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
175 XSync(dpy, False);
176 } else {
177 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
179 if (WFLAGP(wwin, no_focusable))
180 return;
182 /* if this is not the focused window focus it */
183 if (focused != wwin) {
184 /* change the focus window list order */
185 if (wwin->prev)
186 wwin->prev->next = wwin->next;
188 if (wwin->next)
189 wwin->next->prev = wwin->prev;
191 wwin->prev = focused;
192 focused->next = wwin;
193 wwin->next = NULL;
194 scr->focused_window = wwin;
196 if (oapp && oapp != napp) {
197 wAppMenuUnmap(oapp->menu);
198 #ifdef NEWAPPICON
199 wApplicationDeactivate(oapp);
200 #endif
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);
213 #ifdef NEWAPPICON
214 wApplicationActivate(napp);
215 #endif
218 XFlush(dpy);
219 old_scr = scr;
222 void wShadeWindow(WWindow *wwin)
225 if (wwin->flags.shaded)
226 return;
228 XLowerWindow(dpy, wwin->client_win);
229 shade_animate(wwin, SHADE);
231 wwin->flags.skip_next_animation = 0;
232 wwin->flags.shaded = 1;
233 wwin->flags.mapped = 0;
234 /* prevent window withdrawal when getting UnmapNotify */
235 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
236 XUnmapWindow(dpy, wwin->client_win);
237 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
239 /* for the client it's just like iconification */
240 wFrameWindowResize(wwin->frame, wwin->frame->core->width, wwin->frame->top_width - 1);
242 wwin->client.y = wwin->frame_y - wwin->client.height + wwin->frame->top_width;
243 wWindowSynthConfigureNotify(wwin);
246 wClientSetState(wwin, IconicState, None);
249 WMPostNotificationName(WMNChangedState, wwin, "shade");
251 #ifdef ANIMATIONS
252 if (!wwin->screen_ptr->flags.startup) {
253 /* Catch up with events not processed while animation was running */
254 ProcessPendingEvents();
256 #endif
259 void wUnshadeWindow(WWindow *wwin)
262 if (!wwin->flags.shaded)
263 return;
265 wwin->flags.shaded = 0;
266 wwin->flags.mapped = 1;
267 XMapWindow(dpy, wwin->client_win);
269 shade_animate(wwin, UNSHADE);
271 wwin->flags.skip_next_animation = 0;
272 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
273 wwin->frame->top_width + wwin->client.height + wwin->frame->bottom_width);
275 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
276 wWindowSynthConfigureNotify(wwin);
279 wClientSetState(wwin, NormalState, None);
281 /* if the window is focused, set the focus again as it was disabled during
282 * shading */
283 if (wwin->flags.focused)
284 wSetFocusTo(wwin->screen_ptr, wwin);
286 WMPostNotificationName(WMNChangedState, wwin, "shade");
289 /* Set the old coordinates using the current values */
290 static void save_old_geometry(WWindow *wwin)
292 wwin->old_geometry.width = wwin->client.width;
293 wwin->old_geometry.height = wwin->client.height;
294 wwin->old_geometry.x = wwin->frame_x;
295 wwin->old_geometry.y = wwin->frame_y;
298 void wMaximizeWindow(WWindow * wwin, int directions)
300 int new_x, new_y;
301 unsigned int new_width, new_height, half_scr_width;
302 WArea usableArea, totalArea;
303 Bool has_border = 1;
304 int adj_size;
306 if (!IS_RESIZABLE(wwin))
307 return;
309 if (!HAS_BORDER(wwin))
310 has_border = 0;
312 /* the size to adjust the geometry */
313 adj_size = FRAME_BORDER_WIDTH * 2 * has_border;
315 /* save old coordinates before we change the current values */
316 save_old_geometry(wwin);
318 totalArea.x1 = 0;
319 totalArea.y1 = 0;
320 totalArea.x2 = wwin->screen_ptr->scr_width;
321 totalArea.y2 = wwin->screen_ptr->scr_height;
322 usableArea = totalArea;
324 if (!(directions & MAX_IGNORE_XINERAMA)) {
325 WScreen *scr = wwin->screen_ptr;
326 int head;
328 if (directions & MAX_KEYBOARD)
329 head = wGetHeadForWindow(wwin);
330 else
331 head = wGetHeadForPointerLocation(scr);
333 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
336 /* Only save directions, not kbd or xinerama hints */
337 directions &= (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_MAXIMUS);
339 if (WFLAGP(wwin, full_maximize)) {
340 usableArea = totalArea;
342 half_scr_width = (usableArea.x2 - usableArea.x1)/2;
344 if (wwin->flags.shaded) {
345 wwin->flags.skip_next_animation = 1;
346 wUnshadeWindow(wwin);
349 if (directions & MAX_HORIZONTAL) {
350 new_width = usableArea.x2 - usableArea.x1 - adj_size;
351 new_x = usableArea.x1;
352 } else if (directions & MAX_LEFTHALF) {
353 new_width = half_scr_width - adj_size;
354 new_x = usableArea.x1;
355 } else if (directions & MAX_RIGHTHALF) {
356 new_width = half_scr_width - adj_size;
357 new_x = usableArea.x1 + half_scr_width;
358 } else {
359 new_x = wwin->frame_x;
360 new_width = wwin->frame->core->width;
363 if (directions & MAX_VERTICAL) {
364 new_height = usableArea.y2 - usableArea.y1 - adj_size;
365 new_y = usableArea.y1;
366 if (WFLAGP(wwin, full_maximize)) {
367 new_y -= wwin->frame->top_width;
368 new_height += wwin->frame->bottom_width - 1;
370 } else {
371 new_y = wwin->frame_y;
372 new_height = wwin->frame->core->height;
375 if (!WFLAGP(wwin, full_maximize)) {
376 new_height -= wwin->frame->top_width + wwin->frame->bottom_width;
379 if (directions & MAX_MAXIMUS) {
380 find_Maximus_geometry(wwin, usableArea, &new_x, &new_y, &new_width, &new_height);
381 if (WFLAGP(wwin, full_maximize) && new_y == 0) {
382 new_y -= wwin->frame->top_width;
383 new_height += wwin->frame->top_width - 1;
387 wWindowConstrainSize(wwin, &new_width, &new_height);
389 wWindowCropSize(wwin, usableArea.x2 - usableArea.x1,
390 usableArea.y2 - usableArea.y1, &new_width, &new_height);
392 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
394 WMPostNotificationName(WMNChangedState, wwin, "maximize");
396 /* set maximization state */
397 wwin->flags.maximized = directions;
401 * Maximus: tiled maximization (maximize without overlapping other windows)
403 * The window to be maximized will be denoted by w_0 (sub-index zero)
404 * while the windows which will stop the maximization of w_0 are denoted by w_j.
406 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
407 unsigned int *new_width, unsigned int *new_height)
409 WWindow *tmp;
410 int x_0 = wwin->frame_x;
411 int y_0 = wwin->frame_y;
412 int width_0 = wwin->frame->core->width;
413 int height_0 = wwin->frame->core->height;
414 int botton_0 = y_0 + height_0;
415 int right_border_0 = x_0 + width_0;
416 int new_x_0, new_y_0, new_botton_0, new_right_border_0, new_height_0;
417 int x_j, y_j, width_j, height_j, botton_j, top_j, right_border_j;
418 int x_intsect, y_intsect;
419 short int tbar_height_0 = 0, rbar_height_0 = 0;
420 short int bd_width_0 = 0, bd_width_j = 0;
421 short int adjust_height;
423 /* Try to fully maximize first, then readjust later */
424 new_x_0 = usableArea.x1;
425 new_y_0 = usableArea.y1;
426 new_botton_0 = usableArea.y2;
427 new_right_border_0 = usableArea.x2;
429 if (HAS_TITLEBAR(wwin))
430 tbar_height_0 = TITLEBAR_HEIGHT;
431 if (HAS_RESIZEBAR(wwin))
432 rbar_height_0 = RESIZEBAR_HEIGHT;
433 if (HAS_BORDER(wwin))
434 bd_width_0 = FRAME_BORDER_WIDTH;
436 /* the lengths to be subtracted if w_0 has titlebar, etc */
437 adjust_height = tbar_height_0 + 2 * bd_width_0 + rbar_height_0;
439 tmp = wwin;
440 /* The focused window is always the last in the list */
441 while (tmp->prev) {
442 /* ignore windows in other workspaces etc */
443 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
444 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
445 tmp = tmp->prev;
446 continue;
448 tmp = tmp->prev;
450 if (HAS_BORDER(tmp))
451 bd_width_j = FRAME_BORDER_WIDTH;
452 else
453 bd_width_j = 0;
456 * Set the w_j window coordinates. It is convenient
457 * to not use "corrected" sizes for width and height,
458 * otherwise bottom_j and right_border_j would be
459 * incorrect.
461 x_j = tmp->frame_x - bd_width_j;
462 y_j = tmp->frame_y - bd_width_j;
463 width_j = tmp->frame->core->width;
464 height_j = tmp->frame->core->height;
465 botton_j = y_j + height_j + bd_width_j;
466 top_j = y_j - bd_width_j;
467 right_border_j = x_j + width_j + bd_width_j;
469 /* Try to maximize in the y direction first */
470 x_intsect = calcIntersectionLength(x_0, width_0, x_j, width_j);
471 if (x_intsect != 0) {
472 /* TODO: Consider the case when coords are equal */
473 if (botton_j < y_0 && botton_j > new_y_0) {
474 /* w_0 is below the botton of w_j */
475 new_y_0 = botton_j;
477 if (botton_0 < top_j && top_j < new_botton_0) {
478 /* The botton of w_0 is above the top of w_j */
479 new_botton_0 = top_j;
484 tmp = wwin;
485 while (tmp->prev) {
486 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
487 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
488 tmp = tmp->prev;
489 continue;
491 tmp = tmp->prev;
493 if (HAS_BORDER(tmp))
494 bd_width_j = FRAME_BORDER_WIDTH;
495 else
496 bd_width_j = 0;
498 /* set the w_j window coordinates */
499 x_j = tmp->frame_x - bd_width_j;
500 y_j = tmp->frame_y - bd_width_j;
501 width_j = tmp->frame->core->width;
502 height_j = tmp->frame->core->height;
503 botton_j = y_j + height_j + bd_width_j;
504 top_j = y_j - bd_width_j;
505 right_border_j = x_j + width_j + bd_width_j;
508 * Use the updated y coordinates from the above step to account
509 * the possibility that the new value of y_0 will have different
510 * intersections with w_j
512 new_height_0 = new_botton_0 - new_y_0 - adjust_height;
513 y_intsect = calcIntersectionLength(new_y_0, new_height_0, y_j, height_j);
514 if (y_intsect != 0) {
515 if (right_border_j < x_0 && right_border_j > new_x_0) {
516 /* w_0 is completely to the right of w_j */
517 new_x_0 = right_border_j + 1;
519 if (right_border_0 < x_j && x_j < new_right_border_0) {
520 /* w_0 is completely to the left of w_j */
521 new_right_border_0 = x_j - 1;
526 new_height_0 = new_botton_0 - new_y_0 - adjust_height;
527 *new_x = new_x_0;
528 *new_y = new_y_0;
529 *new_height = new_height_0;
530 *new_width = new_right_border_0 - new_x_0;
533 void wUnmaximizeWindow(WWindow * wwin)
535 int x, y, w, h;
536 WMRect old_geom_rect;
537 int old_head;
538 Bool same_head;
540 if (!wwin->flags.maximized)
541 return;
543 if (wwin->flags.shaded) {
544 wwin->flags.skip_next_animation = 1;
545 wUnshadeWindow(wwin);
547 /* Use old coordinates if they are set, current values otherwise */
548 old_geom_rect = wmkrect(wwin->old_geometry.x, wwin->old_geometry.y, wwin->old_geometry.width, wwin->old_geometry.height);
549 old_head = wGetHeadForRect(wwin->screen_ptr, old_geom_rect);
550 same_head = (wGetHeadForWindow(wwin) == old_head);
551 x = (wwin->old_geometry.x && same_head) ? wwin->old_geometry.x : wwin->frame_x;
552 y = (wwin->old_geometry.y && same_head) ? wwin->old_geometry.y : wwin->frame_y;
553 w = wwin->old_geometry.width ? wwin->old_geometry.width : wwin->client.width;
554 h = wwin->old_geometry.height ? wwin->old_geometry.height : wwin->client.height;
556 wwin->flags.maximized = 0;
557 wWindowConfigure(wwin, x, y, w, h);
559 WMPostNotificationName(WMNChangedState, wwin, "maximize");
562 void wFullscreenWindow(WWindow * wwin)
564 int head;
565 WMRect rect;
567 if (wwin->flags.fullscreen)
568 return;
570 wwin->flags.fullscreen = True;
572 wWindowConfigureBorders(wwin);
574 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
576 wwin->bfs_geometry.x = wwin->frame_x;
577 wwin->bfs_geometry.y = wwin->frame_y;
578 wwin->bfs_geometry.width = wwin->frame->core->width;
579 wwin->bfs_geometry.height = wwin->frame->core->height;
581 head = wGetHeadForWindow(wwin);
582 rect = wGetRectForHead(wwin->screen_ptr, head);
583 wWindowConfigure(wwin, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
585 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
588 void wUnfullscreenWindow(WWindow * wwin)
590 if (!wwin->flags.fullscreen)
591 return;
593 wwin->flags.fullscreen = False;
595 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
596 if (WFLAGP(wwin, sunken)) {
597 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
598 } else if (WFLAGP(wwin, floating)) {
599 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
600 } else {
601 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
605 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
606 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
608 wWindowConfigureBorders(wwin);
610 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
611 wFrameWindowPaint(wwin->frame);
614 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
617 #ifdef ANIMATIONS
618 static void animateResizeFlip(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
620 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
621 float cx, cy, cw, ch;
622 float xstep, ystep, wstep, hstep;
623 XPoint points[5];
624 float dx, dch, midy;
625 float angle, final_angle, delta;
627 xstep = (float)(fx - x) / steps;
628 ystep = (float)(fy - y) / steps;
629 wstep = (float)(fw - w) / steps;
630 hstep = (float)(fh - h) / steps;
632 cx = (float)x;
633 cy = (float)y;
634 cw = (float)w;
635 ch = (float)h;
637 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_F;
638 delta = (float)(final_angle / FRAMES);
639 for (angle = 0;; angle += delta) {
640 if (angle > final_angle)
641 angle = final_angle;
643 dx = (cw / 10) - ((cw / 5) * sin(angle));
644 dch = (ch / 2) * cos(angle);
645 midy = cy + (ch / 2);
647 points[0].x = cx + dx;
648 points[0].y = midy - dch;
649 points[1].x = cx + cw - dx;
650 points[1].y = points[0].y;
651 points[2].x = cx + cw + dx;
652 points[2].y = midy + dch;
653 points[3].x = cx - dx;
654 points[3].y = points[2].y;
655 points[4].x = points[0].x;
656 points[4].y = points[0].y;
658 XGrabServer(dpy);
659 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
660 XFlush(dpy);
661 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
662 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
663 #else
664 wusleep(10);
665 #endif
667 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
668 XUngrabServer(dpy);
669 cx += xstep;
670 cy += ystep;
671 cw += wstep;
672 ch += hstep;
673 if (angle >= final_angle)
674 break;
677 XFlush(dpy);
680 #undef FRAMES
682 static void
683 animateResizeTwist(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
685 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
686 float cx, cy, cw, ch;
687 float xstep, ystep, wstep, hstep;
688 XPoint points[5];
689 float angle, final_angle, a, d, delta;
691 x += w / 2;
692 y += h / 2;
693 fx += fw / 2;
694 fy += fh / 2;
696 xstep = (float)(fx - x) / steps;
697 ystep = (float)(fy - y) / steps;
698 wstep = (float)(fw - w) / steps;
699 hstep = (float)(fh - h) / steps;
701 cx = (float)x;
702 cy = (float)y;
703 cw = (float)w;
704 ch = (float)h;
706 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_T;
707 delta = (float)(final_angle / FRAMES);
708 for (angle = 0;; angle += delta) {
709 if (angle > final_angle)
710 angle = final_angle;
712 a = atan(ch / cw);
713 d = sqrt((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
715 points[0].x = cx + cos(angle - a) * d;
716 points[0].y = cy + sin(angle - a) * d;
717 points[1].x = cx + cos(angle + a) * d;
718 points[1].y = cy + sin(angle + a) * d;
719 points[2].x = cx + cos(angle - a + WM_PI) * d;
720 points[2].y = cy + sin(angle - a + WM_PI) * d;
721 points[3].x = cx + cos(angle + a + WM_PI) * d;
722 points[3].y = cy + sin(angle + a + WM_PI) * d;
723 points[4].x = cx + cos(angle - a) * d;
724 points[4].y = cy + sin(angle - a) * d;
725 XGrabServer(dpy);
726 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
727 XFlush(dpy);
728 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
729 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
730 #else
731 wusleep(10);
732 #endif
734 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
735 XUngrabServer(dpy);
736 cx += xstep;
737 cy += ystep;
738 cw += wstep;
739 ch += hstep;
740 if (angle >= final_angle)
741 break;
744 XFlush(dpy);
747 #undef FRAMES
749 static void animateResizeZoom(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
751 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
752 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
753 float xstep, ystep, wstep, hstep;
754 int i, j;
756 xstep = (float)(fx - x) / steps;
757 ystep = (float)(fy - y) / steps;
758 wstep = (float)(fw - w) / steps;
759 hstep = (float)(fh - h) / steps;
761 for (j = 0; j < FRAMES; j++) {
762 cx[j] = (float)x;
763 cy[j] = (float)y;
764 cw[j] = (float)w;
765 ch[j] = (float)h;
767 XGrabServer(dpy);
768 for (i = 0; i < steps; i++) {
769 for (j = 0; j < FRAMES; j++) {
770 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
771 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
773 XFlush(dpy);
774 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
775 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
776 #else
777 wusleep(10);
778 #endif
779 for (j = 0; j < FRAMES; j++) {
780 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
781 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
782 if (j < FRAMES - 1) {
783 cx[j] = cx[j + 1];
784 cy[j] = cy[j + 1];
785 cw[j] = cw[j + 1];
786 ch[j] = ch[j + 1];
787 } else {
788 cx[j] += xstep;
789 cy[j] += ystep;
790 cw[j] += wstep;
791 ch[j] += hstep;
796 for (j = 0; j < FRAMES; j++) {
797 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
799 XFlush(dpy);
800 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
801 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
802 #else
803 wusleep(10);
804 #endif
805 for (j = 0; j < FRAMES; j++) {
806 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
809 XUngrabServer(dpy);
812 #undef FRAMES
814 void animateResize(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int hiding)
816 int style = wPreferences.iconification_style; /* Catch the value */
817 int steps, k;
819 if (style == WIS_NONE)
820 return;
822 if (style == WIS_RANDOM) {
823 style = rand() % 3;
826 k = (hiding ? 2 : 3);
828 switch (style) {
829 case WIS_TWIST:
830 steps = (MINIATURIZE_ANIMATION_STEPS_T * k) / 3;
831 if (steps > 0)
832 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
833 break;
834 case WIS_FLIP:
835 steps = (MINIATURIZE_ANIMATION_STEPS_F * k) / 3;
836 if (steps > 0)
837 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
838 break;
839 case WIS_ZOOM:
840 default:
841 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k) / 3;
842 if (steps > 0)
843 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
844 break;
847 #endif /* ANIMATIONS */
849 static void flushExpose()
851 XEvent tmpev;
853 while (XCheckTypedEvent(dpy, Expose, &tmpev))
854 WMHandleEvent(&tmpev);
855 XSync(dpy, 0);
858 static void unmapTransientsFor(WWindow * wwin)
860 WWindow *tmp;
862 tmp = wwin->screen_ptr->focused_window;
863 while (tmp) {
864 /* unmap the transients for this transient */
865 if (tmp != wwin && tmp->transient_for == wwin->client_win
866 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup || tmp->flags.shaded)) {
867 unmapTransientsFor(tmp);
868 tmp->flags.miniaturized = 1;
869 if (!tmp->flags.shaded) {
870 wWindowUnmap(tmp);
871 } else {
872 XUnmapWindow(dpy, tmp->frame->core->window);
875 if (!tmp->flags.shaded)
877 wClientSetState(tmp, IconicState, None);
879 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
881 tmp = tmp->prev;
885 static void mapTransientsFor(WWindow * wwin)
887 WWindow *tmp;
889 tmp = wwin->screen_ptr->focused_window;
890 while (tmp) {
891 /* recursively map the transients for this transient */
892 if (tmp != wwin && tmp->transient_for == wwin->client_win && /*!tmp->flags.mapped */ tmp->flags.miniaturized
893 && tmp->icon == NULL) {
894 mapTransientsFor(tmp);
895 tmp->flags.miniaturized = 0;
896 if (!tmp->flags.shaded) {
897 wWindowMap(tmp);
898 } else {
899 XMapWindow(dpy, tmp->frame->core->window);
901 tmp->flags.semi_focused = 0;
903 if (!tmp->flags.shaded)
905 wClientSetState(tmp, NormalState, None);
907 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
909 tmp = tmp->prev;
913 #if 0
914 static void setupIconGrabs(WIcon * icon)
916 /* setup passive grabs on the icon */
917 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
918 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
919 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
920 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
921 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
922 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
923 XSync(dpy, 0);
925 #endif
927 static WWindow *recursiveTransientFor(WWindow * wwin)
929 int i;
931 if (!wwin)
932 return None;
934 /* hackish way to detect transient_for cycle */
935 i = wwin->screen_ptr->window_count + 1;
937 while (wwin && wwin->transient_for != None && i > 0) {
938 wwin = wWindowFor(wwin->transient_for);
939 i--;
941 if (i == 0 && wwin) {
942 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin->frame->title);
943 return NULL;
946 return wwin;
949 #if 0
950 static void removeIconGrabs(WIcon * icon)
952 /* remove passive grabs on the icon */
953 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
954 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
955 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
956 XSync(dpy, 0);
958 #endif
960 void wIconifyWindow(WWindow * wwin)
962 XWindowAttributes attribs;
963 int present;
965 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
966 /* the window doesn't exist anymore */
967 return;
970 if (wwin->flags.miniaturized) {
971 return;
974 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
975 WWindow *owner = wWindowFor(wwin->transient_for);
977 if (owner && owner->flags.miniaturized)
978 return;
981 present = wwin->frame->workspace == wwin->screen_ptr->current_workspace;
983 /* if the window is in another workspace, simplify process */
984 if (present) {
985 /* icon creation may take a while */
986 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
987 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
988 GrabModeAsync, None, None, CurrentTime);
991 if (!wPreferences.disable_miniwindows
992 #ifdef NETWM_HINTS
993 && !wwin->flags.net_handle_icon
994 #endif
996 if (!wwin->flags.icon_moved) {
997 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
999 wwin->icon = wIconCreate(wwin);
1001 wwin->icon->mapped = 1;
1004 wwin->flags.miniaturized = 1;
1005 wwin->flags.mapped = 0;
1007 /* unmap transients */
1009 unmapTransientsFor(wwin);
1011 if (present) {
1012 XUngrabPointer(dpy, CurrentTime);
1013 wWindowUnmap(wwin);
1014 /* let all Expose events arrive so that we can repaint
1015 * something before the animation starts (and the server is grabbed) */
1016 XSync(dpy, 0);
1018 if (wPreferences.disable_miniwindows
1019 #ifdef NETWM_HINTS
1020 || wwin->flags.net_handle_icon
1021 #endif
1023 wClientSetState(wwin, IconicState, None);
1024 else
1025 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
1027 flushExpose();
1028 #ifdef ANIMATIONS
1029 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
1030 && !wPreferences.no_animations) {
1031 int ix, iy, iw, ih;
1033 if (!wPreferences.disable_miniwindows
1034 #ifdef NETWM_HINTS
1035 && !wwin->flags.net_handle_icon
1036 #endif
1038 ix = wwin->icon_x;
1039 iy = wwin->icon_y;
1040 iw = wwin->icon->core->width;
1041 ih = wwin->icon->core->height;
1042 } else {
1043 #ifdef NETWM_HINTS
1044 if (wwin->flags.net_handle_icon) {
1045 ix = wwin->icon_x;
1046 iy = wwin->icon_y;
1047 iw = wwin->icon_w;
1048 ih = wwin->icon_h;
1049 } else
1050 #endif
1052 ix = 0;
1053 iy = 0;
1054 iw = wwin->screen_ptr->scr_width;
1055 ih = wwin->screen_ptr->scr_height;
1058 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1059 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih, False);
1061 #endif
1064 wwin->flags.skip_next_animation = 0;
1066 if (!wPreferences.disable_miniwindows
1067 #ifdef NETWM_HINTS
1068 && !wwin->flags.net_handle_icon
1069 #endif
1072 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace ||
1073 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1075 XMapWindow(dpy, wwin->icon->core->window);
1077 AddToStackList(wwin->icon->core);
1079 wLowerFrame(wwin->icon->core);
1082 if (present) {
1083 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1086 * It doesn't seem to be working and causes button event hangup
1087 * when deiconifying a transient window.
1088 setupIconGrabs(wwin->icon);
1090 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
1091 && wPreferences.focus_mode == WKF_CLICK) {
1092 WWindow *tmp;
1094 tmp = wwin->prev;
1095 while (tmp) {
1096 if (!WFLAGP(tmp, no_focusable)
1097 && !(tmp->flags.hidden || tmp->flags.miniaturized)
1098 && (wwin->frame->workspace == tmp->frame->workspace))
1099 break;
1100 tmp = tmp->prev;
1102 wSetFocusTo(wwin->screen_ptr, tmp);
1103 } else if (wPreferences.focus_mode != WKF_CLICK) {
1104 wSetFocusTo(wwin->screen_ptr, NULL);
1106 #ifdef ANIMATIONS
1107 if (!wwin->screen_ptr->flags.startup) {
1108 /* Catch up with events not processed while animation was running */
1109 Window clientwin = wwin->client_win;
1111 ProcessPendingEvents();
1113 /* the window can disappear while ProcessPendingEvents() runs */
1114 if (!wWindowFor(clientwin)) {
1115 return;
1118 #endif
1121 /* maybe we want to do this regardless of net_handle_icon
1122 * it seems to me we might break behaviour this way.
1124 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1125 #ifdef NETWM_HINTS
1126 && !wwin->flags.net_handle_icon
1127 #endif
1129 wIconSelect(wwin->icon);
1131 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1133 if (wPreferences.auto_arrange_icons)
1134 wArrangeIcons(wwin->screen_ptr, True);
1137 void wDeiconifyWindow(WWindow * wwin)
1139 #ifdef NETWM_HINTS
1140 /* we're hiding for show_desktop */
1141 int netwm_hidden = wwin->flags.net_show_desktop &&
1142 wwin->frame->workspace != wwin->screen_ptr->current_workspace;
1143 #else
1144 int netwm_hidden = False;
1145 #endif
1147 if (!netwm_hidden)
1148 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1150 if (!wwin->flags.miniaturized)
1151 return;
1153 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1154 WWindow *owner = recursiveTransientFor(wwin);
1156 if (owner && owner->flags.miniaturized) {
1157 wDeiconifyWindow(owner);
1158 wSetFocusTo(wwin->screen_ptr, wwin);
1159 wRaiseFrame(wwin->frame->core);
1160 return;
1164 wwin->flags.miniaturized = 0;
1166 if (!netwm_hidden && !wwin->flags.shaded) {
1167 wwin->flags.mapped = 1;
1170 if (!netwm_hidden || wPreferences.sticky_icons) {
1171 /* maybe we want to do this regardless of net_handle_icon
1172 * it seems to me we might break behaviour this way.
1174 if (!wPreferences.disable_miniwindows
1175 #ifdef NETWM_HINTS
1176 && !wwin->flags.net_handle_icon
1177 #endif
1178 && wwin->icon != NULL) {
1179 if (wwin->icon->selected)
1180 wIconSelect(wwin->icon);
1182 XUnmapWindow(dpy, wwin->icon->core->window);
1186 /* if the window is in another workspace, do it silently */
1187 if (!netwm_hidden) {
1188 #ifdef ANIMATIONS
1189 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1190 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1191 int ix, iy, iw, ih;
1193 if (!wPreferences.disable_miniwindows
1194 #ifdef NETWM_HINTS
1195 && !wwin->flags.net_handle_icon
1196 #endif
1198 ix = wwin->icon_x;
1199 iy = wwin->icon_y;
1200 iw = wwin->icon->core->width;
1201 ih = wwin->icon->core->height;
1202 } else {
1203 #ifdef NETWM_HINTS
1204 if (wwin->flags.net_handle_icon) {
1205 ix = wwin->icon_x;
1206 iy = wwin->icon_y;
1207 iw = wwin->icon_w;
1208 ih = wwin->icon_h;
1209 } else
1210 #endif
1212 ix = 0;
1213 iy = 0;
1214 iw = wwin->screen_ptr->scr_width;
1215 ih = wwin->screen_ptr->scr_height;
1218 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1219 wwin->frame_x, wwin->frame_y,
1220 wwin->frame->core->width, wwin->frame->core->height, False);
1222 #endif /* ANIMATIONS */
1223 wwin->flags.skip_next_animation = 0;
1224 XGrabServer(dpy);
1225 if (!wwin->flags.shaded) {
1226 XMapWindow(dpy, wwin->client_win);
1228 XMapWindow(dpy, wwin->frame->core->window);
1229 wRaiseFrame(wwin->frame->core);
1230 if (!wwin->flags.shaded) {
1231 wClientSetState(wwin, NormalState, None);
1233 mapTransientsFor(wwin);
1236 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1237 #ifdef NETWM_HINTS
1238 && !wwin->flags.net_handle_icon
1239 #endif
1241 RemoveFromStackList(wwin->icon->core);
1242 /* removeIconGrabs(wwin->icon); */
1243 wIconDestroy(wwin->icon);
1244 wwin->icon = NULL;
1247 if (!netwm_hidden) {
1248 XUngrabServer(dpy);
1250 wSetFocusTo(wwin->screen_ptr, wwin);
1252 #ifdef ANIMATIONS
1253 if (!wwin->screen_ptr->flags.startup) {
1254 /* Catch up with events not processed while animation was running */
1255 Window clientwin = wwin->client_win;
1257 ProcessPendingEvents();
1259 /* the window can disappear while ProcessPendingEvents() runs */
1260 if (!wWindowFor(clientwin)) {
1261 return;
1264 #endif
1267 if (wPreferences.auto_arrange_icons) {
1268 wArrangeIcons(wwin->screen_ptr, True);
1271 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1273 /* In case we were shaded and iconified, also unshade */
1274 if (!netwm_hidden)
1275 wUnshadeWindow(wwin);
1278 static void hideWindow(WIcon * icon, int icon_x, int icon_y, WWindow * wwin, int animate)
1280 if (wwin->flags.miniaturized) {
1281 if (wwin->icon) {
1282 XUnmapWindow(dpy, wwin->icon->core->window);
1283 wwin->icon->mapped = 0;
1285 wwin->flags.hidden = 1;
1287 WMPostNotificationName(WMNChangedState, wwin, "hide");
1288 return;
1291 if (wwin->flags.inspector_open) {
1292 wHideInspectorForWindow(wwin);
1295 wwin->flags.hidden = 1;
1296 wWindowUnmap(wwin);
1298 wClientSetState(wwin, IconicState, icon->icon_win);
1299 flushExpose();
1301 #ifdef ANIMATIONS
1302 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1303 !wwin->flags.skip_next_animation && animate) {
1304 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1305 wwin->frame->core->width, wwin->frame->core->height,
1306 icon_x, icon_y, icon->core->width, icon->core->height, True);
1308 #endif
1309 wwin->flags.skip_next_animation = 0;
1311 WMPostNotificationName(WMNChangedState, wwin, "hide");
1314 void wHideOtherApplications(WWindow * awin)
1316 WWindow *wwin;
1317 WApplication *tapp;
1319 if (!awin)
1320 return;
1321 wwin = awin->screen_ptr->focused_window;
1323 while (wwin) {
1324 if (wwin != awin
1325 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1326 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1327 && !wwin->flags.internal_window
1328 && wGetWindowOfInspectorForWindow(wwin) != awin && !WFLAGP(wwin, no_hide_others)) {
1330 if (wwin->main_window == None || WFLAGP(wwin, no_appicon)) {
1331 if (!WFLAGP(wwin, no_miniaturizable)) {
1332 wwin->flags.skip_next_animation = 1;
1333 wIconifyWindow(wwin);
1335 } else if (wwin->main_window != None && awin->main_window != wwin->main_window) {
1336 tapp = wApplicationOf(wwin->main_window);
1337 if (tapp) {
1338 tapp->flags.skip_next_animation = 1;
1339 wHideApplication(tapp);
1340 } else {
1341 if (!WFLAGP(wwin, no_miniaturizable)) {
1342 wwin->flags.skip_next_animation = 1;
1343 wIconifyWindow(wwin);
1348 wwin = wwin->prev;
1351 wSetFocusTo(awin->screen_ptr, awin);
1355 void wHideApplication(WApplication * wapp)
1357 WScreen *scr;
1358 WWindow *wlist;
1359 int hadfocus;
1360 int animate;
1362 if (!wapp) {
1363 wwarning("trying to hide a non grouped window");
1364 return;
1366 if (!wapp->main_window_desc) {
1367 wwarning("group leader not found for window group");
1368 return;
1370 scr = wapp->main_window_desc->screen_ptr;
1371 hadfocus = 0;
1372 wlist = scr->focused_window;
1373 if (!wlist)
1374 return;
1376 if (wlist->main_window == wapp->main_window)
1377 wapp->last_focused = wlist;
1378 else
1379 wapp->last_focused = NULL;
1381 animate = !wapp->flags.skip_next_animation;
1383 while (wlist) {
1384 if (wlist->main_window == wapp->main_window) {
1385 if (wlist->flags.focused) {
1386 hadfocus = 1;
1388 if (wapp->app_icon) {
1389 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1390 wapp->app_icon->y_pos, wlist, animate);
1391 animate = False;
1394 wlist = wlist->prev;
1397 wapp->flags.skip_next_animation = 0;
1399 if (hadfocus) {
1400 if (wPreferences.focus_mode == WKF_CLICK) {
1401 wlist = scr->focused_window;
1402 while (wlist) {
1403 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1404 && (wlist->flags.mapped || wlist->flags.shaded))
1405 break;
1406 wlist = wlist->prev;
1408 wSetFocusTo(scr, wlist);
1409 } else {
1410 wSetFocusTo(scr, NULL);
1414 wapp->flags.hidden = 1;
1416 if (wPreferences.auto_arrange_icons) {
1417 wArrangeIcons(scr, True);
1419 #ifdef HIDDENDOT
1420 if (wapp->app_icon)
1421 wAppIconPaint(wapp->app_icon);
1422 #endif
1425 static void unhideWindow(WIcon * icon, int icon_x, int icon_y, WWindow * wwin, int animate, int bringToCurrentWS)
1427 if (bringToCurrentWS)
1428 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1430 wwin->flags.hidden = 0;
1432 #ifdef ANIMATIONS
1433 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1434 animateResize(wwin->screen_ptr, icon_x, icon_y,
1435 icon->core->width, icon->core->height,
1436 wwin->frame_x, wwin->frame_y,
1437 wwin->frame->core->width, wwin->frame->core->height, True);
1439 #endif
1440 wwin->flags.skip_next_animation = 0;
1441 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1442 XMapWindow(dpy, wwin->client_win);
1443 XMapWindow(dpy, wwin->frame->core->window);
1444 wClientSetState(wwin, NormalState, None);
1445 wwin->flags.mapped = 1;
1446 wRaiseFrame(wwin->frame->core);
1448 if (wwin->flags.inspector_open) {
1449 wUnhideInspectorForWindow(wwin);
1452 WMPostNotificationName(WMNChangedState, wwin, "hide");
1455 void wUnhideApplication(WApplication * wapp, Bool miniwindows, Bool bringToCurrentWS)
1457 WScreen *scr;
1458 WWindow *wlist, *next;
1459 WWindow *focused = NULL;
1460 int animate;
1462 if (!wapp)
1463 return;
1465 scr = wapp->main_window_desc->screen_ptr;
1466 wlist = scr->focused_window;
1467 if (!wlist)
1468 return;
1470 /* goto beginning of list */
1471 while (wlist->prev)
1472 wlist = wlist->prev;
1474 animate = !wapp->flags.skip_next_animation;
1476 while (wlist) {
1477 next = wlist->next;
1479 if (wlist->main_window == wapp->main_window) {
1480 if (wlist->flags.focused)
1481 focused = wlist;
1482 else if (!focused || !focused->flags.focused)
1483 focused = wlist;
1485 if (wlist->flags.miniaturized) {
1486 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1487 wlist->frame->workspace == scr->current_workspace) && wlist->icon) {
1488 if (!wlist->icon->mapped) {
1489 int x, y;
1491 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1492 if (wlist->icon_x != x || wlist->icon_y != y) {
1493 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1495 wlist->icon_x = x;
1496 wlist->icon_y = y;
1497 XMapWindow(dpy, wlist->icon->core->window);
1498 wlist->icon->mapped = 1;
1500 wRaiseFrame(wlist->icon->core);
1502 if (bringToCurrentWS)
1503 wWindowChangeWorkspace(wlist, scr->current_workspace);
1504 wlist->flags.hidden = 0;
1505 if (miniwindows && wlist->frame->workspace == scr->current_workspace) {
1506 wDeiconifyWindow(wlist);
1508 WMPostNotificationName(WMNChangedState, wlist, "hide");
1509 } else if (wlist->flags.shaded) {
1510 if (bringToCurrentWS)
1511 wWindowChangeWorkspace(wlist, scr->current_workspace);
1512 wlist->flags.hidden = 0;
1513 if (wlist->frame->workspace == scr->current_workspace) {
1514 XMapWindow(dpy, wlist->frame->core->window);
1515 if (miniwindows) {
1516 wUnshadeWindow(wlist);
1517 wRaiseFrame(wlist->frame->core);
1520 WMPostNotificationName(WMNChangedState, wlist, "hide");
1521 } else if (wlist->flags.hidden) {
1522 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1523 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1524 animate = False;
1525 } else {
1526 if (bringToCurrentWS && wlist->frame->workspace != scr->current_workspace) {
1527 wWindowChangeWorkspace(wlist, scr->current_workspace);
1529 wRaiseFrame(wlist->frame->core);
1532 wlist = next;
1535 wapp->flags.skip_next_animation = 0;
1536 wapp->flags.hidden = 0;
1538 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1539 wRaiseFrame(wapp->last_focused->frame->core);
1540 wSetFocusTo(scr, wapp->last_focused);
1541 } else if (focused) {
1542 wSetFocusTo(scr, focused);
1544 wapp->last_focused = NULL;
1545 if (wPreferences.auto_arrange_icons) {
1546 wArrangeIcons(scr, True);
1548 #ifdef HIDDENDOT
1549 wAppIconPaint(wapp->app_icon);
1550 #endif
1553 void wShowAllWindows(WScreen * scr)
1555 WWindow *wwin, *old_foc;
1556 WApplication *wapp;
1558 old_foc = wwin = scr->focused_window;
1559 while (wwin) {
1560 if (!wwin->flags.internal_window &&
1561 (scr->current_workspace == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1562 if (wwin->flags.miniaturized) {
1563 wwin->flags.skip_next_animation = 1;
1564 wDeiconifyWindow(wwin);
1565 } else if (wwin->flags.hidden) {
1566 wapp = wApplicationOf(wwin->main_window);
1567 if (wapp) {
1568 wUnhideApplication(wapp, False, False);
1569 } else {
1570 wwin->flags.skip_next_animation = 1;
1571 wDeiconifyWindow(wwin);
1575 wwin = wwin->prev;
1577 wSetFocusTo(scr, old_foc);
1578 /*wRaiseFrame(old_foc->frame->core); */
1581 void wRefreshDesktop(WScreen * scr)
1583 Window win;
1584 XSetWindowAttributes attr;
1586 attr.backing_store = NotUseful;
1587 attr.save_under = False;
1588 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1589 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1590 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1591 XMapRaised(dpy, win);
1592 XDestroyWindow(dpy, win);
1593 XFlush(dpy);
1596 void wArrangeIcons(WScreen * scr, Bool arrangeAll)
1598 WWindow *wwin;
1599 WAppIcon *aicon;
1601 int head;
1602 const int heads = wXineramaHeads(scr);
1604 struct HeadVars {
1605 int pf; /* primary axis */
1606 int sf; /* secondary axis */
1607 int fullW;
1608 int fullH;
1609 int pi, si;
1610 int sx1, sx2, sy1, sy2; /* screen boundary */
1611 int sw, sh;
1612 int xo, yo;
1613 int xs, ys;
1614 } *vars;
1616 int isize = wPreferences.icon_size;
1618 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
1620 for (head = 0; head < heads; ++head) {
1621 #if 0
1622 WMRect rect = wGetRectForHead(scr, head);
1623 #else
1624 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1625 WMRect rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
1626 #endif
1628 vars[head].pi = vars[head].si = 0;
1629 vars[head].sx1 = rect.pos.x;
1630 vars[head].sy1 = rect.pos.y;
1631 vars[head].sw = rect.size.width;
1632 vars[head].sh = rect.size.height;
1633 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1634 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1636 #if 0
1637 if (scr->dock) {
1638 if (scr->dock->on_right_side)
1639 vars[head].sx2 -= isize + DOCK_EXTRA_SPACE;
1640 else
1641 vars[head].sx1 += isize + DOCK_EXTRA_SPACE;
1643 #endif
1645 vars[head].sw = isize * (vars[head].sw / isize);
1646 vars[head].sh = isize * (vars[head].sh / isize);
1647 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
1648 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
1650 /* icon yard boundaries */
1651 if (wPreferences.icon_yard & IY_VERT) {
1652 vars[head].pf = vars[head].fullH;
1653 vars[head].sf = vars[head].fullW;
1654 } else {
1655 vars[head].pf = vars[head].fullW;
1656 vars[head].sf = vars[head].fullH;
1658 if (wPreferences.icon_yard & IY_RIGHT) {
1659 vars[head].xo = vars[head].sx2 - isize;
1660 vars[head].xs = -1;
1661 } else {
1662 vars[head].xo = vars[head].sx1;
1663 vars[head].xs = 1;
1665 if (wPreferences.icon_yard & IY_TOP) {
1666 vars[head].yo = vars[head].sy1;
1667 vars[head].ys = 1;
1668 } else {
1669 vars[head].yo = vars[head].sy2 - isize;
1670 vars[head].ys = -1;
1674 #define X ((wPreferences.icon_yard & IY_VERT) \
1675 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1676 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1678 #define Y ((wPreferences.icon_yard & IY_VERT) \
1679 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1680 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1682 /* arrange application icons */
1683 aicon = scr->app_icon_list;
1684 /* reverse them to avoid unnecessarily sliding of icons */
1685 while (aicon && aicon->next)
1686 aicon = aicon->next;
1688 while (aicon) {
1689 if (!aicon->docked) {
1690 /* CHECK: can icon be NULL here ? */
1691 /* The intention here is to place the AppIcon on the head that
1692 * contains most of the applications _main_ window. */
1693 head = wGetHeadForWindow(aicon->icon->owner);
1695 if (aicon->x_pos != X || aicon->y_pos != Y) {
1696 #ifdef ANIMATIONS
1697 if (!wPreferences.no_animations) {
1698 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1700 #endif /* ANIMATIONS */
1702 wAppIconMove(aicon, X, Y);
1703 vars[head].pi++;
1704 if (vars[head].pi >= vars[head].pf) {
1705 vars[head].pi = 0;
1706 vars[head].si++;
1709 aicon = aicon->prev;
1712 /* arrange miniwindows */
1713 wwin = scr->focused_window;
1714 /* reverse them to avoid unnecessarily shuffling */
1715 while (wwin && wwin->prev)
1716 wwin = wwin->prev;
1718 while (wwin) {
1719 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1720 (wwin->frame->workspace == scr->current_workspace ||
1721 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1723 head = wGetHeadForWindow(wwin);
1725 if (arrangeAll || !wwin->flags.icon_moved) {
1726 if (wwin->icon_x != X || wwin->icon_y != Y) {
1727 #ifdef ANIMATIONS
1728 if (wPreferences.no_animations) {
1729 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1730 } else {
1731 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1732 wwin->icon_y, X, Y);
1734 #else
1735 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1736 #endif /* ANIMATIONS */
1738 wwin->icon_x = X;
1739 wwin->icon_y = Y;
1741 vars[head].pi++;
1742 if (vars[head].pi >= vars[head].pf) {
1743 vars[head].pi = 0;
1744 vars[head].si++;
1748 if (arrangeAll) {
1749 wwin->flags.icon_moved = 0;
1751 /* we reversed the order, so we use next */
1752 wwin = wwin->next;
1755 wfree(vars);
1758 #if 0
1759 void wArrangeIcons(WScreen * scr, Bool arrangeAll)
1761 WWindow *wwin;
1762 WAppIcon *aicon;
1763 int pf; /* primary axis */
1764 int sf; /* secondary axis */
1765 int fullW;
1766 int fullH;
1767 int pi, si;
1768 int sx1, sx2, sy1, sy2; /* screen boundary */
1769 int sw, sh;
1770 int xo, yo;
1771 int xs, ys;
1772 int isize = wPreferences.icon_size;
1775 * Find out screen boundaries.
1779 * Allows each head to have miniwindows
1781 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1783 sx1 = rect.pos.x;
1784 sy1 = rect.pos.y;
1785 sw = rect.size.width;
1786 sh = rect.size.height;
1787 sx2 = sx1 + sw;
1788 sy2 = sy1 + sh;
1789 if (scr->dock) {
1790 if (scr->dock->on_right_side)
1791 sx2 -= isize + DOCK_EXTRA_SPACE;
1792 else
1793 sx1 += isize + DOCK_EXTRA_SPACE;
1795 #if 0
1796 sw = isize * (scr->scr_width / isize);
1797 sh = isize * (scr->scr_height / isize);
1798 #else
1799 sw = isize * (sw / isize);
1800 sh = isize * (sh / isize);
1801 #endif
1802 fullW = (sx2 - sx1) / isize;
1803 fullH = (sy2 - sy1) / isize;
1805 /* icon yard boundaries */
1806 if (wPreferences.icon_yard & IY_VERT) {
1807 pf = fullH;
1808 sf = fullW;
1809 } else {
1810 pf = fullW;
1811 sf = fullH;
1813 if (wPreferences.icon_yard & IY_RIGHT) {
1814 xo = sx2 - isize;
1815 xs = -1;
1816 } else {
1817 xo = sx1;
1818 xs = 1;
1820 if (wPreferences.icon_yard & IY_TOP) {
1821 yo = sy1;
1822 ys = 1;
1823 } else {
1824 yo = sy2 - isize;
1825 ys = -1;
1828 /* arrange icons putting the most recently focused window
1829 * as the last icon */
1830 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1831 : xo + xs*(pi*isize))
1832 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1833 : yo + ys*(si*isize))
1835 /* arrange application icons */
1836 aicon = scr->app_icon_list;
1837 /* reverse them to avoid unnecessarily sliding of icons */
1838 while (aicon && aicon->next)
1839 aicon = aicon->next;
1841 pi = 0;
1842 si = 0;
1843 while (aicon) {
1844 if (!aicon->docked) {
1845 if (aicon->x_pos != X || aicon->y_pos != Y) {
1846 #ifdef ANIMATIONS
1847 if (!wPreferences.no_animations) {
1848 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1850 #endif /* ANIMATIONS */
1852 wAppIconMove(aicon, X, Y);
1853 pi++;
1855 /* we reversed the order so we use prev */
1856 aicon = aicon->prev;
1857 if (pi >= pf) {
1858 pi = 0;
1859 si++;
1863 /* arrange miniwindows */
1865 wwin = scr->focused_window;
1866 /* reverse them to avoid unnecessarily shuffling */
1867 while (wwin && wwin->prev)
1868 wwin = wwin->prev;
1870 while (wwin) {
1871 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1872 (wwin->frame->workspace == scr->current_workspace ||
1873 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1875 if (arrangeAll || !wwin->flags.icon_moved) {
1876 if (wwin->icon_x != X || wwin->icon_y != Y) {
1877 #ifdef ANIMATIONS
1878 if (wPreferences.no_animations) {
1879 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1880 } else {
1881 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1882 wwin->icon_y, X, Y);
1884 #else
1885 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1886 #endif /* ANIMATIONS */
1888 wwin->icon_x = X;
1889 wwin->icon_y = Y;
1890 pi++;
1893 if (arrangeAll) {
1894 wwin->flags.icon_moved = 0;
1896 /* we reversed the order, so we use next */
1897 wwin = wwin->next;
1898 if (pi >= pf) {
1899 pi = 0;
1900 si++;
1904 #endif
1906 void wSelectWindow(WWindow * wwin, Bool flag)
1908 WScreen *scr = wwin->screen_ptr;
1910 if (flag) {
1911 wwin->flags.selected = 1;
1912 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1914 if (!HAS_BORDER(wwin)) {
1915 XSetWindowBorderWidth(dpy, wwin->frame->core->window, FRAME_BORDER_WIDTH);
1918 if (!scr->selected_windows)
1919 scr->selected_windows = WMCreateArray(4);
1920 WMAddToArray(scr->selected_windows, wwin);
1921 } else {
1922 wwin->flags.selected = 0;
1923 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
1925 if (!HAS_BORDER(wwin)) {
1926 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1929 if (scr->selected_windows) {
1930 WMRemoveFromArray(scr->selected_windows, wwin);
1935 void wMakeWindowVisible(WWindow * wwin)
1937 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1938 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1940 if (wwin->flags.shaded) {
1941 wUnshadeWindow(wwin);
1943 if (wwin->flags.hidden) {
1944 WApplication *app;
1946 app = wApplicationOf(wwin->main_window);
1947 if (app) {
1948 /* trick to get focus to this window */
1949 app->last_focused = wwin;
1950 wUnhideApplication(app, False, False);
1953 if (wwin->flags.miniaturized) {
1954 wDeiconifyWindow(wwin);
1955 } else {
1956 if (!WFLAGP(wwin, no_focusable))
1957 wSetFocusTo(wwin->screen_ptr, wwin);
1958 wRaiseFrame(wwin->frame->core);
1963 * Do the animation while shading (called with what = SHADE)
1964 * or unshading (what = UNSHADE).
1966 #ifdef ANIMATIONS
1967 static void shade_animate(WWindow *wwin, Bool what)
1969 int y, s, w, h;
1970 time_t time0 = time(NULL);
1972 if (wwin->flags.skip_next_animation && wPreferences.no_animations)
1973 return;
1975 switch(what) {
1976 case SHADE:
1977 if (!wwin->screen_ptr->flags.startup) {
1978 /* do the shading animation */
1979 h = wwin->frame->core->height;
1980 s = h / SHADE_STEPS;
1981 if (s < 1)
1982 s = 1;
1983 w = wwin->frame->core->width;
1984 y = wwin->frame->top_width;
1985 while (h > wwin->frame->top_width + 1) {
1986 XMoveWindow(dpy, wwin->client_win, 0, y);
1987 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1988 XFlush(dpy);
1990 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1991 break;
1993 if (SHADE_DELAY > 0) {
1994 wusleep(SHADE_DELAY * 1000L);
1995 } else {
1996 wusleep(10);
1998 h -= s;
1999 y -= s;
2001 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2003 break;
2005 case UNSHADE:
2006 h = wwin->frame->top_width + wwin->frame->bottom_width;
2007 y = wwin->frame->top_width - wwin->client.height;
2008 s = abs(y) / SHADE_STEPS;
2009 if (s < 1)
2010 s = 1;
2011 w = wwin->frame->core->width;
2012 XMoveWindow(dpy, wwin->client_win, 0, y);
2013 if (s > 0) {
2014 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
2015 XResizeWindow(dpy, wwin->frame->core->window, w, h);
2016 XMoveWindow(dpy, wwin->client_win, 0, y);
2017 XFlush(dpy);
2018 if (SHADE_DELAY > 0) {
2019 wusleep(SHADE_DELAY * 2000L / 3);
2020 } else {
2021 wusleep(10);
2023 h += s;
2024 y += s;
2026 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
2027 break;
2030 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2031 break;
2034 #else
2035 static void shade_animate(WWindow *wwin, Bool what) { return; }
2036 #endif /* ANIMATIONS */