Maximus: Consider the full_maximize window attribute
[wmaker-crm.git] / src / actions.c
blob1a383f293c08fe1e0b11378b9a4faec585a387b5
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();
63 extern int calcIntersectionLength(int p1, int l1, int p2, int l2);
65 /******* Local Variables *******/
66 static struct {
67 int steps;
68 int delay;
69 } shadePars[5] = {
71 SHADE_STEPS_UF, SHADE_DELAY_UF}, {
72 SHADE_STEPS_F, SHADE_DELAY_F}, {
73 SHADE_STEPS_M, SHADE_DELAY_M}, {
74 SHADE_STEPS_S, SHADE_DELAY_S}, {
75 SHADE_STEPS_US, SHADE_DELAY_US}};
77 #define UNSHADE 0
78 #define SHADE 1
79 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
80 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
82 static int compareTimes(Time t1, Time t2)
84 Time diff;
85 if (t1 == t2)
86 return 0;
87 diff = t1 - t2;
88 return (diff < 60000) ? 1 : -1;
92 *----------------------------------------------------------------------
93 * wSetFocusTo--
94 * Changes the window focus to the one passed as argument.
95 * If the window to focus is not already focused, it will be brought
96 * to the head of the list of windows. Previously focused window is
97 * unfocused.
99 * Side effects:
100 * Window list may be reordered and the window focus is changed.
102 *----------------------------------------------------------------------
104 void wSetFocusTo(WScreen * scr, WWindow * wwin)
106 static WScreen *old_scr = NULL;
108 WWindow *old_focused;
109 WWindow *focused = scr->focused_window;
110 Time timestamp = LastTimestamp;
111 WApplication *oapp = NULL, *napp = NULL;
112 int wasfocused;
114 if (scr->flags.ignore_focus_events || compareTimes(LastFocusChange, timestamp) > 0)
115 return;
117 if (!old_scr)
118 old_scr = scr;
119 old_focused = old_scr->focused_window;
121 LastFocusChange = timestamp;
123 if (old_focused)
124 oapp = wApplicationOf(old_focused->main_window);
126 if (wwin == NULL) {
127 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
128 if (old_focused) {
129 wWindowUnfocus(old_focused);
131 if (oapp) {
132 wAppMenuUnmap(oapp->menu);
133 #ifdef NEWAPPICON
134 wApplicationDeactivate(oapp);
135 #endif
138 WMPostNotificationName(WMNChangedFocus, NULL, (void *)True);
139 return;
140 } else if (old_scr != scr && old_focused) {
141 wWindowUnfocus(old_focused);
144 wasfocused = wwin->flags.focused;
145 napp = wApplicationOf(wwin->main_window);
147 /* remember last workspace where the app has been */
148 if (napp) {
149 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
150 napp->last_workspace = wwin->frame->workspace;
153 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
154 /* install colormap if colormap mode is lock mode */
155 if (wPreferences.colormap_mode == WCM_CLICK)
156 wColormapInstallForWindow(scr, wwin);
158 /* set input focus */
159 switch (wwin->focus_mode) {
160 case WFM_NO_INPUT:
161 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
162 break;
164 case WFM_PASSIVE:
165 case WFM_LOCALLY_ACTIVE:
166 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
167 break;
169 case WFM_GLOBALLY_ACTIVE:
170 break;
172 XFlush(dpy);
173 if (wwin->protocols.TAKE_FOCUS) {
174 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
176 XSync(dpy, False);
177 } else {
178 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
180 if (WFLAGP(wwin, no_focusable))
181 return;
183 /* if this is not the focused window focus it */
184 if (focused != wwin) {
185 /* change the focus window list order */
186 if (wwin->prev)
187 wwin->prev->next = wwin->next;
189 if (wwin->next)
190 wwin->next->prev = wwin->prev;
192 wwin->prev = focused;
193 focused->next = wwin;
194 wwin->next = NULL;
195 scr->focused_window = wwin;
197 if (oapp && oapp != napp) {
198 wAppMenuUnmap(oapp->menu);
199 #ifdef NEWAPPICON
200 wApplicationDeactivate(oapp);
201 #endif
205 wWindowFocus(wwin, focused);
207 if (napp && !wasfocused) {
208 #ifdef USER_MENU
209 wUserMenuRefreshInstances(napp->menu, wwin);
210 #endif /* USER_MENU */
212 if (wwin->flags.mapped)
213 wAppMenuMap(napp->menu, wwin);
214 #ifdef NEWAPPICON
215 wApplicationActivate(napp);
216 #endif
219 XFlush(dpy);
220 old_scr = scr;
223 void wShadeWindow(WWindow *wwin)
226 if (wwin->flags.shaded)
227 return;
229 XLowerWindow(dpy, wwin->client_win);
230 wSoundPlay(WSOUND_SHADE);
231 shade_animate(wwin, SHADE);
233 wwin->flags.skip_next_animation = 0;
234 wwin->flags.shaded = 1;
235 wwin->flags.mapped = 0;
236 /* prevent window withdrawal when getting UnmapNotify */
237 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
238 XUnmapWindow(dpy, wwin->client_win);
239 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
241 /* for the client it's just like iconification */
242 wFrameWindowResize(wwin->frame, wwin->frame->core->width, wwin->frame->top_width - 1);
244 wwin->client.y = wwin->frame_y - wwin->client.height + wwin->frame->top_width;
245 wWindowSynthConfigureNotify(wwin);
248 wClientSetState(wwin, IconicState, None);
251 WMPostNotificationName(WMNChangedState, wwin, "shade");
253 #ifdef ANIMATIONS
254 if (!wwin->screen_ptr->flags.startup) {
255 /* Catch up with events not processed while animation was running */
256 ProcessPendingEvents();
258 #endif
261 void wUnshadeWindow(WWindow *wwin)
264 if (!wwin->flags.shaded)
265 return;
267 wwin->flags.shaded = 0;
268 wwin->flags.mapped = 1;
269 XMapWindow(dpy, wwin->client_win);
271 wSoundPlay(WSOUND_UNSHADE);
272 shade_animate(wwin, UNSHADE);
274 wwin->flags.skip_next_animation = 0;
275 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
276 wwin->frame->top_width + wwin->client.height + wwin->frame->bottom_width);
278 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
279 wWindowSynthConfigureNotify(wwin);
282 wClientSetState(wwin, NormalState, None);
284 /* if the window is focused, set the focus again as it was disabled during
285 * shading */
286 if (wwin->flags.focused)
287 wSetFocusTo(wwin->screen_ptr, wwin);
289 WMPostNotificationName(WMNChangedState, wwin, "shade");
292 /* Set the old coordinates using the current values */
293 static void save_old_geometry(WWindow *wwin)
295 wwin->old_geometry.width = wwin->client.width;
296 wwin->old_geometry.height = wwin->client.height;
297 wwin->old_geometry.x = wwin->frame_x;
298 wwin->old_geometry.y = wwin->frame_y;
301 void wMaximizeWindow(WWindow * wwin, int directions)
303 int new_x, new_y;
304 unsigned int new_width, new_height, half_scr_width;
305 WArea usableArea, totalArea;
306 Bool has_border = 1;
307 int adj_size;
309 if (!IS_RESIZABLE(wwin))
310 return;
312 if (!HAS_BORDER(wwin))
313 has_border = 0;
315 /* the size to adjust the geometry */
316 adj_size = FRAME_BORDER_WIDTH * 2 * has_border;
318 /* save old coordinates before we change the current values */
319 save_old_geometry(wwin);
321 totalArea.x1 = 0;
322 totalArea.y1 = 0;
323 totalArea.x2 = wwin->screen_ptr->scr_width;
324 totalArea.y2 = wwin->screen_ptr->scr_height;
325 usableArea = totalArea;
327 if (!(directions & MAX_IGNORE_XINERAMA)) {
328 WScreen *scr = wwin->screen_ptr;
329 int head;
331 if (directions & MAX_KEYBOARD)
332 head = wGetHeadForWindow(wwin);
333 else
334 head = wGetHeadForPointerLocation(scr);
336 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
339 /* Only save directions, not kbd or xinerama hints */
340 directions &= (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_MAXIMUS);
342 if (WFLAGP(wwin, full_maximize)) {
343 usableArea = totalArea;
345 half_scr_width = (usableArea.x2 - usableArea.x1)/2;
347 if (wwin->flags.shaded) {
348 wwin->flags.skip_next_animation = 1;
349 wUnshadeWindow(wwin);
352 if (directions & MAX_HORIZONTAL) {
353 new_width = usableArea.x2 - usableArea.x1 - adj_size;
354 new_x = usableArea.x1;
355 } else if (directions & MAX_LEFTHALF) {
356 new_width = half_scr_width - adj_size;
357 new_x = usableArea.x1;
358 } else if (directions & MAX_RIGHTHALF) {
359 new_width = half_scr_width - adj_size;
360 new_x = usableArea.x1 + half_scr_width;
361 } else {
362 new_x = wwin->frame_x;
363 new_width = wwin->frame->core->width;
366 if (directions & MAX_VERTICAL) {
367 new_height = usableArea.y2 - usableArea.y1 - adj_size;
368 new_y = usableArea.y1;
369 if (WFLAGP(wwin, full_maximize)) {
370 new_y -= wwin->frame->top_width;
371 new_height += wwin->frame->bottom_width - 1;
373 } else {
374 new_y = wwin->frame_y;
375 new_height = wwin->frame->core->height;
378 if (!WFLAGP(wwin, full_maximize)) {
379 new_height -= wwin->frame->top_width + wwin->frame->bottom_width;
382 if (directions & MAX_MAXIMUS) {
383 find_Maximus_geometry(wwin, usableArea, &new_x, &new_y, &new_width, &new_height);
384 if (WFLAGP(wwin, full_maximize) && new_y == 0) {
385 new_y -= wwin->frame->top_width;
386 new_height += wwin->frame->top_width - 1;
390 wWindowConstrainSize(wwin, &new_width, &new_height);
392 wWindowCropSize(wwin, usableArea.x2 - usableArea.x1,
393 usableArea.y2 - usableArea.y1, &new_width, &new_height);
395 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
397 WMPostNotificationName(WMNChangedState, wwin, "maximize");
399 wSoundPlay(WSOUND_MAXIMIZE);
400 /* set maximization state */
401 wwin->flags.maximized = directions;
405 * Maximus: tiled maximization (maximize without overlapping other windows)
407 * The window to be maximized will be denoted by w_0 (sub-index zero)
408 * while the windows which will stop the maximization of w_0 are denoted by w_j.
410 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
411 unsigned int *new_width, unsigned int *new_height)
413 WWindow *tmp;
414 int x_0 = wwin->frame_x;
415 int y_0 = wwin->frame_y;
416 int width_0 = wwin->frame->core->width;
417 int height_0 = wwin->frame->core->height;
418 int botton_0 = y_0 + height_0;
419 int right_border_0 = x_0 + width_0;
420 int new_x_0, new_y_0, new_botton_0, new_right_border_0, new_height_0;
421 int x_j, y_j, width_j, height_j, botton_j, top_j, right_border_j;
422 int x_intsect, y_intsect;
423 /* Assume that the window w_0 has titlebar etc */
424 int has_titlebar = 1, has_resizebar = 1, has_border = 1;
425 int adjust_height, adjust_width;
427 /* Try to fully maximize first, then readjust later */
428 new_x_0 = usableArea.x1;
429 new_y_0 = usableArea.y1;
430 new_botton_0 = usableArea.y2;
431 new_right_border_0 = usableArea.x2;
433 if (!HAS_TITLEBAR(wwin))
434 has_titlebar = 0;
435 if (!HAS_RESIZEBAR(wwin))
436 has_resizebar = 0;
437 if (!HAS_BORDER(wwin))
438 has_border = 0;
440 /* the lengths to be subtracted if w_0 has titlebar, etc */
441 adjust_height = TITLEBAR_HEIGHT * has_titlebar
442 + 2 * FRAME_BORDER_WIDTH * has_border + RESIZEBAR_HEIGHT * has_resizebar;
443 adjust_width = 2 * FRAME_BORDER_WIDTH * has_border;
445 tmp = wwin;
446 /* TODO: Is the focused window always the last in the list? */
447 while (tmp->prev) {
448 /* ignore windows in other workspaces or minimized */
449 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
450 || tmp->prev->flags.miniaturized) {
451 tmp = tmp->prev;
452 continue;
454 tmp = tmp->prev;
456 /* set the w_j window coordinates */
457 x_j = tmp->frame_x;
458 y_j = tmp->frame_y;
459 width_j = tmp->frame->core->width;
460 height_j = tmp->frame->core->height;
461 botton_j = y_j + height_j;
462 top_j = y_j;
463 right_border_j = x_j + width_j;
465 /* Try to maximize in the y direction first */
466 x_intsect = calcIntersectionLength(x_0, width_0, x_j, width_j);
467 if (x_intsect != 0) {
468 if (botton_j < y_0 && botton_j > new_y_0) {
469 /* w_0 is below the botton of w_j */
470 new_y_0 = botton_j;
472 if (botton_0 < top_j && top_j < new_botton_0) {
473 /* The botton of w_0 is above the top of w_j */
474 new_botton_0 = top_j;
479 * Use the updated y coordinates from the above step to account
480 * the possibility that the new value of y_0 will have different
481 * intersections with w_j
483 new_height_0 = new_botton_0 - new_y_0 - adjust_height;
484 y_intsect = calcIntersectionLength(new_y_0, new_height_0, y_j, height_j);
485 if (y_intsect != 0) {
486 if (right_border_j < x_0 && right_border_j > new_x_0) {
487 /* w_0 is completely to the right of w_j */
488 new_x_0 = right_border_j;
490 if (right_border_0 < x_j && x_j < new_right_border_0) {
491 /* w_0 is completely to the left of w_j */
492 new_right_border_0 = x_j;
497 new_height_0 = new_botton_0 - new_y_0 - adjust_height;
498 *new_x = new_x_0;
499 *new_y = new_y_0;
500 *new_height = new_height_0;
501 *new_width = new_right_border_0 - new_x_0 - adjust_width;
504 void wUnmaximizeWindow(WWindow * wwin)
506 int x, y, w, h;
507 WMRect old_geom_rect;
508 int old_head;
509 Bool same_head;
511 if (!wwin->flags.maximized)
512 return;
514 if (wwin->flags.shaded) {
515 wwin->flags.skip_next_animation = 1;
516 wUnshadeWindow(wwin);
518 /* Use old coordinates if they are set, current values otherwise */
519 old_geom_rect = wmkrect(wwin->old_geometry.x, wwin->old_geometry.y, wwin->old_geometry.width, wwin->old_geometry.height);
520 old_head = wGetHeadForRect(wwin->screen_ptr, old_geom_rect);
521 same_head = (wGetHeadForWindow(wwin) == old_head);
522 x = (wwin->old_geometry.x && same_head) ? wwin->old_geometry.x : wwin->frame_x;
523 y = (wwin->old_geometry.y && same_head) ? wwin->old_geometry.y : wwin->frame_y;
524 w = wwin->old_geometry.width ? wwin->old_geometry.width : wwin->client.width;
525 h = wwin->old_geometry.height ? wwin->old_geometry.height : wwin->client.height;
527 wwin->flags.maximized = 0;
528 wWindowConfigure(wwin, x, y, w, h);
530 WMPostNotificationName(WMNChangedState, wwin, "maximize");
532 wSoundPlay(WSOUND_UNMAXIMIZE);
535 void wFullscreenWindow(WWindow * wwin)
537 int head;
538 WMRect rect;
540 if (wwin->flags.fullscreen)
541 return;
543 wwin->flags.fullscreen = True;
545 wWindowConfigureBorders(wwin);
547 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
549 wwin->bfs_geometry.x = wwin->frame_x;
550 wwin->bfs_geometry.y = wwin->frame_y;
551 wwin->bfs_geometry.width = wwin->frame->core->width;
552 wwin->bfs_geometry.height = wwin->frame->core->height;
554 head = wGetHeadForWindow(wwin);
555 rect = wGetRectForHead(wwin->screen_ptr, head);
556 wWindowConfigure(wwin, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
558 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
561 void wUnfullscreenWindow(WWindow * wwin)
563 if (!wwin->flags.fullscreen)
564 return;
566 wwin->flags.fullscreen = False;
568 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
569 if (WFLAGP(wwin, sunken)) {
570 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
571 } else if (WFLAGP(wwin, floating)) {
572 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
573 } else {
574 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
578 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
579 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
581 wWindowConfigureBorders(wwin);
583 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
584 wFrameWindowPaint(wwin->frame);
587 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
590 #ifdef ANIMATIONS
591 static void animateResizeFlip(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
593 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
594 float cx, cy, cw, ch;
595 float xstep, ystep, wstep, hstep;
596 XPoint points[5];
597 float dx, dch, midy;
598 float angle, final_angle, delta;
600 xstep = (float)(fx - x) / steps;
601 ystep = (float)(fy - y) / steps;
602 wstep = (float)(fw - w) / steps;
603 hstep = (float)(fh - h) / steps;
605 cx = (float)x;
606 cy = (float)y;
607 cw = (float)w;
608 ch = (float)h;
610 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_F;
611 delta = (float)(final_angle / FRAMES);
612 for (angle = 0;; angle += delta) {
613 if (angle > final_angle)
614 angle = final_angle;
616 dx = (cw / 10) - ((cw / 5) * sin(angle));
617 dch = (ch / 2) * cos(angle);
618 midy = cy + (ch / 2);
620 points[0].x = cx + dx;
621 points[0].y = midy - dch;
622 points[1].x = cx + cw - dx;
623 points[1].y = points[0].y;
624 points[2].x = cx + cw + dx;
625 points[2].y = midy + dch;
626 points[3].x = cx - dx;
627 points[3].y = points[2].y;
628 points[4].x = points[0].x;
629 points[4].y = points[0].y;
631 XGrabServer(dpy);
632 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
633 XFlush(dpy);
634 #if (MINIATURIZE_ANIMATION_DELAY_F > 0)
635 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
636 #else
637 wusleep(10);
638 #endif
640 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
641 XUngrabServer(dpy);
642 cx += xstep;
643 cy += ystep;
644 cw += wstep;
645 ch += hstep;
646 if (angle >= final_angle)
647 break;
650 XFlush(dpy);
653 #undef FRAMES
655 static void
656 animateResizeTwist(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
658 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
659 float cx, cy, cw, ch;
660 float xstep, ystep, wstep, hstep;
661 XPoint points[5];
662 float angle, final_angle, a, d, delta;
664 x += w / 2;
665 y += h / 2;
666 fx += fw / 2;
667 fy += fh / 2;
669 xstep = (float)(fx - x) / steps;
670 ystep = (float)(fy - y) / steps;
671 wstep = (float)(fw - w) / steps;
672 hstep = (float)(fh - h) / steps;
674 cx = (float)x;
675 cy = (float)y;
676 cw = (float)w;
677 ch = (float)h;
679 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_T;
680 delta = (float)(final_angle / FRAMES);
681 for (angle = 0;; angle += delta) {
682 if (angle > final_angle)
683 angle = final_angle;
685 a = atan(ch / cw);
686 d = sqrt((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
688 points[0].x = cx + cos(angle - a) * d;
689 points[0].y = cy + sin(angle - a) * d;
690 points[1].x = cx + cos(angle + a) * d;
691 points[1].y = cy + sin(angle + a) * d;
692 points[2].x = cx + cos(angle - a + WM_PI) * d;
693 points[2].y = cy + sin(angle - a + WM_PI) * d;
694 points[3].x = cx + cos(angle + a + WM_PI) * d;
695 points[3].y = cy + sin(angle + a + WM_PI) * d;
696 points[4].x = cx + cos(angle - a) * d;
697 points[4].y = cy + sin(angle - a) * d;
698 XGrabServer(dpy);
699 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
700 XFlush(dpy);
701 #if (MINIATURIZE_ANIMATION_DELAY_T > 0)
702 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
703 #else
704 wusleep(10);
705 #endif
707 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
708 XUngrabServer(dpy);
709 cx += xstep;
710 cy += ystep;
711 cw += wstep;
712 ch += hstep;
713 if (angle >= final_angle)
714 break;
717 XFlush(dpy);
720 #undef FRAMES
722 static void animateResizeZoom(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
724 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
725 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
726 float xstep, ystep, wstep, hstep;
727 int i, j;
729 xstep = (float)(fx - x) / steps;
730 ystep = (float)(fy - y) / steps;
731 wstep = (float)(fw - w) / steps;
732 hstep = (float)(fh - h) / steps;
734 for (j = 0; j < FRAMES; j++) {
735 cx[j] = (float)x;
736 cy[j] = (float)y;
737 cw[j] = (float)w;
738 ch[j] = (float)h;
740 XGrabServer(dpy);
741 for (i = 0; i < steps; i++) {
742 for (j = 0; j < FRAMES; j++) {
743 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
744 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
746 XFlush(dpy);
747 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
748 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
749 #else
750 wusleep(10);
751 #endif
752 for (j = 0; j < FRAMES; j++) {
753 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
754 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
755 if (j < FRAMES - 1) {
756 cx[j] = cx[j + 1];
757 cy[j] = cy[j + 1];
758 cw[j] = cw[j + 1];
759 ch[j] = ch[j + 1];
760 } else {
761 cx[j] += xstep;
762 cy[j] += ystep;
763 cw[j] += wstep;
764 ch[j] += hstep;
769 for (j = 0; j < FRAMES; j++) {
770 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
772 XFlush(dpy);
773 #if (MINIATURIZE_ANIMATION_DELAY_Z > 0)
774 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
775 #else
776 wusleep(10);
777 #endif
778 for (j = 0; j < FRAMES; j++) {
779 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
782 XUngrabServer(dpy);
785 #undef FRAMES
787 void animateResize(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int hiding)
789 int style = wPreferences.iconification_style; /* Catch the value */
790 int steps, k;
792 if (style == WIS_NONE)
793 return;
795 if (style == WIS_RANDOM) {
796 style = rand() % 3;
799 k = (hiding ? 2 : 3);
801 switch (style) {
802 case WIS_TWIST:
803 steps = (MINIATURIZE_ANIMATION_STEPS_T * k) / 3;
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 * k) / 3;
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 * k) / 3;
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 #if 0
887 static void setupIconGrabs(WIcon * icon)
889 /* setup passive grabs on the icon */
890 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
891 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
892 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
893 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
894 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
895 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
896 XSync(dpy, 0);
898 #endif
900 static WWindow *recursiveTransientFor(WWindow * wwin)
902 int i;
904 if (!wwin)
905 return None;
907 /* hackish way to detect transient_for cycle */
908 i = wwin->screen_ptr->window_count + 1;
910 while (wwin && wwin->transient_for != None && i > 0) {
911 wwin = wWindowFor(wwin->transient_for);
912 i--;
914 if (i == 0 && wwin) {
915 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin->frame->title);
916 return NULL;
919 return wwin;
922 #if 0
923 static void removeIconGrabs(WIcon * icon)
925 /* remove passive grabs on the icon */
926 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
927 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
928 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
929 XSync(dpy, 0);
931 #endif
933 void wIconifyWindow(WWindow * wwin)
935 XWindowAttributes attribs;
936 int present;
938 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
939 /* the window doesn't exist anymore */
940 return;
943 if (wwin->flags.miniaturized) {
944 return;
947 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
948 WWindow *owner = wWindowFor(wwin->transient_for);
950 if (owner && owner->flags.miniaturized)
951 return;
954 present = wwin->frame->workspace == wwin->screen_ptr->current_workspace;
956 /* if the window is in another workspace, simplify process */
957 if (present) {
958 /* icon creation may take a while */
959 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
960 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
961 GrabModeAsync, None, None, CurrentTime);
964 if (!wPreferences.disable_miniwindows
965 #ifdef NETWM_HINTS
966 && !wwin->flags.net_handle_icon
967 #endif
969 if (!wwin->flags.icon_moved) {
970 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
972 wwin->icon = wIconCreate(wwin);
974 wwin->icon->mapped = 1;
977 wwin->flags.miniaturized = 1;
978 wwin->flags.mapped = 0;
980 /* unmap transients */
982 unmapTransientsFor(wwin);
984 if (present) {
985 wSoundPlay(WSOUND_ICONIFY);
987 XUngrabPointer(dpy, CurrentTime);
988 wWindowUnmap(wwin);
989 /* let all Expose events arrive so that we can repaint
990 * something before the animation starts (and the server is grabbed) */
991 XSync(dpy, 0);
993 if (wPreferences.disable_miniwindows
994 #ifdef NETWM_HINTS
995 || wwin->flags.net_handle_icon
996 #endif
998 wClientSetState(wwin, IconicState, None);
999 else
1000 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
1002 flushExpose();
1003 #ifdef ANIMATIONS
1004 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
1005 && !wPreferences.no_animations) {
1006 int ix, iy, iw, ih;
1008 if (!wPreferences.disable_miniwindows
1009 #ifdef NETWM_HINTS
1010 && !wwin->flags.net_handle_icon
1011 #endif
1013 ix = wwin->icon_x;
1014 iy = wwin->icon_y;
1015 iw = wwin->icon->core->width;
1016 ih = wwin->icon->core->height;
1017 } else {
1018 #ifdef NETWM_HINTS
1019 if (wwin->flags.net_handle_icon) {
1020 ix = wwin->icon_x;
1021 iy = wwin->icon_y;
1022 iw = wwin->icon_w;
1023 ih = wwin->icon_h;
1024 } else
1025 #endif
1027 ix = 0;
1028 iy = 0;
1029 iw = wwin->screen_ptr->scr_width;
1030 ih = wwin->screen_ptr->scr_height;
1033 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1034 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih, False);
1036 #endif
1039 wwin->flags.skip_next_animation = 0;
1041 if (!wPreferences.disable_miniwindows
1042 #ifdef NETWM_HINTS
1043 && !wwin->flags.net_handle_icon
1044 #endif
1047 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace ||
1048 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1050 XMapWindow(dpy, wwin->icon->core->window);
1052 AddToStackList(wwin->icon->core);
1054 wLowerFrame(wwin->icon->core);
1057 if (present) {
1058 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1061 * It doesn't seem to be working and causes button event hangup
1062 * when deiconifying a transient window.
1063 setupIconGrabs(wwin->icon);
1065 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
1066 && wPreferences.focus_mode == WKF_CLICK) {
1067 WWindow *tmp;
1069 tmp = wwin->prev;
1070 while (tmp) {
1071 if (!WFLAGP(tmp, no_focusable)
1072 && !(tmp->flags.hidden || tmp->flags.miniaturized)
1073 && (wwin->frame->workspace == tmp->frame->workspace))
1074 break;
1075 tmp = tmp->prev;
1077 wSetFocusTo(wwin->screen_ptr, tmp);
1078 } else if (wPreferences.focus_mode != WKF_CLICK) {
1079 wSetFocusTo(wwin->screen_ptr, NULL);
1081 #ifdef ANIMATIONS
1082 if (!wwin->screen_ptr->flags.startup) {
1083 /* Catch up with events not processed while animation was running */
1084 Window clientwin = wwin->client_win;
1086 ProcessPendingEvents();
1088 /* the window can disappear while ProcessPendingEvents() runs */
1089 if (!wWindowFor(clientwin)) {
1090 return;
1093 #endif
1096 /* maybe we want to do this regardless of net_handle_icon
1097 * it seems to me we might break behaviour this way.
1099 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1100 #ifdef NETWM_HINTS
1101 && !wwin->flags.net_handle_icon
1102 #endif
1104 wIconSelect(wwin->icon);
1106 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1108 if (wPreferences.auto_arrange_icons)
1109 wArrangeIcons(wwin->screen_ptr, True);
1112 void wDeiconifyWindow(WWindow * wwin)
1114 #ifdef NETWM_HINTS
1115 /* we're hiding for show_desktop */
1116 int netwm_hidden = wwin->flags.net_show_desktop &&
1117 wwin->frame->workspace != wwin->screen_ptr->current_workspace;
1118 #else
1119 int netwm_hidden = False;
1120 #endif
1122 if (!netwm_hidden)
1123 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1125 if (!wwin->flags.miniaturized)
1126 return;
1128 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1129 WWindow *owner = recursiveTransientFor(wwin);
1131 if (owner && owner->flags.miniaturized) {
1132 wDeiconifyWindow(owner);
1133 wSetFocusTo(wwin->screen_ptr, wwin);
1134 wRaiseFrame(wwin->frame->core);
1135 return;
1139 wwin->flags.miniaturized = 0;
1141 if (!netwm_hidden && !wwin->flags.shaded) {
1142 wwin->flags.mapped = 1;
1145 if (!netwm_hidden || wPreferences.sticky_icons) {
1146 /* maybe we want to do this regardless of net_handle_icon
1147 * it seems to me we might break behaviour this way.
1149 if (!wPreferences.disable_miniwindows
1150 #ifdef NETWM_HINTS
1151 && !wwin->flags.net_handle_icon
1152 #endif
1153 && wwin->icon != NULL) {
1154 if (wwin->icon->selected)
1155 wIconSelect(wwin->icon);
1157 XUnmapWindow(dpy, wwin->icon->core->window);
1161 if (!netwm_hidden)
1162 wSoundPlay(WSOUND_DEICONIFY);
1164 /* if the window is in another workspace, do it silently */
1165 if (!netwm_hidden) {
1166 #ifdef ANIMATIONS
1167 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1168 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1169 int ix, iy, iw, ih;
1171 if (!wPreferences.disable_miniwindows
1172 #ifdef NETWM_HINTS
1173 && !wwin->flags.net_handle_icon
1174 #endif
1176 ix = wwin->icon_x;
1177 iy = wwin->icon_y;
1178 iw = wwin->icon->core->width;
1179 ih = wwin->icon->core->height;
1180 } else {
1181 #ifdef NETWM_HINTS
1182 if (wwin->flags.net_handle_icon) {
1183 ix = wwin->icon_x;
1184 iy = wwin->icon_y;
1185 iw = wwin->icon_w;
1186 ih = wwin->icon_h;
1187 } else
1188 #endif
1190 ix = 0;
1191 iy = 0;
1192 iw = wwin->screen_ptr->scr_width;
1193 ih = wwin->screen_ptr->scr_height;
1196 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1197 wwin->frame_x, wwin->frame_y,
1198 wwin->frame->core->width, wwin->frame->core->height, False);
1200 #endif /* ANIMATIONS */
1201 wwin->flags.skip_next_animation = 0;
1202 XGrabServer(dpy);
1203 if (!wwin->flags.shaded) {
1204 XMapWindow(dpy, wwin->client_win);
1206 XMapWindow(dpy, wwin->frame->core->window);
1207 wRaiseFrame(wwin->frame->core);
1208 if (!wwin->flags.shaded) {
1209 wClientSetState(wwin, NormalState, None);
1211 mapTransientsFor(wwin);
1214 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1215 #ifdef NETWM_HINTS
1216 && !wwin->flags.net_handle_icon
1217 #endif
1219 RemoveFromStackList(wwin->icon->core);
1220 /* removeIconGrabs(wwin->icon); */
1221 wIconDestroy(wwin->icon);
1222 wwin->icon = NULL;
1225 if (!netwm_hidden) {
1226 XUngrabServer(dpy);
1228 wSetFocusTo(wwin->screen_ptr, wwin);
1230 #ifdef ANIMATIONS
1231 if (!wwin->screen_ptr->flags.startup) {
1232 /* Catch up with events not processed while animation was running */
1233 Window clientwin = wwin->client_win;
1235 ProcessPendingEvents();
1237 /* the window can disappear while ProcessPendingEvents() runs */
1238 if (!wWindowFor(clientwin)) {
1239 return;
1242 #endif
1245 if (wPreferences.auto_arrange_icons) {
1246 wArrangeIcons(wwin->screen_ptr, True);
1249 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1251 /* In case we were shaded and iconified, also unshade */
1252 if (!netwm_hidden)
1253 wUnshadeWindow(wwin);
1256 static void hideWindow(WIcon * icon, int icon_x, int icon_y, WWindow * wwin, int animate)
1258 if (wwin->flags.miniaturized) {
1259 if (wwin->icon) {
1260 XUnmapWindow(dpy, wwin->icon->core->window);
1261 wwin->icon->mapped = 0;
1263 wwin->flags.hidden = 1;
1265 WMPostNotificationName(WMNChangedState, wwin, "hide");
1266 return;
1269 if (wwin->flags.inspector_open) {
1270 wHideInspectorForWindow(wwin);
1273 wwin->flags.hidden = 1;
1274 wWindowUnmap(wwin);
1276 wClientSetState(wwin, IconicState, icon->icon_win);
1277 flushExpose();
1278 wSoundPlay(WSOUND_HIDE);
1279 #ifdef ANIMATIONS
1280 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1281 !wwin->flags.skip_next_animation && animate) {
1282 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1283 wwin->frame->core->width, wwin->frame->core->height,
1284 icon_x, icon_y, icon->core->width, icon->core->height, True);
1286 #endif
1287 wwin->flags.skip_next_animation = 0;
1289 WMPostNotificationName(WMNChangedState, wwin, "hide");
1292 void wHideOtherApplications(WWindow * awin)
1294 WWindow *wwin;
1295 WApplication *tapp;
1297 if (!awin)
1298 return;
1299 wwin = awin->screen_ptr->focused_window;
1301 while (wwin) {
1302 if (wwin != awin
1303 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1304 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1305 && !wwin->flags.internal_window
1306 && wGetWindowOfInspectorForWindow(wwin) != awin && !WFLAGP(wwin, no_hide_others)) {
1308 if (wwin->main_window == None || WFLAGP(wwin, no_appicon)) {
1309 if (!WFLAGP(wwin, no_miniaturizable)) {
1310 wwin->flags.skip_next_animation = 1;
1311 wIconifyWindow(wwin);
1313 } else if (wwin->main_window != None && awin->main_window != wwin->main_window) {
1314 tapp = wApplicationOf(wwin->main_window);
1315 if (tapp) {
1316 tapp->flags.skip_next_animation = 1;
1317 wHideApplication(tapp);
1318 } else {
1319 if (!WFLAGP(wwin, no_miniaturizable)) {
1320 wwin->flags.skip_next_animation = 1;
1321 wIconifyWindow(wwin);
1326 wwin = wwin->prev;
1329 wSetFocusTo(awin->screen_ptr, awin);
1333 void wHideApplication(WApplication * wapp)
1335 WScreen *scr;
1336 WWindow *wlist;
1337 int hadfocus;
1338 int animate;
1340 if (!wapp) {
1341 wwarning("trying to hide a non grouped window");
1342 return;
1344 if (!wapp->main_window_desc) {
1345 wwarning("group leader not found for window group");
1346 return;
1348 scr = wapp->main_window_desc->screen_ptr;
1349 hadfocus = 0;
1350 wlist = scr->focused_window;
1351 if (!wlist)
1352 return;
1354 if (wlist->main_window == wapp->main_window)
1355 wapp->last_focused = wlist;
1356 else
1357 wapp->last_focused = NULL;
1359 animate = !wapp->flags.skip_next_animation;
1361 while (wlist) {
1362 if (wlist->main_window == wapp->main_window) {
1363 if (wlist->flags.focused) {
1364 hadfocus = 1;
1366 if (wapp->app_icon) {
1367 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1368 wapp->app_icon->y_pos, wlist, animate);
1369 animate = False;
1372 wlist = wlist->prev;
1375 wapp->flags.skip_next_animation = 0;
1377 if (hadfocus) {
1378 if (wPreferences.focus_mode == WKF_CLICK) {
1379 wlist = scr->focused_window;
1380 while (wlist) {
1381 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1382 && (wlist->flags.mapped || wlist->flags.shaded))
1383 break;
1384 wlist = wlist->prev;
1386 wSetFocusTo(scr, wlist);
1387 } else {
1388 wSetFocusTo(scr, NULL);
1392 wapp->flags.hidden = 1;
1394 if (wPreferences.auto_arrange_icons) {
1395 wArrangeIcons(scr, True);
1397 #ifdef HIDDENDOT
1398 if (wapp->app_icon)
1399 wAppIconPaint(wapp->app_icon);
1400 #endif
1403 static void unhideWindow(WIcon * icon, int icon_x, int icon_y, WWindow * wwin, int animate, int bringToCurrentWS)
1405 if (bringToCurrentWS)
1406 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1408 wwin->flags.hidden = 0;
1410 wSoundPlay(WSOUND_UNHIDE);
1411 #ifdef ANIMATIONS
1412 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1413 animateResize(wwin->screen_ptr, icon_x, icon_y,
1414 icon->core->width, icon->core->height,
1415 wwin->frame_x, wwin->frame_y,
1416 wwin->frame->core->width, wwin->frame->core->height, True);
1418 #endif
1419 wwin->flags.skip_next_animation = 0;
1420 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1421 XMapWindow(dpy, wwin->client_win);
1422 XMapWindow(dpy, wwin->frame->core->window);
1423 wClientSetState(wwin, NormalState, None);
1424 wwin->flags.mapped = 1;
1425 wRaiseFrame(wwin->frame->core);
1427 if (wwin->flags.inspector_open) {
1428 wUnhideInspectorForWindow(wwin);
1431 WMPostNotificationName(WMNChangedState, wwin, "hide");
1434 void wUnhideApplication(WApplication * wapp, Bool miniwindows, Bool bringToCurrentWS)
1436 WScreen *scr;
1437 WWindow *wlist, *next;
1438 WWindow *focused = NULL;
1439 int animate;
1441 if (!wapp)
1442 return;
1444 scr = wapp->main_window_desc->screen_ptr;
1445 wlist = scr->focused_window;
1446 if (!wlist)
1447 return;
1449 /* goto beginning of list */
1450 while (wlist->prev)
1451 wlist = wlist->prev;
1453 animate = !wapp->flags.skip_next_animation;
1455 while (wlist) {
1456 next = wlist->next;
1458 if (wlist->main_window == wapp->main_window) {
1459 if (wlist->flags.focused)
1460 focused = wlist;
1461 else if (!focused || !focused->flags.focused)
1462 focused = wlist;
1464 if (wlist->flags.miniaturized) {
1465 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1466 wlist->frame->workspace == scr->current_workspace) && wlist->icon) {
1467 if (!wlist->icon->mapped) {
1468 int x, y;
1470 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1471 if (wlist->icon_x != x || wlist->icon_y != y) {
1472 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1474 wlist->icon_x = x;
1475 wlist->icon_y = y;
1476 XMapWindow(dpy, wlist->icon->core->window);
1477 wlist->icon->mapped = 1;
1479 wRaiseFrame(wlist->icon->core);
1481 if (bringToCurrentWS)
1482 wWindowChangeWorkspace(wlist, scr->current_workspace);
1483 wlist->flags.hidden = 0;
1484 if (miniwindows && wlist->frame->workspace == scr->current_workspace) {
1485 wDeiconifyWindow(wlist);
1487 WMPostNotificationName(WMNChangedState, wlist, "hide");
1488 } else if (wlist->flags.shaded) {
1489 if (bringToCurrentWS)
1490 wWindowChangeWorkspace(wlist, scr->current_workspace);
1491 wlist->flags.hidden = 0;
1492 if (wlist->frame->workspace == scr->current_workspace) {
1493 XMapWindow(dpy, wlist->frame->core->window);
1494 if (miniwindows) {
1495 wUnshadeWindow(wlist);
1496 wRaiseFrame(wlist->frame->core);
1499 WMPostNotificationName(WMNChangedState, wlist, "hide");
1500 } else if (wlist->flags.hidden) {
1501 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1502 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1503 animate = False;
1504 } else {
1505 if (bringToCurrentWS && wlist->frame->workspace != scr->current_workspace) {
1506 wWindowChangeWorkspace(wlist, scr->current_workspace);
1508 wRaiseFrame(wlist->frame->core);
1511 wlist = next;
1514 wapp->flags.skip_next_animation = 0;
1515 wapp->flags.hidden = 0;
1517 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1518 wRaiseFrame(wapp->last_focused->frame->core);
1519 wSetFocusTo(scr, wapp->last_focused);
1520 } else if (focused) {
1521 wSetFocusTo(scr, focused);
1523 wapp->last_focused = NULL;
1524 if (wPreferences.auto_arrange_icons) {
1525 wArrangeIcons(scr, True);
1527 #ifdef HIDDENDOT
1528 wAppIconPaint(wapp->app_icon);
1529 #endif
1532 void wShowAllWindows(WScreen * scr)
1534 WWindow *wwin, *old_foc;
1535 WApplication *wapp;
1537 old_foc = wwin = scr->focused_window;
1538 while (wwin) {
1539 if (!wwin->flags.internal_window &&
1540 (scr->current_workspace == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1541 if (wwin->flags.miniaturized) {
1542 wwin->flags.skip_next_animation = 1;
1543 wDeiconifyWindow(wwin);
1544 } else if (wwin->flags.hidden) {
1545 wapp = wApplicationOf(wwin->main_window);
1546 if (wapp) {
1547 wUnhideApplication(wapp, False, False);
1548 } else {
1549 wwin->flags.skip_next_animation = 1;
1550 wDeiconifyWindow(wwin);
1554 wwin = wwin->prev;
1556 wSetFocusTo(scr, old_foc);
1557 /*wRaiseFrame(old_foc->frame->core); */
1560 void wRefreshDesktop(WScreen * scr)
1562 Window win;
1563 XSetWindowAttributes attr;
1565 attr.backing_store = NotUseful;
1566 attr.save_under = False;
1567 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1568 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1569 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1570 XMapRaised(dpy, win);
1571 XDestroyWindow(dpy, win);
1572 XFlush(dpy);
1575 void wArrangeIcons(WScreen * scr, Bool arrangeAll)
1577 WWindow *wwin;
1578 WAppIcon *aicon;
1580 int head;
1581 const int heads = wXineramaHeads(scr);
1583 struct HeadVars {
1584 int pf; /* primary axis */
1585 int sf; /* secondary axis */
1586 int fullW;
1587 int fullH;
1588 int pi, si;
1589 int sx1, sx2, sy1, sy2; /* screen boundary */
1590 int sw, sh;
1591 int xo, yo;
1592 int xs, ys;
1593 } *vars;
1595 int isize = wPreferences.icon_size;
1597 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
1599 for (head = 0; head < heads; ++head) {
1600 #if 0
1601 WMRect rect = wGetRectForHead(scr, head);
1602 #else
1603 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1604 WMRect rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
1605 #endif
1607 vars[head].pi = vars[head].si = 0;
1608 vars[head].sx1 = rect.pos.x;
1609 vars[head].sy1 = rect.pos.y;
1610 vars[head].sw = rect.size.width;
1611 vars[head].sh = rect.size.height;
1612 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1613 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1615 #if 0
1616 if (scr->dock) {
1617 if (scr->dock->on_right_side)
1618 vars[head].sx2 -= isize + DOCK_EXTRA_SPACE;
1619 else
1620 vars[head].sx1 += isize + DOCK_EXTRA_SPACE;
1622 #endif
1624 vars[head].sw = isize * (vars[head].sw / isize);
1625 vars[head].sh = isize * (vars[head].sh / isize);
1626 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
1627 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
1629 /* icon yard boundaries */
1630 if (wPreferences.icon_yard & IY_VERT) {
1631 vars[head].pf = vars[head].fullH;
1632 vars[head].sf = vars[head].fullW;
1633 } else {
1634 vars[head].pf = vars[head].fullW;
1635 vars[head].sf = vars[head].fullH;
1637 if (wPreferences.icon_yard & IY_RIGHT) {
1638 vars[head].xo = vars[head].sx2 - isize;
1639 vars[head].xs = -1;
1640 } else {
1641 vars[head].xo = vars[head].sx1;
1642 vars[head].xs = 1;
1644 if (wPreferences.icon_yard & IY_TOP) {
1645 vars[head].yo = vars[head].sy1;
1646 vars[head].ys = 1;
1647 } else {
1648 vars[head].yo = vars[head].sy2 - isize;
1649 vars[head].ys = -1;
1653 #define X ((wPreferences.icon_yard & IY_VERT) \
1654 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1655 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1657 #define Y ((wPreferences.icon_yard & IY_VERT) \
1658 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1659 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1661 /* arrange application icons */
1662 aicon = scr->app_icon_list;
1663 /* reverse them to avoid unnecessarily sliding of icons */
1664 while (aicon && aicon->next)
1665 aicon = aicon->next;
1667 while (aicon) {
1668 if (!aicon->docked) {
1669 /* CHECK: can icon be NULL here ? */
1670 /* The intention here is to place the AppIcon on the head that
1671 * contains most of the applications _main_ window. */
1672 head = wGetHeadForWindow(aicon->icon->owner);
1674 if (aicon->x_pos != X || aicon->y_pos != Y) {
1675 #ifdef ANIMATIONS
1676 if (!wPreferences.no_animations) {
1677 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1679 #endif /* ANIMATIONS */
1681 wAppIconMove(aicon, X, Y);
1682 vars[head].pi++;
1683 if (vars[head].pi >= vars[head].pf) {
1684 vars[head].pi = 0;
1685 vars[head].si++;
1688 aicon = aicon->prev;
1691 /* arrange miniwindows */
1692 wwin = scr->focused_window;
1693 /* reverse them to avoid unnecessarily shuffling */
1694 while (wwin && wwin->prev)
1695 wwin = wwin->prev;
1697 while (wwin) {
1698 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1699 (wwin->frame->workspace == scr->current_workspace ||
1700 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1702 head = wGetHeadForWindow(wwin);
1704 if (arrangeAll || !wwin->flags.icon_moved) {
1705 if (wwin->icon_x != X || wwin->icon_y != Y) {
1706 #ifdef ANIMATIONS
1707 if (wPreferences.no_animations) {
1708 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1709 } else {
1710 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1711 wwin->icon_y, X, Y);
1713 #else
1714 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1715 #endif /* ANIMATIONS */
1717 wwin->icon_x = X;
1718 wwin->icon_y = Y;
1720 vars[head].pi++;
1721 if (vars[head].pi >= vars[head].pf) {
1722 vars[head].pi = 0;
1723 vars[head].si++;
1727 if (arrangeAll) {
1728 wwin->flags.icon_moved = 0;
1730 /* we reversed the order, so we use next */
1731 wwin = wwin->next;
1734 wfree(vars);
1737 #if 0
1738 void wArrangeIcons(WScreen * scr, Bool arrangeAll)
1740 WWindow *wwin;
1741 WAppIcon *aicon;
1742 int pf; /* primary axis */
1743 int sf; /* secondary axis */
1744 int fullW;
1745 int fullH;
1746 int pi, si;
1747 int sx1, sx2, sy1, sy2; /* screen boundary */
1748 int sw, sh;
1749 int xo, yo;
1750 int xs, ys;
1751 int isize = wPreferences.icon_size;
1754 * Find out screen boundaries.
1758 * Allows each head to have miniwindows
1760 WMRect rect = wGetRectForHead(scr, wGetHeadForPointerLocation(scr));
1762 sx1 = rect.pos.x;
1763 sy1 = rect.pos.y;
1764 sw = rect.size.width;
1765 sh = rect.size.height;
1766 sx2 = sx1 + sw;
1767 sy2 = sy1 + sh;
1768 if (scr->dock) {
1769 if (scr->dock->on_right_side)
1770 sx2 -= isize + DOCK_EXTRA_SPACE;
1771 else
1772 sx1 += isize + DOCK_EXTRA_SPACE;
1774 #if 0
1775 sw = isize * (scr->scr_width / isize);
1776 sh = isize * (scr->scr_height / isize);
1777 #else
1778 sw = isize * (sw / isize);
1779 sh = isize * (sh / isize);
1780 #endif
1781 fullW = (sx2 - sx1) / isize;
1782 fullH = (sy2 - sy1) / isize;
1784 /* icon yard boundaries */
1785 if (wPreferences.icon_yard & IY_VERT) {
1786 pf = fullH;
1787 sf = fullW;
1788 } else {
1789 pf = fullW;
1790 sf = fullH;
1792 if (wPreferences.icon_yard & IY_RIGHT) {
1793 xo = sx2 - isize;
1794 xs = -1;
1795 } else {
1796 xo = sx1;
1797 xs = 1;
1799 if (wPreferences.icon_yard & IY_TOP) {
1800 yo = sy1;
1801 ys = 1;
1802 } else {
1803 yo = sy2 - isize;
1804 ys = -1;
1807 /* arrange icons putting the most recently focused window
1808 * as the last icon */
1809 #define X ((wPreferences.icon_yard & IY_VERT) ? xo + xs*(si*isize)\
1810 : xo + xs*(pi*isize))
1811 #define Y ((wPreferences.icon_yard & IY_VERT) ? yo + ys*(pi*isize)\
1812 : yo + ys*(si*isize))
1814 /* arrange application icons */
1815 aicon = scr->app_icon_list;
1816 /* reverse them to avoid unnecessarily sliding of icons */
1817 while (aicon && aicon->next)
1818 aicon = aicon->next;
1820 pi = 0;
1821 si = 0;
1822 while (aicon) {
1823 if (!aicon->docked) {
1824 if (aicon->x_pos != X || aicon->y_pos != Y) {
1825 #ifdef ANIMATIONS
1826 if (!wPreferences.no_animations) {
1827 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1829 #endif /* ANIMATIONS */
1831 wAppIconMove(aicon, X, Y);
1832 pi++;
1834 /* we reversed the order so we use prev */
1835 aicon = aicon->prev;
1836 if (pi >= pf) {
1837 pi = 0;
1838 si++;
1842 /* arrange miniwindows */
1844 wwin = scr->focused_window;
1845 /* reverse them to avoid unnecessarily shuffling */
1846 while (wwin && wwin->prev)
1847 wwin = wwin->prev;
1849 while (wwin) {
1850 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1851 (wwin->frame->workspace == scr->current_workspace ||
1852 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1854 if (arrangeAll || !wwin->flags.icon_moved) {
1855 if (wwin->icon_x != X || wwin->icon_y != Y) {
1856 #ifdef ANIMATIONS
1857 if (wPreferences.no_animations) {
1858 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1859 } else {
1860 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1861 wwin->icon_y, X, Y);
1863 #else
1864 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1865 #endif /* ANIMATIONS */
1867 wwin->icon_x = X;
1868 wwin->icon_y = Y;
1869 pi++;
1872 if (arrangeAll) {
1873 wwin->flags.icon_moved = 0;
1875 /* we reversed the order, so we use next */
1876 wwin = wwin->next;
1877 if (pi >= pf) {
1878 pi = 0;
1879 si++;
1883 #endif
1885 void wSelectWindow(WWindow * wwin, Bool flag)
1887 WScreen *scr = wwin->screen_ptr;
1889 if (flag) {
1890 wwin->flags.selected = 1;
1891 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1893 if (!HAS_BORDER(wwin)) {
1894 XSetWindowBorderWidth(dpy, wwin->frame->core->window, FRAME_BORDER_WIDTH);
1897 if (!scr->selected_windows)
1898 scr->selected_windows = WMCreateArray(4);
1899 WMAddToArray(scr->selected_windows, wwin);
1900 } else {
1901 wwin->flags.selected = 0;
1902 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
1904 if (!HAS_BORDER(wwin)) {
1905 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1908 if (scr->selected_windows) {
1909 WMRemoveFromArray(scr->selected_windows, wwin);
1914 void wMakeWindowVisible(WWindow * wwin)
1916 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1917 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1919 if (wwin->flags.shaded) {
1920 wUnshadeWindow(wwin);
1922 if (wwin->flags.hidden) {
1923 WApplication *app;
1925 app = wApplicationOf(wwin->main_window);
1926 if (app) {
1927 /* trick to get focus to this window */
1928 app->last_focused = wwin;
1929 wUnhideApplication(app, False, False);
1932 if (wwin->flags.miniaturized) {
1933 wDeiconifyWindow(wwin);
1934 } else {
1935 if (!WFLAGP(wwin, no_focusable))
1936 wSetFocusTo(wwin->screen_ptr, wwin);
1937 wRaiseFrame(wwin->frame->core);
1942 * Do the animation while shading (called with what = SHADE)
1943 * or unshading (what = UNSHADE).
1945 #ifdef ANIMATIONS
1946 static void shade_animate(WWindow *wwin, Bool what)
1948 int y, s, w, h;
1949 time_t time0 = time(NULL);
1951 if (wwin->flags.skip_next_animation && wPreferences.no_animations)
1952 return;
1954 switch(what) {
1955 case SHADE:
1956 if (!wwin->screen_ptr->flags.startup) {
1957 /* do the shading animation */
1958 h = wwin->frame->core->height;
1959 s = h / SHADE_STEPS;
1960 if (s < 1)
1961 s = 1;
1962 w = wwin->frame->core->width;
1963 y = wwin->frame->top_width;
1964 while (h > wwin->frame->top_width + 1) {
1965 XMoveWindow(dpy, wwin->client_win, 0, y);
1966 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1967 XFlush(dpy);
1969 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1970 break;
1972 if (SHADE_DELAY > 0) {
1973 wusleep(SHADE_DELAY * 1000L);
1974 } else {
1975 wusleep(10);
1977 h -= s;
1978 y -= s;
1980 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1982 break;
1984 case UNSHADE:
1985 h = wwin->frame->top_width + wwin->frame->bottom_width;
1986 y = wwin->frame->top_width - wwin->client.height;
1987 s = abs(y) / SHADE_STEPS;
1988 if (s < 1)
1989 s = 1;
1990 w = wwin->frame->core->width;
1991 XMoveWindow(dpy, wwin->client_win, 0, y);
1992 if (s > 0) {
1993 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
1994 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1995 XMoveWindow(dpy, wwin->client_win, 0, y);
1996 XFlush(dpy);
1997 if (SHADE_DELAY > 0) {
1998 wusleep(SHADE_DELAY * 2000L / 3);
1999 } else {
2000 wusleep(10);
2002 h += s;
2003 y += s;
2005 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
2006 break;
2009 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
2010 break;
2013 #else
2014 static void shade_animate(WWindow *wwin, Bool what) { return; }
2015 #endif /* ANIMATIONS */