Remove static function declaration from header file
[wmaker-crm.git] / src / actions.c
blobc308ed0433381c65862e0fa106bf282a232202d2
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;
94 #ifdef ANIMATIONS
95 static void shade_animate(WWindow *wwin, Bool what);
96 #else
97 static void shade_animate(WWindow *wwin, Bool what) { }
98 #endif
101 *----------------------------------------------------------------------
102 * wSetFocusTo--
103 * Changes the window focus to the one passed as argument.
104 * If the window to focus is not already focused, it will be brought
105 * to the head of the list of windows. Previously focused window is
106 * unfocused.
108 * Side effects:
109 * Window list may be reordered and the window focus is changed.
111 *----------------------------------------------------------------------
113 void wSetFocusTo(WScreen * scr, WWindow * wwin)
115 static WScreen *old_scr = NULL;
117 WWindow *old_focused;
118 WWindow *focused = scr->focused_window;
119 Time timestamp = LastTimestamp;
120 WApplication *oapp = NULL, *napp = NULL;
121 int wasfocused;
123 if (scr->flags.ignore_focus_events || compareTimes(LastFocusChange, timestamp) > 0)
124 return;
126 if (!old_scr)
127 old_scr = scr;
128 old_focused = old_scr->focused_window;
130 LastFocusChange = timestamp;
132 if (old_focused)
133 oapp = wApplicationOf(old_focused->main_window);
135 if (wwin == NULL) {
136 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
137 if (old_focused) {
138 wWindowUnfocus(old_focused);
140 if (oapp) {
141 wAppMenuUnmap(oapp->menu);
142 #ifdef NEWAPPICON
143 wApplicationDeactivate(oapp);
144 #endif
147 WMPostNotificationName(WMNChangedFocus, NULL, (void *)True);
148 return;
149 } else if (old_scr != scr && old_focused) {
150 wWindowUnfocus(old_focused);
153 wasfocused = wwin->flags.focused;
154 napp = wApplicationOf(wwin->main_window);
156 /* remember last workspace where the app has been */
157 if (napp) {
158 /*napp->last_workspace = wwin->screen_ptr->current_workspace; */
159 napp->last_workspace = wwin->frame->workspace;
162 if (wwin->flags.mapped && !WFLAGP(wwin, no_focusable)) {
163 /* install colormap if colormap mode is lock mode */
164 if (wPreferences.colormap_mode == WCM_CLICK)
165 wColormapInstallForWindow(scr, wwin);
167 /* set input focus */
168 switch (wwin->focus_mode) {
169 case WFM_NO_INPUT:
170 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
171 break;
173 case WFM_PASSIVE:
174 case WFM_LOCALLY_ACTIVE:
175 XSetInputFocus(dpy, wwin->client_win, RevertToParent, CurrentTime);
176 break;
178 case WFM_GLOBALLY_ACTIVE:
179 break;
181 XFlush(dpy);
182 if (wwin->protocols.TAKE_FOCUS) {
183 wClientSendProtocol(wwin, _XA_WM_TAKE_FOCUS, timestamp);
185 XSync(dpy, False);
186 } else {
187 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
189 if (WFLAGP(wwin, no_focusable))
190 return;
192 /* if this is not the focused window focus it */
193 if (focused != wwin) {
194 /* change the focus window list order */
195 if (wwin->prev)
196 wwin->prev->next = wwin->next;
198 if (wwin->next)
199 wwin->next->prev = wwin->prev;
201 wwin->prev = focused;
202 focused->next = wwin;
203 wwin->next = NULL;
204 scr->focused_window = wwin;
206 if (oapp && oapp != napp) {
207 wAppMenuUnmap(oapp->menu);
208 #ifdef NEWAPPICON
209 wApplicationDeactivate(oapp);
210 #endif
214 wWindowFocus(wwin, focused);
216 if (napp && !wasfocused) {
217 #ifdef USER_MENU
218 wUserMenuRefreshInstances(napp->menu, wwin);
219 #endif /* USER_MENU */
221 if (wwin->flags.mapped)
222 wAppMenuMap(napp->menu, wwin);
223 #ifdef NEWAPPICON
224 wApplicationActivate(napp);
225 #endif
228 XFlush(dpy);
229 old_scr = scr;
232 void wShadeWindow(WWindow *wwin)
235 if (wwin->flags.shaded)
236 return;
238 XLowerWindow(dpy, wwin->client_win);
239 shade_animate(wwin, SHADE);
241 wwin->flags.skip_next_animation = 0;
242 wwin->flags.shaded = 1;
243 wwin->flags.mapped = 0;
244 /* prevent window withdrawal when getting UnmapNotify */
245 XSelectInput(dpy, wwin->client_win, wwin->event_mask & ~StructureNotifyMask);
246 XUnmapWindow(dpy, wwin->client_win);
247 XSelectInput(dpy, wwin->client_win, wwin->event_mask);
249 /* for the client it's just like iconification */
250 wFrameWindowResize(wwin->frame, wwin->frame->core->width, wwin->frame->top_width - 1);
252 wwin->client.y = wwin->frame_y - wwin->client.height + wwin->frame->top_width;
253 wWindowSynthConfigureNotify(wwin);
256 wClientSetState(wwin, IconicState, None);
259 WMPostNotificationName(WMNChangedState, wwin, "shade");
261 #ifdef ANIMATIONS
262 if (!wwin->screen_ptr->flags.startup) {
263 /* Catch up with events not processed while animation was running */
264 ProcessPendingEvents();
266 #endif
269 void wUnshadeWindow(WWindow *wwin)
272 if (!wwin->flags.shaded)
273 return;
275 wwin->flags.shaded = 0;
276 wwin->flags.mapped = 1;
277 XMapWindow(dpy, wwin->client_win);
279 shade_animate(wwin, UNSHADE);
281 wwin->flags.skip_next_animation = 0;
282 wFrameWindowResize(wwin->frame, wwin->frame->core->width,
283 wwin->frame->top_width + wwin->client.height + wwin->frame->bottom_width);
285 wwin->client.y = wwin->frame_y + wwin->frame->top_width;
286 wWindowSynthConfigureNotify(wwin);
289 wClientSetState(wwin, NormalState, None);
291 /* if the window is focused, set the focus again as it was disabled during
292 * shading */
293 if (wwin->flags.focused)
294 wSetFocusTo(wwin->screen_ptr, wwin);
296 WMPostNotificationName(WMNChangedState, wwin, "shade");
299 /* Set the old coordinates using the current values */
300 static void save_old_geometry(WWindow *wwin)
302 wwin->old_geometry.width = wwin->client.width;
303 wwin->old_geometry.height = wwin->client.height;
304 wwin->old_geometry.x = wwin->frame_x;
305 wwin->old_geometry.y = wwin->frame_y;
308 void wMaximizeWindow(WWindow * wwin, int directions)
310 int new_x, new_y;
311 unsigned int new_width, new_height, half_scr_width;
312 WArea usableArea, totalArea;
313 Bool has_border = 1;
314 int adj_size;
316 if (!IS_RESIZABLE(wwin))
317 return;
319 if (!HAS_BORDER(wwin))
320 has_border = 0;
322 /* the size to adjust the geometry */
323 adj_size = FRAME_BORDER_WIDTH * 2 * has_border;
325 /* save old coordinates before we change the current values */
326 save_old_geometry(wwin);
328 totalArea.x1 = 0;
329 totalArea.y1 = 0;
330 totalArea.x2 = wwin->screen_ptr->scr_width;
331 totalArea.y2 = wwin->screen_ptr->scr_height;
332 usableArea = totalArea;
334 if (!(directions & MAX_IGNORE_XINERAMA)) {
335 WScreen *scr = wwin->screen_ptr;
336 int head;
338 if (directions & MAX_KEYBOARD)
339 head = wGetHeadForWindow(wwin);
340 else
341 head = wGetHeadForPointerLocation(scr);
343 usableArea = wGetUsableAreaForHead(scr, head, &totalArea, True);
346 /* Only save directions, not kbd or xinerama hints */
347 directions &= (MAX_HORIZONTAL | MAX_VERTICAL | MAX_LEFTHALF | MAX_RIGHTHALF | MAX_MAXIMUS);
349 if (WFLAGP(wwin, full_maximize)) {
350 usableArea = totalArea;
352 half_scr_width = (usableArea.x2 - usableArea.x1)/2;
354 if (wwin->flags.shaded) {
355 wwin->flags.skip_next_animation = 1;
356 wUnshadeWindow(wwin);
359 if (directions & MAX_HORIZONTAL) {
360 new_width = usableArea.x2 - usableArea.x1 - adj_size;
361 new_x = usableArea.x1;
362 } else if (directions & MAX_LEFTHALF) {
363 new_width = half_scr_width - adj_size;
364 new_x = usableArea.x1;
365 } else if (directions & MAX_RIGHTHALF) {
366 new_width = half_scr_width - adj_size;
367 new_x = usableArea.x1 + half_scr_width;
368 } else {
369 new_x = wwin->frame_x;
370 new_width = wwin->frame->core->width;
373 if (directions & MAX_VERTICAL) {
374 new_height = usableArea.y2 - usableArea.y1 - adj_size;
375 new_y = usableArea.y1;
376 if (WFLAGP(wwin, full_maximize)) {
377 new_y -= wwin->frame->top_width;
378 new_height += wwin->frame->bottom_width - 1;
380 } else {
381 new_y = wwin->frame_y;
382 new_height = wwin->frame->core->height;
385 if (!WFLAGP(wwin, full_maximize)) {
386 new_height -= wwin->frame->top_width + wwin->frame->bottom_width;
389 if (directions & MAX_MAXIMUS) {
390 find_Maximus_geometry(wwin, usableArea, &new_x, &new_y, &new_width, &new_height);
391 new_width -= adj_size;
392 new_height -= adj_size;
393 if (WFLAGP(wwin, full_maximize) && new_y == 0) {
394 new_y -= wwin->frame->top_width;
395 new_height += wwin->frame->top_width - 1;
399 wWindowConstrainSize(wwin, &new_width, &new_height);
401 wWindowCropSize(wwin, usableArea.x2 - usableArea.x1,
402 usableArea.y2 - usableArea.y1, &new_width, &new_height);
404 wWindowConfigure(wwin, new_x, new_y, new_width, new_height);
406 WMPostNotificationName(WMNChangedState, wwin, "maximize");
408 /* set maximization state */
409 wwin->flags.maximized = directions;
413 * Maximus: tiled maximization (maximize without overlapping other windows)
415 * The window to be maximized will be denoted by w_0 (sub-index zero)
416 * while the windows which will stop the maximization of w_0 are denoted by w_j.
418 static void find_Maximus_geometry(WWindow *wwin, WArea usableArea, int *new_x, int *new_y,
419 unsigned int *new_width, unsigned int *new_height)
421 WWindow *tmp;
422 int x_0 = wwin->frame_x;
423 int y_0 = wwin->frame_y;
424 int width_0 = wwin->frame->core->width;
425 int height_0 = wwin->frame->core->height;
426 int botton_0 = y_0 + height_0;
427 int right_border_0 = x_0 + width_0;
428 int new_x_0, new_y_0, new_botton_0, new_right_border_0, new_height_0;
429 int x_j, y_j, width_j, height_j, botton_j, top_j, right_border_j;
430 int x_intsect, y_intsect;
431 short int tbar_height_0 = 0, rbar_height_0 = 0;
432 short int bd_width_0 = 0, bd_width_j = 0;
433 short int adjust_height;
435 /* Try to fully maximize first, then readjust later */
436 new_x_0 = usableArea.x1;
437 new_y_0 = usableArea.y1;
438 new_botton_0 = usableArea.y2;
439 new_right_border_0 = usableArea.x2;
441 if (HAS_TITLEBAR(wwin))
442 tbar_height_0 = TITLEBAR_HEIGHT;
443 if (HAS_RESIZEBAR(wwin))
444 rbar_height_0 = RESIZEBAR_HEIGHT;
445 if (HAS_BORDER(wwin))
446 bd_width_0 = FRAME_BORDER_WIDTH;
448 /* the lengths to be subtracted if w_0 has titlebar, etc */
449 adjust_height = tbar_height_0 + 2 * bd_width_0 + rbar_height_0;
451 tmp = wwin;
452 /* The focused window is always the last in the list */
453 while (tmp->prev) {
454 /* ignore windows in other workspaces etc */
455 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
456 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
457 tmp = tmp->prev;
458 continue;
460 tmp = tmp->prev;
462 if (HAS_BORDER(tmp))
463 bd_width_j = FRAME_BORDER_WIDTH;
464 else
465 bd_width_j = 0;
468 * Set the w_j window coordinates. It is convenient
469 * to not use "corrected" sizes for width and height,
470 * otherwise bottom_j and right_border_j would be
471 * incorrect.
473 x_j = tmp->frame_x - bd_width_j;
474 y_j = tmp->frame_y - bd_width_j;
475 width_j = tmp->frame->core->width;
476 height_j = tmp->frame->core->height;
477 botton_j = y_j + height_j + bd_width_j;
478 top_j = y_j - bd_width_j;
479 right_border_j = x_j + width_j + bd_width_j;
481 /* Try to maximize in the y direction first */
482 x_intsect = calcIntersectionLength(x_0, width_0, x_j, width_j);
483 if (x_intsect != 0) {
484 /* TODO: Consider the case when coords are equal */
485 if (botton_j < y_0 && botton_j > new_y_0) {
486 /* w_0 is below the botton of w_j */
487 new_y_0 = botton_j;
489 if (botton_0 < top_j && top_j < new_botton_0) {
490 /* The botton of w_0 is above the top of w_j */
491 new_botton_0 = top_j;
496 tmp = wwin;
497 while (tmp->prev) {
498 if (tmp->prev->frame->workspace != wwin->screen_ptr->current_workspace
499 || tmp->prev->flags.miniaturized || tmp->prev->flags.hidden) {
500 tmp = tmp->prev;
501 continue;
503 tmp = tmp->prev;
505 if (HAS_BORDER(tmp))
506 bd_width_j = FRAME_BORDER_WIDTH;
507 else
508 bd_width_j = 0;
510 /* set the w_j window coordinates */
511 x_j = tmp->frame_x - bd_width_j;
512 y_j = tmp->frame_y - bd_width_j;
513 width_j = tmp->frame->core->width;
514 height_j = tmp->frame->core->height;
515 botton_j = y_j + height_j + bd_width_j;
516 top_j = y_j - bd_width_j;
517 right_border_j = x_j + width_j + bd_width_j;
520 * Use the updated y coordinates from the above step to account
521 * the possibility that the new value of y_0 will have different
522 * intersections with w_j
524 new_height_0 = new_botton_0 - new_y_0 - adjust_height;
525 y_intsect = calcIntersectionLength(new_y_0, new_height_0, y_j, height_j);
526 if (y_intsect != 0) {
527 if (right_border_j < x_0 && right_border_j > new_x_0) {
528 /* w_0 is completely to the right of w_j */
529 new_x_0 = right_border_j + 1;
531 if (right_border_0 < x_j && x_j < new_right_border_0) {
532 /* w_0 is completely to the left of w_j */
533 new_right_border_0 = x_j - 1;
538 new_height_0 = new_botton_0 - new_y_0 - adjust_height;
539 *new_x = new_x_0;
540 *new_y = new_y_0;
541 *new_height = new_height_0;
542 *new_width = new_right_border_0 - new_x_0;
545 void wUnmaximizeWindow(WWindow * wwin)
547 int x, y, w, h;
548 WMRect old_geom_rect;
549 int old_head;
550 Bool same_head;
552 if (!wwin->flags.maximized)
553 return;
555 if (wwin->flags.shaded) {
556 wwin->flags.skip_next_animation = 1;
557 wUnshadeWindow(wwin);
559 /* Use old coordinates if they are set, current values otherwise */
560 old_geom_rect = wmkrect(wwin->old_geometry.x, wwin->old_geometry.y, wwin->old_geometry.width, wwin->old_geometry.height);
561 old_head = wGetHeadForRect(wwin->screen_ptr, old_geom_rect);
562 same_head = (wGetHeadForWindow(wwin) == old_head);
563 x = (wwin->old_geometry.x && same_head) ? wwin->old_geometry.x : wwin->frame_x;
564 y = (wwin->old_geometry.y && same_head) ? wwin->old_geometry.y : wwin->frame_y;
565 w = wwin->old_geometry.width ? wwin->old_geometry.width : wwin->client.width;
566 h = wwin->old_geometry.height ? wwin->old_geometry.height : wwin->client.height;
568 wwin->flags.maximized = 0;
569 wWindowConfigure(wwin, x, y, w, h);
571 WMPostNotificationName(WMNChangedState, wwin, "maximize");
574 void wFullscreenWindow(WWindow * wwin)
576 int head;
577 WMRect rect;
579 if (wwin->flags.fullscreen)
580 return;
582 wwin->flags.fullscreen = True;
584 wWindowConfigureBorders(wwin);
586 ChangeStackingLevel(wwin->frame->core, WMFullscreenLevel);
588 wwin->bfs_geometry.x = wwin->frame_x;
589 wwin->bfs_geometry.y = wwin->frame_y;
590 wwin->bfs_geometry.width = wwin->frame->core->width;
591 wwin->bfs_geometry.height = wwin->frame->core->height;
593 head = wGetHeadForWindow(wwin);
594 rect = wGetRectForHead(wwin->screen_ptr, head);
595 wWindowConfigure(wwin, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height);
597 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
600 void wUnfullscreenWindow(WWindow * wwin)
602 if (!wwin->flags.fullscreen)
603 return;
605 wwin->flags.fullscreen = False;
607 if (wwin->frame->core->stacking->window_level == WMFullscreenLevel) {
608 if (WFLAGP(wwin, sunken)) {
609 ChangeStackingLevel(wwin->frame->core, WMSunkenLevel);
610 } else if (WFLAGP(wwin, floating)) {
611 ChangeStackingLevel(wwin->frame->core, WMFloatingLevel);
612 } else {
613 ChangeStackingLevel(wwin->frame->core, WMNormalLevel);
617 wWindowConfigure(wwin, wwin->bfs_geometry.x, wwin->bfs_geometry.y,
618 wwin->bfs_geometry.width, wwin->bfs_geometry.height);
620 wWindowConfigureBorders(wwin);
622 // seems unnecessary, but also harmless (doesn't generate flicker) -Dan
623 wFrameWindowPaint(wwin->frame);
626 WMPostNotificationName(WMNChangedState, wwin, "fullscreen");
629 #ifdef ANIMATIONS
630 static void animateResizeFlip(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
632 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_F)
633 float cx, cy, cw, ch;
634 float xstep, ystep, wstep, hstep;
635 XPoint points[5];
636 float dx, dch, midy;
637 float angle, final_angle, delta;
639 xstep = (float)(fx - x) / steps;
640 ystep = (float)(fy - y) / steps;
641 wstep = (float)(fw - w) / steps;
642 hstep = (float)(fh - h) / steps;
644 cx = (float)x;
645 cy = (float)y;
646 cw = (float)w;
647 ch = (float)h;
649 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_F;
650 delta = (float)(final_angle / FRAMES);
651 for (angle = 0;; angle += delta) {
652 if (angle > final_angle)
653 angle = final_angle;
655 dx = (cw / 10) - ((cw / 5) * sin(angle));
656 dch = (ch / 2) * cos(angle);
657 midy = cy + (ch / 2);
659 points[0].x = cx + dx;
660 points[0].y = midy - dch;
661 points[1].x = cx + cw - dx;
662 points[1].y = points[0].y;
663 points[2].x = cx + cw + dx;
664 points[2].y = midy + dch;
665 points[3].x = cx - dx;
666 points[3].y = points[2].y;
667 points[4].x = points[0].x;
668 points[4].y = points[0].y;
670 XGrabServer(dpy);
671 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
672 XFlush(dpy);
673 wusleep(MINIATURIZE_ANIMATION_DELAY_F);
675 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
676 XUngrabServer(dpy);
677 cx += xstep;
678 cy += ystep;
679 cw += wstep;
680 ch += hstep;
681 if (angle >= final_angle)
682 break;
685 XFlush(dpy);
688 #undef FRAMES
690 static void
691 animateResizeTwist(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
693 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_T)
694 float cx, cy, cw, ch;
695 float xstep, ystep, wstep, hstep;
696 XPoint points[5];
697 float angle, final_angle, a, d, delta;
699 x += w / 2;
700 y += h / 2;
701 fx += fw / 2;
702 fy += fh / 2;
704 xstep = (float)(fx - x) / steps;
705 ystep = (float)(fy - y) / steps;
706 wstep = (float)(fw - w) / steps;
707 hstep = (float)(fh - h) / steps;
709 cx = (float)x;
710 cy = (float)y;
711 cw = (float)w;
712 ch = (float)h;
714 final_angle = 2 * WM_PI * MINIATURIZE_ANIMATION_TWIST_T;
715 delta = (float)(final_angle / FRAMES);
716 for (angle = 0;; angle += delta) {
717 if (angle > final_angle)
718 angle = final_angle;
720 a = atan(ch / cw);
721 d = sqrt((cw / 2) * (cw / 2) + (ch / 2) * (ch / 2));
723 points[0].x = cx + cos(angle - a) * d;
724 points[0].y = cy + sin(angle - a) * d;
725 points[1].x = cx + cos(angle + a) * d;
726 points[1].y = cy + sin(angle + a) * d;
727 points[2].x = cx + cos(angle - a + WM_PI) * d;
728 points[2].y = cy + sin(angle - a + WM_PI) * d;
729 points[3].x = cx + cos(angle + a + WM_PI) * d;
730 points[3].y = cy + sin(angle + a + WM_PI) * d;
731 points[4].x = cx + cos(angle - a) * d;
732 points[4].y = cy + sin(angle - a) * d;
733 XGrabServer(dpy);
734 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
735 XFlush(dpy);
736 wusleep(MINIATURIZE_ANIMATION_DELAY_T);
738 XDrawLines(dpy, scr->root_win, scr->frame_gc, points, 5, CoordModeOrigin);
739 XUngrabServer(dpy);
740 cx += xstep;
741 cy += ystep;
742 cw += wstep;
743 ch += hstep;
744 if (angle >= final_angle)
745 break;
748 XFlush(dpy);
751 #undef FRAMES
753 static void animateResizeZoom(WScreen * scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh, int steps)
755 #define FRAMES (MINIATURIZE_ANIMATION_FRAMES_Z)
756 float cx[FRAMES], cy[FRAMES], cw[FRAMES], ch[FRAMES];
757 float xstep, ystep, wstep, hstep;
758 int i, j;
760 xstep = (float)(fx - x) / steps;
761 ystep = (float)(fy - y) / steps;
762 wstep = (float)(fw - w) / steps;
763 hstep = (float)(fh - h) / steps;
765 for (j = 0; j < FRAMES; j++) {
766 cx[j] = (float)x;
767 cy[j] = (float)y;
768 cw[j] = (float)w;
769 ch[j] = (float)h;
771 XGrabServer(dpy);
772 for (i = 0; i < steps; i++) {
773 for (j = 0; j < FRAMES; j++) {
774 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
775 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
777 XFlush(dpy);
778 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
780 for (j = 0; j < FRAMES; j++) {
781 XDrawRectangle(dpy, scr->root_win, scr->frame_gc,
782 (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
783 if (j < FRAMES - 1) {
784 cx[j] = cx[j + 1];
785 cy[j] = cy[j + 1];
786 cw[j] = cw[j + 1];
787 ch[j] = ch[j + 1];
788 } else {
789 cx[j] += xstep;
790 cy[j] += ystep;
791 cw[j] += wstep;
792 ch[j] += hstep;
797 for (j = 0; j < FRAMES; j++) {
798 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
800 XFlush(dpy);
801 wusleep(MINIATURIZE_ANIMATION_DELAY_Z);
803 for (j = 0; j < FRAMES; j++) {
804 XDrawRectangle(dpy, scr->root_win, scr->frame_gc, (int)cx[j], (int)cy[j], (int)cw[j], (int)ch[j]);
807 XUngrabServer(dpy);
810 #undef FRAMES
812 void animateResize(WScreen *scr, int x, int y, int w, int h, int fx, int fy, int fw, int fh)
814 int style = wPreferences.iconification_style; /* Catch the value */
815 int steps;
817 if (style == WIS_NONE)
818 return;
820 if (style == WIS_RANDOM) {
821 style = rand() % 3;
824 switch (style) {
825 case WIS_TWIST:
826 steps = MINIATURIZE_ANIMATION_STEPS_T;
827 if (steps > 0)
828 animateResizeTwist(scr, x, y, w, h, fx, fy, fw, fh, steps);
829 break;
830 case WIS_FLIP:
831 steps = MINIATURIZE_ANIMATION_STEPS_F;
832 if (steps > 0)
833 animateResizeFlip(scr, x, y, w, h, fx, fy, fw, fh, steps);
834 break;
835 case WIS_ZOOM:
836 default:
837 steps = MINIATURIZE_ANIMATION_STEPS_Z;
838 if (steps > 0)
839 animateResizeZoom(scr, x, y, w, h, fx, fy, fw, fh, steps);
840 break;
843 #endif /* ANIMATIONS */
845 static void flushExpose()
847 XEvent tmpev;
849 while (XCheckTypedEvent(dpy, Expose, &tmpev))
850 WMHandleEvent(&tmpev);
851 XSync(dpy, 0);
854 static void unmapTransientsFor(WWindow * wwin)
856 WWindow *tmp;
858 tmp = wwin->screen_ptr->focused_window;
859 while (tmp) {
860 /* unmap the transients for this transient */
861 if (tmp != wwin && tmp->transient_for == wwin->client_win
862 && (tmp->flags.mapped || wwin->screen_ptr->flags.startup || tmp->flags.shaded)) {
863 unmapTransientsFor(tmp);
864 tmp->flags.miniaturized = 1;
865 if (!tmp->flags.shaded) {
866 wWindowUnmap(tmp);
867 } else {
868 XUnmapWindow(dpy, tmp->frame->core->window);
871 if (!tmp->flags.shaded)
873 wClientSetState(tmp, IconicState, None);
875 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
877 tmp = tmp->prev;
881 static void mapTransientsFor(WWindow * wwin)
883 WWindow *tmp;
885 tmp = wwin->screen_ptr->focused_window;
886 while (tmp) {
887 /* recursively map the transients for this transient */
888 if (tmp != wwin && tmp->transient_for == wwin->client_win && /*!tmp->flags.mapped */ tmp->flags.miniaturized
889 && tmp->icon == NULL) {
890 mapTransientsFor(tmp);
891 tmp->flags.miniaturized = 0;
892 if (!tmp->flags.shaded) {
893 wWindowMap(tmp);
894 } else {
895 XMapWindow(dpy, tmp->frame->core->window);
897 tmp->flags.semi_focused = 0;
899 if (!tmp->flags.shaded)
901 wClientSetState(tmp, NormalState, None);
903 WMPostNotificationName(WMNChangedState, tmp, "iconify-transient");
905 tmp = tmp->prev;
909 #if 0
910 static void setupIconGrabs(WIcon * icon)
912 /* setup passive grabs on the icon */
913 XGrabButton(dpy, Button1, AnyModifier, icon->core->window, True,
914 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
915 XGrabButton(dpy, Button2, AnyModifier, icon->core->window, True,
916 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
917 XGrabButton(dpy, Button3, AnyModifier, icon->core->window, True,
918 ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);
919 XSync(dpy, 0);
921 #endif
923 static WWindow *recursiveTransientFor(WWindow * wwin)
925 int i;
927 if (!wwin)
928 return None;
930 /* hackish way to detect transient_for cycle */
931 i = wwin->screen_ptr->window_count + 1;
933 while (wwin && wwin->transient_for != None && i > 0) {
934 wwin = wWindowFor(wwin->transient_for);
935 i--;
937 if (i == 0 && wwin) {
938 wwarning("%s has a severely broken WM_TRANSIENT_FOR hint.", wwin->frame->title);
939 return NULL;
942 return wwin;
945 #if 0
946 static void removeIconGrabs(WIcon * icon)
948 /* remove passive grabs on the icon */
949 XUngrabButton(dpy, Button1, AnyModifier, icon->core->window);
950 XUngrabButton(dpy, Button2, AnyModifier, icon->core->window);
951 XUngrabButton(dpy, Button3, AnyModifier, icon->core->window);
952 XSync(dpy, 0);
954 #endif
956 void wIconifyWindow(WWindow * wwin)
958 XWindowAttributes attribs;
959 int present;
961 if (!XGetWindowAttributes(dpy, wwin->client_win, &attribs)) {
962 /* the window doesn't exist anymore */
963 return;
966 if (wwin->flags.miniaturized) {
967 return;
970 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
971 WWindow *owner = wWindowFor(wwin->transient_for);
973 if (owner && owner->flags.miniaturized)
974 return;
977 present = wwin->frame->workspace == wwin->screen_ptr->current_workspace;
979 /* if the window is in another workspace, simplify process */
980 if (present) {
981 /* icon creation may take a while */
982 XGrabPointer(dpy, wwin->screen_ptr->root_win, False,
983 ButtonMotionMask | ButtonReleaseMask, GrabModeAsync,
984 GrabModeAsync, None, None, CurrentTime);
987 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
988 if (!wwin->flags.icon_moved) {
989 PlaceIcon(wwin->screen_ptr, &wwin->icon_x, &wwin->icon_y, wGetHeadForWindow(wwin));
991 wwin->icon = wIconCreate(wwin);
993 wwin->icon->mapped = 1;
996 wwin->flags.miniaturized = 1;
997 wwin->flags.mapped = 0;
999 /* unmap transients */
1001 unmapTransientsFor(wwin);
1003 if (present) {
1004 XUngrabPointer(dpy, CurrentTime);
1005 wWindowUnmap(wwin);
1006 /* let all Expose events arrive so that we can repaint
1007 * something before the animation starts (and the server is grabbed) */
1008 XSync(dpy, 0);
1010 if (wPreferences.disable_miniwindows || wwin->flags.net_handle_icon)
1011 wClientSetState(wwin, IconicState, None);
1012 else
1013 wClientSetState(wwin, IconicState, wwin->icon->icon_win);
1015 flushExpose();
1016 #ifdef ANIMATIONS
1017 if (!wwin->screen_ptr->flags.startup && !wwin->flags.skip_next_animation
1018 && !wPreferences.no_animations) {
1019 int ix, iy, iw, ih;
1021 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1022 ix = wwin->icon_x;
1023 iy = wwin->icon_y;
1024 iw = wwin->icon->core->width;
1025 ih = wwin->icon->core->height;
1026 } else {
1027 if (wwin->flags.net_handle_icon) {
1028 ix = wwin->icon_x;
1029 iy = wwin->icon_y;
1030 iw = wwin->icon_w;
1031 ih = wwin->icon_h;
1032 } else {
1033 ix = 0;
1034 iy = 0;
1035 iw = wwin->screen_ptr->scr_width;
1036 ih = wwin->screen_ptr->scr_height;
1039 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1040 wwin->frame->core->width, wwin->frame->core->height, ix, iy, iw, ih);
1042 #endif
1045 wwin->flags.skip_next_animation = 0;
1047 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon) {
1048 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace ||
1049 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)
1051 XMapWindow(dpy, wwin->icon->core->window);
1053 AddToStackList(wwin->icon->core);
1055 wLowerFrame(wwin->icon->core);
1058 if (present) {
1059 WWindow *owner = recursiveTransientFor(wwin->screen_ptr->focused_window);
1062 * It doesn't seem to be working and causes button event hangup
1063 * when deiconifying a transient window.
1064 setupIconGrabs(wwin->icon);
1066 if ((wwin->flags.focused || (owner && wwin->client_win == owner->client_win))
1067 && wPreferences.focus_mode == WKF_CLICK) {
1068 WWindow *tmp;
1070 tmp = wwin->prev;
1071 while (tmp) {
1072 if (!WFLAGP(tmp, no_focusable)
1073 && !(tmp->flags.hidden || tmp->flags.miniaturized)
1074 && (wwin->frame->workspace == tmp->frame->workspace))
1075 break;
1076 tmp = tmp->prev;
1078 wSetFocusTo(wwin->screen_ptr, tmp);
1079 } else if (wPreferences.focus_mode != WKF_CLICK) {
1080 wSetFocusTo(wwin->screen_ptr, NULL);
1082 #ifdef ANIMATIONS
1083 if (!wwin->screen_ptr->flags.startup) {
1084 /* Catch up with events not processed while animation was running */
1085 Window clientwin = wwin->client_win;
1087 ProcessPendingEvents();
1089 /* the window can disappear while ProcessPendingEvents() runs */
1090 if (!wWindowFor(clientwin)) {
1091 return;
1094 #endif
1097 /* maybe we want to do this regardless of net_handle_icon
1098 * it seems to me we might break behaviour this way.
1100 if (wwin->flags.selected && !wPreferences.disable_miniwindows
1101 && !wwin->flags.net_handle_icon)
1102 wIconSelect(wwin->icon);
1104 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1106 if (wPreferences.auto_arrange_icons)
1107 wArrangeIcons(wwin->screen_ptr, True);
1110 void wDeiconifyWindow(WWindow * wwin)
1112 /* we're hiding for show_desktop */
1113 int netwm_hidden = wwin->flags.net_show_desktop &&
1114 wwin->frame->workspace != wwin->screen_ptr->current_workspace;
1116 if (!netwm_hidden)
1117 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1119 if (!wwin->flags.miniaturized)
1120 return;
1122 if (wwin->transient_for != None && wwin->transient_for != wwin->screen_ptr->root_win) {
1123 WWindow *owner = recursiveTransientFor(wwin);
1125 if (owner && owner->flags.miniaturized) {
1126 wDeiconifyWindow(owner);
1127 wSetFocusTo(wwin->screen_ptr, wwin);
1128 wRaiseFrame(wwin->frame->core);
1129 return;
1133 wwin->flags.miniaturized = 0;
1135 if (!netwm_hidden && !wwin->flags.shaded) {
1136 wwin->flags.mapped = 1;
1139 if (!netwm_hidden || wPreferences.sticky_icons) {
1140 /* maybe we want to do this regardless of net_handle_icon
1141 * it seems to me we might break behaviour this way.
1143 if (!wPreferences.disable_miniwindows && !wwin->flags.net_handle_icon
1144 && wwin->icon != NULL) {
1145 if (wwin->icon->selected)
1146 wIconSelect(wwin->icon);
1148 XUnmapWindow(dpy, wwin->icon->core->window);
1152 /* if the window is in another workspace, do it silently */
1153 if (!netwm_hidden) {
1154 #ifdef ANIMATIONS
1155 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations
1156 && !wwin->flags.skip_next_animation && wwin->icon != NULL) {
1157 int ix, iy, iw, ih;
1159 if (!wPreferences.disable_miniwindows
1160 && !wwin->flags.net_handle_icon) {
1161 ix = wwin->icon_x;
1162 iy = wwin->icon_y;
1163 iw = wwin->icon->core->width;
1164 ih = wwin->icon->core->height;
1165 } else {
1166 if (wwin->flags.net_handle_icon) {
1167 ix = wwin->icon_x;
1168 iy = wwin->icon_y;
1169 iw = wwin->icon_w;
1170 ih = wwin->icon_h;
1171 } else {
1172 ix = 0;
1173 iy = 0;
1174 iw = wwin->screen_ptr->scr_width;
1175 ih = wwin->screen_ptr->scr_height;
1178 animateResize(wwin->screen_ptr, ix, iy, iw, ih,
1179 wwin->frame_x, wwin->frame_y,
1180 wwin->frame->core->width, wwin->frame->core->height);
1182 #endif /* ANIMATIONS */
1183 wwin->flags.skip_next_animation = 0;
1184 XGrabServer(dpy);
1185 if (!wwin->flags.shaded) {
1186 XMapWindow(dpy, wwin->client_win);
1188 XMapWindow(dpy, wwin->frame->core->window);
1189 wRaiseFrame(wwin->frame->core);
1190 if (!wwin->flags.shaded) {
1191 wClientSetState(wwin, NormalState, None);
1193 mapTransientsFor(wwin);
1196 if (!wPreferences.disable_miniwindows && wwin->icon != NULL
1197 && !wwin->flags.net_handle_icon) {
1198 RemoveFromStackList(wwin->icon->core);
1199 /* removeIconGrabs(wwin->icon); */
1200 wIconDestroy(wwin->icon);
1201 wwin->icon = NULL;
1204 if (!netwm_hidden) {
1205 XUngrabServer(dpy);
1207 wSetFocusTo(wwin->screen_ptr, wwin);
1209 #ifdef ANIMATIONS
1210 if (!wwin->screen_ptr->flags.startup) {
1211 /* Catch up with events not processed while animation was running */
1212 Window clientwin = wwin->client_win;
1214 ProcessPendingEvents();
1216 /* the window can disappear while ProcessPendingEvents() runs */
1217 if (!wWindowFor(clientwin)) {
1218 return;
1221 #endif
1224 if (wPreferences.auto_arrange_icons) {
1225 wArrangeIcons(wwin->screen_ptr, True);
1228 WMPostNotificationName(WMNChangedState, wwin, "iconify");
1230 /* In case we were shaded and iconified, also unshade */
1231 if (!netwm_hidden)
1232 wUnshadeWindow(wwin);
1235 static void hideWindow(WIcon * icon, int icon_x, int icon_y, WWindow * wwin, int animate)
1237 if (wwin->flags.miniaturized) {
1238 if (wwin->icon) {
1239 XUnmapWindow(dpy, wwin->icon->core->window);
1240 wwin->icon->mapped = 0;
1242 wwin->flags.hidden = 1;
1244 WMPostNotificationName(WMNChangedState, wwin, "hide");
1245 return;
1248 if (wwin->flags.inspector_open) {
1249 wHideInspectorForWindow(wwin);
1252 wwin->flags.hidden = 1;
1253 wWindowUnmap(wwin);
1255 wClientSetState(wwin, IconicState, icon->icon_win);
1256 flushExpose();
1258 #ifdef ANIMATIONS
1259 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations &&
1260 !wwin->flags.skip_next_animation && animate) {
1261 animateResize(wwin->screen_ptr, wwin->frame_x, wwin->frame_y,
1262 wwin->frame->core->width, wwin->frame->core->height,
1263 icon_x, icon_y, icon->core->width, icon->core->height);
1265 #endif
1266 wwin->flags.skip_next_animation = 0;
1268 WMPostNotificationName(WMNChangedState, wwin, "hide");
1271 void wHideOtherApplications(WWindow * awin)
1273 WWindow *wwin;
1274 WApplication *tapp;
1276 if (!awin)
1277 return;
1278 wwin = awin->screen_ptr->focused_window;
1280 while (wwin) {
1281 if (wwin != awin
1282 && wwin->frame->workspace == awin->screen_ptr->current_workspace
1283 && !(wwin->flags.miniaturized || wwin->flags.hidden)
1284 && !wwin->flags.internal_window
1285 && wGetWindowOfInspectorForWindow(wwin) != awin && !WFLAGP(wwin, no_hide_others)) {
1287 if (wwin->main_window == None || WFLAGP(wwin, no_appicon)) {
1288 if (!WFLAGP(wwin, no_miniaturizable)) {
1289 wwin->flags.skip_next_animation = 1;
1290 wIconifyWindow(wwin);
1292 } else if (wwin->main_window != None && awin->main_window != wwin->main_window) {
1293 tapp = wApplicationOf(wwin->main_window);
1294 if (tapp) {
1295 tapp->flags.skip_next_animation = 1;
1296 wHideApplication(tapp);
1297 } else {
1298 if (!WFLAGP(wwin, no_miniaturizable)) {
1299 wwin->flags.skip_next_animation = 1;
1300 wIconifyWindow(wwin);
1305 wwin = wwin->prev;
1308 wSetFocusTo(awin->screen_ptr, awin);
1312 void wHideApplication(WApplication * wapp)
1314 WScreen *scr;
1315 WWindow *wlist;
1316 int hadfocus;
1317 int animate;
1319 if (!wapp) {
1320 wwarning("trying to hide a non grouped window");
1321 return;
1323 if (!wapp->main_window_desc) {
1324 wwarning("group leader not found for window group");
1325 return;
1327 scr = wapp->main_window_desc->screen_ptr;
1328 hadfocus = 0;
1329 wlist = scr->focused_window;
1330 if (!wlist)
1331 return;
1333 if (wlist->main_window == wapp->main_window)
1334 wapp->last_focused = wlist;
1335 else
1336 wapp->last_focused = NULL;
1338 animate = !wapp->flags.skip_next_animation;
1340 while (wlist) {
1341 if (wlist->main_window == wapp->main_window) {
1342 if (wlist->flags.focused) {
1343 hadfocus = 1;
1345 if (wapp->app_icon) {
1346 hideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1347 wapp->app_icon->y_pos, wlist, animate);
1348 animate = False;
1351 wlist = wlist->prev;
1354 wapp->flags.skip_next_animation = 0;
1356 if (hadfocus) {
1357 if (wPreferences.focus_mode == WKF_CLICK) {
1358 wlist = scr->focused_window;
1359 while (wlist) {
1360 if (!WFLAGP(wlist, no_focusable) && !wlist->flags.hidden
1361 && (wlist->flags.mapped || wlist->flags.shaded))
1362 break;
1363 wlist = wlist->prev;
1365 wSetFocusTo(scr, wlist);
1366 } else {
1367 wSetFocusTo(scr, NULL);
1371 wapp->flags.hidden = 1;
1373 if (wPreferences.auto_arrange_icons) {
1374 wArrangeIcons(scr, True);
1376 #ifdef HIDDENDOT
1377 if (wapp->app_icon)
1378 wAppIconPaint(wapp->app_icon);
1379 #endif
1382 static void unhideWindow(WIcon * icon, int icon_x, int icon_y, WWindow * wwin, int animate, int bringToCurrentWS)
1384 if (bringToCurrentWS)
1385 wWindowChangeWorkspace(wwin, wwin->screen_ptr->current_workspace);
1387 wwin->flags.hidden = 0;
1389 #ifdef ANIMATIONS
1390 if (!wwin->screen_ptr->flags.startup && !wPreferences.no_animations && animate) {
1391 animateResize(wwin->screen_ptr, icon_x, icon_y,
1392 icon->core->width, icon->core->height,
1393 wwin->frame_x, wwin->frame_y,
1394 wwin->frame->core->width, wwin->frame->core->height);
1396 #endif
1397 wwin->flags.skip_next_animation = 0;
1398 if (wwin->screen_ptr->current_workspace == wwin->frame->workspace) {
1399 XMapWindow(dpy, wwin->client_win);
1400 XMapWindow(dpy, wwin->frame->core->window);
1401 wClientSetState(wwin, NormalState, None);
1402 wwin->flags.mapped = 1;
1403 wRaiseFrame(wwin->frame->core);
1405 if (wwin->flags.inspector_open) {
1406 wUnhideInspectorForWindow(wwin);
1409 WMPostNotificationName(WMNChangedState, wwin, "hide");
1412 void wUnhideApplication(WApplication * wapp, Bool miniwindows, Bool bringToCurrentWS)
1414 WScreen *scr;
1415 WWindow *wlist, *next;
1416 WWindow *focused = NULL;
1417 int animate;
1419 if (!wapp)
1420 return;
1422 scr = wapp->main_window_desc->screen_ptr;
1423 wlist = scr->focused_window;
1424 if (!wlist)
1425 return;
1427 /* goto beginning of list */
1428 while (wlist->prev)
1429 wlist = wlist->prev;
1431 animate = !wapp->flags.skip_next_animation;
1433 while (wlist) {
1434 next = wlist->next;
1436 if (wlist->main_window == wapp->main_window) {
1437 if (wlist->flags.focused)
1438 focused = wlist;
1439 else if (!focused || !focused->flags.focused)
1440 focused = wlist;
1442 if (wlist->flags.miniaturized) {
1443 if ((bringToCurrentWS || wPreferences.sticky_icons ||
1444 wlist->frame->workspace == scr->current_workspace) && wlist->icon) {
1445 if (!wlist->icon->mapped) {
1446 int x, y;
1448 PlaceIcon(scr, &x, &y, wGetHeadForWindow(wlist));
1449 if (wlist->icon_x != x || wlist->icon_y != y) {
1450 XMoveWindow(dpy, wlist->icon->core->window, x, y);
1452 wlist->icon_x = x;
1453 wlist->icon_y = y;
1454 XMapWindow(dpy, wlist->icon->core->window);
1455 wlist->icon->mapped = 1;
1457 wRaiseFrame(wlist->icon->core);
1459 if (bringToCurrentWS)
1460 wWindowChangeWorkspace(wlist, scr->current_workspace);
1461 wlist->flags.hidden = 0;
1462 if (miniwindows && wlist->frame->workspace == scr->current_workspace) {
1463 wDeiconifyWindow(wlist);
1465 WMPostNotificationName(WMNChangedState, wlist, "hide");
1466 } else if (wlist->flags.shaded) {
1467 if (bringToCurrentWS)
1468 wWindowChangeWorkspace(wlist, scr->current_workspace);
1469 wlist->flags.hidden = 0;
1470 if (wlist->frame->workspace == scr->current_workspace) {
1471 XMapWindow(dpy, wlist->frame->core->window);
1472 if (miniwindows) {
1473 wUnshadeWindow(wlist);
1474 wRaiseFrame(wlist->frame->core);
1477 WMPostNotificationName(WMNChangedState, wlist, "hide");
1478 } else if (wlist->flags.hidden) {
1479 unhideWindow(wapp->app_icon->icon, wapp->app_icon->x_pos,
1480 wapp->app_icon->y_pos, wlist, animate, bringToCurrentWS);
1481 animate = False;
1482 } else {
1483 if (bringToCurrentWS && wlist->frame->workspace != scr->current_workspace) {
1484 wWindowChangeWorkspace(wlist, scr->current_workspace);
1486 wRaiseFrame(wlist->frame->core);
1489 wlist = next;
1492 wapp->flags.skip_next_animation = 0;
1493 wapp->flags.hidden = 0;
1495 if (wapp->last_focused && wapp->last_focused->flags.mapped) {
1496 wRaiseFrame(wapp->last_focused->frame->core);
1497 wSetFocusTo(scr, wapp->last_focused);
1498 } else if (focused) {
1499 wSetFocusTo(scr, focused);
1501 wapp->last_focused = NULL;
1502 if (wPreferences.auto_arrange_icons) {
1503 wArrangeIcons(scr, True);
1505 #ifdef HIDDENDOT
1506 wAppIconPaint(wapp->app_icon);
1507 #endif
1510 void wShowAllWindows(WScreen * scr)
1512 WWindow *wwin, *old_foc;
1513 WApplication *wapp;
1515 old_foc = wwin = scr->focused_window;
1516 while (wwin) {
1517 if (!wwin->flags.internal_window &&
1518 (scr->current_workspace == wwin->frame->workspace || IS_OMNIPRESENT(wwin))) {
1519 if (wwin->flags.miniaturized) {
1520 wwin->flags.skip_next_animation = 1;
1521 wDeiconifyWindow(wwin);
1522 } else if (wwin->flags.hidden) {
1523 wapp = wApplicationOf(wwin->main_window);
1524 if (wapp) {
1525 wUnhideApplication(wapp, False, False);
1526 } else {
1527 wwin->flags.skip_next_animation = 1;
1528 wDeiconifyWindow(wwin);
1532 wwin = wwin->prev;
1534 wSetFocusTo(scr, old_foc);
1535 /*wRaiseFrame(old_foc->frame->core); */
1538 void wRefreshDesktop(WScreen * scr)
1540 Window win;
1541 XSetWindowAttributes attr;
1543 attr.backing_store = NotUseful;
1544 attr.save_under = False;
1545 win = XCreateWindow(dpy, scr->root_win, 0, 0, scr->scr_width,
1546 scr->scr_height, 0, CopyFromParent, CopyFromParent,
1547 (Visual *) CopyFromParent, CWBackingStore | CWSaveUnder, &attr);
1548 XMapRaised(dpy, win);
1549 XDestroyWindow(dpy, win);
1550 XFlush(dpy);
1553 void wArrangeIcons(WScreen * scr, Bool arrangeAll)
1555 WWindow *wwin;
1556 WAppIcon *aicon;
1558 int head;
1559 const int heads = wXineramaHeads(scr);
1561 struct HeadVars {
1562 int pf; /* primary axis */
1563 int sf; /* secondary axis */
1564 int fullW;
1565 int fullH;
1566 int pi, si;
1567 int sx1, sx2, sy1, sy2; /* screen boundary */
1568 int sw, sh;
1569 int xo, yo;
1570 int xs, ys;
1571 } *vars;
1573 int isize = wPreferences.icon_size;
1575 vars = (struct HeadVars *)wmalloc(sizeof(struct HeadVars) * heads);
1577 for (head = 0; head < heads; ++head) {
1578 #if 0
1579 WMRect rect = wGetRectForHead(scr, head);
1580 #else
1581 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1582 WMRect rect = wmkrect(area.x1, area.y1, area.x2 - area.x1, area.y2 - area.y1);
1583 #endif
1585 vars[head].pi = vars[head].si = 0;
1586 vars[head].sx1 = rect.pos.x;
1587 vars[head].sy1 = rect.pos.y;
1588 vars[head].sw = rect.size.width;
1589 vars[head].sh = rect.size.height;
1590 vars[head].sx2 = vars[head].sx1 + vars[head].sw;
1591 vars[head].sy2 = vars[head].sy1 + vars[head].sh;
1593 #if 0
1594 if (scr->dock) {
1595 if (scr->dock->on_right_side)
1596 vars[head].sx2 -= isize + DOCK_EXTRA_SPACE;
1597 else
1598 vars[head].sx1 += isize + DOCK_EXTRA_SPACE;
1600 #endif
1602 vars[head].sw = isize * (vars[head].sw / isize);
1603 vars[head].sh = isize * (vars[head].sh / isize);
1604 vars[head].fullW = (vars[head].sx2 - vars[head].sx1) / isize;
1605 vars[head].fullH = (vars[head].sy2 - vars[head].sy1) / isize;
1607 /* icon yard boundaries */
1608 if (wPreferences.icon_yard & IY_VERT) {
1609 vars[head].pf = vars[head].fullH;
1610 vars[head].sf = vars[head].fullW;
1611 } else {
1612 vars[head].pf = vars[head].fullW;
1613 vars[head].sf = vars[head].fullH;
1615 if (wPreferences.icon_yard & IY_RIGHT) {
1616 vars[head].xo = vars[head].sx2 - isize;
1617 vars[head].xs = -1;
1618 } else {
1619 vars[head].xo = vars[head].sx1;
1620 vars[head].xs = 1;
1622 if (wPreferences.icon_yard & IY_TOP) {
1623 vars[head].yo = vars[head].sy1;
1624 vars[head].ys = 1;
1625 } else {
1626 vars[head].yo = vars[head].sy2 - isize;
1627 vars[head].ys = -1;
1631 #define X ((wPreferences.icon_yard & IY_VERT) \
1632 ? vars[head].xo + vars[head].xs*(vars[head].si*isize) \
1633 : vars[head].xo + vars[head].xs*(vars[head].pi*isize))
1635 #define Y ((wPreferences.icon_yard & IY_VERT) \
1636 ? vars[head].yo + vars[head].ys*(vars[head].pi*isize) \
1637 : vars[head].yo + vars[head].ys*(vars[head].si*isize))
1639 /* arrange application icons */
1640 aicon = scr->app_icon_list;
1641 /* reverse them to avoid unnecessarily sliding of icons */
1642 while (aicon && aicon->next)
1643 aicon = aicon->next;
1645 while (aicon) {
1646 if (!aicon->docked) {
1647 /* CHECK: can icon be NULL here ? */
1648 /* The intention here is to place the AppIcon on the head that
1649 * contains most of the applications _main_ window. */
1650 head = wGetHeadForWindow(aicon->icon->owner);
1652 if (aicon->x_pos != X || aicon->y_pos != Y) {
1653 #ifdef ANIMATIONS
1654 if (!wPreferences.no_animations) {
1655 SlideWindow(aicon->icon->core->window, aicon->x_pos, aicon->y_pos, X, Y);
1657 #endif /* ANIMATIONS */
1659 wAppIconMove(aicon, X, Y);
1660 vars[head].pi++;
1661 if (vars[head].pi >= vars[head].pf) {
1662 vars[head].pi = 0;
1663 vars[head].si++;
1666 aicon = aicon->prev;
1669 /* arrange miniwindows */
1670 wwin = scr->focused_window;
1671 /* reverse them to avoid unnecessarily shuffling */
1672 while (wwin && wwin->prev)
1673 wwin = wwin->prev;
1675 while (wwin) {
1676 if (wwin->icon && wwin->flags.miniaturized && !wwin->flags.hidden &&
1677 (wwin->frame->workspace == scr->current_workspace ||
1678 IS_OMNIPRESENT(wwin) || wPreferences.sticky_icons)) {
1680 head = wGetHeadForWindow(wwin);
1682 if (arrangeAll || !wwin->flags.icon_moved) {
1683 if (wwin->icon_x != X || wwin->icon_y != Y) {
1684 #ifdef ANIMATIONS
1685 if (wPreferences.no_animations) {
1686 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1687 } else {
1688 SlideWindow(wwin->icon->core->window, wwin->icon_x,
1689 wwin->icon_y, X, Y);
1691 #else
1692 XMoveWindow(dpy, wwin->icon->core->window, X, Y);
1693 #endif /* ANIMATIONS */
1695 wwin->icon_x = X;
1696 wwin->icon_y = Y;
1698 vars[head].pi++;
1699 if (vars[head].pi >= vars[head].pf) {
1700 vars[head].pi = 0;
1701 vars[head].si++;
1705 if (arrangeAll) {
1706 wwin->flags.icon_moved = 0;
1708 /* we reversed the order, so we use next */
1709 wwin = wwin->next;
1712 wfree(vars);
1715 void wSelectWindow(WWindow * wwin, Bool flag)
1717 WScreen *scr = wwin->screen_ptr;
1719 if (flag) {
1720 wwin->flags.selected = 1;
1721 XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel);
1723 if (!HAS_BORDER(wwin)) {
1724 XSetWindowBorderWidth(dpy, wwin->frame->core->window, FRAME_BORDER_WIDTH);
1727 if (!scr->selected_windows)
1728 scr->selected_windows = WMCreateArray(4);
1729 WMAddToArray(scr->selected_windows, wwin);
1730 } else {
1731 wwin->flags.selected = 0;
1732 XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel);
1734 if (!HAS_BORDER(wwin)) {
1735 XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0);
1738 if (scr->selected_windows) {
1739 WMRemoveFromArray(scr->selected_windows, wwin);
1744 void wMakeWindowVisible(WWindow * wwin)
1746 if (wwin->frame->workspace != wwin->screen_ptr->current_workspace)
1747 wWorkspaceChange(wwin->screen_ptr, wwin->frame->workspace);
1749 if (wwin->flags.shaded) {
1750 wUnshadeWindow(wwin);
1752 if (wwin->flags.hidden) {
1753 WApplication *app;
1755 app = wApplicationOf(wwin->main_window);
1756 if (app) {
1757 /* trick to get focus to this window */
1758 app->last_focused = wwin;
1759 wUnhideApplication(app, False, False);
1762 if (wwin->flags.miniaturized) {
1763 wDeiconifyWindow(wwin);
1764 } else {
1765 if (!WFLAGP(wwin, no_focusable))
1766 wSetFocusTo(wwin->screen_ptr, wwin);
1767 wRaiseFrame(wwin->frame->core);
1772 * Do the animation while shading (called with what = SHADE)
1773 * or unshading (what = UNSHADE).
1775 #ifdef ANIMATIONS
1776 static void shade_animate(WWindow *wwin, Bool what)
1778 int y, s, w, h;
1779 time_t time0 = time(NULL);
1781 if (wwin->flags.skip_next_animation && wPreferences.no_animations)
1782 return;
1784 switch(what) {
1785 case SHADE:
1786 if (!wwin->screen_ptr->flags.startup) {
1787 /* do the shading animation */
1788 h = wwin->frame->core->height;
1789 s = h / SHADE_STEPS;
1790 if (s < 1)
1791 s = 1;
1792 w = wwin->frame->core->width;
1793 y = wwin->frame->top_width;
1794 while (h > wwin->frame->top_width + 1) {
1795 XMoveWindow(dpy, wwin->client_win, 0, y);
1796 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1797 XFlush(dpy);
1799 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1800 break;
1802 if (SHADE_DELAY > 0) {
1803 wusleep(SHADE_DELAY * 1000L);
1804 } else {
1805 wusleep(10);
1807 h -= s;
1808 y -= s;
1810 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1812 break;
1814 case UNSHADE:
1815 h = wwin->frame->top_width + wwin->frame->bottom_width;
1816 y = wwin->frame->top_width - wwin->client.height;
1817 s = abs(y) / SHADE_STEPS;
1818 if (s < 1)
1819 s = 1;
1820 w = wwin->frame->core->width;
1821 XMoveWindow(dpy, wwin->client_win, 0, y);
1822 if (s > 0) {
1823 while (h < wwin->client.height + wwin->frame->top_width + wwin->frame->bottom_width) {
1824 XResizeWindow(dpy, wwin->frame->core->window, w, h);
1825 XMoveWindow(dpy, wwin->client_win, 0, y);
1826 XFlush(dpy);
1827 if (SHADE_DELAY > 0) {
1828 wusleep(SHADE_DELAY * 2000L / 3);
1829 } else {
1830 wusleep(10);
1832 h += s;
1833 y += s;
1835 if (time(NULL) - time0 > MAX_ANIMATION_TIME)
1836 break;
1839 XMoveWindow(dpy, wwin->client_win, 0, wwin->frame->top_width);
1840 break;
1843 #endif