Minor fixes to appicon highlighting
[wmaker-crm.git] / src / actions.c
blob13b6b73a4c6683dbabf1b50b1be6859a52c940a2
1 /* action.c- misc. window commands (miniaturize, hide etc.)
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #include "wconfig.h"
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <math.h>
32 #include <time.h>
34 #include "WindowMaker.h"
35 #include "framewin.h"
36 #include "window.h"
37 #include "client.h"
38 #include "icon.h"
39 #include "funcs.h"
40 #include "application.h"
41 #include "actions.h"
42 #include "stacking.h"
43 #include "appicon.h"
44 #include "dock.h"
45 #include "appmenu.h"
46 #include "winspector.h"
47 #include "workspace.h"
48 #include "xinerama.h"
50 /****** Global Variables ******/
52 int ignore_wks_change = 0;
53 extern Time LastTimestamp;
54 extern Time LastFocusChange;
55 extern WPreferences wPreferences;
56 extern Atom _XA_WM_TAKE_FOCUS;
57 extern void ProcessPendingEvents();
58 extern int calcIntersectionLength(int p1, int l1, int p2, int l2);
60 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
61 unsigned int *new_width, unsigned int *new_height);
62 static void save_old_geometry(WWindow *wwin);
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;
90 #ifdef ANIMATIONS
91 static void shade_animate(WWindow *wwin, Bool what);
92 #else
93 static void shade_animate(WWindow *wwin, Bool what) { }
94 #endif
97 *----------------------------------------------------------------------
98 * wSetFocusTo--
99 * Changes the window focus to the one passed as argument.
100 * If the window to focus is not already focused, it will be brought
101 * to the head of the list of windows. Previously focused window is
102 * unfocused.
104 * Side effects:
105 * Window list may be reordered and the window focus is changed.
107 *----------------------------------------------------------------------
109 void wSetFocusTo(WScreen *scr, WWindow *wwin)
111 static WScreen *old_scr = NULL;
113 WWindow *old_focused;
114 WWindow *focused = scr->focused_window;
115 Time timestamp = LastTimestamp;
116 WApplication *oapp = NULL, *napp = NULL;
117 int wasfocused;
119 if (scr->flags.ignore_focus_events || compareTimes(LastFocusChange, timestamp) > 0)
120 return;
122 if (!old_scr)
123 old_scr = scr;
124 old_focused = old_scr->focused_window;
126 LastFocusChange = timestamp;
128 if (old_focused)
129 oapp = wApplicationOf(old_focused->main_window);
131 if (wwin == NULL) {
132 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
133 if (old_focused)
134 wWindowUnfocus(old_focused);
135 if (oapp) {
136 wAppMenuUnmap(oapp->menu);
137 wApplicationDeactivate(oapp);
140 WMPostNotificationName(WMNChangedFocus, NULL, (void *)True);
141 return;
142 } else if (old_scr != scr && old_focused) {
143 wWindowUnfocus(old_focused);
146 wasfocused = wwin->flags.focused;
147 napp = wApplicationOf(wwin->main_window);
149 /* remember last workspace where the app has been */
150 if (napp) {
151 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
152 napp->last_workspace = wwin->frame->workspace;
155 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
156 /* install colormap if colormap mode is lock mode */
157 if (wPreferences.colormap_mode == WCM_CLICK)
158 wColormapInstallForWindow(scr, wwin);
160 /* set input focus */
161 switch (wwin->focus_mode) {
162 case WFM_NO_INPUT:
163 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
164 break;
166 case WFM_PASSIVE:
167 case WFM_LOCALLY_ACTIVE:
168 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
169 break;
171 case WFM_GLOBALLY_ACTIVE:
172 break;
174 XFlush(dpy);
175 if (wwin->protocols.TAKE_FOCUS) {
176 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
178 XSync(dpy, False);
179 } else {
180 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
182 if (WFLAGP(wwin, no_focusable))
183 return;
185 /* if this is not the focused window focus it */
186 if (focused != wwin) {
187 /* change the focus window list order */
188 if (wwin->prev)
189 wwin->prev->next = wwin->next;
191 if (wwin->next)
192 wwin->next->prev = wwin->prev;
194 wwin->prev = focused;
195 focused->next = wwin;
196 wwin->next = NULL;
197 scr->focused_window = wwin;
199 if (oapp && oapp != napp) {
200 wAppMenuUnmap(oapp->menu);
201 wApplicationDeactivate(oapp);
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);
215 if (napp)
216 wApplicationActivate(napp);
218 XFlush(dpy);
219 old_scr = scr;
222 void wShadeWindow(WWindow *wwin)
225 if (wwin->flags.shaded)
226 return;
228 XLowerWindow(dpy, wwin->client_win);
229 shade_animate(wwin, SHADE);
231 wwin->flags.skip_next_animation = 0;
232 wwin->flags.shaded = 1;
233 wwin->flags.mapped = 0;
234 /* prevent window withdrawal when getting UnmapNotify */
235 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
236 XUnmapWindow(dpy, wwin->client_win);
237 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
239 /* for the client it's just like iconification */
240 wFrameWindowResize(wwin->frame, wwin->frame->core->width, wwin->frame->top_width - 1);
242 wwin->client.y = wwin->frame_y - wwin->client.height + wwin->frame->top_width;
243 wWindowSynthConfigureNotify(wwin);
246 wClientSetState(wwin, IconicState, None);
249 WMPostNotificationName(WMNChangedState, wwin, "shade");
251 #ifdef ANIMATIONS
252 if (!wwin->screen_ptr->flags.startup) {
253 /* Catch up with events not processed while animation was running */
254 ProcessPendingEvents();
256 #endif
259 void wUnshadeWindow(WWindow *wwin)
262 if (!wwin->flags.shaded)
263 return;
265 wwin->flags.shaded = 0;
266 wwin->flags.mapped = 1;
267 XMapWindow(dpy, wwin->client_win);
269 shade_animate(wwin, UNSHADE);
271 wwin->flags.skip_next_animation = 0;
272 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
273 wwin->frame->top_width + wwin->client.height + wwin->frame->bottom_width);
275 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
276 wWindowSynthConfigureNotify(wwin);
278 /* if the window is focused, set the focus again as it was disabled during
279 * shading */
280 if (wwin->flags.focused)
281 wSetFocusTo(wwin->screen_ptr, wwin);
283 WMPostNotificationName(WMNChangedState, wwin, "shade");
286 /* Set the old coordinates using the current values */
287 static void save_old_geometry(WWindow *wwin)
289 wwin->old_geometry.width = wwin->client.width;
290 wwin->old_geometry.height = wwin->client.height;
291 wwin->old_geometry.x = wwin->frame_x;
292 wwin->old_geometry.y = wwin->frame_y;
295 void wMaximizeWindow(WWindow *wwin, int directions)
297 int new_x, new_y;
298 unsigned int new_width, new_height, half_scr_width;
299 WArea usableArea, totalArea;
300 Bool has_border = 1;
301 int adj_size;
303 if (!IS_RESIZABLE(wwin))
304 return;
306 if (!HAS_BORDER(wwin))
307 has_border = 0;
309 /* the size to adjust the geometry */
310 adj_size = FRAME_BORDER_WIDTH * 2 * has_border;
312 /* save old coordinates before we change the current values */
313 save_old_geometry(wwin);
315 totalArea.x1 = 0;
316 totalArea.y1 = 0;
317 totalArea.x2 = wwin->screen_ptr->scr_width;
318 totalArea.y2 = wwin->screen_ptr->scr_height;
319 usableArea = totalArea;
321 if (!(directions & MAX_IGNORE_XINERAMA)) {
322 WScreen *scr = wwin->screen_ptr;
323 int head;
325 if (directions & MAX_KEYBOARD)
326 head = wGetHeadForWindow(wwin);
327 else
328 head = wGetHeadForPointerLocation(scr);
330 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
333 /* Only save directions, not kbd or xinerama hints */
334 directions &= (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_MAXIMUS);
336 if (WFLAGP(wwin, full_maximize)) {
337 usableArea = totalArea;
339 half_scr_width = (usableArea.x2 - usableArea.x1)/2;
341 if (wwin->flags.shaded) {
342 wwin->flags.skip_next_animation = 1;
343 wUnshadeWindow(wwin);
346 if (directions & MAX_HORIZONTAL) {
347 new_width = usableArea.x2 - usableArea.x1 - adj_size;
348 new_x = usableArea.x1;
349 } else if (directions & MAX_LEFTHALF) {
350 new_width = half_scr_width - adj_size;
351 new_x = usableArea.x1;
352 } else if (directions & MAX_RIGHTHALF) {
353 new_width = half_scr_width - adj_size;
354 new_x = usableArea.x1 + half_scr_width;
355 } else {
356 new_x = wwin->frame_x;
357 new_width = wwin->frame->core->width;
360 if (directions & MAX_VERTICAL) {
361 new_height = usableArea.y2 - usableArea.y1 - adj_size;
362 new_y = usableArea.y1;
363 if (WFLAGP(wwin, full_maximize)) {
364 new_y -= wwin->frame->top_width;
365 new_height += wwin->frame->bottom_width - 1;
367 } else {
368 new_y = wwin->frame_y;
369 new_height = wwin->frame->core->height;
372 if (!WFLAGP(wwin, full_maximize)) {
373 new_height -= wwin->frame->top_width + wwin->frame->bottom_width;
376 if (directions & MAX_MAXIMUS) {
377 find_Maximus_geometry(wwin, usableArea, &new_x, &new_y, &new_width, &new_height);
378 new_width -= adj_size;
379 new_height -= adj_size;
380 if (WFLAGP(wwin, full_maximize) && new_y == 0) {
381 new_y -= wwin->frame->top_width;
382 new_height += wwin->frame->top_width - 1;
386 wWindowConstrainSize(wwin, &new_width, &new_height);
388 wWindowCropSize(wwin, usableArea.x2 - usableArea.x1,
389 usableArea.y2 - usableArea.y1, &new_width, &new_height);
391 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
393 WMPostNotificationName(WMNChangedState, wwin, "maximize");
395 /* set maximization state */
396 wwin->flags.maximized = directions;
399 /* the window boundary coordinates */
400 typedef struct {
401 int left;
402 int right;
403 int bottom;
404 int top;
405 int width;
406 int height;
407 } win_coords;
409 static void set_window_coords(WWindow *wwin, win_coords *obs)
411 obs->left = wwin->frame_x;
412 obs->top = wwin->frame_y;
413 obs->width = wwin->frame->core->width;
414 obs->height = wwin->frame->core->height;
415 obs->bottom = obs->top + obs->height;
416 obs->right = obs->left + obs->width;
420 * Maximus: tiled maximization (maximize without overlapping other windows)
422 * The original window 'orig' will be maximized to new coordinates 'new'.
423 * The windows obstructing the maximization of 'orig' are denoted 'obs'.
425 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
426 unsigned int *new_width, unsigned int *new_height)
428 WWindow *tmp;
429 short int tbar_height_0 = 0, rbar_height_0 = 0, bd_width_0 = 0;
430 short int adjust_height;
431 int x_intsect, y_intsect;
432 /* the obstructing, original and new windows */
433 win_coords obs, orig, new;
435 /* set the original coordinate positions of the window to be Maximumized */
436 set_window_coords(wwin, &orig);
438 /* Try to fully maximize first, then readjust later */
439 new.left = usableArea.x1;
440 new.right = usableArea.x2;
441 new.top = usableArea.y1;
442 new.bottom = usableArea.y2;
444 if (HAS_TITLEBAR(wwin))
445 tbar_height_0 = TITLEBAR_HEIGHT;
446 if (HAS_RESIZEBAR(wwin))
447 rbar_height_0 = RESIZEBAR_HEIGHT;
448 if (HAS_BORDER(wwin))
449 bd_width_0 = FRAME_BORDER_WIDTH;
451 /* the length to be subtracted if the window has titlebar, etc */
452 adjust_height = tbar_height_0 + 2 * bd_width_0 + rbar_height_0;
454 tmp = wwin;
455 /* The focused window is always the last in the list */
456 while (tmp->prev) {
457 /* ignore windows in other workspaces etc */
458 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
459 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
460 tmp = tmp->prev;
461 continue;
463 tmp = tmp->prev;
465 /* Set the coordinates of obstructing window */
466 set_window_coords(tmp, &obs);
468 /* Try to maximize in the y direction first */
469 x_intsect = calcIntersectionLength(orig.left, orig.width, obs.left, obs.width);
470 if (x_intsect != 0) {
471 /* TODO: Consider the case when coords are equal */
472 if (obs.bottom < orig.top && obs.bottom > new.top) {
473 /* w_0 is below the bottom of w_j */
474 new.top = obs.bottom + 1;
476 if (orig.bottom < obs.top && obs.top < new.bottom) {
477 /* The bottom of w_0 is above the top of w_j */
478 new.bottom = obs.top - 1;
483 tmp = wwin;
484 while (tmp->prev) {
485 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
486 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
487 tmp = tmp->prev;
488 continue;
490 tmp = tmp->prev;
492 set_window_coords(tmp, &obs);
495 * Use the new.top and new.height instead of original values
496 * as they may have different intersections with the obstructing windows
498 new.height = new.bottom - new.top - adjust_height;
499 y_intsect = calcIntersectionLength(new.top, new.height, obs.top, obs.height);
500 if (y_intsect != 0) {
501 if (obs.right < orig.left && obs.right > new.left) {
502 /* w_0 is completely to the right of w_j */
503 new.left = obs.right + 1;
505 if (orig.right < obs.left && obs.left < new.right) {
506 /* w_0 is completely to the left of w_j */
507 new.right = obs.left - 1;
512 *new_x = new.left;
513 *new_y = new.top;
514 /* xcalc needs -7 here, but other apps don't */
515 *new_height = new.bottom - new.top - adjust_height - 1;;
516 *new_width = new.right - new.left;
519 void wUnmaximizeWindow(WWindow *wwin)
521 int x, y, w, h;
522 WMRect old_geom_rect;
523 int old_head;
524 Bool same_head;
526 if (!wwin->flags.maximized)
527 return;
529 if (wwin->flags.shaded) {
530 wwin->flags.skip_next_animation = 1;
531 wUnshadeWindow(wwin);
533 /* Use old coordinates if they are set, current values otherwise */
534 old_geom_rect = wmkrect(wwin->old_geometry.x, wwin->old_geometry.y, wwin->old_geometry.width, wwin->old_geometry.height);
535 old_head = wGetHeadForRect(wwin->screen_ptr, old_geom_rect);
536 same_head = (wGetHeadForWindow(wwin) == old_head);
537 x = (wwin->old_geometry.x && same_head) ? wwin->old_geometry.x : wwin->frame_x;
538 y = (wwin->old_geometry.y && same_head) ? wwin->old_geometry.y : wwin->frame_y;
539 w = wwin->old_geometry.width ? wwin->old_geometry.width : wwin->client.width;
540 h = wwin->old_geometry.height ? wwin->old_geometry.height : wwin->client.height;
542 wwin->flags.maximized = 0;
543 wWindowConfigure(wwin, x, y, w, h);
545 WMPostNotificationName(WMNChangedState, wwin, "maximize");
548 void wFullscreenWindow(WWindow *wwin)
550 int head;
551 WMRect rect;
553 if (wwin->flags.fullscreen)
554 return;
556 wwin->flags.fullscreen = True;
558 wWindowConfigureBorders(wwin);
560 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
562 wwin->bfs_geometry.x = wwin->frame_x;
563 wwin->bfs_geometry.y = wwin->frame_y;
564 wwin->bfs_geometry.width = wwin->frame->core->width;
565 wwin->bfs_geometry.height = wwin->frame->core->height;
567 head = wGetHeadForWindow(wwin);
568 rect = wGetRectForHead(wwin->screen_ptr, head);
569 wWindowConfigure(wwin, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
571 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
574 void wUnfullscreenWindow(WWindow *wwin)
576 if (!wwin->flags.fullscreen)
577 return;
579 wwin->flags.fullscreen = False;
581 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
582 if (WFLAGP(wwin, sunken)) {
583 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
584 } else if (WFLAGP(wwin, floating)) {
585 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
586 } else {
587 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
591 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
592 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
594 wWindowConfigureBorders(wwin);
596 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
597 wFrameWindowPaint(wwin->frame);
600 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
603 #ifdef ANIMATIONS
604 static void animateResizeFlip(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
606 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
607 float cx, cy, cw, ch;
608 float xstep, ystep, wstep, hstep;
609 XPoint points[5];
610 float dx, dch, midy;
611 float angle, final_angle, delta;
613 xstep = (float)(fx - x) / steps;
614 ystep = (float)(fy - y) / steps;
615 wstep = (float)(fw - w) / steps;
616 hstep = (float)(fh - h) / steps;
618 cx = (float)x;
619 cy = (float)y;
620 cw = (float)w;
621 ch = (float)h;
623 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_F;
624 delta = (float)(final_angle / FRAMES);
625 for (angle = 0;; angle += delta) {
626 if (angle > final_angle)
627 angle = final_angle;
629 dx = (cw / 10) - ((cw / 5) * sin(angle));
630 dch = (ch / 2) * cos(angle);
631 midy = cy + (ch / 2);
633 points[0].x = cx + dx;
634 points[0].y = midy - dch;
635 points[1].x = cx + cw - dx;
636 points[1].y = points[0].y;
637 points[2].x = cx + cw + dx;
638 points[2].y = midy + dch;
639 points[3].x = cx - dx;
640 points[3].y = points[2].y;
641 points[4].x = points[0].x;
642 points[4].y = points[0].y;
644 XGrabServer(dpy);
645 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
646 XFlush(dpy);
647 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
649 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
650 XUngrabServer(dpy);
651 cx += xstep;
652 cy += ystep;
653 cw += wstep;
654 ch += hstep;
655 if (angle >= final_angle)
656 break;
659 XFlush(dpy);
662 #undef FRAMES
664 static void
665 animateResizeTwist(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
667 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
668 float cx, cy, cw, ch;
669 float xstep, ystep, wstep, hstep;
670 XPoint points[5];
671 float angle, final_angle, a, d, delta;
673 x += w / 2;
674 y += h / 2;
675 fx += fw / 2;
676 fy += fh / 2;
678 xstep = (float)(fx - x) / steps;
679 ystep = (float)(fy - y) / steps;
680 wstep = (float)(fw - w) / steps;
681 hstep = (float)(fh - h) / steps;
683 cx = (float)x;
684 cy = (float)y;
685 cw = (float)w;
686 ch = (float)h;
688 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_T;
689 delta = (float)(final_angle / FRAMES);
690 for (angle = 0;; angle += delta) {
691 if (angle > final_angle)
692 angle = final_angle;
694 a = atan(ch / cw);
695 d = sqrt((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
697 points[0].x = cx + cos(angle - a) * d;
698 points[0].y = cy + sin(angle - a) * d;
699 points[1].x = cx + cos(angle + a) * d;
700 points[1].y = cy + sin(angle + a) * d;
701 points[2].x = cx + cos(angle - a + WM_PI) * d;
702 points[2].y = cy + sin(angle - a + WM_PI) * d;
703 points[3].x = cx + cos(angle + a + WM_PI) * d;
704 points[3].y = cy + sin(angle + a + WM_PI) * d;
705 points[4].x = cx + cos(angle - a) * d;
706 points[4].y = cy + sin(angle - a) * d;
707 XGrabServer(dpy);
708 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
709 XFlush(dpy);
710 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
712 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
713 XUngrabServer(dpy);
714 cx += xstep;
715 cy += ystep;
716 cw += wstep;
717 ch += hstep;
718 if (angle >= final_angle)
719 break;
722 XFlush(dpy);
725 #undef FRAMES
727 static void animateResizeZoom(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
729 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
730 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
731 float xstep, ystep, wstep, hstep;
732 int i, j;
734 xstep = (float)(fx - x) / steps;
735 ystep = (float)(fy - y) / steps;
736 wstep = (float)(fw - w) / steps;
737 hstep = (float)(fh - h) / steps;
739 for (j = 0; j < FRAMES; j++) {
740 cx[j] = (float)x;
741 cy[j] = (float)y;
742 cw[j] = (float)w;
743 ch[j] = (float)h;
745 XGrabServer(dpy);
746 for (i = 0; i < steps; i++) {
747 for (j = 0; j < FRAMES; j++) {
748 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
749 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
751 XFlush(dpy);
752 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
754 for (j = 0; j < FRAMES; j++) {
755 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
756 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
757 if (j < FRAMES - 1) {
758 cx[j] = cx[j + 1];
759 cy[j] = cy[j + 1];
760 cw[j] = cw[j + 1];
761 ch[j] = ch[j + 1];
762 } else {
763 cx[j] += xstep;
764 cy[j] += ystep;
765 cw[j] += wstep;
766 ch[j] += hstep;
771 for (j = 0; j < FRAMES; j++) {
772 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
774 XFlush(dpy);
775 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
777 for (j = 0; j < FRAMES; j++) {
778 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
781 XUngrabServer(dpy);
784 #undef FRAMES
786 void animateResize(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh)
788 int style = wPreferences.iconification_style; /* Catch the value */
789 int steps;
791 if (style == WIS_NONE)
792 return;
794 if (style == WIS_RANDOM) {
795 style = rand() % 3;
798 switch (style) {
799 case WIS_TWIST:
800 steps = MINIATURIZE_ANIMATION_STEPS_T;
801 if (steps > 0)
802 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
803 break;
804 case WIS_FLIP:
805 steps = MINIATURIZE_ANIMATION_STEPS_F;
806 if (steps > 0)
807 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
808 break;
809 case WIS_ZOOM:
810 default:
811 steps = MINIATURIZE_ANIMATION_STEPS_Z;
812 if (steps > 0)
813 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
814 break;
817 #endif /* ANIMATIONS */
819 static void flushExpose(void)
821 XEvent tmpev;
823 while (XCheckTypedEvent(dpy, Expose, &tmpev))
824 WMHandleEvent(&tmpev);
825 XSync(dpy, 0);
828 static void unmapTransientsFor(WWindow *wwin)
830 WWindow *tmp;
832 tmp = wwin->screen_ptr->focused_window;
833 while (tmp) {
834 /* unmap the transients for this transient */
835 if (tmp != wwin && tmp->transient_for == wwin->client_win
836 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup || tmp->flags.shaded)) {
837 unmapTransientsFor(tmp);
838 tmp->flags.miniaturized = 1;
839 if (!tmp->flags.shaded) {
840 wWindowUnmap(tmp);
841 } else {
842 XUnmapWindow(dpy, tmp->frame->core->window);
845 if (!tmp->flags.shaded)
847 wClientSetState(tmp, IconicState, None);
849 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
851 tmp = tmp->prev;
855 static void mapTransientsFor(WWindow *wwin)
857 WWindow *tmp;
859 tmp = wwin->screen_ptr->focused_window;
860 while (tmp) {
861 /* recursively map the transients for this transient */
862 if (tmp != wwin && tmp->transient_for == wwin->client_win && /*!tmp->flags.mapped */ tmp->flags.miniaturized
863 && tmp->icon == NULL) {
864 mapTransientsFor(tmp);
865 tmp->flags.miniaturized = 0;
866 if (!tmp->flags.shaded) {
867 wWindowMap(tmp);
868 } else {
869 XMapWindow(dpy, tmp->frame->core->window);
871 tmp->flags.semi_focused = 0;
873 if (!tmp->flags.shaded)
875 wClientSetState(tmp, NormalState, None);
877 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
879 tmp = tmp->prev;
883 static WWindow *recursiveTransientFor(WWindow * wwin)
885 int i;
887 if (!wwin)
888 return None;
890 /* hackish way to detect transient_for cycle */
891 i = wwin->screen_ptr->window_count + 1;
893 while (wwin && wwin->transient_for != None && i > 0) {
894 wwin = wWindowFor(wwin->transient_for);
895 i--;
897 if (i == 0 && wwin) {
898 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin->frame->title);
899 return NULL;
902 return wwin;
905 void wIconifyWindow(WWindow * wwin)
907 XWindowAttributes attribs;
908 int present;
910 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
911 /* the window doesn't exist anymore */
912 return;
915 if (wwin->flags.miniaturized) {
916 return;
919 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
920 WWindow *owner = wWindowFor(wwin->transient_for);
922 if (owner && owner->flags.miniaturized)
923 return;
926 present = wwin->frame->workspace == wwin->screen_ptr->current_workspace;
928 /* if the window is in another workspace, simplify process */
929 if (present) {
930 /* icon creation may take a while */
931 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
932 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
933 GrabModeAsync, None, None, CurrentTime);
936 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
937 if (!wwin->flags.icon_moved) {
938 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
940 wwin->icon = wIconCreate(wwin);
942 wwin->icon->mapped = 1;
945 wwin->flags.miniaturized = 1;
946 wwin->flags.mapped = 0;
948 /* unmap transients */
950 unmapTransientsFor(wwin);
952 if (present) {
953 XUngrabPointer(dpy, CurrentTime);
954 wWindowUnmap(wwin);
955 /* let all Expose events arrive so that we can repaint
956 * something before the animation starts (and the server is grabbed) */
957 XSync(dpy, 0);
959 if (wPreferences.disable_miniwindows || wwin->flags.net_handle_icon)
960 wClientSetState(wwin, IconicState, None);
961 else
962 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
964 flushExpose();
965 #ifdef ANIMATIONS
966 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
967 && !wPreferences.no_animations) {
968 int ix, iy, iw, ih;
970 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
971 ix = wwin->icon_x;
972 iy = wwin->icon_y;
973 iw = wwin->icon->core->width;
974 ih = wwin->icon->core->height;
975 } else {
976 if (wwin->flags.net_handle_icon) {
977 ix = wwin->icon_x;
978 iy = wwin->icon_y;
979 iw = wwin->icon_w;
980 ih = wwin->icon_h;
981 } else {
982 ix = 0;
983 iy = 0;
984 iw = wwin->screen_ptr->scr_width;
985 ih = wwin->screen_ptr->scr_height;
988 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
989 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih);
991 #endif
994 wwin->flags.skip_next_animation = 0;
996 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
997 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace ||
998 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1000 XMapWindow(dpy, wwin->icon->core->window);
1002 AddToStackList(wwin->icon->core);
1004 wLowerFrame(wwin->icon->core);
1007 if (present) {
1008 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1011 * It doesn't seem to be working and causes button event hangup
1012 * when deiconifying a transient window.
1013 setupIconGrabs(wwin->icon);
1015 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
1016 && wPreferences.focus_mode == WKF_CLICK) {
1017 WWindow *tmp;
1019 tmp = wwin->prev;
1020 while (tmp) {
1021 if (!WFLAGP(tmp, no_focusable)
1022 && !(tmp->flags.hidden || tmp->flags.miniaturized)
1023 && (wwin->frame->workspace == tmp->frame->workspace))
1024 break;
1025 tmp = tmp->prev;
1027 wSetFocusTo(wwin->screen_ptr, tmp);
1028 } else if (wPreferences.focus_mode != WKF_CLICK) {
1029 wSetFocusTo(wwin->screen_ptr, NULL);
1031 #ifdef ANIMATIONS
1032 if (!wwin->screen_ptr->flags.startup) {
1033 /* Catch up with events not processed while animation was running */
1034 Window clientwin = wwin->client_win;
1036 ProcessPendingEvents();
1038 /* the window can disappear while ProcessPendingEvents() runs */
1039 if (!wWindowFor(clientwin)) {
1040 return;
1043 #endif
1046 /* maybe we want to do this regardless of net_handle_icon
1047 * it seems to me we might break behaviour this way.
1049 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1050 && !wwin->flags.net_handle_icon)
1051 wIconSelect(wwin->icon);
1053 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1055 if (wPreferences.auto_arrange_icons)
1056 wArrangeIcons(wwin->screen_ptr, True);
1059 void wDeiconifyWindow(WWindow *wwin)
1061 /* Let's avoid changing workspace while deiconifying */
1062 ignore_wks_change = 1;
1064 /* we're hiding for show_desktop */
1065 int netwm_hidden = wwin->flags.net_show_desktop &&
1066 wwin->frame->workspace != wwin->screen_ptr->current_workspace;
1068 if (!netwm_hidden)
1069 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1071 if (!wwin->flags.miniaturized)
1072 return;
1074 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1075 WWindow *owner = recursiveTransientFor(wwin);
1077 if (owner && owner->flags.miniaturized) {
1078 wDeiconifyWindow(owner);
1079 wSetFocusTo(wwin->screen_ptr, wwin);
1080 wRaiseFrame(wwin->frame->core);
1081 return;
1085 wwin->flags.miniaturized = 0;
1087 if (!netwm_hidden && !wwin->flags.shaded) {
1088 wwin->flags.mapped = 1;
1091 if (!netwm_hidden || wPreferences.sticky_icons) {
1092 /* maybe we want to do this regardless of net_handle_icon
1093 * it seems to me we might break behaviour this way.
1095 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon
1096 && wwin->icon != NULL) {
1097 if (wwin->icon->selected)
1098 wIconSelect(wwin->icon);
1100 XUnmapWindow(dpy, wwin->icon->core->window);
1104 /* if the window is in another workspace, do it silently */
1105 if (!netwm_hidden) {
1106 #ifdef ANIMATIONS
1107 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1108 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1109 int ix, iy, iw, ih;
1111 if (!wPreferences.disable_miniwindows
1112 && !wwin->flags.net_handle_icon) {
1113 ix = wwin->icon_x;
1114 iy = wwin->icon_y;
1115 iw = wwin->icon->core->width;
1116 ih = wwin->icon->core->height;
1117 } else {
1118 if (wwin->flags.net_handle_icon) {
1119 ix = wwin->icon_x;
1120 iy = wwin->icon_y;
1121 iw = wwin->icon_w;
1122 ih = wwin->icon_h;
1123 } else {
1124 ix = 0;
1125 iy = 0;
1126 iw = wwin->screen_ptr->scr_width;
1127 ih = wwin->screen_ptr->scr_height;
1130 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1131 wwin->frame_x, wwin->frame_y,
1132 wwin->frame->core->width, wwin->frame->core->height);
1134 #endif /* ANIMATIONS */
1135 wwin->flags.skip_next_animation = 0;
1136 XGrabServer(dpy);
1137 if (!wwin->flags.shaded) {
1138 XMapWindow(dpy, wwin->client_win);
1140 XMapWindow(dpy, wwin->frame->core->window);
1141 wRaiseFrame(wwin->frame->core);
1142 if (!wwin->flags.shaded) {
1143 wClientSetState(wwin, NormalState, None);
1145 mapTransientsFor(wwin);
1148 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1149 && !wwin->flags.net_handle_icon) {
1150 RemoveFromStackList(wwin->icon->core);
1151 /* removeIconGrabs(wwin->icon); */
1152 wIconDestroy(wwin->icon);
1153 wwin->icon = NULL;
1156 if (!netwm_hidden) {
1157 XUngrabServer(dpy);
1159 wSetFocusTo(wwin->screen_ptr, wwin);
1161 #ifdef ANIMATIONS
1162 if (!wwin->screen_ptr->flags.startup) {
1163 /* Catch up with events not processed while animation was running */
1164 Window clientwin = wwin->client_win;
1166 ProcessPendingEvents();
1168 /* the window can disappear while ProcessPendingEvents() runs */
1169 if (!wWindowFor(clientwin)) {
1170 return;
1173 #endif
1176 if (wPreferences.auto_arrange_icons) {
1177 wArrangeIcons(wwin->screen_ptr, True);
1180 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1182 /* In case we were shaded and iconified, also unshade */
1183 if (!netwm_hidden)
1184 wUnshadeWindow(wwin);
1186 ignore_wks_change = 0;
1189 static void hideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate)
1191 if (wwin->flags.miniaturized) {
1192 if (wwin->icon) {
1193 XUnmapWindow(dpy, wwin->icon->core->window);
1194 wwin->icon->mapped = 0;
1196 wwin->flags.hidden = 1;
1198 WMPostNotificationName(WMNChangedState, wwin, "hide");
1199 return;
1202 if (wwin->flags.inspector_open) {
1203 wHideInspectorForWindow(wwin);
1206 wwin->flags.hidden = 1;
1207 wWindowUnmap(wwin);
1209 wClientSetState(wwin, IconicState, icon->icon_win);
1210 flushExpose();
1212 #ifdef ANIMATIONS
1213 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1214 !wwin->flags.skip_next_animation && animate) {
1215 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1216 wwin->frame->core->width, wwin->frame->core->height,
1217 icon_x, icon_y, icon->core->width, icon->core->height);
1219 #endif
1220 wwin->flags.skip_next_animation = 0;
1222 WMPostNotificationName(WMNChangedState, wwin, "hide");
1225 void wHideAll(WScreen *scr)
1227 WWindow *wwin;
1228 WWindow **windows;
1229 Window FocusedWin;
1230 WMenu *menu;
1231 unsigned int wcount = 0;
1232 int FocusState;
1233 int i;
1235 if (!scr)
1236 return;
1238 menu = scr->switch_menu;
1240 windows = malloc(sizeof(WWindow *));
1242 if (menu != NULL) {
1243 for (i = 0; i < menu->entry_no; i++) {
1244 windows[wcount] = (WWindow *) menu->entries[i]->clientdata;
1245 wcount++;
1246 windows = realloc(windows, sizeof(WWindow *) * (wcount+1));
1248 } else {
1249 wwin = scr->focused_window;
1251 while (wwin) {
1252 windows[wcount] = wwin;
1253 wcount++;
1254 windows = realloc(windows, sizeof(WWindow *) * (wcount+1));
1255 wwin = wwin->prev;
1260 for (i = 0; i < wcount; i++) {
1261 wwin = windows[i];
1262 if (wwin->frame->workspace == scr->current_workspace
1263 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1264 && !wwin->flags.internal_window
1265 && !WFLAGP(wwin, no_miniaturizable)
1267 wwin->flags.skip_next_animation = 1;
1268 wIconifyWindow(wwin);
1273 void wHideOtherApplications(WWindow *awin)
1275 WWindow *wwin;
1276 WApplication *tapp;
1278 if (!awin)
1279 return;
1280 wwin = awin->screen_ptr->focused_window;
1282 while (wwin) {
1283 if (wwin != awin
1284 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1285 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1286 && !wwin->flags.internal_window
1287 && wGetWindowOfInspectorForWindow(wwin) != awin && !WFLAGP(wwin, no_hide_others)) {
1289 if (wwin->main_window == None || WFLAGP(wwin, no_appicon)) {
1290 if (!WFLAGP(wwin, no_miniaturizable)) {
1291 wwin->flags.skip_next_animation = 1;
1292 wIconifyWindow(wwin);
1294 } else if (wwin->main_window != None && awin->main_window != wwin->main_window) {
1295 tapp = wApplicationOf(wwin->main_window);
1296 if (tapp) {
1297 tapp->flags.skip_next_animation = 1;
1298 wHideApplication(tapp);
1299 } else {
1300 if (!WFLAGP(wwin, no_miniaturizable)) {
1301 wwin->flags.skip_next_animation = 1;
1302 wIconifyWindow(wwin);
1307 wwin = wwin->prev;
1310 wSetFocusTo(awin->screen_ptr, awin);
1314 void wHideApplication(WApplication *wapp)
1316 WScreen *scr;
1317 WWindow *wlist;
1318 int hadfocus;
1319 int animate;
1321 if (!wapp) {
1322 wwarning("trying to hide a non grouped window");
1323 return;
1325 if (!wapp->main_window_desc) {
1326 wwarning("group leader not found for window group");
1327 return;
1329 scr = wapp->main_window_desc->screen_ptr;
1330 hadfocus = 0;
1331 wlist = scr->focused_window;
1332 if (!wlist)
1333 return;
1335 if (wlist->main_window == wapp->main_window)
1336 wapp->last_focused = wlist;
1337 else
1338 wapp->last_focused = NULL;
1340 animate = !wapp->flags.skip_next_animation;
1342 while (wlist) {
1343 if (wlist->main_window == wapp->main_window) {
1344 if (wlist->flags.focused) {
1345 hadfocus = 1;
1347 if (wapp->app_icon) {
1348 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1349 wapp->app_icon->y_pos, wlist, animate);
1350 animate = False;
1353 wlist = wlist->prev;
1356 wapp->flags.skip_next_animation = 0;
1358 if (hadfocus) {
1359 if (wPreferences.focus_mode == WKF_CLICK) {
1360 wlist = scr->focused_window;
1361 while (wlist) {
1362 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1363 && (wlist->flags.mapped || wlist->flags.shaded))
1364 break;
1365 wlist = wlist->prev;
1367 wSetFocusTo(scr, wlist);
1368 } else {
1369 wSetFocusTo(scr, NULL);
1373 wapp->flags.hidden = 1;
1375 if (wPreferences.auto_arrange_icons) {
1376 wArrangeIcons(scr, True);
1378 #ifdef HIDDENDOT
1379 if (wapp->app_icon)
1380 wAppIconPaint(wapp->app_icon);
1381 #endif
1384 static void unhideWindow(WIcon *icon, int icon_x, int icon_y, WWindow *wwin, int animate, int bringToCurrentWS)
1386 if (bringToCurrentWS)
1387 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1389 wwin->flags.hidden = 0;
1391 #ifdef ANIMATIONS
1392 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1393 animateResize(wwin->screen_ptr, icon_x, icon_y,
1394 icon->core->width, icon->core->height,
1395 wwin->frame_x, wwin->frame_y,
1396 wwin->frame->core->width, wwin->frame->core->height);
1398 #endif
1399 wwin->flags.skip_next_animation = 0;
1400 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1401 XMapWindow(dpy, wwin->client_win);
1402 XMapWindow(dpy, wwin->frame->core->window);
1403 wClientSetState(wwin, NormalState, None);
1404 wwin->flags.mapped = 1;
1405 wRaiseFrame(wwin->frame->core);
1407 if (wwin->flags.inspector_open) {
1408 wUnhideInspectorForWindow(wwin);
1411 WMPostNotificationName(WMNChangedState, wwin, "hide");
1414 void wUnhideApplication(WApplication *wapp, Bool miniwindows, Bool bringToCurrentWS)
1416 WScreen *scr;
1417 WWindow *wlist, *next;
1418 WWindow *focused = NULL;
1419 int animate;
1421 if (!wapp)
1422 return;
1424 scr = wapp->main_window_desc->screen_ptr;
1425 wlist = scr->focused_window;
1426 if (!wlist)
1427 return;
1429 /* goto beginning of list */
1430 while (wlist->prev)
1431 wlist = wlist->prev;
1433 animate = !wapp->flags.skip_next_animation;
1435 while (wlist) {
1436 next = wlist->next;
1438 if (wlist->main_window == wapp->main_window) {
1439 if (wlist->flags.focused)
1440 focused = wlist;
1441 else if (!focused || !focused->flags.focused)
1442 focused = wlist;
1444 if (wlist->flags.miniaturized) {
1445 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1446 wlist->frame->workspace == scr->current_workspace) && wlist->icon) {
1447 if (!wlist->icon->mapped) {
1448 int x, y;
1450 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1451 if (wlist->icon_x != x || wlist->icon_y != y) {
1452 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1454 wlist->icon_x = x;
1455 wlist->icon_y = y;
1456 XMapWindow(dpy, wlist->icon->core->window);
1457 wlist->icon->mapped = 1;
1459 wRaiseFrame(wlist->icon->core);
1461 if (bringToCurrentWS)
1462 wWindowChangeWorkspace(wlist, scr->current_workspace);
1463 wlist->flags.hidden = 0;
1464 if (miniwindows && wlist->frame->workspace == scr->current_workspace) {
1465 wDeiconifyWindow(wlist);
1467 WMPostNotificationName(WMNChangedState, wlist, "hide");
1468 } else if (wlist->flags.shaded) {
1469 if (bringToCurrentWS)
1470 wWindowChangeWorkspace(wlist, scr->current_workspace);
1471 wlist->flags.hidden = 0;
1472 wRaiseFrame(wlist->frame->core);
1473 if (wlist->frame->workspace == scr->current_workspace) {
1474 XMapWindow(dpy, wlist->frame->core->window);
1475 if (miniwindows) {
1476 wUnshadeWindow(wlist);
1479 WMPostNotificationName(WMNChangedState, wlist, "hide");
1480 } else if (wlist->flags.hidden) {
1481 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1482 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1483 animate = False;
1484 } else {
1485 if (bringToCurrentWS && wlist->frame->workspace != scr->current_workspace) {
1486 wWindowChangeWorkspace(wlist, scr->current_workspace);
1488 wRaiseFrame(wlist->frame->core);
1491 wlist = next;
1494 wapp->flags.skip_next_animation = 0;
1495 wapp->flags.hidden = 0;
1497 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1498 wRaiseFrame(wapp->last_focused->frame->core);
1499 wSetFocusTo(scr, wapp->last_focused);
1500 } else if (focused) {
1501 wSetFocusTo(scr, focused);
1503 wapp->last_focused = NULL;
1504 if (wPreferences.auto_arrange_icons) {
1505 wArrangeIcons(scr, True);
1507 #ifdef HIDDENDOT
1508 wAppIconPaint(wapp->app_icon);
1509 #endif
1512 void wShowAllWindows(WScreen *scr)
1514 WWindow *wwin, *old_foc;
1515 WApplication *wapp;
1517 old_foc = wwin = scr->focused_window;
1518 while (wwin) {
1519 if (!wwin->flags.internal_window &&
1520 (scr->current_workspace == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1521 if (wwin->flags.miniaturized) {
1522 wwin->flags.skip_next_animation = 1;
1523 wDeiconifyWindow(wwin);
1524 } else if (wwin->flags.hidden) {
1525 wapp = wApplicationOf(wwin->main_window);
1526 if (wapp) {
1527 wUnhideApplication(wapp, False, False);
1528 } else {
1529 wwin->flags.skip_next_animation = 1;
1530 wDeiconifyWindow(wwin);
1534 wwin = wwin->prev;
1536 wSetFocusTo(scr, old_foc);
1537 /*wRaiseFrame(old_foc->frame->core); */
1540 void wRefreshDesktop(WScreen *scr)
1542 Window win;
1543 XSetWindowAttributes attr;
1545 attr.backing_store = NotUseful;
1546 attr.save_under = False;
1547 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1548 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1549 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1550 XMapRaised(dpy, win);
1551 XDestroyWindow(dpy, win);
1552 XFlush(dpy);
1555 void wArrangeIcons(WScreen *scr, Bool arrangeAll)
1557 WWindow *wwin;
1558 WAppIcon *aicon;
1560 int head;
1561 const int heads = wXineramaHeads(scr);
1563 struct HeadVars {
1564 int pf; /* primary axis */
1565 int sf; /* secondary axis */
1566 int fullW;
1567 int fullH;
1568 int pi, si;
1569 int sx1, sx2, sy1, sy2; /* screen boundary */
1570 int sw, sh;
1571 int xo, yo;
1572 int xs, ys;
1573 } *vars;
1575 int isize = wPreferences.icon_size;
1577 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
1579 for (head = 0; head < heads; ++head) {
1580 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1581 WMRect rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
1582 vars[head].pi = vars[head].si = 0;
1583 vars[head].sx1 = rect.pos.x;
1584 vars[head].sy1 = rect.pos.y;
1585 vars[head].sw = rect.size.width;
1586 vars[head].sh = rect.size.height;
1587 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1588 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1589 vars[head].sw = isize * (vars[head].sw / isize);
1590 vars[head].sh = isize * (vars[head].sh / isize);
1591 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
1592 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
1594 /* icon yard boundaries */
1595 if (wPreferences.icon_yard & IY_VERT) {
1596 vars[head].pf = vars[head].fullH;
1597 vars[head].sf = vars[head].fullW;
1598 } else {
1599 vars[head].pf = vars[head].fullW;
1600 vars[head].sf = vars[head].fullH;
1602 if (wPreferences.icon_yard & IY_RIGHT) {
1603 vars[head].xo = vars[head].sx2 - isize;
1604 vars[head].xs = -1;
1605 } else {
1606 vars[head].xo = vars[head].sx1;
1607 vars[head].xs = 1;
1609 if (wPreferences.icon_yard & IY_TOP) {
1610 vars[head].yo = vars[head].sy1;
1611 vars[head].ys = 1;
1612 } else {
1613 vars[head].yo = vars[head].sy2 - isize;
1614 vars[head].ys = -1;
1618 #define X ((wPreferences.icon_yard & IY_VERT) \
1619 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1620 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1622 #define Y ((wPreferences.icon_yard & IY_VERT) \
1623 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1624 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1626 /* arrange application icons */
1627 aicon = scr->app_icon_list;
1628 /* reverse them to avoid unnecessarily sliding of icons */
1629 while (aicon && aicon->next)
1630 aicon = aicon->next;
1632 while (aicon) {
1633 if (!aicon->docked) {
1634 /* CHECK: can icon be NULL here ? */
1635 /* The intention here is to place the AppIcon on the head that
1636 * contains most of the applications _main_ window. */
1637 head = wGetHeadForWindow(aicon->icon->owner);
1639 if (aicon->x_pos != X || aicon->y_pos != Y) {
1640 #ifdef ANIMATIONS
1641 if (!wPreferences.no_animations) {
1642 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1644 #endif /* ANIMATIONS */
1646 wAppIconMove(aicon, X, Y);
1647 vars[head].pi++;
1648 if (vars[head].pi >= vars[head].pf) {
1649 vars[head].pi = 0;
1650 vars[head].si++;
1653 aicon = aicon->prev;
1656 /* arrange miniwindows */
1657 wwin = scr->focused_window;
1658 /* reverse them to avoid unnecessarily shuffling */
1659 while (wwin && wwin->prev)
1660 wwin = wwin->prev;
1662 while (wwin) {
1663 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1664 (wwin->frame->workspace == scr->current_workspace ||
1665 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1667 head = wGetHeadForWindow(wwin);
1669 if (arrangeAll || !wwin->flags.icon_moved) {
1670 if (wwin->icon_x != X || wwin->icon_y != Y) {
1671 #ifdef ANIMATIONS
1672 if (wPreferences.no_animations) {
1673 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1674 } else {
1675 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1676 wwin->icon_y, X, Y);
1678 #else
1679 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1680 #endif /* ANIMATIONS */
1682 wwin->icon_x = X;
1683 wwin->icon_y = Y;
1685 vars[head].pi++;
1686 if (vars[head].pi >= vars[head].pf) {
1687 vars[head].pi = 0;
1688 vars[head].si++;
1692 if (arrangeAll) {
1693 wwin->flags.icon_moved = 0;
1695 /* we reversed the order, so we use next */
1696 wwin = wwin->next;
1699 wfree(vars);
1702 void wSelectWindow(WWindow *wwin, Bool flag)
1704 WScreen *scr = wwin->screen_ptr;
1706 if (flag) {
1707 wwin->flags.selected = 1;
1708 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1710 if (!HAS_BORDER(wwin)) {
1711 XSetWindowBorderWidth(dpy, wwin->frame->core->window, FRAME_BORDER_WIDTH);
1714 if (!scr->selected_windows)
1715 scr->selected_windows = WMCreateArray(4);
1716 WMAddToArray(scr->selected_windows, wwin);
1717 } else {
1718 wwin->flags.selected = 0;
1719 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
1721 if (!HAS_BORDER(wwin)) {
1722 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1725 if (scr->selected_windows) {
1726 WMRemoveFromArray(scr->selected_windows, wwin);
1731 void wMakeWindowVisible(WWindow *wwin)
1733 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1734 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1736 if (wwin->flags.shaded) {
1737 wUnshadeWindow(wwin);
1739 if (wwin->flags.hidden) {
1740 WApplication *app;
1742 app = wApplicationOf(wwin->main_window);
1743 if (app) {
1744 /* trick to get focus to this window */
1745 app->last_focused = wwin;
1746 wUnhideApplication(app, False, False);
1749 if (wwin->flags.miniaturized) {
1750 wDeiconifyWindow(wwin);
1751 } else {
1752 if (!WFLAGP(wwin, no_focusable))
1753 wSetFocusTo(wwin->screen_ptr, wwin);
1754 wRaiseFrame(wwin->frame->core);
1759 * Do the animation while shading (called with what = SHADE)
1760 * or unshading (what = UNSHADE).
1762 #ifdef ANIMATIONS
1763 static void shade_animate(WWindow *wwin, Bool what)
1765 int y, s, w, h;
1766 time_t time0 = time(NULL);
1768 if (wwin->flags.skip_next_animation && wPreferences.no_animations)
1769 return;
1771 switch(what) {
1772 case SHADE:
1773 if (!wwin->screen_ptr->flags.startup) {
1774 /* do the shading animation */
1775 h = wwin->frame->core->height;
1776 s = h / SHADE_STEPS;
1777 if (s < 1)
1778 s = 1;
1779 w = wwin->frame->core->width;
1780 y = wwin->frame->top_width;
1781 while (h > wwin->frame->top_width + 1) {
1782 XMoveWindow(dpy, wwin->client_win, 0, y);
1783 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1784 XFlush(dpy);
1786 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1787 break;
1789 if (SHADE_DELAY > 0) {
1790 wusleep(SHADE_DELAY * 1000L);
1791 } else {
1792 wusleep(10);
1794 h -= s;
1795 y -= s;
1797 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1799 break;
1801 case UNSHADE:
1802 h = wwin->frame->top_width + wwin->frame->bottom_width;
1803 y = wwin->frame->top_width - wwin->client.height;
1804 s = abs(y) / SHADE_STEPS;
1805 if (s < 1)
1806 s = 1;
1807 w = wwin->frame->core->width;
1808 XMoveWindow(dpy, wwin->client_win, 0, y);
1809 if (s > 0) {
1810 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
1811 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1812 XMoveWindow(dpy, wwin->client_win, 0, y);
1813 XFlush(dpy);
1814 if (SHADE_DELAY > 0) {
1815 wusleep(SHADE_DELAY * 2000L / 3);
1816 } else {
1817 wusleep(10);
1819 h += s;
1820 y += s;
1822 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1823 break;
1826 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1827 break;
1830 #endif