activate XGrabServer again
[wmaker-crm.git] / src / actions.c
blob43b4906c6d975548ca9c683fc0df3a6ec6e13efb
1 /* action.c- misc. window commands (miniaturize, hide etc.)
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #include "wconfig.h"
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <math.h>
32 #include <time.h>
34 #include "WindowMaker.h"
35 #include "wcore.h"
36 #include "framewin.h"
37 #include "window.h"
38 #include "client.h"
39 #include "icon.h"
40 #include "funcs.h"
41 #include "application.h"
42 #include "actions.h"
43 #include "stacking.h"
44 #include "appicon.h"
45 #include "dock.h"
46 #include "appmenu.h"
47 #include "winspector.h"
48 #include "workspace.h"
49 #include "xinerama.h"
51 /****** Global Variables ******/
52 extern Time LastTimestamp;
53 extern Time LastFocusChange;
55 extern Cursor wCursor[WCUR_LAST];
57 extern WPreferences wPreferences;
59 extern Atom _XA_WM_TAKE_FOCUS;
61 extern void ProcessPendingEvents();
62 extern int calcIntersectionLength(int p1, int l1, int p2, int l2);
64 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
65 unsigned int *new_width, unsigned int *new_height);
66 static void save_old_geometry(WWindow *wwin);
68 /******* Local Variables *******/
69 static struct {
70 int steps;
71 int delay;
72 } shadePars[5] = {
74 SHADE_STEPS_UF, SHADE_DELAY_UF}, {
75 SHADE_STEPS_F, SHADE_DELAY_F}, {
76 SHADE_STEPS_M, SHADE_DELAY_M}, {
77 SHADE_STEPS_S, SHADE_DELAY_S}, {
78 SHADE_STEPS_US, SHADE_DELAY_US}};
80 #define UNSHADE 0
81 #define SHADE 1
82 #define SHADE_STEPS shadePars[(int)wPreferences.shade_speed].steps
83 #define SHADE_DELAY shadePars[(int)wPreferences.shade_speed].delay
85 static int compareTimes(Time t1, Time t2)
87 Time diff;
88 if (t1 == t2)
89 return 0;
90 diff = t1 - t2;
91 return (diff < 60000) ? 1 : -1;
95 *----------------------------------------------------------------------
96 * wSetFocusTo--
97 * Changes the window focus to the one passed as argument.
98 * If the window to focus is not already focused, it will be brought
99 * to the head of the list of windows. Previously focused window is
100 * unfocused.
102 * Side effects:
103 * Window list may be reordered and the window focus is changed.
105 *----------------------------------------------------------------------
107 void wSetFocusTo(WScreen * scr, WWindow * wwin)
109 static WScreen *old_scr = NULL;
111 WWindow *old_focused;
112 WWindow *focused = scr->focused_window;
113 Time timestamp = LastTimestamp;
114 WApplication *oapp = NULL, *napp = NULL;
115 int wasfocused;
117 if (scr->flags.ignore_focus_events || compareTimes(LastFocusChange, timestamp) > 0)
118 return;
120 if (!old_scr)
121 old_scr = scr;
122 old_focused = old_scr->focused_window;
124 LastFocusChange = timestamp;
126 if (old_focused)
127 oapp = wApplicationOf(old_focused->main_window);
129 if (wwin == NULL) {
130 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
131 if (old_focused) {
132 wWindowUnfocus(old_focused);
134 if (oapp) {
135 wAppMenuUnmap(oapp->menu);
136 #ifdef NEWAPPICON
137 wApplicationDeactivate(oapp);
138 #endif
141 WMPostNotificationName(WMNChangedFocus, NULL, (void *)True);
142 return;
143 } else if (old_scr != scr && old_focused) {
144 wWindowUnfocus(old_focused);
147 wasfocused = wwin->flags.focused;
148 napp = wApplicationOf(wwin->main_window);
150 /* remember last workspace where the app has been */
151 if (napp) {
152 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
153 napp->last_workspace = wwin->frame->workspace;
156 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
157 /* install colormap if colormap mode is lock mode */
158 if (wPreferences.colormap_mode == WCM_CLICK)
159 wColormapInstallForWindow(scr, wwin);
161 /* set input focus */
162 switch (wwin->focus_mode) {
163 case WFM_NO_INPUT:
164 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
165 break;
167 case WFM_PASSIVE:
168 case WFM_LOCALLY_ACTIVE:
169 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
170 break;
172 case WFM_GLOBALLY_ACTIVE:
173 break;
175 XFlush(dpy);
176 if (wwin->protocols.TAKE_FOCUS) {
177 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
179 XSync(dpy, False);
180 } else {
181 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
183 if (WFLAGP(wwin, no_focusable))
184 return;
186 /* if this is not the focused window focus it */
187 if (focused != wwin) {
188 /* change the focus window list order */
189 if (wwin->prev)
190 wwin->prev->next = wwin->next;
192 if (wwin->next)
193 wwin->next->prev = wwin->prev;
195 wwin->prev = focused;
196 focused->next = wwin;
197 wwin->next = NULL;
198 scr->focused_window = wwin;
200 if (oapp && oapp != napp) {
201 wAppMenuUnmap(oapp->menu);
202 #ifdef NEWAPPICON
203 wApplicationDeactivate(oapp);
204 #endif
208 wWindowFocus(wwin, focused);
210 if (napp && !wasfocused) {
211 #ifdef USER_MENU
212 wUserMenuRefreshInstances(napp->menu, wwin);
213 #endif /* USER_MENU */
215 if (wwin->flags.mapped)
216 wAppMenuMap(napp->menu, wwin);
217 #ifdef NEWAPPICON
218 wApplicationActivate(napp);
219 #endif
222 XFlush(dpy);
223 old_scr = scr;
226 void wShadeWindow(WWindow *wwin)
229 if (wwin->flags.shaded)
230 return;
232 XLowerWindow(dpy, wwin->client_win);
233 shade_animate(wwin, SHADE);
235 wwin->flags.skip_next_animation = 0;
236 wwin->flags.shaded = 1;
237 wwin->flags.mapped = 0;
238 /* prevent window withdrawal when getting UnmapNotify */
239 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
240 XUnmapWindow(dpy, wwin->client_win);
241 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
243 /* for the client it's just like iconification */
244 wFrameWindowResize(wwin->frame, wwin->frame->core->width, wwin->frame->top_width - 1);
246 wwin->client.y = wwin->frame_y - wwin->client.height + wwin->frame->top_width;
247 wWindowSynthConfigureNotify(wwin);
250 wClientSetState(wwin, IconicState, None);
253 WMPostNotificationName(WMNChangedState, wwin, "shade");
255 #ifdef ANIMATIONS
256 if (!wwin->screen_ptr->flags.startup) {
257 /* Catch up with events not processed while animation was running */
258 ProcessPendingEvents();
260 #endif
263 void wUnshadeWindow(WWindow *wwin)
266 if (!wwin->flags.shaded)
267 return;
269 wwin->flags.shaded = 0;
270 wwin->flags.mapped = 1;
271 XMapWindow(dpy, wwin->client_win);
273 shade_animate(wwin, UNSHADE);
275 wwin->flags.skip_next_animation = 0;
276 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
277 wwin->frame->top_width + wwin->client.height + wwin->frame->bottom_width);
279 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
280 wWindowSynthConfigureNotify(wwin);
283 wClientSetState(wwin, NormalState, None);
285 /* if the window is focused, set the focus again as it was disabled during
286 * shading */
287 if (wwin->flags.focused)
288 wSetFocusTo(wwin->screen_ptr, wwin);
290 WMPostNotificationName(WMNChangedState, wwin, "shade");
293 /* Set the old coordinates using the current values */
294 static void save_old_geometry(WWindow *wwin)
296 wwin->old_geometry.width = wwin->client.width;
297 wwin->old_geometry.height = wwin->client.height;
298 wwin->old_geometry.x = wwin->frame_x;
299 wwin->old_geometry.y = wwin->frame_y;
302 void wMaximizeWindow(WWindow * wwin, int directions)
304 int new_x, new_y;
305 unsigned int new_width, new_height, half_scr_width;
306 WArea usableArea, totalArea;
307 Bool has_border = 1;
308 int adj_size;
310 if (!IS_RESIZABLE(wwin))
311 return;
313 if (!HAS_BORDER(wwin))
314 has_border = 0;
316 /* the size to adjust the geometry */
317 adj_size = FRAME_BORDER_WIDTH * 2 * has_border;
319 /* save old coordinates before we change the current values */
320 save_old_geometry(wwin);
322 totalArea.x1 = 0;
323 totalArea.y1 = 0;
324 totalArea.x2 = wwin->screen_ptr->scr_width;
325 totalArea.y2 = wwin->screen_ptr->scr_height;
326 usableArea = totalArea;
328 if (!(directions & MAX_IGNORE_XINERAMA)) {
329 WScreen *scr = wwin->screen_ptr;
330 int head;
332 if (directions & MAX_KEYBOARD)
333 head = wGetHeadForWindow(wwin);
334 else
335 head = wGetHeadForPointerLocation(scr);
337 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
340 /* Only save directions, not kbd or xinerama hints */
341 directions &= (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_MAXIMUS);
343 if (WFLAGP(wwin, full_maximize)) {
344 usableArea = totalArea;
346 half_scr_width = (usableArea.x2 - usableArea.x1)/2;
348 if (wwin->flags.shaded) {
349 wwin->flags.skip_next_animation = 1;
350 wUnshadeWindow(wwin);
353 if (directions & MAX_HORIZONTAL) {
354 new_width = usableArea.x2 - usableArea.x1 - adj_size;
355 new_x = usableArea.x1;
356 } else if (directions & MAX_LEFTHALF) {
357 new_width = half_scr_width - adj_size;
358 new_x = usableArea.x1;
359 } else if (directions & MAX_RIGHTHALF) {
360 new_width = half_scr_width - adj_size;
361 new_x = usableArea.x1 + half_scr_width;
362 } else {
363 new_x = wwin->frame_x;
364 new_width = wwin->frame->core->width;
367 if (directions & MAX_VERTICAL) {
368 new_height = usableArea.y2 - usableArea.y1 - adj_size;
369 new_y = usableArea.y1;
370 if (WFLAGP(wwin, full_maximize)) {
371 new_y -= wwin->frame->top_width;
372 new_height += wwin->frame->bottom_width - 1;
374 } else {
375 new_y = wwin->frame_y;
376 new_height = wwin->frame->core->height;
379 if (!WFLAGP(wwin, full_maximize)) {
380 new_height -= wwin->frame->top_width + wwin->frame->bottom_width;
383 if (directions & MAX_MAXIMUS) {
384 find_Maximus_geometry(wwin, usableArea, &new_x, &new_y, &new_width, &new_height);
385 if (WFLAGP(wwin, full_maximize) && new_y == 0) {
386 new_y -= wwin->frame->top_width;
387 new_height += wwin->frame->top_width - 1;
391 wWindowConstrainSize(wwin, &new_width, &new_height);
393 wWindowCropSize(wwin, usableArea.x2 - usableArea.x1,
394 usableArea.y2 - usableArea.y1, &new_width, &new_height);
396 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
398 WMPostNotificationName(WMNChangedState, wwin, "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 short int tbar_height_0 = 0, rbar_height_0 = 0;
424 short int bd_width_0 = 0, bd_width_j = 0;
425 short int adjust_height;
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 tbar_height_0 = TITLEBAR_HEIGHT;
435 if (HAS_RESIZEBAR(wwin))
436 rbar_height_0 = RESIZEBAR_HEIGHT;
437 if (HAS_BORDER(wwin))
438 bd_width_0 = FRAME_BORDER_WIDTH;
440 /* the lengths to be subtracted if w_0 has titlebar, etc */
441 adjust_height = tbar_height_0 + 2 * bd_width_0 + rbar_height_0;
443 tmp = wwin;
444 /* The focused window is always the last in the list */
445 while (tmp->prev) {
446 /* ignore windows in other workspaces etc */
447 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
448 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
449 tmp = tmp->prev;
450 continue;
452 tmp = tmp->prev;
454 if (HAS_BORDER(tmp))
455 bd_width_j = FRAME_BORDER_WIDTH;
456 else
457 bd_width_j = 0;
460 * Set the w_j window coordinates. It is convenient
461 * to not use "corrected" sizes for width and height,
462 * otherwise bottom_j and right_border_j would be
463 * incorrect.
465 x_j = tmp->frame_x - bd_width_j;
466 y_j = tmp->frame_y - bd_width_j;
467 width_j = tmp->frame->core->width;
468 height_j = tmp->frame->core->height;
469 botton_j = y_j + height_j + bd_width_j;
470 top_j = y_j - bd_width_j;
471 right_border_j = x_j + width_j + bd_width_j;
473 /* Try to maximize in the y direction first */
474 x_intsect = calcIntersectionLength(x_0, width_0, x_j, width_j);
475 if (x_intsect != 0) {
476 /* TODO: Consider the case when coords are equal */
477 if (botton_j < y_0 && botton_j > new_y_0) {
478 /* w_0 is below the botton of w_j */
479 new_y_0 = botton_j;
481 if (botton_0 < top_j && top_j < new_botton_0) {
482 /* The botton of w_0 is above the top of w_j */
483 new_botton_0 = top_j;
488 tmp = wwin;
489 while (tmp->prev) {
490 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
491 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
492 tmp = tmp->prev;
493 continue;
495 tmp = tmp->prev;
497 if (HAS_BORDER(tmp))
498 bd_width_j = FRAME_BORDER_WIDTH;
499 else
500 bd_width_j = 0;
502 /* set the w_j window coordinates */
503 x_j = tmp->frame_x - bd_width_j;
504 y_j = tmp->frame_y - bd_width_j;
505 width_j = tmp->frame->core->width;
506 height_j = tmp->frame->core->height;
507 botton_j = y_j + height_j + bd_width_j;
508 top_j = y_j - bd_width_j;
509 right_border_j = x_j + width_j + bd_width_j;
512 * Use the updated y coordinates from the above step to account
513 * the possibility that the new value of y_0 will have different
514 * intersections with w_j
516 new_height_0 = new_botton_0 - new_y_0 - adjust_height;
517 y_intsect = calcIntersectionLength(new_y_0, new_height_0, y_j, height_j);
518 if (y_intsect != 0) {
519 if (right_border_j < x_0 && right_border_j > new_x_0) {
520 /* w_0 is completely to the right of w_j */
521 new_x_0 = right_border_j + 1;
523 if (right_border_0 < x_j && x_j < new_right_border_0) {
524 /* w_0 is completely to the left of w_j */
525 new_right_border_0 = x_j - 1;
530 new_height_0 = new_botton_0 - new_y_0 - adjust_height;
531 *new_x = new_x_0;
532 *new_y = new_y_0;
533 *new_height = new_height_0;
534 *new_width = new_right_border_0 - new_x_0;
537 void wUnmaximizeWindow(WWindow * wwin)
539 int x, y, w, h;
540 WMRect old_geom_rect;
541 int old_head;
542 Bool same_head;
544 if (!wwin->flags.maximized)
545 return;
547 if (wwin->flags.shaded) {
548 wwin->flags.skip_next_animation = 1;
549 wUnshadeWindow(wwin);
551 /* Use old coordinates if they are set, current values otherwise */
552 old_geom_rect = wmkrect(wwin->old_geometry.x, wwin->old_geometry.y, wwin->old_geometry.width, wwin->old_geometry.height);
553 old_head = wGetHeadForRect(wwin->screen_ptr, old_geom_rect);
554 same_head = (wGetHeadForWindow(wwin) == old_head);
555 x = (wwin->old_geometry.x && same_head) ? wwin->old_geometry.x : wwin->frame_x;
556 y = (wwin->old_geometry.y && same_head) ? wwin->old_geometry.y : wwin->frame_y;
557 w = wwin->old_geometry.width ? wwin->old_geometry.width : wwin->client.width;
558 h = wwin->old_geometry.height ? wwin->old_geometry.height : wwin->client.height;
560 wwin->flags.maximized = 0;
561 wWindowConfigure(wwin, x, y, w, h);
563 WMPostNotificationName(WMNChangedState, wwin, "maximize");
566 void wFullscreenWindow(WWindow * wwin)
568 int head;
569 WMRect rect;
571 if (wwin->flags.fullscreen)
572 return;
574 wwin->flags.fullscreen = True;
576 wWindowConfigureBorders(wwin);
578 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
580 wwin->bfs_geometry.x = wwin->frame_x;
581 wwin->bfs_geometry.y = wwin->frame_y;
582 wwin->bfs_geometry.width = wwin->frame->core->width;
583 wwin->bfs_geometry.height = wwin->frame->core->height;
585 head = wGetHeadForWindow(wwin);
586 rect = wGetRectForHead(wwin->screen_ptr, head);
587 wWindowConfigure(wwin, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
589 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
592 void wUnfullscreenWindow(WWindow * wwin)
594 if (!wwin->flags.fullscreen)
595 return;
597 wwin->flags.fullscreen = False;
599 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
600 if (WFLAGP(wwin, sunken)) {
601 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
602 } else if (WFLAGP(wwin, floating)) {
603 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
604 } else {
605 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
609 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
610 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
612 wWindowConfigureBorders(wwin);
614 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
615 wFrameWindowPaint(wwin->frame);
618 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
621 #ifdef ANIMATIONS
622 static void animateResizeFlip(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
624 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
625 float cx, cy, cw, ch;
626 float xstep, ystep, wstep, hstep;
627 XPoint points[5];
628 float dx, dch, midy;
629 float angle, final_angle, delta;
631 xstep = (float)(fx - x) / steps;
632 ystep = (float)(fy - y) / steps;
633 wstep = (float)(fw - w) / steps;
634 hstep = (float)(fh - h) / steps;
636 cx = (float)x;
637 cy = (float)y;
638 cw = (float)w;
639 ch = (float)h;
641 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_F;
642 delta = (float)(final_angle / FRAMES);
643 for (angle = 0;; angle += delta) {
644 if (angle > final_angle)
645 angle = final_angle;
647 dx = (cw / 10) - ((cw / 5) * sin(angle));
648 dch = (ch / 2) * cos(angle);
649 midy = cy + (ch / 2);
651 points[0].x = cx + dx;
652 points[0].y = midy - dch;
653 points[1].x = cx + cw - dx;
654 points[1].y = points[0].y;
655 points[2].x = cx + cw + dx;
656 points[2].y = midy + dch;
657 points[3].x = cx - dx;
658 points[3].y = points[2].y;
659 points[4].x = points[0].x;
660 points[4].y = points[0].y;
662 XGrabServer(dpy);
663 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
664 XFlush(dpy);
665 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
667 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
668 XUngrabServer(dpy);
669 cx += xstep;
670 cy += ystep;
671 cw += wstep;
672 ch += hstep;
673 if (angle >= final_angle)
674 break;
677 XFlush(dpy);
680 #undef FRAMES
682 static void
683 animateResizeTwist(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
685 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
686 float cx, cy, cw, ch;
687 float xstep, ystep, wstep, hstep;
688 XPoint points[5];
689 float angle, final_angle, a, d, delta;
691 x += w / 2;
692 y += h / 2;
693 fx += fw / 2;
694 fy += fh / 2;
696 xstep = (float)(fx - x) / steps;
697 ystep = (float)(fy - y) / steps;
698 wstep = (float)(fw - w) / steps;
699 hstep = (float)(fh - h) / steps;
701 cx = (float)x;
702 cy = (float)y;
703 cw = (float)w;
704 ch = (float)h;
706 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_T;
707 delta = (float)(final_angle / FRAMES);
708 for (angle = 0;; angle += delta) {
709 if (angle > final_angle)
710 angle = final_angle;
712 a = atan(ch / cw);
713 d = sqrt((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
715 points[0].x = cx + cos(angle - a) * d;
716 points[0].y = cy + sin(angle - a) * d;
717 points[1].x = cx + cos(angle + a) * d;
718 points[1].y = cy + sin(angle + a) * d;
719 points[2].x = cx + cos(angle - a + WM_PI) * d;
720 points[2].y = cy + sin(angle - a + WM_PI) * d;
721 points[3].x = cx + cos(angle + a + WM_PI) * d;
722 points[3].y = cy + sin(angle + a + WM_PI) * d;
723 points[4].x = cx + cos(angle - a) * d;
724 points[4].y = cy + sin(angle - a) * d;
725 XGrabServer(dpy);
726 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
727 XFlush(dpy);
728 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
730 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
731 XUngrabServer(dpy);
732 cx += xstep;
733 cy += ystep;
734 cw += wstep;
735 ch += hstep;
736 if (angle >= final_angle)
737 break;
740 XFlush(dpy);
743 #undef FRAMES
745 static void animateResizeZoom(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
747 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
748 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
749 float xstep, ystep, wstep, hstep;
750 int i, j;
752 xstep = (float)(fx - x) / steps;
753 ystep = (float)(fy - y) / steps;
754 wstep = (float)(fw - w) / steps;
755 hstep = (float)(fh - h) / steps;
757 for (j = 0; j < FRAMES; j++) {
758 cx[j] = (float)x;
759 cy[j] = (float)y;
760 cw[j] = (float)w;
761 ch[j] = (float)h;
763 XGrabServer(dpy);
764 for (i = 0; i < steps; i++) {
765 for (j = 0; j < FRAMES; j++) {
766 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
767 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
769 XFlush(dpy);
770 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
772 for (j = 0; j < FRAMES; j++) {
773 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
774 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
775 if (j < FRAMES - 1) {
776 cx[j] = cx[j + 1];
777 cy[j] = cy[j + 1];
778 cw[j] = cw[j + 1];
779 ch[j] = ch[j + 1];
780 } else {
781 cx[j] += xstep;
782 cy[j] += ystep;
783 cw[j] += wstep;
784 ch[j] += hstep;
789 for (j = 0; j < FRAMES; j++) {
790 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
792 XFlush(dpy);
793 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
795 for (j = 0; j < FRAMES; j++) {
796 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
799 XUngrabServer(dpy);
802 #undef FRAMES
804 void animateResize(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh)
806 int style = wPreferences.iconification_style; /* Catch the value */
807 int steps;
809 if (style == WIS_NONE)
810 return;
812 if (style == WIS_RANDOM) {
813 style = rand() % 3;
816 switch (style) {
817 case WIS_TWIST:
818 steps = MINIATURIZE_ANIMATION_STEPS_T;
819 if (steps > 0)
820 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
821 break;
822 case WIS_FLIP:
823 steps = MINIATURIZE_ANIMATION_STEPS_F;
824 if (steps > 0)
825 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
826 break;
827 case WIS_ZOOM:
828 default:
829 steps = MINIATURIZE_ANIMATION_STEPS_Z;
830 if (steps > 0)
831 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
832 break;
835 #endif /* ANIMATIONS */
837 static void flushExpose()
839 XEvent tmpev;
841 while (XCheckTypedEvent(dpy, Expose, &tmpev))
842 WMHandleEvent(&tmpev);
843 XSync(dpy, 0);
846 static void unmapTransientsFor(WWindow * wwin)
848 WWindow *tmp;
850 tmp = wwin->screen_ptr->focused_window;
851 while (tmp) {
852 /* unmap the transients for this transient */
853 if (tmp != wwin && tmp->transient_for == wwin->client_win
854 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup || tmp->flags.shaded)) {
855 unmapTransientsFor(tmp);
856 tmp->flags.miniaturized = 1;
857 if (!tmp->flags.shaded) {
858 wWindowUnmap(tmp);
859 } else {
860 XUnmapWindow(dpy, tmp->frame->core->window);
863 if (!tmp->flags.shaded)
865 wClientSetState(tmp, IconicState, None);
867 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
869 tmp = tmp->prev;
873 static void mapTransientsFor(WWindow * wwin)
875 WWindow *tmp;
877 tmp = wwin->screen_ptr->focused_window;
878 while (tmp) {
879 /* recursively map the transients for this transient */
880 if (tmp != wwin && tmp->transient_for == wwin->client_win && /*!tmp->flags.mapped */ tmp->flags.miniaturized
881 && tmp->icon == NULL) {
882 mapTransientsFor(tmp);
883 tmp->flags.miniaturized = 0;
884 if (!tmp->flags.shaded) {
885 wWindowMap(tmp);
886 } else {
887 XMapWindow(dpy, tmp->frame->core->window);
889 tmp->flags.semi_focused = 0;
891 if (!tmp->flags.shaded)
893 wClientSetState(tmp, NormalState, None);
895 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
897 tmp = tmp->prev;
901 #if 0
902 static void setupIconGrabs(WIcon * icon)
904 /* setup passive grabs on the icon */
905 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
906 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
907 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
908 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
909 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
910 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
911 XSync(dpy, 0);
913 #endif
915 static WWindow *recursiveTransientFor(WWindow * wwin)
917 int i;
919 if (!wwin)
920 return None;
922 /* hackish way to detect transient_for cycle */
923 i = wwin->screen_ptr->window_count + 1;
925 while (wwin && wwin->transient_for != None && i > 0) {
926 wwin = wWindowFor(wwin->transient_for);
927 i--;
929 if (i == 0 && wwin) {
930 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin->frame->title);
931 return NULL;
934 return wwin;
937 #if 0
938 static void removeIconGrabs(WIcon * icon)
940 /* remove passive grabs on the icon */
941 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
942 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
943 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
944 XSync(dpy, 0);
946 #endif
948 void wIconifyWindow(WWindow * wwin)
950 XWindowAttributes attribs;
951 int present;
953 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
954 /* the window doesn't exist anymore */
955 return;
958 if (wwin->flags.miniaturized) {
959 return;
962 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
963 WWindow *owner = wWindowFor(wwin->transient_for);
965 if (owner && owner->flags.miniaturized)
966 return;
969 present = wwin->frame->workspace == wwin->screen_ptr->current_workspace;
971 /* if the window is in another workspace, simplify process */
972 if (present) {
973 /* icon creation may take a while */
974 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
975 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
976 GrabModeAsync, None, None, CurrentTime);
979 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
980 if (!wwin->flags.icon_moved) {
981 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
983 wwin->icon = wIconCreate(wwin);
985 wwin->icon->mapped = 1;
988 wwin->flags.miniaturized = 1;
989 wwin->flags.mapped = 0;
991 /* unmap transients */
993 unmapTransientsFor(wwin);
995 if (present) {
996 XUngrabPointer(dpy, CurrentTime);
997 wWindowUnmap(wwin);
998 /* let all Expose events arrive so that we can repaint
999 * something before the animation starts (and the server is grabbed) */
1000 XSync(dpy, 0);
1002 if (wPreferences.disable_miniwindows || wwin->flags.net_handle_icon)
1003 wClientSetState(wwin, IconicState, None);
1004 else
1005 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
1007 flushExpose();
1008 #ifdef ANIMATIONS
1009 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
1010 && !wPreferences.no_animations) {
1011 int ix, iy, iw, ih;
1013 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1014 ix = wwin->icon_x;
1015 iy = wwin->icon_y;
1016 iw = wwin->icon->core->width;
1017 ih = wwin->icon->core->height;
1018 } else {
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 ix = 0;
1026 iy = 0;
1027 iw = wwin->screen_ptr->scr_width;
1028 ih = wwin->screen_ptr->scr_height;
1031 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1032 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih);
1034 #endif
1037 wwin->flags.skip_next_animation = 0;
1039 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1040 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace ||
1041 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1043 XMapWindow(dpy, wwin->icon->core->window);
1045 AddToStackList(wwin->icon->core);
1047 wLowerFrame(wwin->icon->core);
1050 if (present) {
1051 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1054 * It doesn't seem to be working and causes button event hangup
1055 * when deiconifying a transient window.
1056 setupIconGrabs(wwin->icon);
1058 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
1059 && wPreferences.focus_mode == WKF_CLICK) {
1060 WWindow *tmp;
1062 tmp = wwin->prev;
1063 while (tmp) {
1064 if (!WFLAGP(tmp, no_focusable)
1065 && !(tmp->flags.hidden || tmp->flags.miniaturized)
1066 && (wwin->frame->workspace == tmp->frame->workspace))
1067 break;
1068 tmp = tmp->prev;
1070 wSetFocusTo(wwin->screen_ptr, tmp);
1071 } else if (wPreferences.focus_mode != WKF_CLICK) {
1072 wSetFocusTo(wwin->screen_ptr, NULL);
1074 #ifdef ANIMATIONS
1075 if (!wwin->screen_ptr->flags.startup) {
1076 /* Catch up with events not processed while animation was running */
1077 Window clientwin = wwin->client_win;
1079 ProcessPendingEvents();
1081 /* the window can disappear while ProcessPendingEvents() runs */
1082 if (!wWindowFor(clientwin)) {
1083 return;
1086 #endif
1089 /* maybe we want to do this regardless of net_handle_icon
1090 * it seems to me we might break behaviour this way.
1092 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1093 && !wwin->flags.net_handle_icon)
1094 wIconSelect(wwin->icon);
1096 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1098 if (wPreferences.auto_arrange_icons)
1099 wArrangeIcons(wwin->screen_ptr, True);
1102 void wDeiconifyWindow(WWindow * wwin)
1104 /* we're hiding for show_desktop */
1105 int netwm_hidden = wwin->flags.net_show_desktop &&
1106 wwin->frame->workspace != wwin->screen_ptr->current_workspace;
1108 if (!netwm_hidden)
1109 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1111 if (!wwin->flags.miniaturized)
1112 return;
1114 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1115 WWindow *owner = recursiveTransientFor(wwin);
1117 if (owner && owner->flags.miniaturized) {
1118 wDeiconifyWindow(owner);
1119 wSetFocusTo(wwin->screen_ptr, wwin);
1120 wRaiseFrame(wwin->frame->core);
1121 return;
1125 wwin->flags.miniaturized = 0;
1127 if (!netwm_hidden && !wwin->flags.shaded) {
1128 wwin->flags.mapped = 1;
1131 if (!netwm_hidden || wPreferences.sticky_icons) {
1132 /* maybe we want to do this regardless of net_handle_icon
1133 * it seems to me we might break behaviour this way.
1135 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon
1136 && wwin->icon != NULL) {
1137 if (wwin->icon->selected)
1138 wIconSelect(wwin->icon);
1140 XUnmapWindow(dpy, wwin->icon->core->window);
1144 /* if the window is in another workspace, do it silently */
1145 if (!netwm_hidden) {
1146 #ifdef ANIMATIONS
1147 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1148 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1149 int ix, iy, iw, ih;
1151 if (!wPreferences.disable_miniwindows
1152 && !wwin->flags.net_handle_icon) {
1153 ix = wwin->icon_x;
1154 iy = wwin->icon_y;
1155 iw = wwin->icon->core->width;
1156 ih = wwin->icon->core->height;
1157 } else {
1158 if (wwin->flags.net_handle_icon) {
1159 ix = wwin->icon_x;
1160 iy = wwin->icon_y;
1161 iw = wwin->icon_w;
1162 ih = wwin->icon_h;
1163 } else {
1164 ix = 0;
1165 iy = 0;
1166 iw = wwin->screen_ptr->scr_width;
1167 ih = wwin->screen_ptr->scr_height;
1170 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1171 wwin->frame_x, wwin->frame_y,
1172 wwin->frame->core->width, wwin->frame->core->height);
1174 #endif /* ANIMATIONS */
1175 wwin->flags.skip_next_animation = 0;
1176 XGrabServer(dpy);
1177 if (!wwin->flags.shaded) {
1178 XMapWindow(dpy, wwin->client_win);
1180 XMapWindow(dpy, wwin->frame->core->window);
1181 wRaiseFrame(wwin->frame->core);
1182 if (!wwin->flags.shaded) {
1183 wClientSetState(wwin, NormalState, None);
1185 mapTransientsFor(wwin);
1188 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1189 && !wwin->flags.net_handle_icon) {
1190 RemoveFromStackList(wwin->icon->core);
1191 /* removeIconGrabs(wwin->icon); */
1192 wIconDestroy(wwin->icon);
1193 wwin->icon = NULL;
1196 if (!netwm_hidden) {
1197 XUngrabServer(dpy);
1199 wSetFocusTo(wwin->screen_ptr, wwin);
1201 #ifdef ANIMATIONS
1202 if (!wwin->screen_ptr->flags.startup) {
1203 /* Catch up with events not processed while animation was running */
1204 Window clientwin = wwin->client_win;
1206 ProcessPendingEvents();
1208 /* the window can disappear while ProcessPendingEvents() runs */
1209 if (!wWindowFor(clientwin)) {
1210 return;
1213 #endif
1216 if (wPreferences.auto_arrange_icons) {
1217 wArrangeIcons(wwin->screen_ptr, True);
1220 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1222 /* In case we were shaded and iconified, also unshade */
1223 if (!netwm_hidden)
1224 wUnshadeWindow(wwin);
1227 static void hideWindow(WIcon * icon, int icon_x, int icon_y, WWindow * wwin, int animate)
1229 if (wwin->flags.miniaturized) {
1230 if (wwin->icon) {
1231 XUnmapWindow(dpy, wwin->icon->core->window);
1232 wwin->icon->mapped = 0;
1234 wwin->flags.hidden = 1;
1236 WMPostNotificationName(WMNChangedState, wwin, "hide");
1237 return;
1240 if (wwin->flags.inspector_open) {
1241 wHideInspectorForWindow(wwin);
1244 wwin->flags.hidden = 1;
1245 wWindowUnmap(wwin);
1247 wClientSetState(wwin, IconicState, icon->icon_win);
1248 flushExpose();
1250 #ifdef ANIMATIONS
1251 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1252 !wwin->flags.skip_next_animation && animate) {
1253 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1254 wwin->frame->core->width, wwin->frame->core->height,
1255 icon_x, icon_y, icon->core->width, icon->core->height);
1257 #endif
1258 wwin->flags.skip_next_animation = 0;
1260 WMPostNotificationName(WMNChangedState, wwin, "hide");
1263 void wHideOtherApplications(WWindow * awin)
1265 WWindow *wwin;
1266 WApplication *tapp;
1268 if (!awin)
1269 return;
1270 wwin = awin->screen_ptr->focused_window;
1272 while (wwin) {
1273 if (wwin != awin
1274 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1275 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1276 && !wwin->flags.internal_window
1277 && wGetWindowOfInspectorForWindow(wwin) != awin && !WFLAGP(wwin, no_hide_others)) {
1279 if (wwin->main_window == None || WFLAGP(wwin, no_appicon)) {
1280 if (!WFLAGP(wwin, no_miniaturizable)) {
1281 wwin->flags.skip_next_animation = 1;
1282 wIconifyWindow(wwin);
1284 } else if (wwin->main_window != None && awin->main_window != wwin->main_window) {
1285 tapp = wApplicationOf(wwin->main_window);
1286 if (tapp) {
1287 tapp->flags.skip_next_animation = 1;
1288 wHideApplication(tapp);
1289 } else {
1290 if (!WFLAGP(wwin, no_miniaturizable)) {
1291 wwin->flags.skip_next_animation = 1;
1292 wIconifyWindow(wwin);
1297 wwin = wwin->prev;
1300 wSetFocusTo(awin->screen_ptr, awin);
1304 void wHideApplication(WApplication * wapp)
1306 WScreen *scr;
1307 WWindow *wlist;
1308 int hadfocus;
1309 int animate;
1311 if (!wapp) {
1312 wwarning("trying to hide a non grouped window");
1313 return;
1315 if (!wapp->main_window_desc) {
1316 wwarning("group leader not found for window group");
1317 return;
1319 scr = wapp->main_window_desc->screen_ptr;
1320 hadfocus = 0;
1321 wlist = scr->focused_window;
1322 if (!wlist)
1323 return;
1325 if (wlist->main_window == wapp->main_window)
1326 wapp->last_focused = wlist;
1327 else
1328 wapp->last_focused = NULL;
1330 animate = !wapp->flags.skip_next_animation;
1332 while (wlist) {
1333 if (wlist->main_window == wapp->main_window) {
1334 if (wlist->flags.focused) {
1335 hadfocus = 1;
1337 if (wapp->app_icon) {
1338 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1339 wapp->app_icon->y_pos, wlist, animate);
1340 animate = False;
1343 wlist = wlist->prev;
1346 wapp->flags.skip_next_animation = 0;
1348 if (hadfocus) {
1349 if (wPreferences.focus_mode == WKF_CLICK) {
1350 wlist = scr->focused_window;
1351 while (wlist) {
1352 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1353 && (wlist->flags.mapped || wlist->flags.shaded))
1354 break;
1355 wlist = wlist->prev;
1357 wSetFocusTo(scr, wlist);
1358 } else {
1359 wSetFocusTo(scr, NULL);
1363 wapp->flags.hidden = 1;
1365 if (wPreferences.auto_arrange_icons) {
1366 wArrangeIcons(scr, True);
1368 #ifdef HIDDENDOT
1369 if (wapp->app_icon)
1370 wAppIconPaint(wapp->app_icon);
1371 #endif
1374 static void unhideWindow(WIcon * icon, int icon_x, int icon_y, WWindow * wwin, int animate, int bringToCurrentWS)
1376 if (bringToCurrentWS)
1377 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1379 wwin->flags.hidden = 0;
1381 #ifdef ANIMATIONS
1382 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1383 animateResize(wwin->screen_ptr, icon_x, icon_y,
1384 icon->core->width, icon->core->height,
1385 wwin->frame_x, wwin->frame_y,
1386 wwin->frame->core->width, wwin->frame->core->height);
1388 #endif
1389 wwin->flags.skip_next_animation = 0;
1390 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1391 XMapWindow(dpy, wwin->client_win);
1392 XMapWindow(dpy, wwin->frame->core->window);
1393 wClientSetState(wwin, NormalState, None);
1394 wwin->flags.mapped = 1;
1395 wRaiseFrame(wwin->frame->core);
1397 if (wwin->flags.inspector_open) {
1398 wUnhideInspectorForWindow(wwin);
1401 WMPostNotificationName(WMNChangedState, wwin, "hide");
1404 void wUnhideApplication(WApplication * wapp, Bool miniwindows, Bool bringToCurrentWS)
1406 WScreen *scr;
1407 WWindow *wlist, *next;
1408 WWindow *focused = NULL;
1409 int animate;
1411 if (!wapp)
1412 return;
1414 scr = wapp->main_window_desc->screen_ptr;
1415 wlist = scr->focused_window;
1416 if (!wlist)
1417 return;
1419 /* goto beginning of list */
1420 while (wlist->prev)
1421 wlist = wlist->prev;
1423 animate = !wapp->flags.skip_next_animation;
1425 while (wlist) {
1426 next = wlist->next;
1428 if (wlist->main_window == wapp->main_window) {
1429 if (wlist->flags.focused)
1430 focused = wlist;
1431 else if (!focused || !focused->flags.focused)
1432 focused = wlist;
1434 if (wlist->flags.miniaturized) {
1435 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1436 wlist->frame->workspace == scr->current_workspace) && wlist->icon) {
1437 if (!wlist->icon->mapped) {
1438 int x, y;
1440 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1441 if (wlist->icon_x != x || wlist->icon_y != y) {
1442 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1444 wlist->icon_x = x;
1445 wlist->icon_y = y;
1446 XMapWindow(dpy, wlist->icon->core->window);
1447 wlist->icon->mapped = 1;
1449 wRaiseFrame(wlist->icon->core);
1451 if (bringToCurrentWS)
1452 wWindowChangeWorkspace(wlist, scr->current_workspace);
1453 wlist->flags.hidden = 0;
1454 if (miniwindows && wlist->frame->workspace == scr->current_workspace) {
1455 wDeiconifyWindow(wlist);
1457 WMPostNotificationName(WMNChangedState, wlist, "hide");
1458 } else if (wlist->flags.shaded) {
1459 if (bringToCurrentWS)
1460 wWindowChangeWorkspace(wlist, scr->current_workspace);
1461 wlist->flags.hidden = 0;
1462 if (wlist->frame->workspace == scr->current_workspace) {
1463 XMapWindow(dpy, wlist->frame->core->window);
1464 if (miniwindows) {
1465 wUnshadeWindow(wlist);
1466 wRaiseFrame(wlist->frame->core);
1469 WMPostNotificationName(WMNChangedState, wlist, "hide");
1470 } else if (wlist->flags.hidden) {
1471 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1472 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1473 animate = False;
1474 } else {
1475 if (bringToCurrentWS && wlist->frame->workspace != scr->current_workspace) {
1476 wWindowChangeWorkspace(wlist, scr->current_workspace);
1478 wRaiseFrame(wlist->frame->core);
1481 wlist = next;
1484 wapp->flags.skip_next_animation = 0;
1485 wapp->flags.hidden = 0;
1487 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1488 wRaiseFrame(wapp->last_focused->frame->core);
1489 wSetFocusTo(scr, wapp->last_focused);
1490 } else if (focused) {
1491 wSetFocusTo(scr, focused);
1493 wapp->last_focused = NULL;
1494 if (wPreferences.auto_arrange_icons) {
1495 wArrangeIcons(scr, True);
1497 #ifdef HIDDENDOT
1498 wAppIconPaint(wapp->app_icon);
1499 #endif
1502 void wShowAllWindows(WScreen * scr)
1504 WWindow *wwin, *old_foc;
1505 WApplication *wapp;
1507 old_foc = wwin = scr->focused_window;
1508 while (wwin) {
1509 if (!wwin->flags.internal_window &&
1510 (scr->current_workspace == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1511 if (wwin->flags.miniaturized) {
1512 wwin->flags.skip_next_animation = 1;
1513 wDeiconifyWindow(wwin);
1514 } else if (wwin->flags.hidden) {
1515 wapp = wApplicationOf(wwin->main_window);
1516 if (wapp) {
1517 wUnhideApplication(wapp, False, False);
1518 } else {
1519 wwin->flags.skip_next_animation = 1;
1520 wDeiconifyWindow(wwin);
1524 wwin = wwin->prev;
1526 wSetFocusTo(scr, old_foc);
1527 /*wRaiseFrame(old_foc->frame->core); */
1530 void wRefreshDesktop(WScreen * scr)
1532 Window win;
1533 XSetWindowAttributes attr;
1535 attr.backing_store = NotUseful;
1536 attr.save_under = False;
1537 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1538 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1539 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1540 XMapRaised(dpy, win);
1541 XDestroyWindow(dpy, win);
1542 XFlush(dpy);
1545 void wArrangeIcons(WScreen * scr, Bool arrangeAll)
1547 WWindow *wwin;
1548 WAppIcon *aicon;
1550 int head;
1551 const int heads = wXineramaHeads(scr);
1553 struct HeadVars {
1554 int pf; /* primary axis */
1555 int sf; /* secondary axis */
1556 int fullW;
1557 int fullH;
1558 int pi, si;
1559 int sx1, sx2, sy1, sy2; /* screen boundary */
1560 int sw, sh;
1561 int xo, yo;
1562 int xs, ys;
1563 } *vars;
1565 int isize = wPreferences.icon_size;
1567 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
1569 for (head = 0; head < heads; ++head) {
1570 #if 0
1571 WMRect rect = wGetRectForHead(scr, head);
1572 #else
1573 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1574 WMRect rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
1575 #endif
1577 vars[head].pi = vars[head].si = 0;
1578 vars[head].sx1 = rect.pos.x;
1579 vars[head].sy1 = rect.pos.y;
1580 vars[head].sw = rect.size.width;
1581 vars[head].sh = rect.size.height;
1582 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1583 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1585 #if 0
1586 if (scr->dock) {
1587 if (scr->dock->on_right_side)
1588 vars[head].sx2 -= isize + DOCK_EXTRA_SPACE;
1589 else
1590 vars[head].sx1 += isize + DOCK_EXTRA_SPACE;
1592 #endif
1594 vars[head].sw = isize * (vars[head].sw / isize);
1595 vars[head].sh = isize * (vars[head].sh / isize);
1596 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
1597 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
1599 /* icon yard boundaries */
1600 if (wPreferences.icon_yard & IY_VERT) {
1601 vars[head].pf = vars[head].fullH;
1602 vars[head].sf = vars[head].fullW;
1603 } else {
1604 vars[head].pf = vars[head].fullW;
1605 vars[head].sf = vars[head].fullH;
1607 if (wPreferences.icon_yard & IY_RIGHT) {
1608 vars[head].xo = vars[head].sx2 - isize;
1609 vars[head].xs = -1;
1610 } else {
1611 vars[head].xo = vars[head].sx1;
1612 vars[head].xs = 1;
1614 if (wPreferences.icon_yard & IY_TOP) {
1615 vars[head].yo = vars[head].sy1;
1616 vars[head].ys = 1;
1617 } else {
1618 vars[head].yo = vars[head].sy2 - isize;
1619 vars[head].ys = -1;
1623 #define X ((wPreferences.icon_yard & IY_VERT) \
1624 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1625 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1627 #define Y ((wPreferences.icon_yard & IY_VERT) \
1628 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1629 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1631 /* arrange application icons */
1632 aicon = scr->app_icon_list;
1633 /* reverse them to avoid unnecessarily sliding of icons */
1634 while (aicon && aicon->next)
1635 aicon = aicon->next;
1637 while (aicon) {
1638 if (!aicon->docked) {
1639 /* CHECK: can icon be NULL here ? */
1640 /* The intention here is to place the AppIcon on the head that
1641 * contains most of the applications _main_ window. */
1642 head = wGetHeadForWindow(aicon->icon->owner);
1644 if (aicon->x_pos != X || aicon->y_pos != Y) {
1645 #ifdef ANIMATIONS
1646 if (!wPreferences.no_animations) {
1647 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1649 #endif /* ANIMATIONS */
1651 wAppIconMove(aicon, X, Y);
1652 vars[head].pi++;
1653 if (vars[head].pi >= vars[head].pf) {
1654 vars[head].pi = 0;
1655 vars[head].si++;
1658 aicon = aicon->prev;
1661 /* arrange miniwindows */
1662 wwin = scr->focused_window;
1663 /* reverse them to avoid unnecessarily shuffling */
1664 while (wwin && wwin->prev)
1665 wwin = wwin->prev;
1667 while (wwin) {
1668 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1669 (wwin->frame->workspace == scr->current_workspace ||
1670 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1672 head = wGetHeadForWindow(wwin);
1674 if (arrangeAll || !wwin->flags.icon_moved) {
1675 if (wwin->icon_x != X || wwin->icon_y != Y) {
1676 #ifdef ANIMATIONS
1677 if (wPreferences.no_animations) {
1678 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1679 } else {
1680 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1681 wwin->icon_y, X, Y);
1683 #else
1684 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1685 #endif /* ANIMATIONS */
1687 wwin->icon_x = X;
1688 wwin->icon_y = Y;
1690 vars[head].pi++;
1691 if (vars[head].pi >= vars[head].pf) {
1692 vars[head].pi = 0;
1693 vars[head].si++;
1697 if (arrangeAll) {
1698 wwin->flags.icon_moved = 0;
1700 /* we reversed the order, so we use next */
1701 wwin = wwin->next;
1704 wfree(vars);
1707 void wSelectWindow(WWindow * wwin, Bool flag)
1709 WScreen *scr = wwin->screen_ptr;
1711 if (flag) {
1712 wwin->flags.selected = 1;
1713 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1715 if (!HAS_BORDER(wwin)) {
1716 XSetWindowBorderWidth(dpy, wwin->frame->core->window, FRAME_BORDER_WIDTH);
1719 if (!scr->selected_windows)
1720 scr->selected_windows = WMCreateArray(4);
1721 WMAddToArray(scr->selected_windows, wwin);
1722 } else {
1723 wwin->flags.selected = 0;
1724 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
1726 if (!HAS_BORDER(wwin)) {
1727 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1730 if (scr->selected_windows) {
1731 WMRemoveFromArray(scr->selected_windows, wwin);
1736 void wMakeWindowVisible(WWindow * wwin)
1738 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1739 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1741 if (wwin->flags.shaded) {
1742 wUnshadeWindow(wwin);
1744 if (wwin->flags.hidden) {
1745 WApplication *app;
1747 app = wApplicationOf(wwin->main_window);
1748 if (app) {
1749 /* trick to get focus to this window */
1750 app->last_focused = wwin;
1751 wUnhideApplication(app, False, False);
1754 if (wwin->flags.miniaturized) {
1755 wDeiconifyWindow(wwin);
1756 } else {
1757 if (!WFLAGP(wwin, no_focusable))
1758 wSetFocusTo(wwin->screen_ptr, wwin);
1759 wRaiseFrame(wwin->frame->core);
1764 * Do the animation while shading (called with what = SHADE)
1765 * or unshading (what = UNSHADE).
1767 #ifdef ANIMATIONS
1768 static void shade_animate(WWindow *wwin, Bool what)
1770 int y, s, w, h;
1771 time_t time0 = time(NULL);
1773 if (wwin->flags.skip_next_animation && wPreferences.no_animations)
1774 return;
1776 switch(what) {
1777 case SHADE:
1778 if (!wwin->screen_ptr->flags.startup) {
1779 /* do the shading animation */
1780 h = wwin->frame->core->height;
1781 s = h / SHADE_STEPS;
1782 if (s < 1)
1783 s = 1;
1784 w = wwin->frame->core->width;
1785 y = wwin->frame->top_width;
1786 while (h > wwin->frame->top_width + 1) {
1787 XMoveWindow(dpy, wwin->client_win, 0, y);
1788 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1789 XFlush(dpy);
1791 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1792 break;
1794 if (SHADE_DELAY > 0) {
1795 wusleep(SHADE_DELAY * 1000L);
1796 } else {
1797 wusleep(10);
1799 h -= s;
1800 y -= s;
1802 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1804 break;
1806 case UNSHADE:
1807 h = wwin->frame->top_width + wwin->frame->bottom_width;
1808 y = wwin->frame->top_width - wwin->client.height;
1809 s = abs(y) / SHADE_STEPS;
1810 if (s < 1)
1811 s = 1;
1812 w = wwin->frame->core->width;
1813 XMoveWindow(dpy, wwin->client_win, 0, y);
1814 if (s > 0) {
1815 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
1816 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1817 XMoveWindow(dpy, wwin->client_win, 0, y);
1818 XFlush(dpy);
1819 if (SHADE_DELAY > 0) {
1820 wusleep(SHADE_DELAY * 2000L / 3);
1821 } else {
1822 wusleep(10);
1824 h += s;
1825 y += s;
1827 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1828 break;
1831 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1832 break;
1835 #else
1836 static void shade_animate(WWindow *wwin, Bool what) { return; }
1837 #endif /* ANIMATIONS */