Increase the readability of wUnshadeWindow() and wShadeWindow() a little bit
[wmaker-crm.git] / src / actions.c
blob5bdd418ce8a3aec5044b968b4f135f79077b324f
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 "wsound.h"
50 #include "xinerama.h"
52 /****** Global Variables ******/
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();
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 wSoundPlay(WSOUND_SHADE);
230 shade_animate(wwin, SHADE);
232 wwin->flags.skip_next_animation = 0;
233 wwin->flags.shaded = 1;
234 wwin->flags.mapped = 0;
235 /* prevent window withdrawal when getting UnmapNotify */
236 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
237 XUnmapWindow(dpy, wwin->client_win);
238 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
240 /* for the client it's just like iconification */
241 wFrameWindowResize(wwin->frame, wwin->frame->core->width, wwin->frame->top_width - 1);
243 wwin->client.y = wwin->frame_y - wwin->client.height + wwin->frame->top_width;
244 wWindowSynthConfigureNotify(wwin);
247 wClientSetState(wwin, IconicState, None);
250 WMPostNotificationName(WMNChangedState, wwin, "shade");
252 #ifdef ANIMATIONS
253 if (!wwin->screen_ptr->flags.startup) {
254 /* Catch up with events not processed while animation was running */
255 ProcessPendingEvents();
257 #endif
260 void wUnshadeWindow(WWindow *wwin)
263 if (!wwin->flags.shaded)
264 return;
266 wwin->flags.shaded = 0;
267 wwin->flags.mapped = 1;
268 XMapWindow(dpy, wwin->client_win);
270 wSoundPlay(WSOUND_UNSHADE);
271 shade_animate(wwin, UNSHADE);
273 wwin->flags.skip_next_animation = 0;
274 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
275 wwin->frame->top_width + wwin->client.height + wwin->frame->bottom_width);
277 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
278 wWindowSynthConfigureNotify(wwin);
281 wClientSetState(wwin, NormalState, None);
283 /* if the window is focused, set the focus again as it was disabled during
284 * shading */
285 if (wwin->flags.focused)
286 wSetFocusTo(wwin->screen_ptr, wwin);
288 WMPostNotificationName(WMNChangedState, wwin, "shade");
291 void wMaximizeWindow(WWindow * wwin, int directions)
293 int new_x, new_y;
294 unsigned int new_width, new_height;
295 int changed_h, changed_v, shrink_h, shrink_v;
296 WArea usableArea, totalArea;
298 if (!IS_RESIZABLE(wwin))
299 return;
301 totalArea.x1 = 0;
302 totalArea.y1 = 0;
303 totalArea.x2 = wwin->screen_ptr->scr_width;
304 totalArea.y2 = wwin->screen_ptr->scr_height;
305 usableArea = totalArea;
307 if (!(directions & MAX_IGNORE_XINERAMA)) {
308 WScreen *scr = wwin->screen_ptr;
309 int head;
311 if (directions & MAX_KEYBOARD)
312 head = wGetHeadForWindow(wwin);
313 else
314 head = wGetHeadForPointerLocation(scr);
316 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
319 if (WFLAGP(wwin, full_maximize)) {
320 usableArea = totalArea;
323 if (wwin->flags.shaded) {
324 wwin->flags.skip_next_animation = 1;
325 wUnshadeWindow(wwin);
327 /* Only save directions, not kbd or xinerama hints */
328 directions &= (MAX_HORIZONTAL|MAX_VERTICAL|MAX_LEFTHALF|MAX_RIGHTHALF);
330 changed_h = ((wwin->flags.maximized ^ directions) & MAX_HORIZONTAL);
331 changed_v = ((wwin->flags.maximized ^ directions) & MAX_VERTICAL);
332 shrink_h = (changed_h && (directions & MAX_HORIZONTAL) == 0);
333 shrink_v = (changed_v && (directions & MAX_VERTICAL) == 0);
335 if (wwin->flags.maximized) {
336 /* if already maximized in some direction, we only update the
337 * appropriate old x, old y coordinates. This is necessary to
338 * allow succesive maximizations in different directions without
339 * the need to first do an un-maximize (to avoid flicker).
341 if (!(wwin->flags.maximized & (MAX_HORIZONTAL|MAX_LEFTHALF|MAX_RIGHTHALF))) {
342 wwin->old_geometry.x = wwin->frame_x;
344 if (!(wwin->flags.maximized & MAX_VERTICAL)) {
345 wwin->old_geometry.y = wwin->frame_y;
347 } else {
348 wwin->old_geometry.width = wwin->client.width;
349 wwin->old_geometry.height = wwin->client.height;
350 wwin->old_geometry.x = wwin->frame_x;
351 wwin->old_geometry.y = wwin->frame_y;
353 wwin->flags.maximized = directions;
355 if (directions & MAX_HORIZONTAL) {
356 new_width = usableArea.x2 - usableArea.x1;
357 if (HAS_BORDER(wwin))
358 new_width -= FRAME_BORDER_WIDTH * 2;
359 new_x = usableArea.x1;
360 } else if (directions & MAX_LEFTHALF) {
361 new_width = (usableArea.x2 - usableArea.x1)/2;
362 if (HAS_BORDER(wwin))
363 new_width -= FRAME_BORDER_WIDTH * 2;
364 new_x = usableArea.x1;
365 } else if (directions & MAX_RIGHTHALF) {
366 new_width = (usableArea.x2 - usableArea.x1)/2;
367 if (HAS_BORDER(wwin))
368 new_width -= FRAME_BORDER_WIDTH * 2;
369 new_x = usableArea.x1+((usableArea.x2 - usableArea.x1)/2);
370 } else if (shrink_h) {
371 new_x = wwin->old_geometry.x;
372 new_width = wwin->old_geometry.width;
373 } else {
374 new_x = wwin->frame_x;
375 new_width = wwin->frame->core->width;
378 if (directions & MAX_VERTICAL) {
379 new_height = usableArea.y2 - usableArea.y1;
380 if (HAS_BORDER(wwin))
381 new_height -= FRAME_BORDER_WIDTH * 2;
382 new_y = usableArea.y1;
383 if (WFLAGP(wwin, full_maximize)) {
384 new_y -= wwin->frame->top_width;
385 new_height += wwin->frame->bottom_width - 1;
387 } else if (shrink_v) {
388 new_y = wwin->old_geometry.y;
389 new_height = wwin->old_geometry.height;
390 } else {
391 new_y = wwin->frame_y;
392 new_height = wwin->frame->core->height;
395 if (!WFLAGP(wwin, full_maximize)) {
396 new_height -= wwin->frame->top_width + wwin->frame->bottom_width;
399 wWindowConstrainSize(wwin, &new_width, &new_height);
401 wWindowCropSize(wwin, usableArea.x2 - usableArea.x1,
402 usableArea.y2 - usableArea.y1, &new_width, &new_height);
404 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
406 WMPostNotificationName(WMNChangedState, wwin, "maximize");
408 wSoundPlay(WSOUND_MAXIMIZE);
411 void wUnmaximizeWindow(WWindow * wwin)
413 int x, y, w, h;
415 if (!wwin->flags.maximized)
416 return;
418 if (wwin->flags.shaded) {
419 wwin->flags.skip_next_animation = 1;
420 wUnshadeWindow(wwin);
422 x = ((wwin->flags.maximized & (MAX_HORIZONTAL|MAX_LEFTHALF|MAX_RIGHTHALF)) && wwin->old_geometry.x) ?
423 wwin->old_geometry.x : wwin->frame_x;
424 y = ((wwin->flags.maximized & MAX_VERTICAL) && wwin->old_geometry.y) ?
425 wwin->old_geometry.y : wwin->frame_y;
426 w = wwin->old_geometry.width ? wwin->old_geometry.width : wwin->client.width;
427 h = wwin->old_geometry.height ? wwin->old_geometry.height : wwin->client.height;
429 wwin->flags.maximized = 0;
430 wWindowConfigure(wwin, x, y, w, h);
432 WMPostNotificationName(WMNChangedState, wwin, "maximize");
434 wSoundPlay(WSOUND_UNMAXIMIZE);
437 void wFullscreenWindow(WWindow * wwin)
439 int head;
440 WMRect rect;
442 if (wwin->flags.fullscreen)
443 return;
445 wwin->flags.fullscreen = True;
447 wWindowConfigureBorders(wwin);
449 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
451 wwin->bfs_geometry.x = wwin->frame_x;
452 wwin->bfs_geometry.y = wwin->frame_y;
453 wwin->bfs_geometry.width = wwin->frame->core->width;
454 wwin->bfs_geometry.height = wwin->frame->core->height;
456 head = wGetHeadForWindow(wwin);
457 rect = wGetRectForHead(wwin->screen_ptr, head);
458 wWindowConfigure(wwin, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
460 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
463 void wUnfullscreenWindow(WWindow * wwin)
465 if (!wwin->flags.fullscreen)
466 return;
468 wwin->flags.fullscreen = False;
470 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
471 if (WFLAGP(wwin, sunken)) {
472 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
473 } else if (WFLAGP(wwin, floating)) {
474 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
475 } else {
476 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
480 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
481 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
483 wWindowConfigureBorders(wwin);
485 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
486 wFrameWindowPaint(wwin->frame);
489 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
492 #ifdef ANIMATIONS
493 static void animateResizeFlip(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
495 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
496 float cx, cy, cw, ch;
497 float xstep, ystep, wstep, hstep;
498 XPoint points[5];
499 float dx, dch, midy;
500 float angle, final_angle, delta;
502 xstep = (float)(fx - x) / steps;
503 ystep = (float)(fy - y) / steps;
504 wstep = (float)(fw - w) / steps;
505 hstep = (float)(fh - h) / steps;
507 cx = (float)x;
508 cy = (float)y;
509 cw = (float)w;
510 ch = (float)h;
512 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_F;
513 delta = (float)(final_angle / FRAMES);
514 for (angle = 0;; angle += delta) {
515 if (angle > final_angle)
516 angle = final_angle;
518 dx = (cw / 10) - ((cw / 5) * sin(angle));
519 dch = (ch / 2) * cos(angle);
520 midy = cy + (ch / 2);
522 points[0].x = cx + dx;
523 points[0].y = midy - dch;
524 points[1].x = cx + cw - dx;
525 points[1].y = points[0].y;
526 points[2].x = cx + cw + dx;
527 points[2].y = midy + dch;
528 points[3].x = cx - dx;
529 points[3].y = points[2].y;
530 points[4].x = points[0].x;
531 points[4].y = points[0].y;
533 XGrabServer(dpy);
534 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
535 XFlush(dpy);
536 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
537 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
538 #else
539 wusleep(10);
540 #endif
542 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
543 XUngrabServer(dpy);
544 cx += xstep;
545 cy += ystep;
546 cw += wstep;
547 ch += hstep;
548 if (angle >= final_angle)
549 break;
552 XFlush(dpy);
555 #undef FRAMES
557 static void
558 animateResizeTwist(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
560 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
561 float cx, cy, cw, ch;
562 float xstep, ystep, wstep, hstep;
563 XPoint points[5];
564 float angle, final_angle, a, d, delta;
566 x += w / 2;
567 y += h / 2;
568 fx += fw / 2;
569 fy += fh / 2;
571 xstep = (float)(fx - x) / steps;
572 ystep = (float)(fy - y) / steps;
573 wstep = (float)(fw - w) / steps;
574 hstep = (float)(fh - h) / steps;
576 cx = (float)x;
577 cy = (float)y;
578 cw = (float)w;
579 ch = (float)h;
581 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_T;
582 delta = (float)(final_angle / FRAMES);
583 for (angle = 0;; angle += delta) {
584 if (angle > final_angle)
585 angle = final_angle;
587 a = atan(ch / cw);
588 d = sqrt((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
590 points[0].x = cx + cos(angle - a) * d;
591 points[0].y = cy + sin(angle - a) * d;
592 points[1].x = cx + cos(angle + a) * d;
593 points[1].y = cy + sin(angle + a) * d;
594 points[2].x = cx + cos(angle - a + WM_PI) * d;
595 points[2].y = cy + sin(angle - a + WM_PI) * d;
596 points[3].x = cx + cos(angle + a + WM_PI) * d;
597 points[3].y = cy + sin(angle + a + WM_PI) * d;
598 points[4].x = cx + cos(angle - a) * d;
599 points[4].y = cy + sin(angle - a) * d;
600 XGrabServer(dpy);
601 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
602 XFlush(dpy);
603 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
604 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
605 #else
606 wusleep(10);
607 #endif
609 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
610 XUngrabServer(dpy);
611 cx += xstep;
612 cy += ystep;
613 cw += wstep;
614 ch += hstep;
615 if (angle >= final_angle)
616 break;
619 XFlush(dpy);
622 #undef FRAMES
624 static void animateResizeZoom(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
626 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
627 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
628 float xstep, ystep, wstep, hstep;
629 int i, j;
631 xstep = (float)(fx - x) / steps;
632 ystep = (float)(fy - y) / steps;
633 wstep = (float)(fw - w) / steps;
634 hstep = (float)(fh - h) / steps;
636 for (j = 0; j < FRAMES; j++) {
637 cx[j] = (float)x;
638 cy[j] = (float)y;
639 cw[j] = (float)w;
640 ch[j] = (float)h;
642 XGrabServer(dpy);
643 for (i = 0; i < steps; i++) {
644 for (j = 0; j < FRAMES; j++) {
645 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
646 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
648 XFlush(dpy);
649 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
650 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
651 #else
652 wusleep(10);
653 #endif
654 for (j = 0; j < FRAMES; j++) {
655 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
656 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
657 if (j < FRAMES - 1) {
658 cx[j] = cx[j + 1];
659 cy[j] = cy[j + 1];
660 cw[j] = cw[j + 1];
661 ch[j] = ch[j + 1];
662 } else {
663 cx[j] += xstep;
664 cy[j] += ystep;
665 cw[j] += wstep;
666 ch[j] += hstep;
671 for (j = 0; j < FRAMES; j++) {
672 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
674 XFlush(dpy);
675 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
676 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
677 #else
678 wusleep(10);
679 #endif
680 for (j = 0; j < FRAMES; j++) {
681 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
684 XUngrabServer(dpy);
687 #undef FRAMES
689 void animateResize(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int hiding)
691 int style = wPreferences.iconification_style; /* Catch the value */
692 int steps, k;
694 if (style == WIS_NONE)
695 return;
697 if (style == WIS_RANDOM) {
698 style = rand() % 3;
701 k = (hiding ? 2 : 3);
703 switch (style) {
704 case WIS_TWIST:
705 steps = (MINIATURIZE_ANIMATION_STEPS_T * k) / 3;
706 if (steps > 0)
707 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
708 break;
709 case WIS_FLIP:
710 steps = (MINIATURIZE_ANIMATION_STEPS_F * k) / 3;
711 if (steps > 0)
712 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
713 break;
714 case WIS_ZOOM:
715 default:
716 steps = (MINIATURIZE_ANIMATION_STEPS_Z * k) / 3;
717 if (steps > 0)
718 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
719 break;
722 #endif /* ANIMATIONS */
724 static void flushExpose()
726 XEvent tmpev;
728 while (XCheckTypedEvent(dpy, Expose, &tmpev))
729 WMHandleEvent(&tmpev);
730 XSync(dpy, 0);
733 static void unmapTransientsFor(WWindow * wwin)
735 WWindow *tmp;
737 tmp = wwin->screen_ptr->focused_window;
738 while (tmp) {
739 /* unmap the transients for this transient */
740 if (tmp != wwin && tmp->transient_for == wwin->client_win
741 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup || tmp->flags.shaded)) {
742 unmapTransientsFor(tmp);
743 tmp->flags.miniaturized = 1;
744 if (!tmp->flags.shaded) {
745 wWindowUnmap(tmp);
746 } else {
747 XUnmapWindow(dpy, tmp->frame->core->window);
750 if (!tmp->flags.shaded)
752 wClientSetState(tmp, IconicState, None);
754 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
756 tmp = tmp->prev;
760 static void mapTransientsFor(WWindow * wwin)
762 WWindow *tmp;
764 tmp = wwin->screen_ptr->focused_window;
765 while (tmp) {
766 /* recursively map the transients for this transient */
767 if (tmp != wwin && tmp->transient_for == wwin->client_win && /*!tmp->flags.mapped */ tmp->flags.miniaturized
768 && tmp->icon == NULL) {
769 mapTransientsFor(tmp);
770 tmp->flags.miniaturized = 0;
771 if (!tmp->flags.shaded) {
772 wWindowMap(tmp);
773 } else {
774 XMapWindow(dpy, tmp->frame->core->window);
776 tmp->flags.semi_focused = 0;
778 if (!tmp->flags.shaded)
780 wClientSetState(tmp, NormalState, None);
782 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
784 tmp = tmp->prev;
788 #if 0
789 static void setupIconGrabs(WIcon * icon)
791 /* setup passive grabs on the icon */
792 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
793 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
794 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
795 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
796 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
797 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
798 XSync(dpy, 0);
800 #endif
802 static WWindow *recursiveTransientFor(WWindow * wwin)
804 int i;
806 if (!wwin)
807 return None;
809 /* hackish way to detect transient_for cycle */
810 i = wwin->screen_ptr->window_count + 1;
812 while (wwin && wwin->transient_for != None && i > 0) {
813 wwin = wWindowFor(wwin->transient_for);
814 i--;
816 if (i == 0 && wwin) {
817 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin->frame->title);
818 return NULL;
821 return wwin;
824 #if 0
825 static void removeIconGrabs(WIcon * icon)
827 /* remove passive grabs on the icon */
828 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
829 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
830 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
831 XSync(dpy, 0);
833 #endif
835 void wIconifyWindow(WWindow * wwin)
837 XWindowAttributes attribs;
838 int present;
840 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
841 /* the window doesn't exist anymore */
842 return;
845 if (wwin->flags.miniaturized) {
846 return;
849 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
850 WWindow *owner = wWindowFor(wwin->transient_for);
852 if (owner && owner->flags.miniaturized)
853 return;
856 present = wwin->frame->workspace == wwin->screen_ptr->current_workspace;
858 /* if the window is in another workspace, simplify process */
859 if (present) {
860 /* icon creation may take a while */
861 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
862 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
863 GrabModeAsync, None, None, CurrentTime);
866 if (!wPreferences.disable_miniwindows
867 #ifdef NETWM_HINTS
868 && !wwin->flags.net_handle_icon
869 #endif
871 if (!wwin->flags.icon_moved) {
872 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
874 wwin->icon = wIconCreate(wwin);
876 wwin->icon->mapped = 1;
879 wwin->flags.miniaturized = 1;
880 wwin->flags.mapped = 0;
882 /* unmap transients */
884 unmapTransientsFor(wwin);
886 if (present) {
887 wSoundPlay(WSOUND_ICONIFY);
889 XUngrabPointer(dpy, CurrentTime);
890 wWindowUnmap(wwin);
891 /* let all Expose events arrive so that we can repaint
892 * something before the animation starts (and the server is grabbed) */
893 XSync(dpy, 0);
895 if (wPreferences.disable_miniwindows
896 #ifdef NETWM_HINTS
897 || wwin->flags.net_handle_icon
898 #endif
900 wClientSetState(wwin, IconicState, None);
901 else
902 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
904 flushExpose();
905 #ifdef ANIMATIONS
906 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
907 && !wPreferences.no_animations) {
908 int ix, iy, iw, ih;
910 if (!wPreferences.disable_miniwindows
911 #ifdef NETWM_HINTS
912 && !wwin->flags.net_handle_icon
913 #endif
915 ix = wwin->icon_x;
916 iy = wwin->icon_y;
917 iw = wwin->icon->core->width;
918 ih = wwin->icon->core->height;
919 } else {
920 #ifdef NETWM_HINTS
921 if (wwin->flags.net_handle_icon) {
922 ix = wwin->icon_x;
923 iy = wwin->icon_y;
924 iw = wwin->icon_w;
925 ih = wwin->icon_h;
926 } else
927 #endif
929 ix = 0;
930 iy = 0;
931 iw = wwin->screen_ptr->scr_width;
932 ih = wwin->screen_ptr->scr_height;
935 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
936 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih, False);
938 #endif
941 wwin->flags.skip_next_animation = 0;
943 if (!wPreferences.disable_miniwindows
944 #ifdef NETWM_HINTS
945 && !wwin->flags.net_handle_icon
946 #endif
949 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace ||
950 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
952 XMapWindow(dpy, wwin->icon->core->window);
954 AddToStackList(wwin->icon->core);
956 wLowerFrame(wwin->icon->core);
959 if (present) {
960 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
963 * It doesn't seem to be working and causes button event hangup
964 * when deiconifying a transient window.
965 setupIconGrabs(wwin->icon);
967 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
968 && wPreferences.focus_mode == WKF_CLICK) {
969 WWindow *tmp;
971 tmp = wwin->prev;
972 while (tmp) {
973 if (!WFLAGP(tmp, no_focusable)
974 && !(tmp->flags.hidden || tmp->flags.miniaturized)
975 && (wwin->frame->workspace == tmp->frame->workspace))
976 break;
977 tmp = tmp->prev;
979 wSetFocusTo(wwin->screen_ptr, tmp);
980 } else if (wPreferences.focus_mode != WKF_CLICK) {
981 wSetFocusTo(wwin->screen_ptr, NULL);
983 #ifdef ANIMATIONS
984 if (!wwin->screen_ptr->flags.startup) {
985 /* Catch up with events not processed while animation was running */
986 Window clientwin = wwin->client_win;
988 ProcessPendingEvents();
990 /* the window can disappear while ProcessPendingEvents() runs */
991 if (!wWindowFor(clientwin)) {
992 return;
995 #endif
998 /* maybe we want to do this regardless of net_handle_icon
999 * it seems to me we might break behaviour this way.
1001 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1002 #ifdef NETWM_HINTS
1003 && !wwin->flags.net_handle_icon
1004 #endif
1006 wIconSelect(wwin->icon);
1008 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1011 void wDeiconifyWindow(WWindow * wwin)
1013 #ifdef NETWM_HINTS
1014 /* we're hiding for show_desktop */
1015 int netwm_hidden = wwin->flags.net_show_desktop &&
1016 wwin->frame->workspace != wwin->screen_ptr->current_workspace;
1017 #else
1018 int netwm_hidden = False;
1019 #endif
1021 if (!netwm_hidden)
1022 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1024 if (!wwin->flags.miniaturized)
1025 return;
1027 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1028 WWindow *owner = recursiveTransientFor(wwin);
1030 if (owner && owner->flags.miniaturized) {
1031 wDeiconifyWindow(owner);
1032 wSetFocusTo(wwin->screen_ptr, wwin);
1033 wRaiseFrame(wwin->frame->core);
1034 return;
1038 wwin->flags.miniaturized = 0;
1040 if (!netwm_hidden && !wwin->flags.shaded) {
1041 wwin->flags.mapped = 1;
1044 if (!netwm_hidden || wPreferences.sticky_icons) {
1045 /* maybe we want to do this regardless of net_handle_icon
1046 * it seems to me we might break behaviour this way.
1048 if (!wPreferences.disable_miniwindows
1049 #ifdef NETWM_HINTS
1050 && !wwin->flags.net_handle_icon
1051 #endif
1052 && wwin->icon != NULL) {
1053 if (wwin->icon->selected)
1054 wIconSelect(wwin->icon);
1056 XUnmapWindow(dpy, wwin->icon->core->window);
1060 if (!netwm_hidden)
1061 wSoundPlay(WSOUND_DEICONIFY);
1063 /* if the window is in another workspace, do it silently */
1064 if (!netwm_hidden) {
1065 #ifdef ANIMATIONS
1066 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1067 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1068 int ix, iy, iw, ih;
1070 if (!wPreferences.disable_miniwindows
1071 #ifdef NETWM_HINTS
1072 && !wwin->flags.net_handle_icon
1073 #endif
1075 ix = wwin->icon_x;
1076 iy = wwin->icon_y;
1077 iw = wwin->icon->core->width;
1078 ih = wwin->icon->core->height;
1079 } else {
1080 #ifdef NETWM_HINTS
1081 if (wwin->flags.net_handle_icon) {
1082 ix = wwin->icon_x;
1083 iy = wwin->icon_y;
1084 iw = wwin->icon_w;
1085 ih = wwin->icon_h;
1086 } else
1087 #endif
1089 ix = 0;
1090 iy = 0;
1091 iw = wwin->screen_ptr->scr_width;
1092 ih = wwin->screen_ptr->scr_height;
1095 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1096 wwin->frame_x, wwin->frame_y,
1097 wwin->frame->core->width, wwin->frame->core->height, False);
1099 #endif /* ANIMATIONS */
1100 wwin->flags.skip_next_animation = 0;
1101 XGrabServer(dpy);
1102 if (!wwin->flags.shaded) {
1103 XMapWindow(dpy, wwin->client_win);
1105 XMapWindow(dpy, wwin->frame->core->window);
1106 wRaiseFrame(wwin->frame->core);
1107 if (!wwin->flags.shaded) {
1108 wClientSetState(wwin, NormalState, None);
1110 mapTransientsFor(wwin);
1113 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1114 #ifdef NETWM_HINTS
1115 && !wwin->flags.net_handle_icon
1116 #endif
1118 RemoveFromStackList(wwin->icon->core);
1119 /* removeIconGrabs(wwin->icon); */
1120 wIconDestroy(wwin->icon);
1121 wwin->icon = NULL;
1124 if (!netwm_hidden) {
1125 XUngrabServer(dpy);
1127 wSetFocusTo(wwin->screen_ptr, wwin);
1129 #ifdef ANIMATIONS
1130 if (!wwin->screen_ptr->flags.startup) {
1131 /* Catch up with events not processed while animation was running */
1132 Window clientwin = wwin->client_win;
1134 ProcessPendingEvents();
1136 /* the window can disappear while ProcessPendingEvents() runs */
1137 if (!wWindowFor(clientwin)) {
1138 return;
1141 #endif
1144 if (wPreferences.auto_arrange_icons) {
1145 wArrangeIcons(wwin->screen_ptr, True);
1148 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1150 /* In case we were shaded and iconified, also unshade */
1151 if (!netwm_hidden)
1152 wUnshadeWindow(wwin);
1155 static void hideWindow(WIcon * icon, int icon_x, int icon_y, WWindow * wwin, int animate)
1157 if (wwin->flags.miniaturized) {
1158 if (wwin->icon) {
1159 XUnmapWindow(dpy, wwin->icon->core->window);
1160 wwin->icon->mapped = 0;
1162 wwin->flags.hidden = 1;
1164 WMPostNotificationName(WMNChangedState, wwin, "hide");
1165 return;
1168 if (wwin->flags.inspector_open) {
1169 wHideInspectorForWindow(wwin);
1172 wwin->flags.hidden = 1;
1173 wWindowUnmap(wwin);
1175 wClientSetState(wwin, IconicState, icon->icon_win);
1176 flushExpose();
1177 wSoundPlay(WSOUND_HIDE);
1178 #ifdef ANIMATIONS
1179 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1180 !wwin->flags.skip_next_animation && animate) {
1181 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1182 wwin->frame->core->width, wwin->frame->core->height,
1183 icon_x, icon_y, icon->core->width, icon->core->height, True);
1185 #endif
1186 wwin->flags.skip_next_animation = 0;
1188 WMPostNotificationName(WMNChangedState, wwin, "hide");
1191 void wHideOtherApplications(WWindow * awin)
1193 WWindow *wwin;
1194 WApplication *tapp;
1196 if (!awin)
1197 return;
1198 wwin = awin->screen_ptr->focused_window;
1200 while (wwin) {
1201 if (wwin != awin
1202 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1203 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1204 && !wwin->flags.internal_window
1205 && wGetWindowOfInspectorForWindow(wwin) != awin && !WFLAGP(wwin, no_hide_others)) {
1207 if (wwin->main_window == None || WFLAGP(wwin, no_appicon)) {
1208 if (!WFLAGP(wwin, no_miniaturizable)) {
1209 wwin->flags.skip_next_animation = 1;
1210 wIconifyWindow(wwin);
1212 } else if (wwin->main_window != None && awin->main_window != wwin->main_window) {
1213 tapp = wApplicationOf(wwin->main_window);
1214 if (tapp) {
1215 tapp->flags.skip_next_animation = 1;
1216 wHideApplication(tapp);
1217 } else {
1218 if (!WFLAGP(wwin, no_miniaturizable)) {
1219 wwin->flags.skip_next_animation = 1;
1220 wIconifyWindow(wwin);
1225 wwin = wwin->prev;
1228 wSetFocusTo(awin->screen_ptr, awin);
1232 void wHideApplication(WApplication * wapp)
1234 WScreen *scr;
1235 WWindow *wlist;
1236 int hadfocus;
1237 int animate;
1239 if (!wapp) {
1240 wwarning("trying to hide a non grouped window");
1241 return;
1243 if (!wapp->main_window_desc) {
1244 wwarning("group leader not found for window group");
1245 return;
1247 scr = wapp->main_window_desc->screen_ptr;
1248 hadfocus = 0;
1249 wlist = scr->focused_window;
1250 if (!wlist)
1251 return;
1253 if (wlist->main_window == wapp->main_window)
1254 wapp->last_focused = wlist;
1255 else
1256 wapp->last_focused = NULL;
1258 animate = !wapp->flags.skip_next_animation;
1260 while (wlist) {
1261 if (wlist->main_window == wapp->main_window) {
1262 if (wlist->flags.focused) {
1263 hadfocus = 1;
1265 if (wapp->app_icon) {
1266 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1267 wapp->app_icon->y_pos, wlist, animate);
1268 animate = False;
1271 wlist = wlist->prev;
1274 wapp->flags.skip_next_animation = 0;
1276 if (hadfocus) {
1277 if (wPreferences.focus_mode == WKF_CLICK) {
1278 wlist = scr->focused_window;
1279 while (wlist) {
1280 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1281 && (wlist->flags.mapped || wlist->flags.shaded))
1282 break;
1283 wlist = wlist->prev;
1285 wSetFocusTo(scr, wlist);
1286 } else {
1287 wSetFocusTo(scr, NULL);
1291 wapp->flags.hidden = 1;
1293 if (wPreferences.auto_arrange_icons) {
1294 wArrangeIcons(scr, True);
1296 #ifdef HIDDENDOT
1297 if (wapp->app_icon)
1298 wAppIconPaint(wapp->app_icon);
1299 #endif
1302 static void unhideWindow(WIcon * icon, int icon_x, int icon_y, WWindow * wwin, int animate, int bringToCurrentWS)
1304 if (bringToCurrentWS)
1305 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1307 wwin->flags.hidden = 0;
1309 wSoundPlay(WSOUND_UNHIDE);
1310 #ifdef ANIMATIONS
1311 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1312 animateResize(wwin->screen_ptr, icon_x, icon_y,
1313 icon->core->width, icon->core->height,
1314 wwin->frame_x, wwin->frame_y,
1315 wwin->frame->core->width, wwin->frame->core->height, True);
1317 #endif
1318 wwin->flags.skip_next_animation = 0;
1319 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1320 XMapWindow(dpy, wwin->client_win);
1321 XMapWindow(dpy, wwin->frame->core->window);
1322 wClientSetState(wwin, NormalState, None);
1323 wwin->flags.mapped = 1;
1324 wRaiseFrame(wwin->frame->core);
1326 if (wwin->flags.inspector_open) {
1327 wUnhideInspectorForWindow(wwin);
1330 WMPostNotificationName(WMNChangedState, wwin, "hide");
1333 void wUnhideApplication(WApplication * wapp, Bool miniwindows, Bool bringToCurrentWS)
1335 WScreen *scr;
1336 WWindow *wlist, *next;
1337 WWindow *focused = NULL;
1338 int animate;
1340 if (!wapp)
1341 return;
1343 scr = wapp->main_window_desc->screen_ptr;
1344 wlist = scr->focused_window;
1345 if (!wlist)
1346 return;
1348 /* goto beginning of list */
1349 while (wlist->prev)
1350 wlist = wlist->prev;
1352 animate = !wapp->flags.skip_next_animation;
1354 while (wlist) {
1355 next = wlist->next;
1357 if (wlist->main_window == wapp->main_window) {
1358 if (wlist->flags.focused)
1359 focused = wlist;
1360 else if (!focused || !focused->flags.focused)
1361 focused = wlist;
1363 if (wlist->flags.miniaturized) {
1364 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1365 wlist->frame->workspace == scr->current_workspace) && wlist->icon) {
1366 if (!wlist->icon->mapped) {
1367 int x, y;
1369 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1370 if (wlist->icon_x != x || wlist->icon_y != y) {
1371 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1373 wlist->icon_x = x;
1374 wlist->icon_y = y;
1375 XMapWindow(dpy, wlist->icon->core->window);
1376 wlist->icon->mapped = 1;
1378 wRaiseFrame(wlist->icon->core);
1380 if (bringToCurrentWS)
1381 wWindowChangeWorkspace(wlist, scr->current_workspace);
1382 wlist->flags.hidden = 0;
1383 if (miniwindows && wlist->frame->workspace == scr->current_workspace) {
1384 wDeiconifyWindow(wlist);
1386 WMPostNotificationName(WMNChangedState, wlist, "hide");
1387 } else if (wlist->flags.shaded) {
1388 if (bringToCurrentWS)
1389 wWindowChangeWorkspace(wlist, scr->current_workspace);
1390 wlist->flags.hidden = 0;
1391 if (wlist->frame->workspace == scr->current_workspace) {
1392 XMapWindow(dpy, wlist->frame->core->window);
1393 if (miniwindows) {
1394 wUnshadeWindow(wlist);
1395 wRaiseFrame(wlist->frame->core);
1398 WMPostNotificationName(WMNChangedState, wlist, "hide");
1399 } else if (wlist->flags.hidden) {
1400 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1401 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1402 animate = False;
1403 } else {
1404 if (bringToCurrentWS && wlist->frame->workspace != scr->current_workspace) {
1405 wWindowChangeWorkspace(wlist, scr->current_workspace);
1407 wRaiseFrame(wlist->frame->core);
1410 wlist = next;
1413 wapp->flags.skip_next_animation = 0;
1414 wapp->flags.hidden = 0;
1416 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1417 wRaiseFrame(wapp->last_focused->frame->core);
1418 wSetFocusTo(scr, wapp->last_focused);
1419 } else if (focused) {
1420 wSetFocusTo(scr, focused);
1422 wapp->last_focused = NULL;
1423 if (wPreferences.auto_arrange_icons) {
1424 wArrangeIcons(scr, True);
1426 #ifdef HIDDENDOT
1427 wAppIconPaint(wapp->app_icon);
1428 #endif
1431 void wShowAllWindows(WScreen * scr)
1433 WWindow *wwin, *old_foc;
1434 WApplication *wapp;
1436 old_foc = wwin = scr->focused_window;
1437 while (wwin) {
1438 if (!wwin->flags.internal_window &&
1439 (scr->current_workspace == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1440 if (wwin->flags.miniaturized) {
1441 wwin->flags.skip_next_animation = 1;
1442 wDeiconifyWindow(wwin);
1443 } else if (wwin->flags.hidden) {
1444 wapp = wApplicationOf(wwin->main_window);
1445 if (wapp) {
1446 wUnhideApplication(wapp, False, False);
1447 } else {
1448 wwin->flags.skip_next_animation = 1;
1449 wDeiconifyWindow(wwin);
1453 wwin = wwin->prev;
1455 wSetFocusTo(scr, old_foc);
1456 /*wRaiseFrame(old_foc->frame->core); */
1459 void wRefreshDesktop(WScreen * scr)
1461 Window win;
1462 XSetWindowAttributes attr;
1464 attr.backing_store = NotUseful;
1465 attr.save_under = False;
1466 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1467 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1468 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1469 XMapRaised(dpy, win);
1470 XDestroyWindow(dpy, win);
1471 XFlush(dpy);
1474 void wArrangeIcons(WScreen * scr, Bool arrangeAll)
1476 WWindow *wwin;
1477 WAppIcon *aicon;
1479 int head;
1480 const int heads = wXineramaHeads(scr);
1482 struct HeadVars {
1483 int pf; /* primary axis */
1484 int sf; /* secondary axis */
1485 int fullW;
1486 int fullH;
1487 int pi, si;
1488 int sx1, sx2, sy1, sy2; /* screen boundary */
1489 int sw, sh;
1490 int xo, yo;
1491 int xs, ys;
1492 } *vars;
1494 int isize = wPreferences.icon_size;
1496 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
1498 for (head = 0; head < heads; ++head) {
1499 #if 0
1500 WMRect rect = wGetRectForHead(scr, head);
1501 #else
1502 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1503 WMRect rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
1504 #endif
1506 vars[head].pi = vars[head].si = 0;
1507 vars[head].sx1 = rect.pos.x;
1508 vars[head].sy1 = rect.pos.y;
1509 vars[head].sw = rect.size.width;
1510 vars[head].sh = rect.size.height;
1511 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1512 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1514 #if 0
1515 if (scr->dock) {
1516 if (scr->dock->on_right_side)
1517 vars[head].sx2 -= isize + DOCK_EXTRA_SPACE;
1518 else
1519 vars[head].sx1 += isize + DOCK_EXTRA_SPACE;
1521 #endif
1523 vars[head].sw = isize * (vars[head].sw / isize);
1524 vars[head].sh = isize * (vars[head].sh / isize);
1525 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
1526 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
1528 /* icon yard boundaries */
1529 if (wPreferences.icon_yard & IY_VERT) {
1530 vars[head].pf = vars[head].fullH;
1531 vars[head].sf = vars[head].fullW;
1532 } else {
1533 vars[head].pf = vars[head].fullW;
1534 vars[head].sf = vars[head].fullH;
1536 if (wPreferences.icon_yard & IY_RIGHT) {
1537 vars[head].xo = vars[head].sx2 - isize;
1538 vars[head].xs = -1;
1539 } else {
1540 vars[head].xo = vars[head].sx1;
1541 vars[head].xs = 1;
1543 if (wPreferences.icon_yard & IY_TOP) {
1544 vars[head].yo = vars[head].sy1;
1545 vars[head].ys = 1;
1546 } else {
1547 vars[head].yo = vars[head].sy2 - isize;
1548 vars[head].ys = -1;
1552 #define X ((wPreferences.icon_yard & IY_VERT) \
1553 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1554 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1556 #define Y ((wPreferences.icon_yard & IY_VERT) \
1557 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1558 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1560 /* arrange application icons */
1561 aicon = scr->app_icon_list;
1562 /* reverse them to avoid unnecessarily sliding of icons */
1563 while (aicon && aicon->next)
1564 aicon = aicon->next;
1566 while (aicon) {
1567 if (!aicon->docked) {
1568 /* CHECK: can icon be NULL here ? */
1569 /* The intention here is to place the AppIcon on the head that
1570 * contains most of the applications _main_ window. */
1571 head = wGetHeadForWindow(aicon->icon->owner);
1573 if (aicon->x_pos != X || aicon->y_pos != Y) {
1574 #ifdef ANIMATIONS
1575 if (!wPreferences.no_animations) {
1576 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1578 #endif /* ANIMATIONS */
1580 wAppIconMove(aicon, X, Y);
1581 vars[head].pi++;
1582 if (vars[head].pi >= vars[head].pf) {
1583 vars[head].pi = 0;
1584 vars[head].si++;
1587 aicon = aicon->prev;
1590 /* arrange miniwindows */
1591 wwin = scr->focused_window;
1592 /* reverse them to avoid unnecessarily shuffling */
1593 while (wwin && wwin->prev)
1594 wwin = wwin->prev;
1596 while (wwin) {
1597 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1598 (wwin->frame->workspace == scr->current_workspace ||
1599 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1601 head = wGetHeadForWindow(wwin);
1603 if (arrangeAll || !wwin->flags.icon_moved) {
1604 if (wwin->icon_x != X || wwin->icon_y != Y) {
1605 #ifdef ANIMATIONS
1606 if (wPreferences.no_animations) {
1607 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1608 } else {
1609 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1610 wwin->icon_y, X, Y);
1612 #else
1613 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1614 #endif /* ANIMATIONS */
1616 wwin->icon_x = X;
1617 wwin->icon_y = Y;
1619 vars[head].pi++;
1620 if (vars[head].pi >= vars[head].pf) {
1621 vars[head].pi = 0;
1622 vars[head].si++;
1626 if (arrangeAll) {
1627 wwin->flags.icon_moved = 0;
1629 /* we reversed the order, so we use next */
1630 wwin = wwin->next;
1633 wfree(vars);
1636 #if 0
1637 void wArrangeIcons(WScreen * scr, Bool arrangeAll)
1639 WWindow *wwin;
1640 WAppIcon *aicon;
1641 int pf; /* primary axis */
1642 int sf; /* secondary axis */
1643 int fullW;
1644 int fullH;
1645 int pi, si;
1646 int sx1, sx2, sy1, sy2; /* screen boundary */
1647 int sw, sh;
1648 int xo, yo;
1649 int xs, ys;
1650 int isize = wPreferences.icon_size;
1653 * Find out screen boundaries.
1657 * Allows each head to have miniwindows
1659 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1661 sx1 = rect.pos.x;
1662 sy1 = rect.pos.y;
1663 sw = rect.size.width;
1664 sh = rect.size.height;
1665 sx2 = sx1 + sw;
1666 sy2 = sy1 + sh;
1667 if (scr->dock) {
1668 if (scr->dock->on_right_side)
1669 sx2 -= isize + DOCK_EXTRA_SPACE;
1670 else
1671 sx1 += isize + DOCK_EXTRA_SPACE;
1673 #if 0
1674 sw = isize * (scr->scr_width / isize);
1675 sh = isize * (scr->scr_height / isize);
1676 #else
1677 sw = isize * (sw / isize);
1678 sh = isize * (sh / isize);
1679 #endif
1680 fullW = (sx2 - sx1) / isize;
1681 fullH = (sy2 - sy1) / isize;
1683 /* icon yard boundaries */
1684 if (wPreferences.icon_yard & IY_VERT) {
1685 pf = fullH;
1686 sf = fullW;
1687 } else {
1688 pf = fullW;
1689 sf = fullH;
1691 if (wPreferences.icon_yard & IY_RIGHT) {
1692 xo = sx2 - isize;
1693 xs = -1;
1694 } else {
1695 xo = sx1;
1696 xs = 1;
1698 if (wPreferences.icon_yard & IY_TOP) {
1699 yo = sy1;
1700 ys = 1;
1701 } else {
1702 yo = sy2 - isize;
1703 ys = -1;
1706 /* arrange icons putting the most recently focused window
1707 * as the last icon */
1708 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1709 : xo + xs*(pi*isize))
1710 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1711 : yo + ys*(si*isize))
1713 /* arrange application icons */
1714 aicon = scr->app_icon_list;
1715 /* reverse them to avoid unnecessarily sliding of icons */
1716 while (aicon && aicon->next)
1717 aicon = aicon->next;
1719 pi = 0;
1720 si = 0;
1721 while (aicon) {
1722 if (!aicon->docked) {
1723 if (aicon->x_pos != X || aicon->y_pos != Y) {
1724 #ifdef ANIMATIONS
1725 if (!wPreferences.no_animations) {
1726 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1728 #endif /* ANIMATIONS */
1730 wAppIconMove(aicon, X, Y);
1731 pi++;
1733 /* we reversed the order so we use prev */
1734 aicon = aicon->prev;
1735 if (pi >= pf) {
1736 pi = 0;
1737 si++;
1741 /* arrange miniwindows */
1743 wwin = scr->focused_window;
1744 /* reverse them to avoid unnecessarily shuffling */
1745 while (wwin && wwin->prev)
1746 wwin = wwin->prev;
1748 while (wwin) {
1749 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1750 (wwin->frame->workspace == scr->current_workspace ||
1751 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1753 if (arrangeAll || !wwin->flags.icon_moved) {
1754 if (wwin->icon_x != X || wwin->icon_y != Y) {
1755 #ifdef ANIMATIONS
1756 if (wPreferences.no_animations) {
1757 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1758 } else {
1759 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1760 wwin->icon_y, X, Y);
1762 #else
1763 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1764 #endif /* ANIMATIONS */
1766 wwin->icon_x = X;
1767 wwin->icon_y = Y;
1768 pi++;
1771 if (arrangeAll) {
1772 wwin->flags.icon_moved = 0;
1774 /* we reversed the order, so we use next */
1775 wwin = wwin->next;
1776 if (pi >= pf) {
1777 pi = 0;
1778 si++;
1782 #endif
1784 void wSelectWindow(WWindow * wwin, Bool flag)
1786 WScreen *scr = wwin->screen_ptr;
1788 if (flag) {
1789 wwin->flags.selected = 1;
1790 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1792 if (!HAS_BORDER(wwin)) {
1793 XSetWindowBorderWidth(dpy, wwin->frame->core->window, FRAME_BORDER_WIDTH);
1796 if (!scr->selected_windows)
1797 scr->selected_windows = WMCreateArray(4);
1798 WMAddToArray(scr->selected_windows, wwin);
1799 } else {
1800 wwin->flags.selected = 0;
1801 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
1803 if (!HAS_BORDER(wwin)) {
1804 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1807 if (scr->selected_windows) {
1808 WMRemoveFromArray(scr->selected_windows, wwin);
1813 void wMakeWindowVisible(WWindow * wwin)
1815 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1816 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1818 if (wwin->flags.shaded) {
1819 wUnshadeWindow(wwin);
1821 if (wwin->flags.hidden) {
1822 WApplication *app;
1824 app = wApplicationOf(wwin->main_window);
1825 if (app) {
1826 /* trick to get focus to this window */
1827 app->last_focused = wwin;
1828 wUnhideApplication(app, False, False);
1831 if (wwin->flags.miniaturized) {
1832 wDeiconifyWindow(wwin);
1833 } else {
1834 if (!WFLAGP(wwin, no_focusable))
1835 wSetFocusTo(wwin->screen_ptr, wwin);
1836 wRaiseFrame(wwin->frame->core);
1841 * Do the animation while shading (called with what = SHADE)
1842 * or unshading (what = UNSHADE).
1844 #ifdef ANIMATIONS
1845 static void shade_animate(WWindow *wwin, Bool what)
1847 int y, s, w, h;
1848 time_t time0 = time(NULL);
1850 if (wwin->flags.skip_next_animation && wPreferences.no_animations)
1851 return;
1853 switch(what) {
1854 case SHADE:
1855 if (!wwin->screen_ptr->flags.startup) {
1856 /* do the shading animation */
1857 h = wwin->frame->core->height;
1858 s = h / SHADE_STEPS;
1859 if (s < 1)
1860 s = 1;
1861 w = wwin->frame->core->width;
1862 y = wwin->frame->top_width;
1863 while (h > wwin->frame->top_width + 1) {
1864 XMoveWindow(dpy, wwin->client_win, 0, y);
1865 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1866 XFlush(dpy);
1868 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1869 break;
1871 if (SHADE_DELAY > 0) {
1872 wusleep(SHADE_DELAY * 1000L);
1873 } else {
1874 wusleep(10);
1876 h -= s;
1877 y -= s;
1879 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1881 break;
1883 case UNSHADE:
1884 h = wwin->frame->top_width + wwin->frame->bottom_width;
1885 y = wwin->frame->top_width - wwin->client.height;
1886 s = abs(y) / SHADE_STEPS;
1887 if (s < 1)
1888 s = 1;
1889 w = wwin->frame->core->width;
1890 XMoveWindow(dpy, wwin->client_win, 0, y);
1891 if (s > 0) {
1892 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
1893 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1894 XMoveWindow(dpy, wwin->client_win, 0, y);
1895 XFlush(dpy);
1896 if (SHADE_DELAY > 0) {
1897 wusleep(SHADE_DELAY * 2000L / 3);
1898 } else {
1899 wusleep(10);
1901 h += s;
1902 y += s;
1904 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1905 break;
1908 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1909 break;
1912 #else
1913 static void shade_animate(WWindow *wwin, Bool what) { return; }
1914 #endif /* ANIMATIONS */