Cleanup includes of wcore.h, defaults.h and pixmap.h
[wmaker-crm.git] / src / actions.c
blobf6a086725bb4f8bb39cd6414066f8c013bdf76f8
1 /* action.c- misc. window commands (miniaturize, hide etc.)
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #include "wconfig.h"
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <math.h>
32 #include <time.h>
34 #include "WindowMaker.h"
35 #include "framewin.h"
36 #include "window.h"
37 #include "client.h"
38 #include "icon.h"
39 #include "funcs.h"
40 #include "application.h"
41 #include "actions.h"
42 #include "stacking.h"
43 #include "appicon.h"
44 #include "dock.h"
45 #include "appmenu.h"
46 #include "winspector.h"
47 #include "workspace.h"
48 #include "xinerama.h"
50 /****** Global Variables ******/
52 int ignore_wks_change = 0;
53 extern Time LastTimestamp;
54 extern Time LastFocusChange;
56 extern Cursor wCursor[WCUR_LAST];
58 extern WPreferences wPreferences;
60 extern Atom _XA_WM_TAKE_FOCUS;
62 extern void ProcessPendingEvents();
63 extern int calcIntersectionLength(int p1, int l1, int p2, int l2);
65 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
66 unsigned int *new_width, unsigned int *new_height);
67 static void save_old_geometry(WWindow *wwin);
69 /******* Local Variables *******/
70 static struct {
71 int steps;
72 int delay;
73 } shadePars[5] = {
75 SHADE_STEPS_UF, SHADE_DELAY_UF}, {
76 SHADE_STEPS_F, SHADE_DELAY_F}, {
77 SHADE_STEPS_M, SHADE_DELAY_M}, {
78 SHADE_STEPS_S, SHADE_DELAY_S}, {
79 SHADE_STEPS_US, SHADE_DELAY_US}};
81 #define UNSHADE 0
82 #define SHADE 1
83 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
84 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
86 static int compareTimes(Time t1, Time t2)
88 Time diff;
89 if (t1 == t2)
90 return 0;
91 diff = t1 - t2;
92 return (diff < 60000) ? 1 : -1;
95 #ifdef ANIMATIONS
96 static void shade_animate(WWindow *wwin, Bool what);
97 #else
98 static void shade_animate(WWindow *wwin, Bool what) { }
99 #endif
102 *----------------------------------------------------------------------
103 * wSetFocusTo--
104 * Changes the window focus to the one passed as argument.
105 * If the window to focus is not already focused, it will be brought
106 * to the head of the list of windows. Previously focused window is
107 * unfocused.
109 * Side effects:
110 * Window list may be reordered and the window focus is changed.
112 *----------------------------------------------------------------------
114 void wSetFocusTo(WScreen *scr, WWindow *wwin)
116 static WScreen *old_scr = NULL;
118 WWindow *old_focused;
119 WWindow *focused = scr->focused_window;
120 Time timestamp = LastTimestamp;
121 WApplication *oapp = NULL, *napp = NULL;
122 int wasfocused;
124 if (scr->flags.ignore_focus_events || compareTimes(LastFocusChange, timestamp) > 0)
125 return;
127 if (!old_scr)
128 old_scr = scr;
129 old_focused = old_scr->focused_window;
131 LastFocusChange = timestamp;
133 if (old_focused)
134 oapp = wApplicationOf(old_focused->main_window);
136 if (wwin == NULL) {
137 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
138 if (old_focused)
139 wWindowUnfocus(old_focused);
140 if (oapp)
141 wAppMenuUnmap(oapp->menu);
143 WMPostNotificationName(WMNChangedFocus, NULL, (void *)True);
144 return;
145 } else if (old_scr != scr && old_focused) {
146 wWindowUnfocus(old_focused);
149 wasfocused = wwin->flags.focused;
150 napp = wApplicationOf(wwin->main_window);
152 /* remember last workspace where the app has been */
153 if (napp) {
154 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
155 napp->last_workspace = wwin->frame->workspace;
158 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
159 /* install colormap if colormap mode is lock mode */
160 if (wPreferences.colormap_mode == WCM_CLICK)
161 wColormapInstallForWindow(scr, wwin);
163 /* set input focus */
164 switch (wwin->focus_mode) {
165 case WFM_NO_INPUT:
166 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
167 break;
169 case WFM_PASSIVE:
170 case WFM_LOCALLY_ACTIVE:
171 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
172 break;
174 case WFM_GLOBALLY_ACTIVE:
175 break;
177 XFlush(dpy);
178 if (wwin->protocols.TAKE_FOCUS) {
179 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
181 XSync(dpy, False);
182 } else {
183 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
185 if (WFLAGP(wwin, no_focusable))
186 return;
188 /* if this is not the focused window focus it */
189 if (focused != wwin) {
190 /* change the focus window list order */
191 if (wwin->prev)
192 wwin->prev->next = wwin->next;
194 if (wwin->next)
195 wwin->next->prev = wwin->prev;
197 wwin->prev = focused;
198 focused->next = wwin;
199 wwin->next = NULL;
200 scr->focused_window = wwin;
202 if (oapp && oapp != napp)
203 wAppMenuUnmap(oapp->menu);
206 wWindowFocus(wwin, focused);
208 if (napp && !wasfocused) {
209 #ifdef USER_MENU
210 wUserMenuRefreshInstances(napp->menu, wwin);
211 #endif /* USER_MENU */
213 if (wwin->flags.mapped)
214 wAppMenuMap(napp->menu, wwin);
217 XFlush(dpy);
218 old_scr = scr;
221 void wShadeWindow(WWindow *wwin)
224 if (wwin->flags.shaded)
225 return;
227 XLowerWindow(dpy, wwin->client_win);
228 shade_animate(wwin, SHADE);
230 wwin->flags.skip_next_animation = 0;
231 wwin->flags.shaded = 1;
232 wwin->flags.mapped = 0;
233 /* prevent window withdrawal when getting UnmapNotify */
234 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
235 XUnmapWindow(dpy, wwin->client_win);
236 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
238 /* for the client it's just like iconification */
239 wFrameWindowResize(wwin->frame, wwin->frame->core->width, wwin->frame->top_width - 1);
241 wwin->client.y = wwin->frame_y - wwin->client.height + wwin->frame->top_width;
242 wWindowSynthConfigureNotify(wwin);
245 wClientSetState(wwin, IconicState, None);
248 WMPostNotificationName(WMNChangedState, wwin, "shade");
250 #ifdef ANIMATIONS
251 if (!wwin->screen_ptr->flags.startup) {
252 /* Catch up with events not processed while animation was running */
253 ProcessPendingEvents();
255 #endif
258 void wUnshadeWindow(WWindow *wwin)
261 if (!wwin->flags.shaded)
262 return;
264 wwin->flags.shaded = 0;
265 wwin->flags.mapped = 1;
266 XMapWindow(dpy, wwin->client_win);
268 shade_animate(wwin, UNSHADE);
270 wwin->flags.skip_next_animation = 0;
271 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
272 wwin->frame->top_width + wwin->client.height + wwin->frame->bottom_width);
274 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
275 wWindowSynthConfigureNotify(wwin);
277 /* if the window is focused, set the focus again as it was disabled during
278 * shading */
279 if (wwin->flags.focused)
280 wSetFocusTo(wwin->screen_ptr, wwin);
282 WMPostNotificationName(WMNChangedState, wwin, "shade");
285 /* Set the old coordinates using the current values */
286 static void save_old_geometry(WWindow *wwin)
288 wwin->old_geometry.width = wwin->client.width;
289 wwin->old_geometry.height = wwin->client.height;
290 wwin->old_geometry.x = wwin->frame_x;
291 wwin->old_geometry.y = wwin->frame_y;
294 void wMaximizeWindow(WWindow *wwin, int directions)
296 int new_x, new_y;
297 unsigned int new_width, new_height, half_scr_width;
298 WArea usableArea, totalArea;
299 Bool has_border = 1;
300 int adj_size;
302 if (!IS_RESIZABLE(wwin))
303 return;
305 if (!HAS_BORDER(wwin))
306 has_border = 0;
308 /* the size to adjust the geometry */
309 adj_size = FRAME_BORDER_WIDTH * 2 * has_border;
311 /* save old coordinates before we change the current values */
312 save_old_geometry(wwin);
314 totalArea.x1 = 0;
315 totalArea.y1 = 0;
316 totalArea.x2 = wwin->screen_ptr->scr_width;
317 totalArea.y2 = wwin->screen_ptr->scr_height;
318 usableArea = totalArea;
320 if (!(directions & MAX_IGNORE_XINERAMA)) {
321 WScreen *scr = wwin->screen_ptr;
322 int head;
324 if (directions & MAX_KEYBOARD)
325 head = wGetHeadForWindow(wwin);
326 else
327 head = wGetHeadForPointerLocation(scr);
329 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
332 /* Only save directions, not kbd or xinerama hints */
333 directions &= (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_MAXIMUS);
335 if (WFLAGP(wwin, full_maximize)) {
336 usableArea = totalArea;
338 half_scr_width = (usableArea.x2 - usableArea.x1)/2;
340 if (wwin->flags.shaded) {
341 wwin->flags.skip_next_animation = 1;
342 wUnshadeWindow(wwin);
345 if (directions & MAX_HORIZONTAL) {
346 new_width = usableArea.x2 - usableArea.x1 - adj_size;
347 new_x = usableArea.x1;
348 } else if (directions & MAX_LEFTHALF) {
349 new_width = half_scr_width - adj_size;
350 new_x = usableArea.x1;
351 } else if (directions & MAX_RIGHTHALF) {
352 new_width = half_scr_width - adj_size;
353 new_x = usableArea.x1 + half_scr_width;
354 } else {
355 new_x = wwin->frame_x;
356 new_width = wwin->frame->core->width;
359 if (directions & MAX_VERTICAL) {
360 new_height = usableArea.y2 - usableArea.y1 - adj_size;
361 new_y = usableArea.y1;
362 if (WFLAGP(wwin, full_maximize)) {
363 new_y -= wwin->frame->top_width;
364 new_height += wwin->frame->bottom_width - 1;
366 } else {
367 new_y = wwin->frame_y;
368 new_height = wwin->frame->core->height;
371 if (!WFLAGP(wwin, full_maximize)) {
372 new_height -= wwin->frame->top_width + wwin->frame->bottom_width;
375 if (directions & MAX_MAXIMUS) {
376 find_Maximus_geometry(wwin, usableArea, &new_x, &new_y, &new_width, &new_height);
377 new_width -= adj_size;
378 new_height -= adj_size;
379 if (WFLAGP(wwin, full_maximize) && new_y == 0) {
380 new_y -= wwin->frame->top_width;
381 new_height += wwin->frame->top_width - 1;
385 wWindowConstrainSize(wwin, &new_width, &new_height);
387 wWindowCropSize(wwin, usableArea.x2 - usableArea.x1,
388 usableArea.y2 - usableArea.y1, &new_width, &new_height);
390 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
392 WMPostNotificationName(WMNChangedState, wwin, "maximize");
394 /* set maximization state */
395 wwin->flags.maximized = directions;
399 * Maximus: tiled maximization (maximize without overlapping other windows)
401 * The window to be maximized will be denoted by w_0 (sub-index zero)
402 * while the windows which will stop the maximization of w_0 are denoted by w_j.
404 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
405 unsigned int *new_width, unsigned int *new_height)
407 WWindow *tmp;
408 int x_0 = wwin->frame_x;
409 int y_0 = wwin->frame_y;
410 int width_0 = wwin->frame->core->width;
411 int height_0 = wwin->frame->core->height;
412 int bottom_0 = y_0 + height_0;
413 int right_border_0 = x_0 + width_0;
414 int new_x_0, new_y_0, new_bottom_0, new_right_border_0, new_height_0;
415 int x_j, y_j, width_j, height_j, bottom_j, top_j, right_border_j;
416 int x_intsect, y_intsect;
417 short int tbar_height_0 = 0, rbar_height_0 = 0;
418 short int bd_width_0 = 0;
419 short int adjust_height;
421 /* Try to fully maximize first, then readjust later */
422 new_x_0 = usableArea.x1;
423 new_y_0 = usableArea.y1;
424 new_bottom_0 = usableArea.y2;
425 new_right_border_0 = usableArea.x2;
427 if (HAS_TITLEBAR(wwin))
428 tbar_height_0 = TITLEBAR_HEIGHT;
429 if (HAS_RESIZEBAR(wwin))
430 rbar_height_0 = RESIZEBAR_HEIGHT;
431 if (HAS_BORDER(wwin))
432 bd_width_0 = FRAME_BORDER_WIDTH;
434 /* the length to be subtracted if w_0 has titlebar, etc */
435 adjust_height = tbar_height_0 + 2 * bd_width_0 + rbar_height_0;
437 tmp = wwin;
438 /* The focused window is always the last in the list */
439 while (tmp->prev) {
440 /* ignore windows in other workspaces etc */
441 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
442 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
443 tmp = tmp->prev;
444 continue;
446 tmp = tmp->prev;
449 * Set the w_j window coordinates. It is convenient
450 * to not use "corrected" sizes for width and height,
451 * otherwise bottom_j and right_border_j would be
452 * incorrect.
454 x_j = tmp->frame_x;
455 y_j = tmp->frame_y;
456 width_j = tmp->frame->core->width;
457 height_j = tmp->frame->core->height;
458 bottom_j = y_j + height_j;
459 top_j = y_j;
460 right_border_j = x_j + width_j;
462 /* Try to maximize in the y direction first */
463 x_intsect = calcIntersectionLength(x_0, width_0, x_j, width_j);
464 if (x_intsect != 0) {
465 /* TODO: Consider the case when coords are equal */
466 if (bottom_j < y_0 && bottom_j > new_y_0) {
467 /* w_0 is below the bottom of w_j */
468 new_y_0 = bottom_j + 1;
470 if (bottom_0 < top_j && top_j < new_bottom_0) {
471 /* The bottom of w_0 is above the top of w_j */
472 new_bottom_0 = top_j - 1;
477 tmp = wwin;
478 while (tmp->prev) {
479 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
480 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
481 tmp = tmp->prev;
482 continue;
484 tmp = tmp->prev;
486 /* set the w_j window coordinates */
487 x_j = tmp->frame_x;
488 y_j = tmp->frame_y;
489 width_j = tmp->frame->core->width;
490 height_j = tmp->frame->core->height;
491 bottom_j = y_j + height_j;
492 top_j = y_j;
493 right_border_j = x_j + width_j;
496 * Use the updated y coordinates from the above step to account
497 * the possibility that the new value of y_0 will have different
498 * intersections with w_j
500 new_height_0 = new_bottom_0 - new_y_0 - adjust_height;
501 y_intsect = calcIntersectionLength(new_y_0, new_height_0, y_j, height_j);
502 if (y_intsect != 0) {
503 if (right_border_j < x_0 && right_border_j > new_x_0) {
504 /* w_0 is completely to the right of w_j */
505 new_x_0 = right_border_j + 1;
507 if (right_border_0 < x_j && x_j < new_right_border_0) {
508 /* w_0 is completely to the left of w_j */
509 new_right_border_0 = x_j - 1;
514 /* xcalc needs -7 here, but other apps don't */
515 new_height_0 = new_bottom_0 - new_y_0 - adjust_height - 1;
516 *new_x = new_x_0;
517 *new_y = new_y_0;
518 *new_height = new_height_0;
519 *new_width = new_right_border_0 - new_x_0;
522 void wUnmaximizeWindow(WWindow *wwin)
524 int x, y, w, h;
525 WMRect old_geom_rect;
526 int old_head;
527 Bool same_head;
529 if (!wwin->flags.maximized)
530 return;
532 if (wwin->flags.shaded) {
533 wwin->flags.skip_next_animation = 1;
534 wUnshadeWindow(wwin);
536 /* Use old coordinates if they are set, current values otherwise */
537 old_geom_rect = wmkrect(wwin->old_geometry.x, wwin->old_geometry.y, wwin->old_geometry.width, wwin->old_geometry.height);
538 old_head = wGetHeadForRect(wwin->screen_ptr, old_geom_rect);
539 same_head = (wGetHeadForWindow(wwin) == old_head);
540 x = (wwin->old_geometry.x && same_head) ? wwin->old_geometry.x : wwin->frame_x;
541 y = (wwin->old_geometry.y && same_head) ? wwin->old_geometry.y : wwin->frame_y;
542 w = wwin->old_geometry.width ? wwin->old_geometry.width : wwin->client.width;
543 h = wwin->old_geometry.height ? wwin->old_geometry.height : wwin->client.height;
545 wwin->flags.maximized = 0;
546 wWindowConfigure(wwin, x, y, w, h);
548 WMPostNotificationName(WMNChangedState, wwin, "maximize");
551 void wFullscreenWindow(WWindow *wwin)
553 int head;
554 WMRect rect;
556 if (wwin->flags.fullscreen)
557 return;
559 wwin->flags.fullscreen = True;
561 wWindowConfigureBorders(wwin);
563 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
565 wwin->bfs_geometry.x = wwin->frame_x;
566 wwin->bfs_geometry.y = wwin->frame_y;
567 wwin->bfs_geometry.width = wwin->frame->core->width;
568 wwin->bfs_geometry.height = wwin->frame->core->height;
570 head = wGetHeadForWindow(wwin);
571 rect = wGetRectForHead(wwin->screen_ptr, head);
572 wWindowConfigure(wwin, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
574 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
577 void wUnfullscreenWindow(WWindow *wwin)
579 if (!wwin->flags.fullscreen)
580 return;
582 wwin->flags.fullscreen = False;
584 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
585 if (WFLAGP(wwin, sunken)) {
586 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
587 } else if (WFLAGP(wwin, floating)) {
588 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
589 } else {
590 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
594 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
595 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
597 wWindowConfigureBorders(wwin);
599 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
600 wFrameWindowPaint(wwin->frame);
603 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
606 #ifdef ANIMATIONS
607 static void animateResizeFlip(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
609 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
610 float cx, cy, cw, ch;
611 float xstep, ystep, wstep, hstep;
612 XPoint points[5];
613 float dx, dch, midy;
614 float angle, final_angle, delta;
616 xstep = (float)(fx - x) / steps;
617 ystep = (float)(fy - y) / steps;
618 wstep = (float)(fw - w) / steps;
619 hstep = (float)(fh - h) / steps;
621 cx = (float)x;
622 cy = (float)y;
623 cw = (float)w;
624 ch = (float)h;
626 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_F;
627 delta = (float)(final_angle / FRAMES);
628 for (angle = 0;; angle += delta) {
629 if (angle > final_angle)
630 angle = final_angle;
632 dx = (cw / 10) - ((cw / 5) * sin(angle));
633 dch = (ch / 2) * cos(angle);
634 midy = cy + (ch / 2);
636 points[0].x = cx + dx;
637 points[0].y = midy - dch;
638 points[1].x = cx + cw - dx;
639 points[1].y = points[0].y;
640 points[2].x = cx + cw + dx;
641 points[2].y = midy + dch;
642 points[3].x = cx - dx;
643 points[3].y = points[2].y;
644 points[4].x = points[0].x;
645 points[4].y = points[0].y;
647 XGrabServer(dpy);
648 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
649 XFlush(dpy);
650 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
652 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
653 XUngrabServer(dpy);
654 cx += xstep;
655 cy += ystep;
656 cw += wstep;
657 ch += hstep;
658 if (angle >= final_angle)
659 break;
662 XFlush(dpy);
665 #undef FRAMES
667 static void
668 animateResizeTwist(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
670 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
671 float cx, cy, cw, ch;
672 float xstep, ystep, wstep, hstep;
673 XPoint points[5];
674 float angle, final_angle, a, d, delta;
676 x += w / 2;
677 y += h / 2;
678 fx += fw / 2;
679 fy += fh / 2;
681 xstep = (float)(fx - x) / steps;
682 ystep = (float)(fy - y) / steps;
683 wstep = (float)(fw - w) / steps;
684 hstep = (float)(fh - h) / steps;
686 cx = (float)x;
687 cy = (float)y;
688 cw = (float)w;
689 ch = (float)h;
691 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_T;
692 delta = (float)(final_angle / FRAMES);
693 for (angle = 0;; angle += delta) {
694 if (angle > final_angle)
695 angle = final_angle;
697 a = atan(ch / cw);
698 d = sqrt((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
700 points[0].x = cx + cos(angle - a) * d;
701 points[0].y = cy + sin(angle - a) * d;
702 points[1].x = cx + cos(angle + a) * d;
703 points[1].y = cy + sin(angle + a) * d;
704 points[2].x = cx + cos(angle - a + WM_PI) * d;
705 points[2].y = cy + sin(angle - a + WM_PI) * d;
706 points[3].x = cx + cos(angle + a + WM_PI) * d;
707 points[3].y = cy + sin(angle + a + WM_PI) * d;
708 points[4].x = cx + cos(angle - a) * d;
709 points[4].y = cy + sin(angle - a) * d;
710 XGrabServer(dpy);
711 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
712 XFlush(dpy);
713 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
715 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
716 XUngrabServer(dpy);
717 cx += xstep;
718 cy += ystep;
719 cw += wstep;
720 ch += hstep;
721 if (angle >= final_angle)
722 break;
725 XFlush(dpy);
728 #undef FRAMES
730 static void animateResizeZoom(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
732 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
733 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
734 float xstep, ystep, wstep, hstep;
735 int i, j;
737 xstep = (float)(fx - x) / steps;
738 ystep = (float)(fy - y) / steps;
739 wstep = (float)(fw - w) / steps;
740 hstep = (float)(fh - h) / steps;
742 for (j = 0; j < FRAMES; j++) {
743 cx[j] = (float)x;
744 cy[j] = (float)y;
745 cw[j] = (float)w;
746 ch[j] = (float)h;
748 XGrabServer(dpy);
749 for (i = 0; i < steps; i++) {
750 for (j = 0; j < FRAMES; j++) {
751 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
752 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
754 XFlush(dpy);
755 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
757 for (j = 0; j < FRAMES; j++) {
758 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
759 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
760 if (j < FRAMES - 1) {
761 cx[j] = cx[j + 1];
762 cy[j] = cy[j + 1];
763 cw[j] = cw[j + 1];
764 ch[j] = ch[j + 1];
765 } else {
766 cx[j] += xstep;
767 cy[j] += ystep;
768 cw[j] += wstep;
769 ch[j] += hstep;
774 for (j = 0; j < FRAMES; j++) {
775 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
777 XFlush(dpy);
778 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
780 for (j = 0; j < FRAMES; j++) {
781 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
784 XUngrabServer(dpy);
787 #undef FRAMES
789 void animateResize(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh)
791 int style = wPreferences.iconification_style; /* Catch the value */
792 int steps;
794 if (style == WIS_NONE)
795 return;
797 if (style == WIS_RANDOM) {
798 style = rand() % 3;
801 switch (style) {
802 case WIS_TWIST:
803 steps = MINIATURIZE_ANIMATION_STEPS_T;
804 if (steps > 0)
805 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
806 break;
807 case WIS_FLIP:
808 steps = MINIATURIZE_ANIMATION_STEPS_F;
809 if (steps > 0)
810 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
811 break;
812 case WIS_ZOOM:
813 default:
814 steps = MINIATURIZE_ANIMATION_STEPS_Z;
815 if (steps > 0)
816 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
817 break;
820 #endif /* ANIMATIONS */
822 static void flushExpose()
824 XEvent tmpev;
826 while (XCheckTypedEvent(dpy, Expose, &tmpev))
827 WMHandleEvent(&tmpev);
828 XSync(dpy, 0);
831 static void unmapTransientsFor(WWindow *wwin)
833 WWindow *tmp;
835 tmp = wwin->screen_ptr->focused_window;
836 while (tmp) {
837 /* unmap the transients for this transient */
838 if (tmp != wwin && tmp->transient_for == wwin->client_win
839 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup || tmp->flags.shaded)) {
840 unmapTransientsFor(tmp);
841 tmp->flags.miniaturized = 1;
842 if (!tmp->flags.shaded) {
843 wWindowUnmap(tmp);
844 } else {
845 XUnmapWindow(dpy, tmp->frame->core->window);
848 if (!tmp->flags.shaded)
850 wClientSetState(tmp, IconicState, None);
852 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
854 tmp = tmp->prev;
858 static void mapTransientsFor(WWindow *wwin)
860 WWindow *tmp;
862 tmp = wwin->screen_ptr->focused_window;
863 while (tmp) {
864 /* recursively map the transients for this transient */
865 if (tmp != wwin && tmp->transient_for == wwin->client_win && /*!tmp->flags.mapped */ tmp->flags.miniaturized
866 && tmp->icon == NULL) {
867 mapTransientsFor(tmp);
868 tmp->flags.miniaturized = 0;
869 if (!tmp->flags.shaded) {
870 wWindowMap(tmp);
871 } else {
872 XMapWindow(dpy, tmp->frame->core->window);
874 tmp->flags.semi_focused = 0;
876 if (!tmp->flags.shaded)
878 wClientSetState(tmp, NormalState, None);
880 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
882 tmp = tmp->prev;
886 static WWindow *recursiveTransientFor(WWindow * wwin)
888 int i;
890 if (!wwin)
891 return None;
893 /* hackish way to detect transient_for cycle */
894 i = wwin->screen_ptr->window_count + 1;
896 while (wwin && wwin->transient_for != None && i > 0) {
897 wwin = wWindowFor(wwin->transient_for);
898 i--;
900 if (i == 0 && wwin) {
901 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin->frame->title);
902 return NULL;
905 return wwin;
908 void wIconifyWindow(WWindow * wwin)
910 XWindowAttributes attribs;
911 int present;
913 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
914 /* the window doesn't exist anymore */
915 return;
918 if (wwin->flags.miniaturized) {
919 return;
922 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
923 WWindow *owner = wWindowFor(wwin->transient_for);
925 if (owner && owner->flags.miniaturized)
926 return;
929 present = wwin->frame->workspace == wwin->screen_ptr->current_workspace;
931 /* if the window is in another workspace, simplify process */
932 if (present) {
933 /* icon creation may take a while */
934 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
935 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
936 GrabModeAsync, None, None, CurrentTime);
939 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
940 if (!wwin->flags.icon_moved) {
941 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
943 wwin->icon = wIconCreate(wwin);
945 wwin->icon->mapped = 1;
948 wwin->flags.miniaturized = 1;
949 wwin->flags.mapped = 0;
951 /* unmap transients */
953 unmapTransientsFor(wwin);
955 if (present) {
956 XUngrabPointer(dpy, CurrentTime);
957 wWindowUnmap(wwin);
958 /* let all Expose events arrive so that we can repaint
959 * something before the animation starts (and the server is grabbed) */
960 XSync(dpy, 0);
962 if (wPreferences.disable_miniwindows || wwin->flags.net_handle_icon)
963 wClientSetState(wwin, IconicState, None);
964 else
965 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
967 flushExpose();
968 #ifdef ANIMATIONS
969 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
970 && !wPreferences.no_animations) {
971 int ix, iy, iw, ih;
973 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
974 ix = wwin->icon_x;
975 iy = wwin->icon_y;
976 iw = wwin->icon->core->width;
977 ih = wwin->icon->core->height;
978 } else {
979 if (wwin->flags.net_handle_icon) {
980 ix = wwin->icon_x;
981 iy = wwin->icon_y;
982 iw = wwin->icon_w;
983 ih = wwin->icon_h;
984 } else {
985 ix = 0;
986 iy = 0;
987 iw = wwin->screen_ptr->scr_width;
988 ih = wwin->screen_ptr->scr_height;
991 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
992 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih);
994 #endif
997 wwin->flags.skip_next_animation = 0;
999 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1000 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace ||
1001 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1003 XMapWindow(dpy, wwin->icon->core->window);
1005 AddToStackList(wwin->icon->core);
1007 wLowerFrame(wwin->icon->core);
1010 if (present) {
1011 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1014 * It doesn't seem to be working and causes button event hangup
1015 * when deiconifying a transient window.
1016 setupIconGrabs(wwin->icon);
1018 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
1019 && wPreferences.focus_mode == WKF_CLICK) {
1020 WWindow *tmp;
1022 tmp = wwin->prev;
1023 while (tmp) {
1024 if (!WFLAGP(tmp, no_focusable)
1025 && !(tmp->flags.hidden || tmp->flags.miniaturized)
1026 && (wwin->frame->workspace == tmp->frame->workspace))
1027 break;
1028 tmp = tmp->prev;
1030 wSetFocusTo(wwin->screen_ptr, tmp);
1031 } else if (wPreferences.focus_mode != WKF_CLICK) {
1032 wSetFocusTo(wwin->screen_ptr, NULL);
1034 #ifdef ANIMATIONS
1035 if (!wwin->screen_ptr->flags.startup) {
1036 /* Catch up with events not processed while animation was running */
1037 Window clientwin = wwin->client_win;
1039 ProcessPendingEvents();
1041 /* the window can disappear while ProcessPendingEvents() runs */
1042 if (!wWindowFor(clientwin)) {
1043 return;
1046 #endif
1049 /* maybe we want to do this regardless of net_handle_icon
1050 * it seems to me we might break behaviour this way.
1052 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1053 && !wwin->flags.net_handle_icon)
1054 wIconSelect(wwin->icon);
1056 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1058 if (wPreferences.auto_arrange_icons)
1059 wArrangeIcons(wwin->screen_ptr, True);
1062 void wDeiconifyWindow(WWindow *wwin)
1064 /* Let's avoid changing workspace while deiconifying */
1065 ignore_wks_change = 1;
1067 /* we're hiding for show_desktop */
1068 int netwm_hidden = wwin->flags.net_show_desktop &&
1069 wwin->frame->workspace != wwin->screen_ptr->current_workspace;
1071 if (!netwm_hidden)
1072 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1074 if (!wwin->flags.miniaturized)
1075 return;
1077 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1078 WWindow *owner = recursiveTransientFor(wwin);
1080 if (owner && owner->flags.miniaturized) {
1081 wDeiconifyWindow(owner);
1082 wSetFocusTo(wwin->screen_ptr, wwin);
1083 wRaiseFrame(wwin->frame->core);
1084 return;
1088 wwin->flags.miniaturized = 0;
1090 if (!netwm_hidden && !wwin->flags.shaded) {
1091 wwin->flags.mapped = 1;
1094 if (!netwm_hidden || wPreferences.sticky_icons) {
1095 /* maybe we want to do this regardless of net_handle_icon
1096 * it seems to me we might break behaviour this way.
1098 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon
1099 && wwin->icon != NULL) {
1100 if (wwin->icon->selected)
1101 wIconSelect(wwin->icon);
1103 XUnmapWindow(dpy, wwin->icon->core->window);
1107 /* if the window is in another workspace, do it silently */
1108 if (!netwm_hidden) {
1109 #ifdef ANIMATIONS
1110 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1111 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1112 int ix, iy, iw, ih;
1114 if (!wPreferences.disable_miniwindows
1115 && !wwin->flags.net_handle_icon) {
1116 ix = wwin->icon_x;
1117 iy = wwin->icon_y;
1118 iw = wwin->icon->core->width;
1119 ih = wwin->icon->core->height;
1120 } else {
1121 if (wwin->flags.net_handle_icon) {
1122 ix = wwin->icon_x;
1123 iy = wwin->icon_y;
1124 iw = wwin->icon_w;
1125 ih = wwin->icon_h;
1126 } else {
1127 ix = 0;
1128 iy = 0;
1129 iw = wwin->screen_ptr->scr_width;
1130 ih = wwin->screen_ptr->scr_height;
1133 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1134 wwin->frame_x, wwin->frame_y,
1135 wwin->frame->core->width, wwin->frame->core->height);
1137 #endif /* ANIMATIONS */
1138 wwin->flags.skip_next_animation = 0;
1139 XGrabServer(dpy);
1140 if (!wwin->flags.shaded) {
1141 XMapWindow(dpy, wwin->client_win);
1143 XMapWindow(dpy, wwin->frame->core->window);
1144 wRaiseFrame(wwin->frame->core);
1145 if (!wwin->flags.shaded) {
1146 wClientSetState(wwin, NormalState, None);
1148 mapTransientsFor(wwin);
1151 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1152 && !wwin->flags.net_handle_icon) {
1153 RemoveFromStackList(wwin->icon->core);
1154 /* removeIconGrabs(wwin->icon); */
1155 wIconDestroy(wwin->icon);
1156 wwin->icon = NULL;
1159 if (!netwm_hidden) {
1160 XUngrabServer(dpy);
1162 wSetFocusTo(wwin->screen_ptr, wwin);
1164 #ifdef ANIMATIONS
1165 if (!wwin->screen_ptr->flags.startup) {
1166 /* Catch up with events not processed while animation was running */
1167 Window clientwin = wwin->client_win;
1169 ProcessPendingEvents();
1171 /* the window can disappear while ProcessPendingEvents() runs */
1172 if (!wWindowFor(clientwin)) {
1173 return;
1176 #endif
1179 if (wPreferences.auto_arrange_icons) {
1180 wArrangeIcons(wwin->screen_ptr, True);
1183 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1185 /* In case we were shaded and iconified, also unshade */
1186 if (!netwm_hidden)
1187 wUnshadeWindow(wwin);
1189 ignore_wks_change = 0;
1192 static void hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1194 if (wwin->flags.miniaturized) {
1195 if (wwin->icon) {
1196 XUnmapWindow(dpy, wwin->icon->core->window);
1197 wwin->icon->mapped = 0;
1199 wwin->flags.hidden = 1;
1201 WMPostNotificationName(WMNChangedState, wwin, "hide");
1202 return;
1205 if (wwin->flags.inspector_open) {
1206 wHideInspectorForWindow(wwin);
1209 wwin->flags.hidden = 1;
1210 wWindowUnmap(wwin);
1212 wClientSetState(wwin, IconicState, icon->icon_win);
1213 flushExpose();
1215 #ifdef ANIMATIONS
1216 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1217 !wwin->flags.skip_next_animation && animate) {
1218 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1219 wwin->frame->core->width, wwin->frame->core->height,
1220 icon_x, icon_y, icon->core->width, icon->core->height);
1222 #endif
1223 wwin->flags.skip_next_animation = 0;
1225 WMPostNotificationName(WMNChangedState, wwin, "hide");
1228 void wHideOtherApplications(WWindow *awin)
1230 WWindow *wwin;
1231 WApplication *tapp;
1233 if (!awin)
1234 return;
1235 wwin = awin->screen_ptr->focused_window;
1237 while (wwin) {
1238 if (wwin != awin
1239 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1240 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1241 && !wwin->flags.internal_window
1242 && wGetWindowOfInspectorForWindow(wwin) != awin && !WFLAGP(wwin, no_hide_others)) {
1244 if (wwin->main_window == None || WFLAGP(wwin, no_appicon)) {
1245 if (!WFLAGP(wwin, no_miniaturizable)) {
1246 wwin->flags.skip_next_animation = 1;
1247 wIconifyWindow(wwin);
1249 } else if (wwin->main_window != None && awin->main_window != wwin->main_window) {
1250 tapp = wApplicationOf(wwin->main_window);
1251 if (tapp) {
1252 tapp->flags.skip_next_animation = 1;
1253 wHideApplication(tapp);
1254 } else {
1255 if (!WFLAGP(wwin, no_miniaturizable)) {
1256 wwin->flags.skip_next_animation = 1;
1257 wIconifyWindow(wwin);
1262 wwin = wwin->prev;
1265 wSetFocusTo(awin->screen_ptr, awin);
1269 void wHideApplication(WApplication *wapp)
1271 WScreen *scr;
1272 WWindow *wlist;
1273 int hadfocus;
1274 int animate;
1276 if (!wapp) {
1277 wwarning("trying to hide a non grouped window");
1278 return;
1280 if (!wapp->main_window_desc) {
1281 wwarning("group leader not found for window group");
1282 return;
1284 scr = wapp->main_window_desc->screen_ptr;
1285 hadfocus = 0;
1286 wlist = scr->focused_window;
1287 if (!wlist)
1288 return;
1290 if (wlist->main_window == wapp->main_window)
1291 wapp->last_focused = wlist;
1292 else
1293 wapp->last_focused = NULL;
1295 animate = !wapp->flags.skip_next_animation;
1297 while (wlist) {
1298 if (wlist->main_window == wapp->main_window) {
1299 if (wlist->flags.focused) {
1300 hadfocus = 1;
1302 if (wapp->app_icon) {
1303 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1304 wapp->app_icon->y_pos, wlist, animate);
1305 animate = False;
1308 wlist = wlist->prev;
1311 wapp->flags.skip_next_animation = 0;
1313 if (hadfocus) {
1314 if (wPreferences.focus_mode == WKF_CLICK) {
1315 wlist = scr->focused_window;
1316 while (wlist) {
1317 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1318 && (wlist->flags.mapped || wlist->flags.shaded))
1319 break;
1320 wlist = wlist->prev;
1322 wSetFocusTo(scr, wlist);
1323 } else {
1324 wSetFocusTo(scr, NULL);
1328 wapp->flags.hidden = 1;
1330 if (wPreferences.auto_arrange_icons) {
1331 wArrangeIcons(scr, True);
1333 #ifdef HIDDENDOT
1334 if (wapp->app_icon)
1335 wAppIconPaint(wapp->app_icon);
1336 #endif
1339 static void unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate, int bringToCurrentWS)
1341 if (bringToCurrentWS)
1342 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1344 wwin->flags.hidden = 0;
1346 #ifdef ANIMATIONS
1347 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1348 animateResize(wwin->screen_ptr, icon_x, icon_y,
1349 icon->core->width, icon->core->height,
1350 wwin->frame_x, wwin->frame_y,
1351 wwin->frame->core->width, wwin->frame->core->height);
1353 #endif
1354 wwin->flags.skip_next_animation = 0;
1355 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1356 XMapWindow(dpy, wwin->client_win);
1357 XMapWindow(dpy, wwin->frame->core->window);
1358 wClientSetState(wwin, NormalState, None);
1359 wwin->flags.mapped = 1;
1360 wRaiseFrame(wwin->frame->core);
1362 if (wwin->flags.inspector_open) {
1363 wUnhideInspectorForWindow(wwin);
1366 WMPostNotificationName(WMNChangedState, wwin, "hide");
1369 void wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1371 WScreen *scr;
1372 WWindow *wlist, *next;
1373 WWindow *focused = NULL;
1374 int animate;
1376 if (!wapp)
1377 return;
1379 scr = wapp->main_window_desc->screen_ptr;
1380 wlist = scr->focused_window;
1381 if (!wlist)
1382 return;
1384 /* goto beginning of list */
1385 while (wlist->prev)
1386 wlist = wlist->prev;
1388 animate = !wapp->flags.skip_next_animation;
1390 while (wlist) {
1391 next = wlist->next;
1393 if (wlist->main_window == wapp->main_window) {
1394 if (wlist->flags.focused)
1395 focused = wlist;
1396 else if (!focused || !focused->flags.focused)
1397 focused = wlist;
1399 if (wlist->flags.miniaturized) {
1400 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1401 wlist->frame->workspace == scr->current_workspace) && wlist->icon) {
1402 if (!wlist->icon->mapped) {
1403 int x, y;
1405 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1406 if (wlist->icon_x != x || wlist->icon_y != y) {
1407 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1409 wlist->icon_x = x;
1410 wlist->icon_y = y;
1411 XMapWindow(dpy, wlist->icon->core->window);
1412 wlist->icon->mapped = 1;
1414 wRaiseFrame(wlist->icon->core);
1416 if (bringToCurrentWS)
1417 wWindowChangeWorkspace(wlist, scr->current_workspace);
1418 wlist->flags.hidden = 0;
1419 if (miniwindows && wlist->frame->workspace == scr->current_workspace) {
1420 wDeiconifyWindow(wlist);
1422 WMPostNotificationName(WMNChangedState, wlist, "hide");
1423 } else if (wlist->flags.shaded) {
1424 if (bringToCurrentWS)
1425 wWindowChangeWorkspace(wlist, scr->current_workspace);
1426 wlist->flags.hidden = 0;
1427 if (wlist->frame->workspace == scr->current_workspace) {
1428 XMapWindow(dpy, wlist->frame->core->window);
1429 if (miniwindows) {
1430 wUnshadeWindow(wlist);
1431 wRaiseFrame(wlist->frame->core);
1434 WMPostNotificationName(WMNChangedState, wlist, "hide");
1435 } else if (wlist->flags.hidden) {
1436 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1437 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1438 animate = False;
1439 } else {
1440 if (bringToCurrentWS && wlist->frame->workspace != scr->current_workspace) {
1441 wWindowChangeWorkspace(wlist, scr->current_workspace);
1443 wRaiseFrame(wlist->frame->core);
1446 wlist = next;
1449 wapp->flags.skip_next_animation = 0;
1450 wapp->flags.hidden = 0;
1452 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1453 wRaiseFrame(wapp->last_focused->frame->core);
1454 wSetFocusTo(scr, wapp->last_focused);
1455 } else if (focused) {
1456 wSetFocusTo(scr, focused);
1458 wapp->last_focused = NULL;
1459 if (wPreferences.auto_arrange_icons) {
1460 wArrangeIcons(scr, True);
1462 #ifdef HIDDENDOT
1463 wAppIconPaint(wapp->app_icon);
1464 #endif
1467 void wShowAllWindows(WScreen *scr)
1469 WWindow *wwin, *old_foc;
1470 WApplication *wapp;
1472 old_foc = wwin = scr->focused_window;
1473 while (wwin) {
1474 if (!wwin->flags.internal_window &&
1475 (scr->current_workspace == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1476 if (wwin->flags.miniaturized) {
1477 wwin->flags.skip_next_animation = 1;
1478 wDeiconifyWindow(wwin);
1479 } else if (wwin->flags.hidden) {
1480 wapp = wApplicationOf(wwin->main_window);
1481 if (wapp) {
1482 wUnhideApplication(wapp, False, False);
1483 } else {
1484 wwin->flags.skip_next_animation = 1;
1485 wDeiconifyWindow(wwin);
1489 wwin = wwin->prev;
1491 wSetFocusTo(scr, old_foc);
1492 /*wRaiseFrame(old_foc->frame->core); */
1495 void wRefreshDesktop(WScreen *scr)
1497 Window win;
1498 XSetWindowAttributes attr;
1500 attr.backing_store = NotUseful;
1501 attr.save_under = False;
1502 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1503 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1504 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1505 XMapRaised(dpy, win);
1506 XDestroyWindow(dpy, win);
1507 XFlush(dpy);
1510 void wArrangeIcons(WScreen *scr, Bool arrangeAll)
1512 WWindow *wwin;
1513 WAppIcon *aicon;
1515 int head;
1516 const int heads = wXineramaHeads(scr);
1518 struct HeadVars {
1519 int pf; /* primary axis */
1520 int sf; /* secondary axis */
1521 int fullW;
1522 int fullH;
1523 int pi, si;
1524 int sx1, sx2, sy1, sy2; /* screen boundary */
1525 int sw, sh;
1526 int xo, yo;
1527 int xs, ys;
1528 } *vars;
1530 int isize = wPreferences.icon_size;
1532 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
1534 for (head = 0; head < heads; ++head) {
1535 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1536 WMRect rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
1537 vars[head].pi = vars[head].si = 0;
1538 vars[head].sx1 = rect.pos.x;
1539 vars[head].sy1 = rect.pos.y;
1540 vars[head].sw = rect.size.width;
1541 vars[head].sh = rect.size.height;
1542 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1543 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1544 vars[head].sw = isize * (vars[head].sw / isize);
1545 vars[head].sh = isize * (vars[head].sh / isize);
1546 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
1547 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
1549 /* icon yard boundaries */
1550 if (wPreferences.icon_yard & IY_VERT) {
1551 vars[head].pf = vars[head].fullH;
1552 vars[head].sf = vars[head].fullW;
1553 } else {
1554 vars[head].pf = vars[head].fullW;
1555 vars[head].sf = vars[head].fullH;
1557 if (wPreferences.icon_yard & IY_RIGHT) {
1558 vars[head].xo = vars[head].sx2 - isize;
1559 vars[head].xs = -1;
1560 } else {
1561 vars[head].xo = vars[head].sx1;
1562 vars[head].xs = 1;
1564 if (wPreferences.icon_yard & IY_TOP) {
1565 vars[head].yo = vars[head].sy1;
1566 vars[head].ys = 1;
1567 } else {
1568 vars[head].yo = vars[head].sy2 - isize;
1569 vars[head].ys = -1;
1573 #define X ((wPreferences.icon_yard & IY_VERT) \
1574 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1575 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1577 #define Y ((wPreferences.icon_yard & IY_VERT) \
1578 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1579 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1581 /* arrange application icons */
1582 aicon = scr->app_icon_list;
1583 /* reverse them to avoid unnecessarily sliding of icons */
1584 while (aicon && aicon->next)
1585 aicon = aicon->next;
1587 while (aicon) {
1588 if (!aicon->docked) {
1589 /* CHECK: can icon be NULL here ? */
1590 /* The intention here is to place the AppIcon on the head that
1591 * contains most of the applications _main_ window. */
1592 head = wGetHeadForWindow(aicon->icon->owner);
1594 if (aicon->x_pos != X || aicon->y_pos != Y) {
1595 #ifdef ANIMATIONS
1596 if (!wPreferences.no_animations) {
1597 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1599 #endif /* ANIMATIONS */
1601 wAppIconMove(aicon, X, Y);
1602 vars[head].pi++;
1603 if (vars[head].pi >= vars[head].pf) {
1604 vars[head].pi = 0;
1605 vars[head].si++;
1608 aicon = aicon->prev;
1611 /* arrange miniwindows */
1612 wwin = scr->focused_window;
1613 /* reverse them to avoid unnecessarily shuffling */
1614 while (wwin && wwin->prev)
1615 wwin = wwin->prev;
1617 while (wwin) {
1618 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1619 (wwin->frame->workspace == scr->current_workspace ||
1620 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1622 head = wGetHeadForWindow(wwin);
1624 if (arrangeAll || !wwin->flags.icon_moved) {
1625 if (wwin->icon_x != X || wwin->icon_y != Y) {
1626 #ifdef ANIMATIONS
1627 if (wPreferences.no_animations) {
1628 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1629 } else {
1630 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1631 wwin->icon_y, X, Y);
1633 #else
1634 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1635 #endif /* ANIMATIONS */
1637 wwin->icon_x = X;
1638 wwin->icon_y = Y;
1640 vars[head].pi++;
1641 if (vars[head].pi >= vars[head].pf) {
1642 vars[head].pi = 0;
1643 vars[head].si++;
1647 if (arrangeAll) {
1648 wwin->flags.icon_moved = 0;
1650 /* we reversed the order, so we use next */
1651 wwin = wwin->next;
1654 wfree(vars);
1657 void wSelectWindow(WWindow *wwin, Bool flag)
1659 WScreen *scr = wwin->screen_ptr;
1661 if (flag) {
1662 wwin->flags.selected = 1;
1663 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1665 if (!HAS_BORDER(wwin)) {
1666 XSetWindowBorderWidth(dpy, wwin->frame->core->window, FRAME_BORDER_WIDTH);
1669 if (!scr->selected_windows)
1670 scr->selected_windows = WMCreateArray(4);
1671 WMAddToArray(scr->selected_windows, wwin);
1672 } else {
1673 wwin->flags.selected = 0;
1674 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
1676 if (!HAS_BORDER(wwin)) {
1677 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1680 if (scr->selected_windows) {
1681 WMRemoveFromArray(scr->selected_windows, wwin);
1686 void wMakeWindowVisible(WWindow *wwin)
1688 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1689 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1691 if (wwin->flags.shaded) {
1692 wUnshadeWindow(wwin);
1694 if (wwin->flags.hidden) {
1695 WApplication *app;
1697 app = wApplicationOf(wwin->main_window);
1698 if (app) {
1699 /* trick to get focus to this window */
1700 app->last_focused = wwin;
1701 wUnhideApplication(app, False, False);
1704 if (wwin->flags.miniaturized) {
1705 wDeiconifyWindow(wwin);
1706 } else {
1707 if (!WFLAGP(wwin, no_focusable))
1708 wSetFocusTo(wwin->screen_ptr, wwin);
1709 wRaiseFrame(wwin->frame->core);
1714 * Do the animation while shading (called with what = SHADE)
1715 * or unshading (what = UNSHADE).
1717 #ifdef ANIMATIONS
1718 static void shade_animate(WWindow *wwin, Bool what)
1720 int y, s, w, h;
1721 time_t time0 = time(NULL);
1723 if (wwin->flags.skip_next_animation && wPreferences.no_animations)
1724 return;
1726 switch(what) {
1727 case SHADE:
1728 if (!wwin->screen_ptr->flags.startup) {
1729 /* do the shading animation */
1730 h = wwin->frame->core->height;
1731 s = h / SHADE_STEPS;
1732 if (s < 1)
1733 s = 1;
1734 w = wwin->frame->core->width;
1735 y = wwin->frame->top_width;
1736 while (h > wwin->frame->top_width + 1) {
1737 XMoveWindow(dpy, wwin->client_win, 0, y);
1738 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1739 XFlush(dpy);
1741 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1742 break;
1744 if (SHADE_DELAY > 0) {
1745 wusleep(SHADE_DELAY * 1000L);
1746 } else {
1747 wusleep(10);
1749 h -= s;
1750 y -= s;
1752 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1754 break;
1756 case UNSHADE:
1757 h = wwin->frame->top_width + wwin->frame->bottom_width;
1758 y = wwin->frame->top_width - wwin->client.height;
1759 s = abs(y) / SHADE_STEPS;
1760 if (s < 1)
1761 s = 1;
1762 w = wwin->frame->core->width;
1763 XMoveWindow(dpy, wwin->client_win, 0, y);
1764 if (s > 0) {
1765 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
1766 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1767 XMoveWindow(dpy, wwin->client_win, 0, y);
1768 XFlush(dpy);
1769 if (SHADE_DELAY > 0) {
1770 wusleep(SHADE_DELAY * 2000L / 3);
1771 } else {
1772 wusleep(10);
1774 h += s;
1775 y += s;
1777 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1778 break;
1781 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1782 break;
1785 #endif