Remove 'hiding' parameter from animateResize()
[wmaker-crm.git] / src / actions.c
blobd7bf5036a9eee8975f5da660786f7f24b0981dd2
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)
816 int style = wPreferences.iconification_style; /* Catch the value */
817 int steps;
819 if (style == WIS_NONE)
820 return;
822 if (style == WIS_RANDOM) {
823 style = rand() % 3;
826 switch (style) {
827 case WIS_TWIST:
828 steps = MINIATURIZE_ANIMATION_STEPS_T;
829 if (steps > 0)
830 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
831 break;
832 case WIS_FLIP:
833 steps = MINIATURIZE_ANIMATION_STEPS_F;
834 if (steps > 0)
835 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
836 break;
837 case WIS_ZOOM:
838 default:
839 steps = MINIATURIZE_ANIMATION_STEPS_Z;
840 if (steps > 0)
841 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
842 break;
845 #endif /* ANIMATIONS */
847 static void flushExpose()
849 XEvent tmpev;
851 while (XCheckTypedEvent(dpy, Expose, &tmpev))
852 WMHandleEvent(&tmpev);
853 XSync(dpy, 0);
856 static void unmapTransientsFor(WWindow * wwin)
858 WWindow *tmp;
860 tmp = wwin->screen_ptr->focused_window;
861 while (tmp) {
862 /* unmap the transients for this transient */
863 if (tmp != wwin && tmp->transient_for == wwin->client_win
864 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup || tmp->flags.shaded)) {
865 unmapTransientsFor(tmp);
866 tmp->flags.miniaturized = 1;
867 if (!tmp->flags.shaded) {
868 wWindowUnmap(tmp);
869 } else {
870 XUnmapWindow(dpy, tmp->frame->core->window);
873 if (!tmp->flags.shaded)
875 wClientSetState(tmp, IconicState, None);
877 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
879 tmp = tmp->prev;
883 static void mapTransientsFor(WWindow * wwin)
885 WWindow *tmp;
887 tmp = wwin->screen_ptr->focused_window;
888 while (tmp) {
889 /* recursively map the transients for this transient */
890 if (tmp != wwin && tmp->transient_for == wwin->client_win && /*!tmp->flags.mapped */ tmp->flags.miniaturized
891 && tmp->icon == NULL) {
892 mapTransientsFor(tmp);
893 tmp->flags.miniaturized = 0;
894 if (!tmp->flags.shaded) {
895 wWindowMap(tmp);
896 } else {
897 XMapWindow(dpy, tmp->frame->core->window);
899 tmp->flags.semi_focused = 0;
901 if (!tmp->flags.shaded)
903 wClientSetState(tmp, NormalState, None);
905 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
907 tmp = tmp->prev;
911 #if 0
912 static void setupIconGrabs(WIcon * icon)
914 /* setup passive grabs on the icon */
915 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
916 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
917 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
918 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
919 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
920 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
921 XSync(dpy, 0);
923 #endif
925 static WWindow *recursiveTransientFor(WWindow * wwin)
927 int i;
929 if (!wwin)
930 return None;
932 /* hackish way to detect transient_for cycle */
933 i = wwin->screen_ptr->window_count + 1;
935 while (wwin && wwin->transient_for != None && i > 0) {
936 wwin = wWindowFor(wwin->transient_for);
937 i--;
939 if (i == 0 && wwin) {
940 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin->frame->title);
941 return NULL;
944 return wwin;
947 #if 0
948 static void removeIconGrabs(WIcon * icon)
950 /* remove passive grabs on the icon */
951 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
952 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
953 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
954 XSync(dpy, 0);
956 #endif
958 void wIconifyWindow(WWindow * wwin)
960 XWindowAttributes attribs;
961 int present;
963 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
964 /* the window doesn't exist anymore */
965 return;
968 if (wwin->flags.miniaturized) {
969 return;
972 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
973 WWindow *owner = wWindowFor(wwin->transient_for);
975 if (owner && owner->flags.miniaturized)
976 return;
979 present = wwin->frame->workspace == wwin->screen_ptr->current_workspace;
981 /* if the window is in another workspace, simplify process */
982 if (present) {
983 /* icon creation may take a while */
984 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
985 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
986 GrabModeAsync, None, None, CurrentTime);
989 if (!wPreferences.disable_miniwindows
990 #ifdef NETWM_HINTS
991 && !wwin->flags.net_handle_icon
992 #endif
994 if (!wwin->flags.icon_moved) {
995 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
997 wwin->icon = wIconCreate(wwin);
999 wwin->icon->mapped = 1;
1002 wwin->flags.miniaturized = 1;
1003 wwin->flags.mapped = 0;
1005 /* unmap transients */
1007 unmapTransientsFor(wwin);
1009 if (present) {
1010 XUngrabPointer(dpy, CurrentTime);
1011 wWindowUnmap(wwin);
1012 /* let all Expose events arrive so that we can repaint
1013 * something before the animation starts (and the server is grabbed) */
1014 XSync(dpy, 0);
1016 if (wPreferences.disable_miniwindows
1017 #ifdef NETWM_HINTS
1018 || wwin->flags.net_handle_icon
1019 #endif
1021 wClientSetState(wwin, IconicState, None);
1022 else
1023 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
1025 flushExpose();
1026 #ifdef ANIMATIONS
1027 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
1028 && !wPreferences.no_animations) {
1029 int ix, iy, iw, ih;
1031 if (!wPreferences.disable_miniwindows
1032 #ifdef NETWM_HINTS
1033 && !wwin->flags.net_handle_icon
1034 #endif
1036 ix = wwin->icon_x;
1037 iy = wwin->icon_y;
1038 iw = wwin->icon->core->width;
1039 ih = wwin->icon->core->height;
1040 } else {
1041 #ifdef NETWM_HINTS
1042 if (wwin->flags.net_handle_icon) {
1043 ix = wwin->icon_x;
1044 iy = wwin->icon_y;
1045 iw = wwin->icon_w;
1046 ih = wwin->icon_h;
1047 } else
1048 #endif
1050 ix = 0;
1051 iy = 0;
1052 iw = wwin->screen_ptr->scr_width;
1053 ih = wwin->screen_ptr->scr_height;
1056 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1057 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih);
1059 #endif
1062 wwin->flags.skip_next_animation = 0;
1064 if (!wPreferences.disable_miniwindows
1065 #ifdef NETWM_HINTS
1066 && !wwin->flags.net_handle_icon
1067 #endif
1070 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace ||
1071 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1073 XMapWindow(dpy, wwin->icon->core->window);
1075 AddToStackList(wwin->icon->core);
1077 wLowerFrame(wwin->icon->core);
1080 if (present) {
1081 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1084 * It doesn't seem to be working and causes button event hangup
1085 * when deiconifying a transient window.
1086 setupIconGrabs(wwin->icon);
1088 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
1089 && wPreferences.focus_mode == WKF_CLICK) {
1090 WWindow *tmp;
1092 tmp = wwin->prev;
1093 while (tmp) {
1094 if (!WFLAGP(tmp, no_focusable)
1095 && !(tmp->flags.hidden || tmp->flags.miniaturized)
1096 && (wwin->frame->workspace == tmp->frame->workspace))
1097 break;
1098 tmp = tmp->prev;
1100 wSetFocusTo(wwin->screen_ptr, tmp);
1101 } else if (wPreferences.focus_mode != WKF_CLICK) {
1102 wSetFocusTo(wwin->screen_ptr, NULL);
1104 #ifdef ANIMATIONS
1105 if (!wwin->screen_ptr->flags.startup) {
1106 /* Catch up with events not processed while animation was running */
1107 Window clientwin = wwin->client_win;
1109 ProcessPendingEvents();
1111 /* the window can disappear while ProcessPendingEvents() runs */
1112 if (!wWindowFor(clientwin)) {
1113 return;
1116 #endif
1119 /* maybe we want to do this regardless of net_handle_icon
1120 * it seems to me we might break behaviour this way.
1122 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1123 #ifdef NETWM_HINTS
1124 && !wwin->flags.net_handle_icon
1125 #endif
1127 wIconSelect(wwin->icon);
1129 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1131 if (wPreferences.auto_arrange_icons)
1132 wArrangeIcons(wwin->screen_ptr, True);
1135 void wDeiconifyWindow(WWindow * wwin)
1137 #ifdef NETWM_HINTS
1138 /* we're hiding for show_desktop */
1139 int netwm_hidden = wwin->flags.net_show_desktop &&
1140 wwin->frame->workspace != wwin->screen_ptr->current_workspace;
1141 #else
1142 int netwm_hidden = False;
1143 #endif
1145 if (!netwm_hidden)
1146 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1148 if (!wwin->flags.miniaturized)
1149 return;
1151 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1152 WWindow *owner = recursiveTransientFor(wwin);
1154 if (owner && owner->flags.miniaturized) {
1155 wDeiconifyWindow(owner);
1156 wSetFocusTo(wwin->screen_ptr, wwin);
1157 wRaiseFrame(wwin->frame->core);
1158 return;
1162 wwin->flags.miniaturized = 0;
1164 if (!netwm_hidden && !wwin->flags.shaded) {
1165 wwin->flags.mapped = 1;
1168 if (!netwm_hidden || wPreferences.sticky_icons) {
1169 /* maybe we want to do this regardless of net_handle_icon
1170 * it seems to me we might break behaviour this way.
1172 if (!wPreferences.disable_miniwindows
1173 #ifdef NETWM_HINTS
1174 && !wwin->flags.net_handle_icon
1175 #endif
1176 && wwin->icon != NULL) {
1177 if (wwin->icon->selected)
1178 wIconSelect(wwin->icon);
1180 XUnmapWindow(dpy, wwin->icon->core->window);
1184 /* if the window is in another workspace, do it silently */
1185 if (!netwm_hidden) {
1186 #ifdef ANIMATIONS
1187 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1188 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1189 int ix, iy, iw, ih;
1191 if (!wPreferences.disable_miniwindows
1192 #ifdef NETWM_HINTS
1193 && !wwin->flags.net_handle_icon
1194 #endif
1196 ix = wwin->icon_x;
1197 iy = wwin->icon_y;
1198 iw = wwin->icon->core->width;
1199 ih = wwin->icon->core->height;
1200 } else {
1201 #ifdef NETWM_HINTS
1202 if (wwin->flags.net_handle_icon) {
1203 ix = wwin->icon_x;
1204 iy = wwin->icon_y;
1205 iw = wwin->icon_w;
1206 ih = wwin->icon_h;
1207 } else
1208 #endif
1210 ix = 0;
1211 iy = 0;
1212 iw = wwin->screen_ptr->scr_width;
1213 ih = wwin->screen_ptr->scr_height;
1216 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1217 wwin->frame_x, wwin->frame_y,
1218 wwin->frame->core->width, wwin->frame->core->height);
1220 #endif /* ANIMATIONS */
1221 wwin->flags.skip_next_animation = 0;
1222 XGrabServer(dpy);
1223 if (!wwin->flags.shaded) {
1224 XMapWindow(dpy, wwin->client_win);
1226 XMapWindow(dpy, wwin->frame->core->window);
1227 wRaiseFrame(wwin->frame->core);
1228 if (!wwin->flags.shaded) {
1229 wClientSetState(wwin, NormalState, None);
1231 mapTransientsFor(wwin);
1234 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1235 #ifdef NETWM_HINTS
1236 && !wwin->flags.net_handle_icon
1237 #endif
1239 RemoveFromStackList(wwin->icon->core);
1240 /* removeIconGrabs(wwin->icon); */
1241 wIconDestroy(wwin->icon);
1242 wwin->icon = NULL;
1245 if (!netwm_hidden) {
1246 XUngrabServer(dpy);
1248 wSetFocusTo(wwin->screen_ptr, wwin);
1250 #ifdef ANIMATIONS
1251 if (!wwin->screen_ptr->flags.startup) {
1252 /* Catch up with events not processed while animation was running */
1253 Window clientwin = wwin->client_win;
1255 ProcessPendingEvents();
1257 /* the window can disappear while ProcessPendingEvents() runs */
1258 if (!wWindowFor(clientwin)) {
1259 return;
1262 #endif
1265 if (wPreferences.auto_arrange_icons) {
1266 wArrangeIcons(wwin->screen_ptr, True);
1269 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1271 /* In case we were shaded and iconified, also unshade */
1272 if (!netwm_hidden)
1273 wUnshadeWindow(wwin);
1276 static void hideWindow(WIcon * icon, int icon_x, int icon_y, WWindow * wwin, int animate)
1278 if (wwin->flags.miniaturized) {
1279 if (wwin->icon) {
1280 XUnmapWindow(dpy, wwin->icon->core->window);
1281 wwin->icon->mapped = 0;
1283 wwin->flags.hidden = 1;
1285 WMPostNotificationName(WMNChangedState, wwin, "hide");
1286 return;
1289 if (wwin->flags.inspector_open) {
1290 wHideInspectorForWindow(wwin);
1293 wwin->flags.hidden = 1;
1294 wWindowUnmap(wwin);
1296 wClientSetState(wwin, IconicState, icon->icon_win);
1297 flushExpose();
1299 #ifdef ANIMATIONS
1300 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1301 !wwin->flags.skip_next_animation && animate) {
1302 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1303 wwin->frame->core->width, wwin->frame->core->height,
1304 icon_x, icon_y, icon->core->width, icon->core->height);
1306 #endif
1307 wwin->flags.skip_next_animation = 0;
1309 WMPostNotificationName(WMNChangedState, wwin, "hide");
1312 void wHideOtherApplications(WWindow * awin)
1314 WWindow *wwin;
1315 WApplication *tapp;
1317 if (!awin)
1318 return;
1319 wwin = awin->screen_ptr->focused_window;
1321 while (wwin) {
1322 if (wwin != awin
1323 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1324 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1325 && !wwin->flags.internal_window
1326 && wGetWindowOfInspectorForWindow(wwin) != awin && !WFLAGP(wwin, no_hide_others)) {
1328 if (wwin->main_window == None || WFLAGP(wwin, no_appicon)) {
1329 if (!WFLAGP(wwin, no_miniaturizable)) {
1330 wwin->flags.skip_next_animation = 1;
1331 wIconifyWindow(wwin);
1333 } else if (wwin->main_window != None && awin->main_window != wwin->main_window) {
1334 tapp = wApplicationOf(wwin->main_window);
1335 if (tapp) {
1336 tapp->flags.skip_next_animation = 1;
1337 wHideApplication(tapp);
1338 } else {
1339 if (!WFLAGP(wwin, no_miniaturizable)) {
1340 wwin->flags.skip_next_animation = 1;
1341 wIconifyWindow(wwin);
1346 wwin = wwin->prev;
1349 wSetFocusTo(awin->screen_ptr, awin);
1353 void wHideApplication(WApplication * wapp)
1355 WScreen *scr;
1356 WWindow *wlist;
1357 int hadfocus;
1358 int animate;
1360 if (!wapp) {
1361 wwarning("trying to hide a non grouped window");
1362 return;
1364 if (!wapp->main_window_desc) {
1365 wwarning("group leader not found for window group");
1366 return;
1368 scr = wapp->main_window_desc->screen_ptr;
1369 hadfocus = 0;
1370 wlist = scr->focused_window;
1371 if (!wlist)
1372 return;
1374 if (wlist->main_window == wapp->main_window)
1375 wapp->last_focused = wlist;
1376 else
1377 wapp->last_focused = NULL;
1379 animate = !wapp->flags.skip_next_animation;
1381 while (wlist) {
1382 if (wlist->main_window == wapp->main_window) {
1383 if (wlist->flags.focused) {
1384 hadfocus = 1;
1386 if (wapp->app_icon) {
1387 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1388 wapp->app_icon->y_pos, wlist, animate);
1389 animate = False;
1392 wlist = wlist->prev;
1395 wapp->flags.skip_next_animation = 0;
1397 if (hadfocus) {
1398 if (wPreferences.focus_mode == WKF_CLICK) {
1399 wlist = scr->focused_window;
1400 while (wlist) {
1401 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1402 && (wlist->flags.mapped || wlist->flags.shaded))
1403 break;
1404 wlist = wlist->prev;
1406 wSetFocusTo(scr, wlist);
1407 } else {
1408 wSetFocusTo(scr, NULL);
1412 wapp->flags.hidden = 1;
1414 if (wPreferences.auto_arrange_icons) {
1415 wArrangeIcons(scr, True);
1417 #ifdef HIDDENDOT
1418 if (wapp->app_icon)
1419 wAppIconPaint(wapp->app_icon);
1420 #endif
1423 static void unhideWindow(WIcon * icon, int icon_x, int icon_y, WWindow * wwin, int animate, int bringToCurrentWS)
1425 if (bringToCurrentWS)
1426 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1428 wwin->flags.hidden = 0;
1430 #ifdef ANIMATIONS
1431 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1432 animateResize(wwin->screen_ptr, icon_x, icon_y,
1433 icon->core->width, icon->core->height,
1434 wwin->frame_x, wwin->frame_y,
1435 wwin->frame->core->width, wwin->frame->core->height);
1437 #endif
1438 wwin->flags.skip_next_animation = 0;
1439 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1440 XMapWindow(dpy, wwin->client_win);
1441 XMapWindow(dpy, wwin->frame->core->window);
1442 wClientSetState(wwin, NormalState, None);
1443 wwin->flags.mapped = 1;
1444 wRaiseFrame(wwin->frame->core);
1446 if (wwin->flags.inspector_open) {
1447 wUnhideInspectorForWindow(wwin);
1450 WMPostNotificationName(WMNChangedState, wwin, "hide");
1453 void wUnhideApplication(WApplication * wapp, Bool miniwindows, Bool bringToCurrentWS)
1455 WScreen *scr;
1456 WWindow *wlist, *next;
1457 WWindow *focused = NULL;
1458 int animate;
1460 if (!wapp)
1461 return;
1463 scr = wapp->main_window_desc->screen_ptr;
1464 wlist = scr->focused_window;
1465 if (!wlist)
1466 return;
1468 /* goto beginning of list */
1469 while (wlist->prev)
1470 wlist = wlist->prev;
1472 animate = !wapp->flags.skip_next_animation;
1474 while (wlist) {
1475 next = wlist->next;
1477 if (wlist->main_window == wapp->main_window) {
1478 if (wlist->flags.focused)
1479 focused = wlist;
1480 else if (!focused || !focused->flags.focused)
1481 focused = wlist;
1483 if (wlist->flags.miniaturized) {
1484 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1485 wlist->frame->workspace == scr->current_workspace) && wlist->icon) {
1486 if (!wlist->icon->mapped) {
1487 int x, y;
1489 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1490 if (wlist->icon_x != x || wlist->icon_y != y) {
1491 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1493 wlist->icon_x = x;
1494 wlist->icon_y = y;
1495 XMapWindow(dpy, wlist->icon->core->window);
1496 wlist->icon->mapped = 1;
1498 wRaiseFrame(wlist->icon->core);
1500 if (bringToCurrentWS)
1501 wWindowChangeWorkspace(wlist, scr->current_workspace);
1502 wlist->flags.hidden = 0;
1503 if (miniwindows && wlist->frame->workspace == scr->current_workspace) {
1504 wDeiconifyWindow(wlist);
1506 WMPostNotificationName(WMNChangedState, wlist, "hide");
1507 } else if (wlist->flags.shaded) {
1508 if (bringToCurrentWS)
1509 wWindowChangeWorkspace(wlist, scr->current_workspace);
1510 wlist->flags.hidden = 0;
1511 if (wlist->frame->workspace == scr->current_workspace) {
1512 XMapWindow(dpy, wlist->frame->core->window);
1513 if (miniwindows) {
1514 wUnshadeWindow(wlist);
1515 wRaiseFrame(wlist->frame->core);
1518 WMPostNotificationName(WMNChangedState, wlist, "hide");
1519 } else if (wlist->flags.hidden) {
1520 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1521 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1522 animate = False;
1523 } else {
1524 if (bringToCurrentWS && wlist->frame->workspace != scr->current_workspace) {
1525 wWindowChangeWorkspace(wlist, scr->current_workspace);
1527 wRaiseFrame(wlist->frame->core);
1530 wlist = next;
1533 wapp->flags.skip_next_animation = 0;
1534 wapp->flags.hidden = 0;
1536 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1537 wRaiseFrame(wapp->last_focused->frame->core);
1538 wSetFocusTo(scr, wapp->last_focused);
1539 } else if (focused) {
1540 wSetFocusTo(scr, focused);
1542 wapp->last_focused = NULL;
1543 if (wPreferences.auto_arrange_icons) {
1544 wArrangeIcons(scr, True);
1546 #ifdef HIDDENDOT
1547 wAppIconPaint(wapp->app_icon);
1548 #endif
1551 void wShowAllWindows(WScreen * scr)
1553 WWindow *wwin, *old_foc;
1554 WApplication *wapp;
1556 old_foc = wwin = scr->focused_window;
1557 while (wwin) {
1558 if (!wwin->flags.internal_window &&
1559 (scr->current_workspace == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1560 if (wwin->flags.miniaturized) {
1561 wwin->flags.skip_next_animation = 1;
1562 wDeiconifyWindow(wwin);
1563 } else if (wwin->flags.hidden) {
1564 wapp = wApplicationOf(wwin->main_window);
1565 if (wapp) {
1566 wUnhideApplication(wapp, False, False);
1567 } else {
1568 wwin->flags.skip_next_animation = 1;
1569 wDeiconifyWindow(wwin);
1573 wwin = wwin->prev;
1575 wSetFocusTo(scr, old_foc);
1576 /*wRaiseFrame(old_foc->frame->core); */
1579 void wRefreshDesktop(WScreen * scr)
1581 Window win;
1582 XSetWindowAttributes attr;
1584 attr.backing_store = NotUseful;
1585 attr.save_under = False;
1586 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1587 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1588 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1589 XMapRaised(dpy, win);
1590 XDestroyWindow(dpy, win);
1591 XFlush(dpy);
1594 void wArrangeIcons(WScreen * scr, Bool arrangeAll)
1596 WWindow *wwin;
1597 WAppIcon *aicon;
1599 int head;
1600 const int heads = wXineramaHeads(scr);
1602 struct HeadVars {
1603 int pf; /* primary axis */
1604 int sf; /* secondary axis */
1605 int fullW;
1606 int fullH;
1607 int pi, si;
1608 int sx1, sx2, sy1, sy2; /* screen boundary */
1609 int sw, sh;
1610 int xo, yo;
1611 int xs, ys;
1612 } *vars;
1614 int isize = wPreferences.icon_size;
1616 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
1618 for (head = 0; head < heads; ++head) {
1619 #if 0
1620 WMRect rect = wGetRectForHead(scr, head);
1621 #else
1622 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1623 WMRect rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
1624 #endif
1626 vars[head].pi = vars[head].si = 0;
1627 vars[head].sx1 = rect.pos.x;
1628 vars[head].sy1 = rect.pos.y;
1629 vars[head].sw = rect.size.width;
1630 vars[head].sh = rect.size.height;
1631 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1632 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1634 #if 0
1635 if (scr->dock) {
1636 if (scr->dock->on_right_side)
1637 vars[head].sx2 -= isize + DOCK_EXTRA_SPACE;
1638 else
1639 vars[head].sx1 += isize + DOCK_EXTRA_SPACE;
1641 #endif
1643 vars[head].sw = isize * (vars[head].sw / isize);
1644 vars[head].sh = isize * (vars[head].sh / isize);
1645 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
1646 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
1648 /* icon yard boundaries */
1649 if (wPreferences.icon_yard & IY_VERT) {
1650 vars[head].pf = vars[head].fullH;
1651 vars[head].sf = vars[head].fullW;
1652 } else {
1653 vars[head].pf = vars[head].fullW;
1654 vars[head].sf = vars[head].fullH;
1656 if (wPreferences.icon_yard & IY_RIGHT) {
1657 vars[head].xo = vars[head].sx2 - isize;
1658 vars[head].xs = -1;
1659 } else {
1660 vars[head].xo = vars[head].sx1;
1661 vars[head].xs = 1;
1663 if (wPreferences.icon_yard & IY_TOP) {
1664 vars[head].yo = vars[head].sy1;
1665 vars[head].ys = 1;
1666 } else {
1667 vars[head].yo = vars[head].sy2 - isize;
1668 vars[head].ys = -1;
1672 #define X ((wPreferences.icon_yard & IY_VERT) \
1673 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1674 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1676 #define Y ((wPreferences.icon_yard & IY_VERT) \
1677 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1678 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1680 /* arrange application icons */
1681 aicon = scr->app_icon_list;
1682 /* reverse them to avoid unnecessarily sliding of icons */
1683 while (aicon && aicon->next)
1684 aicon = aicon->next;
1686 while (aicon) {
1687 if (!aicon->docked) {
1688 /* CHECK: can icon be NULL here ? */
1689 /* The intention here is to place the AppIcon on the head that
1690 * contains most of the applications _main_ window. */
1691 head = wGetHeadForWindow(aicon->icon->owner);
1693 if (aicon->x_pos != X || aicon->y_pos != Y) {
1694 #ifdef ANIMATIONS
1695 if (!wPreferences.no_animations) {
1696 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1698 #endif /* ANIMATIONS */
1700 wAppIconMove(aicon, X, Y);
1701 vars[head].pi++;
1702 if (vars[head].pi >= vars[head].pf) {
1703 vars[head].pi = 0;
1704 vars[head].si++;
1707 aicon = aicon->prev;
1710 /* arrange miniwindows */
1711 wwin = scr->focused_window;
1712 /* reverse them to avoid unnecessarily shuffling */
1713 while (wwin && wwin->prev)
1714 wwin = wwin->prev;
1716 while (wwin) {
1717 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1718 (wwin->frame->workspace == scr->current_workspace ||
1719 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1721 head = wGetHeadForWindow(wwin);
1723 if (arrangeAll || !wwin->flags.icon_moved) {
1724 if (wwin->icon_x != X || wwin->icon_y != Y) {
1725 #ifdef ANIMATIONS
1726 if (wPreferences.no_animations) {
1727 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1728 } else {
1729 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1730 wwin->icon_y, X, Y);
1732 #else
1733 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1734 #endif /* ANIMATIONS */
1736 wwin->icon_x = X;
1737 wwin->icon_y = Y;
1739 vars[head].pi++;
1740 if (vars[head].pi >= vars[head].pf) {
1741 vars[head].pi = 0;
1742 vars[head].si++;
1746 if (arrangeAll) {
1747 wwin->flags.icon_moved = 0;
1749 /* we reversed the order, so we use next */
1750 wwin = wwin->next;
1753 wfree(vars);
1756 #if 0
1757 void wArrangeIcons(WScreen * scr, Bool arrangeAll)
1759 WWindow *wwin;
1760 WAppIcon *aicon;
1761 int pf; /* primary axis */
1762 int sf; /* secondary axis */
1763 int fullW;
1764 int fullH;
1765 int pi, si;
1766 int sx1, sx2, sy1, sy2; /* screen boundary */
1767 int sw, sh;
1768 int xo, yo;
1769 int xs, ys;
1770 int isize = wPreferences.icon_size;
1773 * Find out screen boundaries.
1777 * Allows each head to have miniwindows
1779 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1781 sx1 = rect.pos.x;
1782 sy1 = rect.pos.y;
1783 sw = rect.size.width;
1784 sh = rect.size.height;
1785 sx2 = sx1 + sw;
1786 sy2 = sy1 + sh;
1787 if (scr->dock) {
1788 if (scr->dock->on_right_side)
1789 sx2 -= isize + DOCK_EXTRA_SPACE;
1790 else
1791 sx1 += isize + DOCK_EXTRA_SPACE;
1793 #if 0
1794 sw = isize * (scr->scr_width / isize);
1795 sh = isize * (scr->scr_height / isize);
1796 #else
1797 sw = isize * (sw / isize);
1798 sh = isize * (sh / isize);
1799 #endif
1800 fullW = (sx2 - sx1) / isize;
1801 fullH = (sy2 - sy1) / isize;
1803 /* icon yard boundaries */
1804 if (wPreferences.icon_yard & IY_VERT) {
1805 pf = fullH;
1806 sf = fullW;
1807 } else {
1808 pf = fullW;
1809 sf = fullH;
1811 if (wPreferences.icon_yard & IY_RIGHT) {
1812 xo = sx2 - isize;
1813 xs = -1;
1814 } else {
1815 xo = sx1;
1816 xs = 1;
1818 if (wPreferences.icon_yard & IY_TOP) {
1819 yo = sy1;
1820 ys = 1;
1821 } else {
1822 yo = sy2 - isize;
1823 ys = -1;
1826 /* arrange icons putting the most recently focused window
1827 * as the last icon */
1828 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1829 : xo + xs*(pi*isize))
1830 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1831 : yo + ys*(si*isize))
1833 /* arrange application icons */
1834 aicon = scr->app_icon_list;
1835 /* reverse them to avoid unnecessarily sliding of icons */
1836 while (aicon && aicon->next)
1837 aicon = aicon->next;
1839 pi = 0;
1840 si = 0;
1841 while (aicon) {
1842 if (!aicon->docked) {
1843 if (aicon->x_pos != X || aicon->y_pos != Y) {
1844 #ifdef ANIMATIONS
1845 if (!wPreferences.no_animations) {
1846 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1848 #endif /* ANIMATIONS */
1850 wAppIconMove(aicon, X, Y);
1851 pi++;
1853 /* we reversed the order so we use prev */
1854 aicon = aicon->prev;
1855 if (pi >= pf) {
1856 pi = 0;
1857 si++;
1861 /* arrange miniwindows */
1863 wwin = scr->focused_window;
1864 /* reverse them to avoid unnecessarily shuffling */
1865 while (wwin && wwin->prev)
1866 wwin = wwin->prev;
1868 while (wwin) {
1869 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1870 (wwin->frame->workspace == scr->current_workspace ||
1871 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1873 if (arrangeAll || !wwin->flags.icon_moved) {
1874 if (wwin->icon_x != X || wwin->icon_y != Y) {
1875 #ifdef ANIMATIONS
1876 if (wPreferences.no_animations) {
1877 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1878 } else {
1879 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1880 wwin->icon_y, X, Y);
1882 #else
1883 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1884 #endif /* ANIMATIONS */
1886 wwin->icon_x = X;
1887 wwin->icon_y = Y;
1888 pi++;
1891 if (arrangeAll) {
1892 wwin->flags.icon_moved = 0;
1894 /* we reversed the order, so we use next */
1895 wwin = wwin->next;
1896 if (pi >= pf) {
1897 pi = 0;
1898 si++;
1902 #endif
1904 void wSelectWindow(WWindow * wwin, Bool flag)
1906 WScreen *scr = wwin->screen_ptr;
1908 if (flag) {
1909 wwin->flags.selected = 1;
1910 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1912 if (!HAS_BORDER(wwin)) {
1913 XSetWindowBorderWidth(dpy, wwin->frame->core->window, FRAME_BORDER_WIDTH);
1916 if (!scr->selected_windows)
1917 scr->selected_windows = WMCreateArray(4);
1918 WMAddToArray(scr->selected_windows, wwin);
1919 } else {
1920 wwin->flags.selected = 0;
1921 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
1923 if (!HAS_BORDER(wwin)) {
1924 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1927 if (scr->selected_windows) {
1928 WMRemoveFromArray(scr->selected_windows, wwin);
1933 void wMakeWindowVisible(WWindow * wwin)
1935 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1936 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1938 if (wwin->flags.shaded) {
1939 wUnshadeWindow(wwin);
1941 if (wwin->flags.hidden) {
1942 WApplication *app;
1944 app = wApplicationOf(wwin->main_window);
1945 if (app) {
1946 /* trick to get focus to this window */
1947 app->last_focused = wwin;
1948 wUnhideApplication(app, False, False);
1951 if (wwin->flags.miniaturized) {
1952 wDeiconifyWindow(wwin);
1953 } else {
1954 if (!WFLAGP(wwin, no_focusable))
1955 wSetFocusTo(wwin->screen_ptr, wwin);
1956 wRaiseFrame(wwin->frame->core);
1961 * Do the animation while shading (called with what = SHADE)
1962 * or unshading (what = UNSHADE).
1964 #ifdef ANIMATIONS
1965 static void shade_animate(WWindow *wwin, Bool what)
1967 int y, s, w, h;
1968 time_t time0 = time(NULL);
1970 if (wwin->flags.skip_next_animation && wPreferences.no_animations)
1971 return;
1973 switch(what) {
1974 case SHADE:
1975 if (!wwin->screen_ptr->flags.startup) {
1976 /* do the shading animation */
1977 h = wwin->frame->core->height;
1978 s = h / SHADE_STEPS;
1979 if (s < 1)
1980 s = 1;
1981 w = wwin->frame->core->width;
1982 y = wwin->frame->top_width;
1983 while (h > wwin->frame->top_width + 1) {
1984 XMoveWindow(dpy, wwin->client_win, 0, y);
1985 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1986 XFlush(dpy);
1988 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1989 break;
1991 if (SHADE_DELAY > 0) {
1992 wusleep(SHADE_DELAY * 1000L);
1993 } else {
1994 wusleep(10);
1996 h -= s;
1997 y -= s;
1999 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2001 break;
2003 case UNSHADE:
2004 h = wwin->frame->top_width + wwin->frame->bottom_width;
2005 y = wwin->frame->top_width - wwin->client.height;
2006 s = abs(y) / SHADE_STEPS;
2007 if (s < 1)
2008 s = 1;
2009 w = wwin->frame->core->width;
2010 XMoveWindow(dpy, wwin->client_win, 0, y);
2011 if (s > 0) {
2012 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
2013 XResizeWindow(dpy, wwin->frame->core->window, w, h);
2014 XMoveWindow(dpy, wwin->client_win, 0, y);
2015 XFlush(dpy);
2016 if (SHADE_DELAY > 0) {
2017 wusleep(SHADE_DELAY * 2000L / 3);
2018 } else {
2019 wusleep(10);
2021 h += s;
2022 y += s;
2024 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
2025 break;
2028 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2029 break;
2032 #else
2033 static void shade_animate(WWindow *wwin, Bool what) { return; }
2034 #endif /* ANIMATIONS */